export const symptoms = [ 'fever' , 'cough' , 'breath' , 'flu' ] as const ; export const getSymptomId = ( question ) => symptoms [ question - 1 ] ; export type Symptoms = Record < typeof symptoms [ number ] , 0 | 1 > ; const symptomIdTranslations = { fever : [ 'fever' , 'الحمى' , 'fièvre' , 'fiabhras' , 'karščiavimas' , 'drudzis' , 'gorączka' , 'febre' ] , cough : [ 'cough' , 'السعال' , 'toux' , 'casacht' , 'kosulys' , 'klepus' , 'kaszel' , 'tosse' ] , breath : [ 'breath' , 'التنفس' , 'resp.' , 'anáil' , 'kvėpavimas' , 'elpa' , 'oddech' , 'resp.' ] , flu : [ 'flu' , 'الإنفلونزا' , 'grippe' , 'fliú' , 'gripas' , 'gripa' , 'grypa' , 'gripe' ] } ; export const getLegacySymptomId = ( id ) => { if ( symptomIdTranslations . hasOwnProperty ( id ) ) { return id ; } const keys = Object . keys ( symptomIdTranslations ) as ( keyof typeof symptomIdTranslations ) [ ] ; return keys . find ( ( key ) => symptomIdTranslations [ key ] . includes ( id ) ) ; } ; export const fixLegacySymptoms = ( legacySymptoms ) => Object . entries ( legacySymptoms ) . reduce ( ( fixedSymptoms , [ symptomId , value ] ) => ( { ... fixedSymptoms , [ getLegacySymptomId ( symptomId ) || '' ] : value } ) , { } as Symptoms ) ;