Skip to content

Commit

Permalink
Patient lookup - use exact match
Browse files Browse the repository at this point in the history
  • Loading branch information
Amy Chen committed Jan 31, 2024
1 parent 4fc6feb commit b094c33
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 9 deletions.
1 change: 0 additions & 1 deletion patientsearch/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,6 @@ def bundle_getpages():
return jsonify_abort(status_code=400, message=str(error))


@api_blueprint.route("/fhir/<string:resource_type>", methods=["GET"])
@api_blueprint.route("/fhir/<string:resource_type>", methods=["GET"])
def resource_bundle(resource_type):
"""Query HAPI for resource_type and return as JSON FHIR Bundle
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ const useStyles = makeStyles((theme) => ({
container: {
backgroundColor: "#FFF",
margin: "auto",
padding: theme.spacing(2),
padding: theme.spacing(1),
position: "absolute",
top: "25%",
width: "480px",
left: "calc(50% - 240px)",
},
buttonsContainer: {
padding: theme.spacing(2),
padding: theme.spacing(2,2,1),
display: "flex",
justifyContent: "center",
alignItems: "center",
Expand Down
22 changes: 19 additions & 3 deletions patientsearch/src/js/context/PatientListContextProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { useUserContext } from "./UserContextProvider";
import * as constants from "../constants/consts";
import DetailPanel from "../components/patientList/DetailPanel";
import {
capitalizeFirstLetter,
fetchData,
getAppLaunchURL,
getFirstResourceFromFhirBundle,
Expand Down Expand Up @@ -398,7 +399,21 @@ export default function PatientListContextProvider({ children }) {
if (isUpdate && data.id) {
return `/fhir/Patient/${data.id}`;
}
let url = `/fhir/Patient?given=${fName}&family=${lName}&birthdate=${birthDate}`;
const matchFNames = [
fName,
fName.toLowerCase(),
fName.toUpperCase(),
capitalizeFirstLetter(fName),
].join(",");
const matchLNames = [
lName,
lName.toLowerCase(),
lName.toUpperCase(),
capitalizeFirstLetter(lName),
].join(",");
// lookup patient with exact match
//e.g., /fhir/Patient?given:exact=Test,test,TEST&family:exact=Bubblegum,bubblegum,BUBBLEGUM&birthdate=2000-01-01
let url = `/fhir/Patient?given:exact=${matchFNames}&family:exact=${matchLNames}&birthdate=${birthDate}`;
if (searchInactive) {
url += `&inactive_search=true`;
} else {
Expand Down Expand Up @@ -802,6 +817,7 @@ export default function PatientListContextProvider({ children }) {
}
const oData = new RowData(rowData);
const payload = JSON.stringify(oData.getFhirData(isCreateNew));
const isUpdate = isReactivate || (!isCreateNew && !!rowData.id);

// error message when no result returned
const noResultErrorMessage = needExternalAPILookup()
Expand All @@ -815,12 +831,12 @@ export default function PatientListContextProvider({ children }) {
fetchData(
_getPatientSearchURL(rowData, {
useActiveFlag: !!getAppSettingByKey("ACTIVE_PATIENT_FLAG"),
isUpdate: !isCreateNew && !!rowData.id,
isUpdate: isUpdate,
}),
{
...searchParams,
body: payload,
method: isCreateNew ? "POST" : "PUT",
method: isUpdate ? "PUT" : "POST",
},
(e) => handleErrorCallback(e)
)
Expand Down
17 changes: 14 additions & 3 deletions patientsearch/src/js/helpers/utility.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,10 @@ export async function fetchData(url, params, errorCallback) {
});
console.log("response json ", json);
} catch (e) {
console.log(`There was error parsing data: ${e}`);
console.log(`There was error parsing data:`, e);
json = null;
errorCallback(e);
throw e;
}

if (!results || !results.ok) {
console.log("no results returned ", results);
if (!results.ok) {
Expand Down Expand Up @@ -619,3 +618,15 @@ export function getErrorDiagnosticTextFromResponse(response) {
response.issue.find((item) => item.severity === "error");
return issue && issue.diagnostics ? issue.diagnostics : "";
}

/*
* return string with first letter capitalized and the rest lower cased
* @param string to be modified
* @return string
*/
export function capitalizeFirstLetter(string) {
if (!string) return "";
const firstCapLetter = string.charAt(0).toUpperCase();
const theRest = string.slice(1);
return firstCapLetter + (theRest ? theRest.toLowerCase() : "");
}

0 comments on commit b094c33

Please sign in to comment.