Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

display custom columns #158

Merged
merged 8 commits into from
Nov 15, 2022
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions patientsearch/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ def load_json_config(potential_json_string):
],
)

FHIR_REST_EXTRA_PARAMS_LIST = os.getenv("FHIR_REST_EXTRA_PARAMS_LIST", [])
LANDING_INTRO = os.getenv("LANDING_INTRO", "")
LANDING_BUTTON_TEXT = os.getenv("LANDING_BUTTON_TEXT", "")
LANDING_BODY = os.getenv("LANDING_BODY", "")
Expand Down
89 changes: 85 additions & 4 deletions patientsearch/src/js/components/PatientListTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
getUrlParameter,
getRolesFromToken,
getClientsByRequiredRoles,
isEmptyArray,
isString,
validateToken,
} from "../helpers/utility";
Expand Down Expand Up @@ -218,6 +219,7 @@ export default function PatientListTable() {
last_name: "family",
birth_date: "birthdate",
last_accessed: "_lastUpdated",
mrn: "identifier"
};
const default_columns = [
{
Expand All @@ -232,6 +234,12 @@ export default function PatientListTable() {
label: "Birth Date",
expr: "$.birthDate",
},
{
label: "Last Accessed",
defaultSort: "desc",
expr: "$.meta.lastUpdated",
dataType: "date",
},
];
const errorStyle = { display: errorMessage ? "block" : "none" };
const toTop = () => {
Expand Down Expand Up @@ -634,6 +642,7 @@ export default function PatientListTable() {
totalCount: 0,
};
let apiURL = `/fhir/Patient?_include=Patient:link&_total=accurate&_count=${pagination.pageSize}`;

if (
pagination.pageNumber > pagination.prevPageNumber &&
pagination.nextPageURL
Expand Down Expand Up @@ -665,8 +674,7 @@ export default function PatientListTable() {
resolve(defaults);
return;
}
let responseData = formatData(response.entry);
setData(responseData || []);

if (needExternalAPILookup()) setNoPMPFlag(responseData);
let responsePageoffset = 0;
let responseSelfLink = response.link
Expand Down Expand Up @@ -711,11 +719,84 @@ export default function PatientListTable() {
totalCount: response.total,
},
});
resolve({

let patientResources = response.entry.filter(
(item) => item.resource && item.resource.resourceType === "Patient"
);

let responseData = formatData(patientResources) || [];

const additionalParams = getAppSettingByKey(
"FHIR_REST_EXTRA_PARAMS_LIST"
);
const resolvedData = {
data: responseData,
page: currentPage,
totalCount: response.total,
});
};
if (isEmptyArray(additionalParams)) {
setData(responseData);
resolve(resolvedData);
return;
}
// query for additional resources if specified via config
// gather patient id(s) from API returned result
const ids = patientResources
.map((item) => item.resource.id)
.join(",");
// FHIR resources request(s)
const requests = additionalParams.map((queryString) =>
fetchData(
`/fhir/${queryString}` +
(queryString.indexOf("?") !== -1 ? "&" : "?") +
`patient=${ids}`,
noCacheParam
)
);
const queryResults = (async () => {
const results = await Promise.all(requests).catch((e) => {
throw new Error(e);
});
if (isEmptyArray(results)) return patientResources;
return patientResources.map((item) => {
let subjectId = item.resource.id;
if (!item.resource["resources"]) item.resource["resources"] = [];
results.forEach((result) => {
if (isEmptyArray(result.entry)) return true;
item.resource["resources"] = [
...item.resource["resources"],
...result.entry
.filter(
(o) =>
o.resource &&
o.resource.subject &&
o.resource.subject.reference &&
o.resource.subject.reference.split("/")[1] === subjectId
)
.map((resourceItem) => resourceItem.resource),
];
});
return item;
});
})();
queryResults
.then((data) => {
const resultData = formatData(data);
setData(resultData || []);
resolve({
data: resultData,
page: currentPage,
totalCount: response.total,
});
})
.catch((e) => {
setErrorMessage(
"Error retrieving additional FHIR resources. See console for detail."
);
console.log(e);
setData(responseData);
resolve(resolvedData);
});
})
.catch((error) => {
console.log("Failed to retrieve data", error);
Expand Down
4 changes: 4 additions & 0 deletions patientsearch/src/js/helpers/utility.js
Original file line number Diff line number Diff line change
Expand Up @@ -353,3 +353,7 @@ export function setFavicon(href) {
if (!faviconEl) return;
faviconEl.href = href;
}

export function isEmptyArray(arrObj) {
return !arrObj || !Array.isArray(arrObj) || arrObj.length === 0;
}