Skip to content

Commit

Permalink
display custom columns (#158)
Browse files Browse the repository at this point in the history
* display custom columns

* remove un-intended changes

* re-code queries

* remove un-needed code

* remove extra line

* Update PatientListTable.js

* add count param

Co-authored-by: Amy Chen <clone@cesium.cirg.washington.edu>
  • Loading branch information
achen2401 and Amy Chen authored Nov 15, 2022
1 parent 1a4b3ef commit ff021cf
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 4 deletions.
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
90 changes: 86 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,85 @@ 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}&_count=1000`,
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) => {
console.log("query result data ", 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;
}

0 comments on commit ff021cf

Please sign in to comment.