From 2de95dc316fd490977dd457c386e193e5bbee9db Mon Sep 17 00:00:00 2001 From: Amy Chen Date: Fri, 2 Aug 2024 16:10:13 -0700 Subject: [PATCH] Followed recipients query fix (#220) * Followed recipients query fix * lint fix * lint fix --------- Co-authored-by: Amy Chen --- .../js/context/PatientListContextProvider.js | 15 ----- patientsearch/src/js/helpers/utility.js | 66 +++++++++++++------ 2 files changed, 45 insertions(+), 36 deletions(-) diff --git a/patientsearch/src/js/context/PatientListContextProvider.js b/patientsearch/src/js/context/PatientListContextProvider.js index 24ca2ec0..c845c1ad 100644 --- a/patientsearch/src/js/context/PatientListContextProvider.js +++ b/patientsearch/src/js/context/PatientListContextProvider.js @@ -111,21 +111,6 @@ export default function PatientListContextProvider({ children }) { const [noDataText, setNoDataText] = React.useState("No record found."); const [filterByTestPatients, setFilterByTestPatients] = React.useState(false); - const existsIndata = (rowData) => { - if (!data || !rowData) return false; - return ( - data.filter((item) => { - return parseInt(item.id) === parseInt(rowData.id); - }).length > 0 - ); - }; - const _addDataRow = (rowData) => { - if (!rowData || !rowData.id) return false; - let newData = _formatData(rowData); - if (newData && !existsIndata(newData[0])) { - setData([newData[0], ...data]); - } - }; const getColumns = () => { const configColumns = getAppSettingByKey("DASHBOARD_COLUMNS"); const defaultSearchFields = constants.defaultSearchableFields; diff --git a/patientsearch/src/js/helpers/utility.js b/patientsearch/src/js/helpers/utility.js index 54b3ffa1..c03777b7 100644 --- a/patientsearch/src/js/helpers/utility.js +++ b/patientsearch/src/js/helpers/utility.js @@ -533,38 +533,62 @@ export const getAppLaunchURL = (patientId, params) => { }; /* - * look up care team resources containing the practitioner ID + * look up CareTeam and Patient FHIR resources containing the practitioner ID * @param practitionerId practitioner id (as id from the Practitioner FHIR resource) * @return {array | null} array of patient ids or null */ export async function getPatientIdsByCareTeamParticipant(practitionerId) { if (!practitionerId) return null; - const results = await fetchData( - `/fhir/CareTeam?participant=Practitioner/${practitionerId}`, - noCacheParam, - (error) => { - if (error) { - console.log("Error retrieving careteam by participant id ", error); - return null; + const results = await Promise.allSettled([ + fetchData( + `/fhir/Patient?general-practitioner=Practitioner/${practitionerId}&_count=200`, + noCacheParam, + (error) => { + if (error) { + console.log( + "Error retrieving patient resources by practitioner id ", + error + ); + return null; + } } - } - ).catch((e) => { - console.log("Error retrieving careteam partipant by id ", e); + ), + fetchData( + `/fhir/CareTeam?participant=Practitioner/${practitionerId}&_count=200`, + noCacheParam, + (error) => { + if (error) { + console.log("Error retrieving careteam by practitioner id ", error); + return null; + } + } + ), + ]).catch((e) => { + console.log("Error retrieving patients followed by practitioner ", e); return null; }); - console.log("care team participant result ", results); - if (results && results.entry.length) { - const matchedPatientIds = results.entry + console.log( + "Query results for patients the practitioner is following: ", + results + ); + let combinedResults = []; + // Patient resources + if (results[0].value && !isEmptyArray(results[0].value.entry)) { + let arrIds = results[0].value.entry.map((o) => o.resource.id); + combinedResults = [...arrIds]; + } + // CareTeam resources + if (results[1].value && !isEmptyArray(results[1].value.entry)) { + let arrIds = results[1].value.entry .filter( (o) => o.resource && o.resource.subject && o.resource.subject.reference ) - .map((o) => { - return o.resource.subject.reference.split("/")[1]; - }); - if (matchedPatientIds.length) { - return matchedPatientIds; - } - return null; + .map((o) => o.resource.subject.reference.split("/")[1]); + combinedResults = [...combinedResults, ...arrIds]; + } + if (!isEmptyArray(combinedResults)) { + // ids without duplicates + return [...new Set(combinedResults)]; } return null; }