Skip to content

Commit

Permalink
Followed recipients query fix (#220)
Browse files Browse the repository at this point in the history
* Followed recipients query fix

* lint fix

* lint fix

---------

Co-authored-by: Amy Chen <[email protected]>
  • Loading branch information
achen2401 and Amy Chen authored Aug 2, 2024
1 parent 5b1c42a commit 2de95dc
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 36 deletions.
15 changes: 0 additions & 15 deletions patientsearch/src/js/context/PatientListContextProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
66 changes: 45 additions & 21 deletions patientsearch/src/js/helpers/utility.js
Original file line number Diff line number Diff line change
Expand Up @@ -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<string> | 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;
}
Expand Down

0 comments on commit 2de95dc

Please sign in to comment.