Puis-je créer un modèle relationnel entre mes varsets?
The relational model can be reached with a development for each project. The simplest method is to use a small part of the Epicraft configuration related to a JS development in a separate file.
More information on how to link the development to the application here.
Examples of development to realize the relationship model
Relational model 1-1 / 1-N
The important part of this example is:
// Foreign key
const sForeignKeyField = 'id_patient';
// Id data of the patient
const sPatientIdData = 'abc123';
// Id data of the newly created visite
const sVisiteIdData = 'def456';
// Define a new variable in the dataset if nonexistent
// That's the foreign key
oDataset.addVariableDefinition({name: sForeignKeyField});
// Set the value for the foreign key
oDataset.updateValue(sVisiteIdData, sForeignKeyField, sPatientIdData);
Whole example
// Library
import React from 'react';
import PropTypes from 'prop-types';
import {View, Text} from 'react-native';
import {Button} from 'epimob-components';
import EpimobCore from 'epimob-core';
export default class ButtonCreateNewVisite extends React.PureComponent {
constructor() {
super();
this.handlePress = this.handlePress.bind(this);
}
handlePress() {
const {changePage, aDatasets, dataset: oPatientDataset, rowId: sIdPatient} = this.props;
// Naïve way to deal with parameters, a better way is to use "options"
// More about that here https://epiconcept-paris.github.io/epimob-reactnative/customProperties.html
const sDatasetName = 'visite';
const sForeignKeyField = 'id_patient';
const sCurrentPatientId = oPatientDataset.getValue(sIdPatient, 'id');
// page id from Epicraft
const sIdPage = 'rpealtqprb1520863668630';
const sNewVisiteId = EpimobCore.getCryptoInterface().uniqId();
// open new page
changePage(sIdPage, sNewVisiteId);
InteractionManager.runAfterInteractions(() => {
const oVisiteDataset = aDatasets.find(oDataset => oDataset.getName() === sDatasetName);
const oForeignKeyDefinition = oVisiteDataset.getVariableDefinition(sForeignKeyField);
if (oForeignKeyDefinition === undefined) {
// alter dataset definition if missing variable
oVisiteDataset.addVariableDefinition({name: sForeignKeyField});
}
oVisiteDataset.updateValue(sNewVisiteId, sForeignKeyField, sCurrentPatientId);
});
}
render() {
const {option, translate} = this.props;
return (
<Button onPress={this.handlePress}>
{translate('New visite')}
</Button>
);
}
}
ButtonCreateNewVisite.displayName = 'ButtonCreateNewVisite';
ButtonCreateNewVisite.propTypes = {
option: PropTypes.object,
dataset: PropTypes.object,
rowId: PropTypes.string,
datasets: PropTypes.array,
translate: PropTypes.func,
changePage: PropTypes.func
};