-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #123 from Rugute/main
Sorted Patient Summaries
- Loading branch information
Showing
24 changed files
with
591 additions
and
67 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
![Node.js CI](https://github.com/palladiumkenya/ampath-esm-3.x/workflows/Node.js%20CI/badge.svg) | ||
![Node.js CI](https://github.com/AMPATH/ampath-esm-3.x/workflows/Node.js%20CI/badge.svg) | ||
|
||
# ESM Care Panel App | ||
|
||
This repository provides a starting point for creating ampath patient care panels | ||
This repository provides a starting point for creating AMPATH patient care panels |
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
18 changes: 18 additions & 0 deletions
18
packages/esm-care-panel-app/src/hooks/usePatientHIVStatus.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,18 @@ | ||
import { openmrsFetch, useConfig } from '@openmrs/esm-framework'; | ||
import useSWR from 'swr'; | ||
import { type CarePanelConfig } from '../config-schema'; | ||
import { type Enrollment } from '../types'; | ||
|
||
const usePatientHIVStatus = (patientUuid: string) => { | ||
const customeRepresentation = 'custom:(uuid,program:(name,uuid))'; | ||
const url = `/ws/rest/v1/programenrollment?v=${customeRepresentation}&patient=${patientUuid}`; | ||
const config = useConfig<CarePanelConfig>(); | ||
const { data, error, isLoading } = useSWR<{ data: { results: Enrollment[] } }>(url, openmrsFetch); | ||
return { | ||
error, | ||
isLoading, | ||
isPositive: (data?.data?.results ?? []).find((en) => en.program.uuid === config.hivProgramUuid) !== undefined, | ||
}; | ||
}; | ||
|
||
export default usePatientHIVStatus; |
19 changes: 19 additions & 0 deletions
19
packages/esm-care-panel-app/src/hooks/usePatientIITScore.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,19 @@ | ||
import { type FetchResponse, openmrsFetch, restBaseUrl } from '@openmrs/esm-framework'; | ||
import useSWR from 'swr'; | ||
import { type IITRiskScore } from '../types'; | ||
import { patientRiskScore } from '../iit-risk-score/risk-score.mock'; | ||
import { useMemo } from 'react'; | ||
|
||
const usePatientIITScore = (patientUuid: string) => { | ||
const url = `${restBaseUrl}/keml/patientiitscore?patientUuid=${patientUuid}`; | ||
const { data, error, isLoading } = useSWR<FetchResponse<IITRiskScore>>(url, openmrsFetch); | ||
|
||
const riskScore = useMemo(() => data?.data ?? patientRiskScore.at(-1), [patientUuid]); | ||
return { | ||
isLoading: false, | ||
error, | ||
riskScore, | ||
}; | ||
}; | ||
|
||
export default usePatientIITScore; |
68 changes: 68 additions & 0 deletions
68
packages/esm-care-panel-app/src/iit-risk-score/iit-risk-score-plot.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,68 @@ | ||
import { LineChart, type LineChartOptions, ScaleTypes } from '@carbon/charts-react'; | ||
import '@carbon/charts/styles.css'; | ||
import React from 'react'; | ||
import styles from './iit-risk-score.scss'; | ||
import usePatientIITScore from '../hooks/usePatientIITScore'; | ||
import { CardHeader } from '@openmrs/esm-patient-common-lib'; | ||
import { patientRiskScore } from './risk-score.mock'; | ||
import { formatDate, parseDate } from '@openmrs/esm-framework'; | ||
|
||
interface CarePanelRiskScorePlotProps { | ||
patientUuid: string; | ||
} | ||
|
||
const CarePanelRiskScorePlot: React.FC<CarePanelRiskScorePlotProps> = ({ patientUuid }) => { | ||
const { isLoading, error, riskScore } = usePatientIITScore(patientUuid); | ||
const options: LineChartOptions = { | ||
title: 'KenyaHMIS ML Model', | ||
legend: { enabled: false }, | ||
axes: { | ||
bottom: { | ||
title: 'Evaluation Time', | ||
mapsTo: 'evaluationDate', | ||
scaleType: ScaleTypes.LABELS, | ||
}, | ||
left: { | ||
mapsTo: 'riskScore', | ||
title: 'Risk Score (%)', | ||
percentage: true, | ||
scaleType: ScaleTypes.LINEAR, | ||
includeZero: true, | ||
}, | ||
}, | ||
curve: 'curveMonotoneX', | ||
height: '400px', | ||
tooltip: { | ||
// Tooltip configuration for displaying descriptions | ||
enabled: true, | ||
|
||
valueFormatter(value, label) { | ||
if (label === 'Risk Score (%)') { | ||
return `${value} (${patientRiskScore.find((r) => `${r.riskScore}` === `${value}`)?.description ?? ''})`; | ||
} | ||
return `${value}`; | ||
}, | ||
}, | ||
}; | ||
|
||
return ( | ||
<div className={styles['risk-score-card']}> | ||
<span className={styles.sectionHeader}>IIT Risk Score Trend</span> | ||
<center> | ||
<strong>Latest risk score: </strong> | ||
{`${riskScore.riskScore}%`} | ||
</center> | ||
<div style={{ padding: '1rem' }}> | ||
<LineChart | ||
data={patientRiskScore.map((risk) => ({ | ||
...risk, | ||
evaluationDate: formatDate(parseDate(risk.evaluationDate)), | ||
}))} | ||
options={options} | ||
/> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default CarePanelRiskScorePlot; |
73 changes: 73 additions & 0 deletions
73
packages/esm-care-panel-app/src/iit-risk-score/iit-risk-score.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,73 @@ | ||
import { Column, Row, SkeletonText } from '@carbon/react'; | ||
import { ErrorState, formatDate, parseDate } from '@openmrs/esm-framework'; | ||
import React from 'react'; | ||
import { useTranslation } from 'react-i18next'; | ||
import usePatientIITScore from '../hooks/usePatientIITScore'; | ||
import styles from './iit-risk-score.scss'; | ||
|
||
interface CarePanellIITRiskScoreProps { | ||
patientUuid: string; | ||
} | ||
|
||
const CarePanellIITRiskScore: React.FC<CarePanellIITRiskScoreProps> = ({ patientUuid }) => { | ||
const { riskScore, error, isLoading } = usePatientIITScore(patientUuid); | ||
const { t } = useTranslation(); | ||
|
||
if (isLoading) { | ||
return ( | ||
<div className={styles['risk-score-card']}> | ||
<Row style={{ display: 'flex' }}> | ||
<Column lg={4} md={4} sm={4} className={styles['risk-score-card__item']}> | ||
<SkeletonText /> | ||
<SkeletonText /> | ||
</Column> | ||
<Column lg={4} md={4} sm={4} className={styles['risk-score-card__item']}> | ||
<SkeletonText /> | ||
<SkeletonText /> | ||
</Column> | ||
</Row> | ||
<Row style={{ display: 'flex' }}> | ||
<Column lg={4} md={4} sm={4} className={styles['risk-score-card__item']}> | ||
<SkeletonText /> | ||
<SkeletonText /> | ||
</Column> | ||
<Column lg={12} md={12} sm={12} className={styles['risk-score-card__item']}> | ||
<SkeletonText /> | ||
<SkeletonText /> | ||
</Column> | ||
</Row> | ||
</div> | ||
); | ||
} | ||
|
||
// if (error) { | ||
// return <ErrorState error={error} headerTitle={t('iitRiscScore', 'IIT Risk Score')} />; | ||
// } | ||
return ( | ||
<div className={styles['risk-score-card']}> | ||
<span className={styles.sectionHeader}>IIT Risk Score</span> | ||
<Row style={{ display: 'flex' }}> | ||
<Column lg={4} md={4} sm={4} className={styles['risk-score-card__item']}> | ||
<strong>Risk Score:</strong> | ||
<p>{`${riskScore?.riskScore ?? 0}%`}</p> | ||
</Column> | ||
<Column lg={4} md={4} sm={4} className={styles['risk-score-card__item']}> | ||
<strong>Evaluation Date:</strong> | ||
<p>{formatDate(parseDate(riskScore?.evaluationDate))}</p> | ||
</Column> | ||
</Row> | ||
<Row style={{ display: 'flex' }}> | ||
<Column lg={4} md={4} sm={4} className={styles['risk-score-card__item']}> | ||
<strong>Description:</strong> | ||
<p>{riskScore?.description}</p> | ||
</Column> | ||
<Column lg={12} md={12} sm={12} className={styles['risk-score-card__item']}> | ||
<strong>Risk Factors:</strong> | ||
<p>{riskScore?.riskFactors}</p> | ||
</Column> | ||
</Row> | ||
</div> | ||
); | ||
}; | ||
|
||
export default CarePanellIITRiskScore; |
39 changes: 39 additions & 0 deletions
39
packages/esm-care-panel-app/src/iit-risk-score/iit-risk-score.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,39 @@ | ||
@use '@carbon/styles/scss/type'; | ||
@use '@carbon/styles/scss/spacing'; | ||
@use '@carbon/colors'; | ||
@import '~@openmrs/esm-styleguide/src/vars'; | ||
|
||
.risk-score-card { | ||
width: 100%; | ||
border: 0.15rem solid $grey-2; | ||
margin-bottom: spacing.$spacing-08; | ||
} | ||
|
||
.risk-score-card__item { | ||
flex: 1; | ||
padding: spacing.$spacing-05; | ||
} | ||
|
||
.sectionHeader { | ||
@include type.type-style('heading-02'); | ||
display: flex; | ||
align-items: center; | ||
justify-content: space-between; | ||
margin: spacing.$spacing-05; | ||
row-gap: 1.5rem; | ||
position: relative; | ||
|
||
&::after { | ||
content: ''; | ||
display: block; | ||
width: 2rem; | ||
border-bottom: 0.375rem solid var(--brand-03); | ||
position: absolute; | ||
bottom: -0.75rem; | ||
left: 0; | ||
} | ||
|
||
& > span { | ||
@include type.type-style('body-01'); | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
packages/esm-care-panel-app/src/iit-risk-score/risk-score.mock.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,56 @@ | ||
export const patientRiskScore = [ | ||
{ | ||
evaluationDate: '2023-01-12T00:00:00.000Z', | ||
riskScore: 0, | ||
description: 'Low Risk', | ||
riskFactors: 'Poor adherance, Missed appointments, Late drug pickup', | ||
}, | ||
{ | ||
evaluationDate: '2023-04-10T00:00:00.000Z', | ||
riskScore: 0, | ||
description: 'Low Risk', | ||
riskFactors: 'Poor adherance, Missed appointments, Late drug pickup', | ||
}, | ||
{ | ||
evaluationDate: '2023-07-06T00:00:00.000Z', | ||
riskScore: 3, | ||
description: 'Medium Risk', | ||
riskFactors: 'Poor adherance, Missed appointments, Late drug pickup', | ||
}, | ||
{ | ||
evaluationDate: '2023-10-13T00:00:00.000Z', | ||
riskScore: 3, | ||
description: 'Medium Risk', | ||
riskFactors: 'Poor adherance, Missed appointments, Late drug pickup', | ||
}, | ||
{ | ||
evaluationDate: '2023-11-23T00:00:00.000Z', | ||
riskScore: 3, | ||
description: 'Medium Risk', | ||
riskFactors: 'Poor adherance, Missed appointments, Late drug pickup', | ||
}, | ||
{ | ||
evaluationDate: '2023-12-17T00:00:00.000Z', | ||
riskScore: 3, | ||
description: 'Medium Risk', | ||
riskFactors: 'Poor adherance, Missed appointments, Late drug pickup', | ||
}, | ||
{ | ||
evaluationDate: '2024-01-17T00:00:00.000Z', | ||
riskScore: 3, | ||
description: 'Medium Risk', | ||
riskFactors: 'Poor adherance, Missed appointments, Late drug pickup', | ||
}, | ||
{ | ||
evaluationDate: '2024-04-09T00:00:00.000Z', | ||
riskScore: 11, | ||
description: 'High Risk', | ||
riskFactors: 'Poor adherance, Missed appointments, Late drug pickup', | ||
}, | ||
{ | ||
evaluationDate: '2024-07-07T00:00:00.000Z', | ||
riskScore: 11, | ||
description: 'High Risk', | ||
riskFactors: 'Poor adherance, Missed appointments, Late drug pickup', | ||
}, | ||
]; |
30 changes: 30 additions & 0 deletions
30
packages/esm-care-panel-app/src/machine-learning/machine-learning.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,30 @@ | ||
import React from 'react'; | ||
import styles from './machine-learning.scss'; | ||
import CarePanellIITRiskScore from '../iit-risk-score/iit-risk-score.component'; | ||
import CarePanelRiskScorePlot from '../iit-risk-score/iit-risk-score-plot'; | ||
import usePatientHIVStatus from '../hooks/usePatientHIVStatus'; | ||
import { ErrorState } from '@openmrs/esm-framework'; | ||
import { useTranslation } from 'react-i18next'; | ||
import { EmptyState } from '@openmrs/esm-patient-common-lib'; | ||
|
||
interface CarePanelMachineLearningProps { | ||
patientUuid: string; | ||
} | ||
|
||
const CarePanelMachineLearning: React.FC<CarePanelMachineLearningProps> = ({ patientUuid }) => { | ||
const { error, isLoading, isPositive } = usePatientHIVStatus(patientUuid); | ||
const { t } = useTranslation(); | ||
const header = t('machineLearning', 'Machine Learning'); | ||
if (error) { | ||
return <ErrorState error={error} headerTitle={header} />; | ||
} | ||
return ( | ||
<div className={styles['machine-learning']}> | ||
{!isPositive && <EmptyState headerTitle={header} displayText="machine learning predictions" />} | ||
{isPositive && <CarePanellIITRiskScore patientUuid={patientUuid} />} | ||
{isPositive && <CarePanelRiskScorePlot patientUuid={patientUuid} />} | ||
</div> | ||
); | ||
}; | ||
|
||
export default CarePanelMachineLearning; |
Oops, something went wrong.