-
Notifications
You must be signed in to change notification settings - Fork 203
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(feat) Revitalized Immunization Support (#1572)
Co-authored-by: Dennis Kigen <kigen.work@gmail.com>
- Loading branch information
1 parent
2808c0f
commit 100ce91
Showing
31 changed files
with
1,149 additions
and
529 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
22 changes: 22 additions & 0 deletions
22
packages/esm-patient-immunizations-app/src/hooks/useImmunizations.ts
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,22 @@ | ||
import { fhirBaseUrl, openmrsFetch } from '@openmrs/esm-framework'; | ||
import useSWR from 'swr'; | ||
import { type FHIRImmunizationBundle } from '../types/fhir-immunization-domain'; | ||
import { mapFromFHIRImmunizationBundle } from '../immunizations/immunization-mapper'; | ||
|
||
export function useImmunizations(patientUuid: string) { | ||
const immunizationsUrl = `${fhirBaseUrl}/Immunization?patient=${patientUuid}`; | ||
|
||
const { data, error, isLoading, isValidating, mutate } = useSWR<{ data: FHIRImmunizationBundle }, Error>( | ||
immunizationsUrl, | ||
openmrsFetch, | ||
); | ||
const existingImmunizations = data ? mapFromFHIRImmunizationBundle(data.data) : null; | ||
|
||
return { | ||
data: existingImmunizations, | ||
error, | ||
isLoading, | ||
isValidating, | ||
mutate, | ||
}; | ||
} |
17 changes: 17 additions & 0 deletions
17
packages/esm-patient-immunizations-app/src/hooks/useImmunizationsConceptSet.ts
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,17 @@ | ||
import { openmrsFetch } from '@openmrs/esm-framework'; | ||
import { type ImmunizationWidgetConfigObject, type OpenmrsConcept } from '../types/fhir-immunization-domain'; | ||
import useSWR from 'swr'; | ||
|
||
export function useImmunizationsConceptSet(config: ImmunizationWidgetConfigObject) { | ||
const conceptRepresentation = | ||
'custom:(uuid,display,answers:(uuid,display),conceptMappings:(conceptReferenceTerm:(conceptSource:(name),code)))'; | ||
|
||
const { data, error, isLoading } = useSWR<{ data: { results: Array<OpenmrsConcept> } }, Error>( | ||
`/ws/rest/v1/concept?references=${config.immunizationConceptSet}&v=${conceptRepresentation}`, | ||
openmrsFetch, | ||
); | ||
return { | ||
immunizationsConceptSet: data && data.data.results[0], | ||
isLoading, | ||
}; | ||
} |
45 changes: 45 additions & 0 deletions
45
packages/esm-patient-immunizations-app/src/immunizations/components/dose-input.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,45 @@ | ||
import React, { useMemo } from 'react'; | ||
import { type ImmunizationSequenceDefinition } from '../../types/fhir-immunization-domain'; | ||
import { useController, type Control } from 'react-hook-form'; | ||
import { Dropdown, NumberInput } from '@carbon/react'; | ||
import styles from './../immunizations-form.scss'; | ||
import { useTranslation } from 'react-i18next'; | ||
|
||
export const DoseInput: React.FC<{ | ||
vaccine: string; | ||
sequences: ImmunizationSequenceDefinition[]; | ||
control: Control; | ||
}> = ({ vaccine, sequences, control }) => { | ||
const { t } = useTranslation(); | ||
const { field } = useController({ name: 'doseNumber', control }); | ||
|
||
const vaccineSequences = useMemo( | ||
() => sequences?.find((sequence) => sequence.vaccineConceptUuid === vaccine)?.sequences || [], | ||
[sequences, vaccine], | ||
); | ||
|
||
return ( | ||
<div className={styles.row}> | ||
{vaccineSequences.length ? ( | ||
<Dropdown | ||
id="sequence" | ||
label={t('pleaseSelect', 'Please select')} | ||
titleText={t('sequence', 'Sequence')} | ||
items={vaccineSequences?.map((sequence) => sequence.sequenceNumber) || []} | ||
itemToString={(item) => vaccineSequences.find((s) => s.sequenceNumber === item)?.sequenceLabel} | ||
onChange={(val) => field.onChange(parseInt(val.selectedItem || 0))} | ||
selectedItem={field.value} | ||
/> | ||
) : ( | ||
<NumberInput | ||
id="doseNumber" | ||
label={t('doseNumber', 'Dose number within series')} | ||
min={0} | ||
onChange={(event) => field.onChange(parseInt(event.target.value || 0))} | ||
value={field.value} | ||
hideSteppers={true} | ||
/> | ||
)} | ||
</div> | ||
); | ||
}; |
107 changes: 107 additions & 0 deletions
107
...immunizations-app/src/immunizations/components/immunizations-sequence-table.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,107 @@ | ||
import React, { useMemo } from 'react'; | ||
import { useTranslation } from 'react-i18next'; | ||
import isEmpty from 'lodash-es/isEmpty'; | ||
import { | ||
Button, | ||
DataTable, | ||
TableContainer, | ||
Table, | ||
TableHead, | ||
TableRow, | ||
TableHeader, | ||
TableBody, | ||
TableCell, | ||
} from '@carbon/react'; | ||
import { Edit } from '@carbon/react/icons'; | ||
import { type ImmunizationGrouped } from '../../types'; | ||
import { formatDate, parseDate } from '@openmrs/esm-framework'; | ||
import { immunizationFormSub } from '../utils'; | ||
import styles from './immunizations-sequence-table.scss'; | ||
|
||
interface SequenceTableProps { | ||
immunizationsByVaccine: ImmunizationGrouped; | ||
launchPatientImmunizationForm: () => void; | ||
} | ||
|
||
const SequenceTable: React.FC<SequenceTableProps> = ({ immunizationsByVaccine, launchPatientImmunizationForm }) => { | ||
const { t } = useTranslation(); | ||
const { existingDoses, sequences, vaccineUuid } = immunizationsByVaccine; | ||
|
||
const tableHeader = useMemo( | ||
() => [ | ||
{ key: 'sequence', header: sequences.length ? t('sequence', 'Sequence') : t('doseNumber', 'Dose Number') }, | ||
{ key: 'vaccinationDate', header: t('vaccinationDate', 'Vaccination Date') }, | ||
{ key: 'expirationDate', header: t('expirationDate', 'Expiration Date') }, | ||
{ key: 'edit', header: '' }, | ||
], | ||
[t], | ||
); | ||
|
||
const tableRows = existingDoses?.map((dose) => { | ||
return { | ||
id: dose?.immunizationObsUuid, | ||
sequence: isEmpty(sequences) | ||
? dose.doseNumber || 0 | ||
: sequences?.find((s) => s.sequenceNumber === dose.doseNumber).sequenceLabel || dose.doseNumber, | ||
vaccinationDate: dose?.occurrenceDateTime && formatDate(new Date(dose.occurrenceDateTime)), | ||
expirationDate: dose?.expirationDate && formatDate(new Date(dose.expirationDate), { noToday: true }), | ||
edit: ( | ||
<Button | ||
kind="ghost" | ||
iconDescription="Edit" | ||
renderIcon={(props) => <Edit size={16} {...props} />} | ||
onClick={() => { | ||
immunizationFormSub.next({ | ||
vaccineUuid: vaccineUuid, | ||
immunizationId: dose.immunizationObsUuid, | ||
vaccinationDate: dose.occurrenceDateTime && parseDate(dose.occurrenceDateTime), | ||
doseNumber: dose.doseNumber, | ||
expirationDate: dose.expirationDate && parseDate(dose.expirationDate), | ||
lotNumber: dose.lotNumber, | ||
manufacturer: dose.manufacturer, | ||
visitId: dose.visitUuid, | ||
}); | ||
launchPatientImmunizationForm(); | ||
}} | ||
> | ||
{t('edit', 'Edit')} | ||
</Button> | ||
), | ||
}; | ||
}); | ||
|
||
return ( | ||
tableRows.length > 0 && ( | ||
<DataTable rows={tableRows} headers={tableHeader} useZebraStyles> | ||
{({ rows, headers, getHeaderProps, getTableProps }) => ( | ||
<TableContainer className={styles.sequenceTable}> | ||
<Table {...getTableProps()}> | ||
<TableHead> | ||
<TableRow> | ||
{headers.map((header) => ( | ||
<TableHeader {...getHeaderProps({ header })}>{header.header}</TableHeader> | ||
))} | ||
</TableRow> | ||
</TableHead> | ||
<TableBody> | ||
{rows.map((row) => { | ||
return ( | ||
<TableRow key={row.id}> | ||
{row.cells.map((cell) => ( | ||
<TableCell key={cell?.id} className={styles.tableCell}> | ||
{cell?.value} | ||
</TableCell> | ||
))} | ||
</TableRow> | ||
); | ||
})} | ||
</TableBody> | ||
</Table> | ||
</TableContainer> | ||
)} | ||
</DataTable> | ||
) | ||
); | ||
}; | ||
|
||
export default SequenceTable; |
7 changes: 7 additions & 0 deletions
7
...-patient-immunizations-app/src/immunizations/components/immunizations-sequence-table.scss
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,7 @@ | ||
.tableCell { | ||
padding: 0rem 1.5rem !important; | ||
} | ||
|
||
.sequenceTable { | ||
margin: 0.5rem 0; | ||
} |
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
17 changes: 0 additions & 17 deletions
17
packages/esm-patient-immunizations-app/src/immunizations/immunization-utils.ts
This file was deleted.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
...ages/esm-patient-immunizations-app/src/immunizations/immunization-widget-config-schema.ts
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
Oops, something went wrong.