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

(feat) : Add real-time patient identifier validation using directives #2191

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ export class FeWrapperComponent implements OnInit, OnDestroy {
private readonly ngZone: NgZone,
private readonly programService: ProgramResourceService,
private readonly formDataSourceService: FormDataSourceService,
private readonly patientResourceService: PatientResourceService,
private readonly visitResourceService: VisitResourceService,
) {}

Expand Down Expand Up @@ -202,57 +201,46 @@ export class FeWrapperComponent implements OnInit, OnDestroy {

private handleFormSubmission() {
this.changeState('submitting');
this.patientResourceService.validateIdentifiers(this.form).subscribe((resp) => {
if (resp.length > 0) {
this.changeState('readyWithValidationErrors');

this.formSubmissionService.submitPayload(this.form).subscribe(
({ encounter }) => {
this.onPostResponse(encounter);
const isOffline = this.singleSpaPropsService.getProp('isOffline', false);

if (!isOffline && encounter?.uuid) {
this.encounterResourceService
.getEncounterByUuid(encounter.uuid)
.pipe(take(1))
.subscribe((encounter) => {
if (Array.isArray(encounter?.orders)) {
const submittedOrders = encounter.orders.filter(({ auditInfo }) => !auditInfo.dateVoided);
this.showLabOrdersNotification(submittedOrders);
}
});
}

this.programService.handlePatientCareProgram(this.form, encounter.uuid);
showSnackbar({
isLowContrast: true,
kind: 'success',
subtitle: this.translateService.instant('formSubmittedSuccessfully'),
title: this.form.schema.display ?? this.form.schema.name,
timeoutInMs: 5000,
});
this.changeState('submitted');
this.closeFormWithSavedChanges();
},
(error: Error) => {
this.changeState('submissionError');
showSnackbar({
title: this.translateService.instant('patientIdentifierDuplication'),
subtitle: this.translateService.instant('patientIdentifierDuplicationDescription'),
isLowContrast: true,
kind: 'error',
isLowContrast: false,
subtitle: this.translateService.instant('formSubmissionFailed').replace('{error}', error.message),
title: this.form.schema.display ?? this.form.schema.name,
timeoutInMs: 5000,
});
} else {
this.formSubmissionService.submitPayload(this.form).subscribe(
({ encounter }) => {
this.onPostResponse(encounter);
const isOffline = this.singleSpaPropsService.getProp('isOffline', false);

if (!isOffline && encounter?.uuid) {
this.encounterResourceService
.getEncounterByUuid(encounter.uuid)
.pipe(take(1))
.subscribe((encounter) => {
if (Array.isArray(encounter?.orders)) {
const submittedOrders = encounter.orders.filter(({ auditInfo }) => !auditInfo.dateVoided);
this.showLabOrdersNotification(submittedOrders);
}
});
}

this.programService.handlePatientCareProgram(this.form, encounter.uuid);
showSnackbar({
isLowContrast: true,
kind: 'success',
subtitle: this.translateService.instant('formSubmittedSuccessfully'),
title: this.form.schema.display ?? this.form.schema.name,
timeoutInMs: 5000,
});
this.changeState('submitted');
this.closeFormWithSavedChanges();
},
(error: Error) => {
this.changeState('submissionError');
showSnackbar({
isLowContrast: true,
kind: 'error',
subtitle: this.translateService.instant('formSubmissionFailed').replace('{error}', error.message),
title: this.form.schema.display ?? this.form.schema.name,
timeoutInMs: 5000,
});
},
);
}
});
},
);
}

private modifyVisitDate(visitUuid: string, visitStartDatetime: string, visitStopDatetime: string) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ export class FormCreationService {

if (patientIdentifiers) {
this.patientIdentifierAdapter.populateForm(form, patientIdentifiers);
// set the patient identifiers in the form valueProcessingInfo
form.valueProcessingInfo.patientIdentifiers = patientIdentifiers;
}
if (encounter) {
const encounterUuid = encounter.uuid;
Expand Down
2 changes: 2 additions & 0 deletions packages/esm-form-entry-app/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
"futureDateRestriction": "Future date is not allowed!",
"hoursAgo": " hours ago",
"invalidDate": "Provided date is invalid!",
"identifierTaken": "This identifier is already assigned to another patient",
"identifierError": "An error occurred while validating the identifier",
"loading": "Loading...",
"loadingComponent": "Loading Component...",
"max": "Max value should be {max}",
Expand Down
Loading