-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
To display HIV Status badge appear on the Infant banner
- Loading branch information
1 parent
cb86c63
commit 9d1efa3
Showing
3 changed files
with
80 additions
and
7 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 }; | ||
}; |