11import { Box , Divider , MenuItem , Select , Stack , Typography , useTheme } from '@mui/material' ;
2- import { HumanName , Patient } from 'fhir/r4b' ;
2+ import { HumanName , Patient , QuestionnaireItem } from 'fhir/r4b' ;
33import { FC , useState } from 'react' ;
44import { Controller , useFormContext } from 'react-hook-form' ;
55import { FormSelect , FormTextField } from 'src/components/form' ;
@@ -14,6 +14,7 @@ import {
1414} from 'src/constants' ;
1515import { dataTestIds } from 'src/constants/data-test-ids' ;
1616import { LANGUAGE_OPTIONS , REQUIRED_FIELD_ERROR_MESSAGE } from 'utils' ;
17+ import inPersonIntakeQuestionnaire from '../../../../../../../../config/oystehr/in-person-intake-questionnaire.json' ;
1718import ShowMoreButton from './ShowMoreButton' ;
1819
1920const FormFields = AllFormFields . patientDetails ;
@@ -35,6 +36,13 @@ export const PatientDetailsContainer: FC<PatientDetailsContainerProps> = ({ pati
3536 const isNonBinaryGender = genderIdentityCurrentValue === 'Non-binary gender identity' ;
3637 const languageValue = watch ( FormFields . language . key ) ;
3738
39+ const questionnaireLanguageOptions =
40+ (
41+ Object . values ( inPersonIntakeQuestionnaire . fhirResources ) [ 0 ]
42+ . resource . item . find ( ( item ) => item . linkId === 'patient-details-page' )
43+ ?. item . find ( ( item ) => item . linkId === 'preferred-language' ) as QuestionnaireItem | undefined
44+ ) ?. answerOption ?. map ( ( option ) => option . valueString ) ?? [ ] ;
45+
3846 return (
3947 < Section title = "Patient details" >
4048 < Row label = "Previous name" >
@@ -199,11 +207,13 @@ export const PatientDetailsContainer: FC<PatientDetailsContainerProps> = ({ pati
199207 sx = { { width : '100%' } }
200208 data-testid = { dataTestIds . patientDetailsContainer . preferredLanguage }
201209 >
202- { Object . entries ( LANGUAGE_OPTIONS ) . map ( ( [ key , value ] ) => (
203- < MenuItem key = { value } value = { value } >
204- { key }
205- </ MenuItem >
206- ) ) }
210+ { Object . entries ( LANGUAGE_OPTIONS )
211+ . filter ( ( [ _key , value ] ) => questionnaireLanguageOptions . includes ( value ) )
212+ . map ( ( [ key , value ] ) => (
213+ < MenuItem key = { value } value = { value } >
214+ { key }
215+ </ MenuItem >
216+ ) ) }
207217 </ Select >
208218 ) }
209219 />
0 commit comments