-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
OHRI-2315: To display HIV Status badge appear on the Infant banner (#…
…1931) * To display HIV Status badge appear on the Infant banner * ensure only the required outcome status display * fix failling test * remove age restriction on displaying the MOther/infant name on the banner
- Loading branch information
1 parent
ecc1a7f
commit 527b2a9
Showing
4 changed files
with
87 additions
and
14 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
36 changes: 36 additions & 0 deletions
36
packages/esm-commons-lib/src/components/banner-tags/useInfantFinalOutcome.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,36 @@ | ||
import { useState, useEffect } from 'react'; | ||
import { openmrsFetch, useConfig } from '@openmrs/esm-framework'; | ||
|
||
export const usePatientOutcome = (patientUuid: string) => { | ||
const [patientOutcome, setPatientOutcome] = useState<string | null>(null); | ||
const [isLoading, setIsLoading] = useState<boolean>(true); | ||
const [isError, setIsError] = useState<boolean>(false); | ||
const config = useConfig(); | ||
|
||
useEffect(() => { | ||
const fetchPatientOutcome = async () => { | ||
try { | ||
const response = await fetch( | ||
`/openmrs/ws/rest/v1/obs?patient=${patientUuid}&concept=${config.obsConcepts.outcomeStatus}&v=full`, | ||
); | ||
const data = await response.json(); | ||
|
||
if (data.results.length > 0) { | ||
const outcome = data.results[0].value; | ||
setPatientOutcome(outcome.display ?? null); | ||
} else { | ||
setPatientOutcome(null); | ||
} | ||
} catch (error) { | ||
console.error('Failed to fetch patient outcome:', error); | ||
setIsError(true); | ||
} finally { | ||
setIsLoading(false); | ||
} | ||
}; | ||
|
||
fetchPatientOutcome(); | ||
}, [patientUuid, config.obsConcepts.outcomeStatus]); | ||
|
||
return { patientOutcome, isLoading, isError }; | ||
}; |
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