73 lines
1.4 KiB
JavaScript
73 lines
1.4 KiB
JavaScript
|
/**
|
|||
|
* @module
|
|||
|
* Définit le modèle de données utilisé par l’application.
|
|||
|
*/
|
|||
|
|
|||
|
import PropTypes from 'prop-types';
|
|||
|
|
|||
|
/**
|
|||
|
* Types de termes existants.
|
|||
|
*/
|
|||
|
export const termTypes = {
|
|||
|
disease: 'Maladie',
|
|||
|
symptom: 'Symptôme',
|
|||
|
sign: 'Signe',
|
|||
|
};
|
|||
|
|
|||
|
/**
|
|||
|
* Type de terme.
|
|||
|
*/
|
|||
|
export const TermType = PropTypes.oneOf(Object.values(termTypes));
|
|||
|
|
|||
|
/**
|
|||
|
* Terme.
|
|||
|
*
|
|||
|
* Peut être une maladie, un symptôme ou un signe.
|
|||
|
*/
|
|||
|
export const Term = PropTypes.exact({
|
|||
|
id: PropTypes.string.isRequired,
|
|||
|
name: PropTypes.string.isRequired,
|
|||
|
alias: PropTypes.arrayOf(PropTypes.string).isRequired,
|
|||
|
types: PropTypes.arrayOf(TermType).isRequired,
|
|||
|
weight: PropTypes.number.isRequired,
|
|||
|
});
|
|||
|
|
|||
|
/**
|
|||
|
* Relation entre deux termes.
|
|||
|
*/
|
|||
|
export const Relation = (props, propName, componentName) =>
|
|||
|
{
|
|||
|
if (!(propName in props))
|
|||
|
{
|
|||
|
return new Error(
|
|||
|
`Missing ${propName} in props supplied to ${componentName}.`
|
|||
|
);
|
|||
|
}
|
|||
|
|
|||
|
const value = props[propName];
|
|||
|
|
|||
|
if (!Array.isArray(value))
|
|||
|
{
|
|||
|
return new Error(
|
|||
|
`Relation ${propName} must be an array.`
|
|||
|
);
|
|||
|
}
|
|||
|
|
|||
|
if (value.length !== 2)
|
|||
|
{
|
|||
|
return new Error(
|
|||
|
`Relation ${propName} must contain exactly two entries.`
|
|||
|
);
|
|||
|
}
|
|||
|
|
|||
|
if (
|
|||
|
typeof value[0] !== 'string'
|
|||
|
|| typeof value[1] !== 'string'
|
|||
|
)
|
|||
|
{
|
|||
|
return new Error(
|
|||
|
`Entries of relation ${propName} must be string IDs.`
|
|||
|
);
|
|||
|
}
|
|||
|
};
|