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

Feature/deactivate account fix #84

Merged
merged 7 commits into from
Jan 18, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
17 changes: 13 additions & 4 deletions src/FhirClientProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,23 @@ 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) => {
return Patient.from(value);
let patient: Patient = Patient.from(value)
if (!patient.isActive()) throw new Error(INACTIVE_ACCOUNT_ERROR_MSG);
return patient;
}
);
}
// Get the Patient resource
return await client.patient.read().then((value: any) => {
return Patient.from(value);
});
let patient: Patient = Patient.from(value)
if (!patient.isActive()) throw new Error(INACTIVE_ACCOUNT_ERROR_MSG);
return patient;
});
}

async function getPractitioner(
Expand Down Expand Up @@ -184,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
2 changes: 1 addition & 1 deletion src/components/ScheduleSetup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ export default class ScheduleSetup extends React.Component<
}
}
);
if (patients.find((o) => o.id !== patient.id)) {
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
3 changes: 2 additions & 1 deletion src/model/CommunicationRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,15 @@ export class CommunicationRequest implements ICommunicationRequest {
sender: Patient | Practitioner = null,
note: string = ""
) {
return this.createNewOutgoingMessage(
let c = this.createNewOutgoingMessage(
messageContent,
patient,
carePlan,
IsaccMessageCategory.isaccManuallySentMessage,
sender,
note
);
return c
}

static createNewOutgoingMessage(
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;
}
}
Loading