generated from openmrs/openmrs-esm-template-app
-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
U4X-520: Setting default program enrolled as HIV (#214)
U4X-520: Setting default program enrolled as HIV (#214)
- Loading branch information
Showing
7 changed files
with
203 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
108 changes: 108 additions & 0 deletions
108
packages/esm-care-panel-app/src/program-enrollment/program-enrollment-tb.component.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
import React, { useEffect, useMemo, useState } from 'react'; | ||
import { useTranslation } from 'react-i18next'; | ||
import styles from './program-enrollment.scss'; | ||
import { launchPatientWorkspace } from '@openmrs/esm-patient-common-lib'; | ||
import dayjs from 'dayjs'; | ||
import orderBy from 'lodash/orderBy'; | ||
import { mutate } from 'swr'; | ||
import { parseStageFromDisplay, usePatientObservations } from './program-enrollment.resource'; | ||
import { ProgramData } from '../types/index'; | ||
import { usePatient } from '@openmrs/esm-framework'; | ||
import { configSchema } from '../config-schema'; | ||
import { ProgramEnrollmentProps } from '../hooks/useCarePrograms'; | ||
|
||
const ProgramEnrollmentTB: React.FC<ProgramEnrollmentProps> = ({ enrollments = [], patientUuid }) => { | ||
const { t } = useTranslation(); | ||
|
||
const { patient } = usePatient(patientUuid); | ||
|
||
const observationConfig = useMemo( | ||
() => [ | ||
{ | ||
key: 'dateStartedTBFirstLineRegimen', | ||
uuidConfig: configSchema.dateStartedTBFirstRegimenUuid._default, | ||
processValue: (date) => { | ||
return date && dayjs(date).isValid() ? dayjs(date).format('DD-MM-YYYY') : '--'; | ||
}, | ||
}, | ||
{ | ||
key: 'dsTBRegimen', | ||
uuidConfig: configSchema.dsTbRegmimenUuid._default, | ||
}, | ||
{ | ||
key: 'tbPatientType', | ||
uuidConfig: configSchema.tbPatientTypeUuid._default, | ||
}, | ||
{ | ||
key: 'tbDiseaseClassification', | ||
uuidConfig: configSchema.tbDiseaseClassificationUuid._default, | ||
}, | ||
], | ||
[], | ||
); | ||
const conceptUuids = observationConfig.map((config) => config.uuidConfig); | ||
|
||
const orderedEnrollments = orderBy(enrollments, 'dateEnrolled', 'desc'); | ||
|
||
const [programData, setProgramData] = useState<ProgramData>({ | ||
dateStartedTBFirstLineRegimen: '--', | ||
dsTBRegimen: '--', | ||
tbDiseaseClassification: '--', | ||
tbPatientType: '--', | ||
}); | ||
|
||
const { observations, isLoading, isError } = usePatientObservations(patientUuid, conceptUuids); | ||
useEffect(() => { | ||
if (observations) { | ||
const newData = observationConfig.reduce((acc, { key, uuidConfig, processValue }) => { | ||
const value = observations[uuidConfig]?.[0] || '--'; | ||
acc[key] = processValue ? processValue(value) : value; | ||
return acc; | ||
}, {}); | ||
|
||
setProgramData((prevState) => ({ ...prevState, ...newData })); | ||
} | ||
}, [observationConfig, observations]); | ||
|
||
if (orderedEnrollments?.length === 0) { | ||
return null; | ||
} | ||
return ( | ||
<div className={styles.bodyContainer}> | ||
<div className={styles.card}> | ||
<h6>{t('diseasClassification', 'Disease Classification/Patient Type')}</h6> | ||
<div className={styles.container}> | ||
<div className={styles.content}> | ||
<p className={styles.label}>{t('diseaseClassification', 'TB Disease Classification')}</p> | ||
<p> | ||
<span className={styles.value}>{programData.tbDiseaseClassification}</span> | ||
</p> | ||
</div> | ||
<div className={styles.content}> | ||
<p className={styles.label}>{t('tbPatientType', 'Patient Type')}</p> | ||
<p> | ||
<span className={styles.value}>{programData.tbPatientType}</span> | ||
</p> | ||
</div> | ||
</div> | ||
<br></br> | ||
<h6>{t('firstLineTreatment', 'First Line Treatment')}</h6> | ||
<div className={styles.container}> | ||
<div className={styles.content}> | ||
<p className={styles.label}>{t('dateStarted', 'Date Started')}</p> | ||
<p> | ||
<span className={styles.value}>{programData.dateStartedTBFirstLineRegimen}</span> | ||
</p> | ||
</div> | ||
<div className={styles.content}> | ||
<p className={styles.label}>{t('dsTbRegmien', 'DS TB Regimen')}</p> | ||
<p> | ||
<span className={styles.value}>{programData.dsTBRegimen}</span> | ||
</p> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
export default ProgramEnrollmentTB; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters