Skip to content

Commit

Permalink
Merge pull request #470 from udsm-dhis2-lab/feature/remote-patient-hi…
Browse files Browse the repository at this point in the history
…story

Feature/remote patient history
  • Loading branch information
josephatJ authored Nov 1, 2024
2 parents b091b0f + 9fcf9ba commit 017561d
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -96,31 +96,38 @@ <h2>{{ editMode ? "Edit Patient" : "Register New Patient" }}</h2>
<mat-form-field appearance="fill" class="w-100 mr-2">
<mat-label>Select Identification</mat-label>
<mat-select
multiple="true"
placeholder="Select Identification"
[ngModel]="selectedIdentifierType?.id"
[ngModel]="definedIdentifierTypes"
[disabled]="disabledIDType"
(selectionChange)="onSelectOtherIdentifier($event)"
>
<mat-option
*ngFor="let identifier of otherPatientIdentifierTypes"
(click)="onSelectOtherIdentifier($event, identifier)"
[value]="identifier.id"
[value]="identifier"
>{{ identifier.name }}</mat-option
>
</mat-select>
</mat-form-field>
<mat-form-field appearance="fill" class="w-100">
<mat-label>{{ selectedIdentifierType?.name }}</mat-label>
<!-- {{ definedIdentifierType | json }} -->
<mat-form-field
appearance="fill"
class="w-100 mr-2"
*ngFor="let definedIdentifierType of definedIdentifierTypes"
>
<mat-label>{{
definedIdentifierType?.name
? definedIdentifierType?.name
: definedIdentifierType?.display
}}</mat-label>
<input
matInput
id="patientTypeID"
[pattern]="selectedIdentifierType?.format"
[placeholder]="selectedIdFormat"
[required]="selectedIdentifierType?.required"
[disabled]="
!selectedIdentifierType || selectedIdentifierType.disabled
"
[(ngModel)]="patient[selectedIdentifierType?.id]"
[value]="patient[selectedIdentifierType?.id]"
[pattern]="definedIdentifierType?.format"
[placeholder]="definedIdentifierType?.format"
[required]="definedIdentifierType?.required"
[(ngModel)]="patient[definedIdentifierType?.id]"
[value]="patient[definedIdentifierType?.id]"
/>
</mat-form-field>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import { Dropdown } from "src/app/shared/modules/form/models/dropdown.model";
import { PatientService } from "src/app/shared/resources/patient/services/patients.service";
import { Field } from "src/app/shared/modules/form/models/field.model";
import { GoogleAnalyticsService } from "src/app/google-analytics.service";
import { MatSelectChange } from "@angular/material/select";
@Component({
selector: "app-registration-add",
templateUrl: "./registration-add.component.html",
Expand Down Expand Up @@ -148,6 +149,7 @@ export class RegistrationAddComponent implements OnInit {
id: "",
format: "",
};
definedIdentifierTypes: any[] = [];
loadingForm: boolean;
loadingFormError: string;

Expand Down Expand Up @@ -548,6 +550,18 @@ export class RegistrationAddComponent implements OnInit {
this.patientIdentifierTypes
);

this.definedIdentifierTypes = !this.patientInformation
? []
: (
this.patientInformation?.patient?.identifiers?.map(
(identifier: any) => {
return this.otherPatientIdentifierTypes.find(
(identifierType) =>
identifierType.id === identifier?.identifierType?.uuid
);
}
) || []
)?.filter((identifierType: any) => identifierType);
const otherIdentifierObject =
this.patientInformation?.patient?.identifiers?.filter(
(identifier) => {
Expand All @@ -563,24 +577,27 @@ export class RegistrationAddComponent implements OnInit {
return attribute.attributeType.display === "patientType";
}
)[0]?.value;
// otherIdentifierObject?.identifierType?.uuid ===
// ("6e7203dd-0d6b-4c92-998d-fdc82a71a1b0" ||
// "9f6496ec-cf8e-4186-b8fc-aaf9e93b3406")
// ? otherIdentifierObject?.identifierType?.display?.split(" ")[0]
// : "Other";

// TODO: Consider reviewing these two lines as they might be duplicate with the afterwards logic
this.selectedIdentifierType.id =
otherIdentifierObject?.identifierType?.uuid;

this.patient[this.selectedIdentifierType?.id] =
otherIdentifierObject?.identifier;
// this.selectedIdentifierType.id = 6e7203dd-0d6b-4c92-998d-fdc82a71a1b0 sTAFF

// this.patientInformation?.patient?.identifiers.filter(
// (identifier) =>
// identifier.identifierType.display === "Student ID" ||
// "Staff ID"
// )[0]?.identifier;
if (
this.patientInformation &&
this.patientInformation?.patient?.identifiers?.length > 0
) {
this.definedIdentifierTypes.forEach((identifierType) => {
this.patient[identifierType.id] =
this.patientInformation?.patient?.identifiers?.find(
(identifier) =>
identifier.identifierType.uuid === identifierType.id
)?.identifier;
});
}

this.patient.dob =
this.patientInformation.patient?.person?.birthdate;
this.dateSet();
Expand Down Expand Up @@ -861,7 +878,11 @@ export class RegistrationAddComponent implements OnInit {
//TODO: add check for edit mode to see if can create or edit mode
if (this.editMode) {
this.registrationService
.updatePatient(patientPayload, this.patientInformation?.id)
.updatePatient(
patientPayload,
this.patientInformation?.id,
this.patientInformation?.patient?.identifiers
)
.subscribe(
(updatePatientResponse) => {
if (!updatePatientResponse?.error) {
Expand Down Expand Up @@ -1076,10 +1097,13 @@ export class RegistrationAddComponent implements OnInit {
}
}

onSelectOtherIdentifier(e: Event, identifier: any): void {
e.stopPropagation();
this.selectedIdentifierType = identifier;
this.patient[identifier.id] = null;
onSelectOtherIdentifier(e: MatSelectChange): void {
this.definedIdentifierTypes = e.value;
this.definedIdentifierTypes.forEach((identifierType: any) => {
if (!this.patient[identifierType.id]) {
this.patient[identifierType.id] = null;
}
});
}

getPatientType(value: string, occupationInfo) {
Expand Down
26 changes: 21 additions & 5 deletions ui/src/app/modules/registration/services/registration.services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { OpenmrsHttpClientService } from "src/app/shared/modules/openmrs-http-cl
import { ICARE_CONFIG } from "src/app/shared/resources/config";
import { Api } from "src/app/shared/resources/openmrs";
import { head } from "lodash";
import { Observable, of } from "rxjs";
import { Observable, of, zip } from "rxjs";

@Injectable({
providedIn: "root",
Expand All @@ -31,10 +31,26 @@ export class RegistrationService {
);
}

updatePatient(patientPayload, uuid) {
let url = `patient/${uuid}?v=full`;
return this.httpClient.post(url, patientPayload).pipe(
map((response) => response),
updatePatient(patientPayload, uuid, existingIdentifiers?: any[]) {
let url = `patient/${uuid}`;
const newIdentifiers =
patientPayload?.identifiers?.filter((identifier) => {
if (existingIdentifiers) {
return !existingIdentifiers.find(
(existingIdentifier) =>
existingIdentifier.identifier === identifier.identifier
);
}
return true;
}) || [];
// TODO: Manage update of identifiers
return zip(
this.httpClient.post(url, patientPayload),
...newIdentifiers.map((identifier) =>
this.httpClient.post(url + "/identifier", identifier)
)
).pipe(
map((responses) => responses[0]),
catchError((error) => of(error))
);
}
Expand Down

0 comments on commit 017561d

Please sign in to comment.