app: Ajoute URL & facteur d’importance @ mock

This commit is contained in:
Mattéo Delabre 2019-12-04 20:38:18 -05:00
parent 268289f1f7
commit c5a408251c
Signed by: matteo
GPG Key ID: AE3FBD02DC583ABB
2 changed files with 122 additions and 40 deletions

View File

@ -15,7 +15,8 @@ export const terms = {
name: 'Grippe', name: 'Grippe',
alias: [], alias: [],
types: [termTypes.disease], types: [termTypes.disease],
weight: 0.000035, weight: -10.68959934320834,
url: 'https://fr.wikipedia.org/wiki/Grippe',
}, },
Q154882: { Q154882: {
id: 'Q154882', id: 'Q154882',
@ -24,14 +25,16 @@ export const terms = {
'Maladie des légionnaires', 'Maladie des légionnaires',
], ],
types: [termTypes.disease], types: [termTypes.disease],
weight: 0.000015, weight: -11.05394782419729,
url: 'https://fr.wikipedia.org/wiki/Légionellose',
}, },
Q155098: { Q155098: {
id: 'Q155098', id: 'Q155098',
name: 'Leptospirose', name: 'Leptospirose',
alias: [], alias: [],
types: [termTypes.disease], types: [termTypes.disease],
weight: 0.00001, weight: -11.3969031483456 ,
url: 'https://fr.wikipedia.org/wiki/Leptospirose',
}, },
Q326663: { Q326663: {
id: 'Q326663', id: 'Q326663',
@ -47,23 +50,28 @@ export const terms = {
'Maladie de Kumlinge', 'Maladie de Kumlinge',
], ],
types: [termTypes.disease], types: [termTypes.disease],
weight: 0.000001, weight: -13.862833353191204,
url: 'https://fr.wikipedia.org/wiki/Encéphalite_à_tiques',
}, },
Q133780: { Q133780: {
id: 'Q133780', id: 'Q133780',
name: 'Peste', name: 'Peste',
alias: [], alias: [],
types: [termTypes.disease], types: [termTypes.disease],
weight: 0.000032, weight: -10.356303313736584,
url: 'https://fr.wikipedia.org/wiki/Peste',
}, },
Q38933: { Q38933: {
id: 'Q38933', id: 'Q38933',
name: 'Fièvre', name: 'Fièvre',
alias: [ alias: [
'Pyrexie', 'Pyrexie',
'Hyperthermie',
'État fébrile',
], ],
types: [termTypes.symptom], types: [termTypes.symptom],
weight: 0, weight: -10.83729224261442,
url: 'https://wikimedi.ca/wiki/Fièvre',
}, },
Q474959: { Q474959: {
id: 'Q474959', id: 'Q474959',
@ -72,7 +80,8 @@ export const terms = {
'Douleur musculaire', 'Douleur musculaire',
], ],
types: [termTypes.symptom], types: [termTypes.symptom],
weight: 0, weight: -12.475240614075794,
url: 'https://fr.wikipedia.org/wiki/Myalgie',
}, },
Q86: { Q86: {
id: 'Q86', id: 'Q86',
@ -81,7 +90,8 @@ export const terms = {
'Mal de tête', 'Mal de tête',
], ],
types: [termTypes.sign], types: [termTypes.sign],
weight: 0, weight: -11.042885864744003,
url: 'https://wikimedi.ca/wiki/C%C3%A9phal%C3%A9e',
}, },
Q1115038: { Q1115038: {
id: 'Q1115038', id: 'Q1115038',
@ -91,14 +101,16 @@ export const terms = {
'Écoulement nasal', 'Écoulement nasal',
], ],
types: [termTypes.symptom], types: [termTypes.symptom],
weight: 0, weight: -13.291547222741679,
url: 'https://fr.wikipedia.org/wiki/Rhinorrh%C3%A9e',
}, },
Q9690: { Q9690: {
id: 'Q9690', id: 'Q9690',
name: 'Fatigue', name: 'Fatigue',
alias: [], alias: [],
types: [termTypes.symptom], types: [termTypes.symptom],
weight: 0, weight: -12.8932707907014,
url: 'https://wikimedi.ca/wiki/Fatigue',
}, },
Q127076: { Q127076: {
id: 'Q127076', id: 'Q127076',
@ -109,7 +121,8 @@ export const terms = {
'Vomir', 'Vomir',
], ],
types: [termTypes.symptom, termTypes.sign], types: [termTypes.symptom, termTypes.sign],
weight: 0, weight: -11.76320423121043,
url: 'https://fr.wikipedia.org/wiki/Vomissement',
}, },
Q178061: { Q178061: {
id: 'Q178061', id: 'Q178061',
@ -118,7 +131,8 @@ export const terms = {
'Insuffisance circulatoire aiguë', 'Insuffisance circulatoire aiguë',
], ],
types: [termTypes.disease], types: [termTypes.disease],
weight: 0.000038, weight: -12.48541367835562,
url: 'https://fr.wikipedia.org/wiki/État_de_choc_circulatoire',
}, },
Q35805: { Q35805: {
id: 'Q35805', id: 'Q35805',
@ -128,53 +142,64 @@ export const terms = {
'Toussote', 'Toussote',
], ],
types: [termTypes.symptom, termTypes.sign], types: [termTypes.symptom, termTypes.sign],
weight: 0, weight: -12.62883965458582,
url: 'https://wikimedi.ca/wiki/Toux',
}, },
Q647099: { Q647099: {
id: 'Q647099', id: 'Q647099',
name: 'Hémoptysie', name: 'Hémoptysie',
alias: [ alias: [
'Expectoration sanglante', 'Expectoration sanglante',
'Crachat sanguin',
], ],
types: [termTypes.symptom], types: [termTypes.symptom],
weight: 0, weight: -11.816428715881282,
url: 'https://wikimedi.ca/wiki/Hémoptysies',
}, },
Q653197: { Q653197: {
id: 'Q653197', id: 'Q653197',
name: 'Rash', name: 'Rash',
alias: [], alias: [
'Éruption cutanée',
],
types: [termTypes.symptom, termTypes.sign], types: [termTypes.symptom, termTypes.sign],
weight: 0, weight: -13.089336365426849,
url: 'https://fr.wikipedia.org/wiki/Rash_(médecine)',
}, },
Q160796: { Q160796: {
id: 'Q160796', id: 'Q160796',
name: 'Syndrome confusionnel', name: 'Syndrome confusionnel',
alias: [ alias: [
'Confusion mentale', 'Confusion mentale',
'Délirium',
], ],
types: [termTypes.disease], types: [termTypes.disease],
weight: 0.000004, weight: -12.406564919730442,
url: 'https://wikimedi.ca/wiki/Délirium',
}, },
Q186235: { Q186235: {
id: 'Q186235', id: 'Q186235',
name: 'Myocardite', name: 'Myocardite',
alias: [], alias: [],
types: [termTypes.disease], types: [termTypes.disease],
weight: 0.0000075, weight: -11.874480758774315,
url: 'https://fr.wikipedia.org/wiki/Myocardite',
}, },
Q476921: { Q476921: {
id: 'Q476921', id: 'Q476921',
name: 'Insuffisance rénale', name: 'Insuffisance rénale',
alias: [], alias: [],
types: [termTypes.disease], types: [termTypes.disease],
weight: 0.0000046, weight: -12.359763775778456,
url: 'https://fr.wikipedia.org/wiki/Insuffisance_rénale',
}, },
Q281289: { Q281289: {
id: 'Q281289', id: 'Q281289',
name: 'Photophobie', name: 'Photophobie',
alias: [], alias: [],
types: [termTypes.sign], types: [termTypes.sign],
weight: 0, weight: -12.568109501931065,
url: 'https://fr.wikipedia.org/wiki/Photophobie',
}, },
Q159557: { Q159557: {
id: 'Q159557', id: 'Q159557',
@ -185,7 +210,8 @@ export const terms = {
'Perte de connaissance', 'Perte de connaissance',
], ],
types: [termTypes.sign], types: [termTypes.sign],
weight: 0, weight: -11.415040299689283,
url: 'https://wikimedi.ca/wiki/Coma',
}, },
}; };

