Skip to content

Commit

Permalink
simplify checks
Browse files Browse the repository at this point in the history
  • Loading branch information
Amy Chen authored and Amy Chen committed Jan 12, 2024
1 parent bc1dc96 commit f06c2a3
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 12 deletions.
15 changes: 10 additions & 5 deletions src/FhirClientProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,21 +42,22 @@ export default function FhirClientProvider(props: Props): JSX.Element {
if (!client) return;
//this is a workaround for when patient id is not embedded within the JWT token
let queryPatientId = sessionStorage.getItem(queryPatientIdKey);
const INACTIVE_ACCOUNT_ERROR_MSG = "Inactive account. No patient data returned.";
if (queryPatientId) {
console.log("Using stored patient id ", queryPatientId);
return getFhirData(client, "/Patient/" + queryPatientId).then(
(value: any) => {
let patient: Patient = Patient.from(value)
let active_patient: Patient = patient.active == true ? patient : undefined;
return active_patient;
if (!patient.isActive()) throw new Error(INACTIVE_ACCOUNT_ERROR_MSG);
return patient;
}
);
}
// Get the Patient resource
return await client.patient.read().then((value: any) => {
let patient: Patient = Patient.from(value)
let active_patient: Patient = patient.active == true ? patient : undefined;
return active_patient;
if (!patient.isActive()) throw new Error(INACTIVE_ACCOUNT_ERROR_MSG);
return patient;
});
}

Expand Down Expand Up @@ -188,7 +189,11 @@ export default function FhirClientProvider(props: Props): JSX.Element {
(result) => result.value && result.value.resourceType === "Patient"
);
if (!hasPatientResult) {
setError("No matching patient data returned.");
const errorReason =
results[1] && results[1].reason
? results[1].reason
: "No matching patient data returned.";
setError(errorReason);
setLoaded(true);
}
results.forEach((result) => {
Expand Down
8 changes: 1 addition & 7 deletions src/components/ScheduleSetup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -463,12 +463,6 @@ export default class ScheduleSetup extends React.Component<
);
}

if (patient.active != true) {
return new Promise((resolve, reject) =>
reject("The patient is not active.")
);
}

let params = new URLSearchParams({
telecom: `${patient.smsContactPoint}`,
// FIXME
Expand All @@ -494,7 +488,7 @@ export default class ScheduleSetup extends React.Component<
}
}
);
if ((patients.find((o) => o.id !== patient.id && o.active == true))) {
if ((patients.find((o:Patient) => o.id !== patient.id && o.isActive()))) {
// exclude current patient, workaround for above FIXME
reject(
`Phone number is already associated with: ${patients
Expand Down
5 changes: 5 additions & 0 deletions src/model/Patient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -469,4 +469,9 @@ export default class Patient implements IPatient {
this.meta.security.push(existingMetaSecurity);
}
}

isActive () {
if (typeof this.active === "undefined") return true;
return this.active;
}
}

0 comments on commit f06c2a3

Please sign in to comment.