View File

@ -14,36 +14,102 @@ export const termTypes = {
sign: 'Signe', sign: 'Signe',
}; };
/**
* Crée un valideur de type de propriété React supportant lextension
* `.isRequired` pour marquer une propriété comme requise.
*
* @param basicValidator Fonction basique de validation.
* @return Fonction augmentée supportant lextension `.isRequired`.
*/
const makePropType = basicValidator =>
{
const validator = (props, propName, componentName) =>
{
// Version optionnelle : on nappelle le valideur que si la propriété a
// été passée
if (propName in props)
{
return basicValidator(props, propName, componentName);
}
};
validator.isRequired = (props, propName, componentName) =>
{
// Version obligatoire : on jette une erreur si la propriété na pas
// été passée puis on procède à la validation
if (!(propName in props))
{
return new Error(
`Missing prop “${propName}” in props supplied to `
+ `${componentName}.`
);
}
return basicValidator(props, propName, componentName);
};
return validator;
};
/** /**
* Type de terme. * Type de terme.
*/ */
export const TermType = PropTypes.oneOf(Object.values(termTypes)); export const TermType = PropTypes.oneOf(Object.values(termTypes));
/**
* URL.
*/
const URL = makePropType((props, propName, componentName) =>
{
const value = props[propName];
if (typeof value !== 'string')
{
return new Error(
`URL passed as ${componentName}s ${propName} prop must be `
+ `a string, not a ${typeof value}.`
);
}
if (!value.startsWith('http://') && !value.startsWith('https://'))
{
return new Error(
`URL “${value}”, passed as ${componentName}s ${propName} `
+ `prop, does not start with “http://” or “https://”.`
);
}
});
/** /**
* Terme. * Terme.
* *
* Peut être une maladie, un symptôme ou un signe. * Peut être une maladie, un symptôme ou un signe.
*/ */
export const Term = PropTypes.exact({ export const Term = PropTypes.exact({
// Identifiant unique
id: PropTypes.string.isRequired, id: PropTypes.string.isRequired,
// Nom canonique
name: PropTypes.string.isRequired, name: PropTypes.string.isRequired,
// Noms alternatifs
alias: PropTypes.arrayOf(PropTypes.string).isRequired, alias: PropTypes.arrayOf(PropTypes.string).isRequired,
// Types (maladie, symptôme, signe)
types: PropTypes.arrayOf(TermType).isRequired, types: PropTypes.arrayOf(TermType).isRequired,
// Facteur dimportance
weight: PropTypes.number.isRequired, weight: PropTypes.number.isRequired,
// Adresse de la ressource de référence
url: URL.isRequired,
}); });
/** /**
* Relation entre deux termes. * Relation entre deux termes.
*/ */
export const Relation = (props, propName, componentName) => export const Relation = makePropType((props, propName, componentName) =>
{ {
if (!(propName in props))
{
return new Error(
`Missing ${propName} in props supplied to ${componentName}.`
);
}
const value = props[propName]; const value = props[propName];
if (!Array.isArray(value)) if (!Array.isArray(value))
@ -59,14 +125,4 @@ export const Relation = (props, propName, componentName) =>
`Relation ${propName} must contain exactly two entries.` `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.`
);
}
};