Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
AlmachiusBenedicto committed Jan 17, 2025
2 parents 4af0166 + f45f278 commit 92548e2
Show file tree
Hide file tree
Showing 4 changed files with 122 additions and 84 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,21 @@ export class PatientClinicalNotesSummaryComponent implements OnInit {
constructor(private store: Store<AppState>) {}

ngOnInit(): void {
this.observations$ = !this.forHistory
? this.store.pipe(select(getGroupedObservationByConcept))
: of(groupObservationByConcept(this.patientVisit?.observations));
if (!this.forHistory) {
this.observations$ = this.store.pipe(select(getGroupedObservationByConcept));
} else {
const groupedObservations = groupObservationByConcept(
this.patientVisit?.observations
);
const notes = this.patientVisit?.visit?.notes || ["No notes available"];
const services = this.patientVisit?.visit?.services || ["No services available"];

this.observations$ = of({
...groupedObservations,
visitNotes: notes,
serviceRecords: services,
});
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,7 @@ ${this.visitHistory?.visitStopDateTime?.date} at ${this.visitHistory?.visitStopD

frameDoc.document.write(`</tbody></table>`);


// -------------------Procedure orders-------------
if (
this.visitHistory?.visitOrderedData?.find(
Expand All @@ -630,8 +631,12 @@ ${this.visitHistory?.visitStopDateTime?.date} at ${this.visitHistory?.visitStopD
</thead>
<tbody>`);
}
this.visitHistory?.visitOrderedData?.forEach((visitData) => {
if (visitData?.category === "PROCEDURE_ORDER") {

// Visit note.....


this.visitHistory?.visitOrderedData?.forEach((visitData) => {
if (visitData?.category === "OBSERVATIONS") {
frameDoc.document.write(`
<tr><td>
${visitData?.concept?.display}
Expand Down Expand Up @@ -668,6 +673,48 @@ ${this.visitHistory?.visitStopDateTime?.date} at ${this.visitHistory?.visitStopD
: "-"
}
</td>
</tr>`);
}
});

//end of visit note

this.visitHistory?.visitOrderedData?.forEach((visitData) => {
if (visitData?.category === "PROCEDURE_ORDER") {
frameDoc.document.write(`
<tr><td>
${visitData?.concept?.display}
</td>
<td> ${visitData?.provider} on
${visitData?.date} ${visitData?.time}
</td> <td>
`);
//................Handle Empty or Undefined Data...............

if (visitData?.results?.length > 0) {
visitData.results.forEach((result) => {
if (!result?.value?.links?.uri) {
frameDoc.document.write(` ${result?.concept?.display || 'N/A'} -
${result?.value?.display || result?.value || 'N/A'}, &nbsp;&nbsp;`);
}
});
} else {
frameDoc.document.write(` Not Attended `);
}

//....................End of Handling Data..................
frameDoc.document.write(`</td>`);
frameDoc.document.write(`
<td>${
visitData?.results[0]?.provider?.display?.split("-")[1]
? visitData?.results[0]?.provider?.display?.split("-")[1] + "on"
: "-"
} ${
visitData?.results[0]?.obsDatetime
? formatDateToString(new Date(visitData?.results[0]?.obsDatetime))
: "-"
}
</td>
</tr>`);
}
});
Expand All @@ -694,15 +741,21 @@ ${this.visitHistory?.visitStopDateTime?.date} at ${this.visitHistory?.visitStopD
</thead>
<tbody>`);

visitData?.obs?.forEach((ob) => {
frameDoc.document.write(`<tr><td> ${ob?.concept?.display} </td><td>
${ob?.value?.display ? ob?.value?.display : ob?.value}
</td></tr>`);
// .............Snippet to process observation..............
if (visitData?.obs?.length > 0) {
visitData.obs.forEach((ob) => {
frameDoc.document.write(`<tr><td>${ob?.concept?.display || 'N/A'}</td><td>
${ob?.value?.display || ob?.value || 'N/A'}
</td></tr>`);
});
} else {
frameDoc.document.write(`<tr><td colspan="2">No Observations Found</td></tr>`);
}
});
}

frameDoc.document.write(`</tbody></table>`);
}
});
}
// this.visitHistory?.visitOrderedData?.forEach((visitData) => {
// if (visitData?.category === "OBSERVATIONS") {
// frameDoc.document.write(`<tr`);
Expand All @@ -716,8 +769,9 @@ ${this.visitHistory?.visitStopDateTime?.date} at ${this.visitHistory?.visitStopD
// }
// });

frameDoc.document.write(`</tbody></table>`);
if (this.visitHistory?.diagnoses?.PROVISIONAL?.length) {
//......Checking both provisional & confirmed are rendered.............

if (Array.isArray(this.visitHistory?.diagnoses?.PROVISIONAL) && this.visitHistory?.diagnoses?.PROVISIONAL.length) {
frameDoc.document.write(`<div>
<h4>Provisional Diagnoses</h4>
`);
Expand All @@ -738,6 +792,8 @@ ${this.visitHistory?.visitStopDateTime?.date} at ${this.visitHistory?.visitStopD
});
}

// ......End of Rendering.............

frameDoc.document.write(`
<div class="footer">
<div class="userDetails">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,12 @@
provider: provider$ | async
} as params"
>
<!-- Loading Indicator -->
<div *ngIf="!params?.visits?.length && loadingData || !params?.provider">
<mat-progress-bar mode="indeterminate"></mat-progress-bar>
</div>

<!-- Visits Display -->
<div *ngIf="params?.visits?.length && !loadingData && params?.provider">
<mat-vertical-stepper [linear]="false" #stepper>
<mat-step *ngFor="let visit of params?.visits">
Expand All @@ -26,16 +29,18 @@
to {{ visit?.visit?.stopDatetime | date: "dd-MM-yyyy HH:mm:ss" }}
</span>
<span *ngIf="!visit?.visit?.stopDatetime">
<i>(On going visit)</i>
<i>(On-going visit)</i>
</span>
</ng-template>

<!-- <div *ngFor="let form of params?.customForms">
<div>{{ form.name }}</div>
</div> -->
<!-- Visit Notes Section -->
<div class="visit-notes">
<strong>Visit Notes:</strong>
<p>{{ visit?.notes || "No notes available" }}</p>
</div>
<!-- End of Visit Notes Section -->

<!-- Patient History Data -->
<app-patient-history-data
[visit]="visit"
[forms]="params?.customForms"
Expand All @@ -49,8 +54,7 @@
[specificDrugConceptUuid]="params?.specificDrugConceptUuid"
></app-patient-history-data>



<!-- Capture Form Data -->
<app-capture-form-data
*ngIf="params?.doctorsIPDRoundForm"
[form]="params?.doctorsIPDRoundForm"
Expand All @@ -59,37 +63,19 @@
(formDataUpdate)="onDoctorsIPDRoundCommentsFormUpdate($event)"
></app-capture-form-data>


<!-- Saved Form Data (Optional Display) -->
<ng-container *ngIf="savedFormData">
<p>Saved Form Data: {{ savedFormData | json }}</p>
</ng-container>

<div class="mt-2 w-100 d-flex justify-content-end">
<!-- <button
mat-flat-button
color="primary"
(click)="onSave($event, params?.doctorsIPDRoundForm,params?.provider, visit)"
>
Save
</button> -->
<!-- Optional Save Button -->
</div>


</mat-step>
</mat-vertical-stepper>
<!-- <div class="history overflow-auto">
<ng-container *ngFor="let visit of params?.visits">
<app-patient-history-data
[visit]="visit"
[forms]="params?.customForms"
[generalPrescriptionOrderType]="params?.generalPrescriptionOrderType"
[prescriptionArrangementFields]="params?.prescriptionArrangementFields"
[specificDrugConceptUuid]="params?.specificDrugConceptUuid"
></app-patient-history-data>
</ng-container>
</div> -->
</div>

<!-- No Visits Found Message -->
<div *ngIf="!params?.visits?.length && !loadingData">
<h4 class="text-center">
{{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ export class PatientHistoryComponent implements OnInit {
@Input() patient: any;
@Input() location: any;
saving: boolean = false;

formData: any;
visits$: Observable<any>;
customForms$: Observable<any>;
Expand All @@ -59,23 +58,11 @@ export class PatientHistoryComponent implements OnInit {
allForms$: Observable<any>;
loadingData: boolean = false;
facilityDetails$: Observable<any>;
currentUser$: Observable<{
userPrivileges: any;
links?: { rel?: string; uri?: string }[];
uuid?: string;
display?: string;
username?: string;
systemId?: string;
userProperties?: object;

// person?: PersonGetRef;
// privileges?: PrivilegeGetRef[];
// roles?: RoleGetRef[];
provider?: { uuid?: string; display?: string };
}>;
currentUser$: Observable<any>;
provider$: Observable<any>;

doctorsIPDRoundForm$: Observable<any>;

constructor(
private visitsService: VisitsService,
private store: Store<AppState>,
Expand All @@ -84,19 +71,30 @@ export class PatientHistoryComponent implements OnInit {
) {}

ngOnInit(): void {
this.initForm();
this.loadData();
}

private initForm(): void {
// Initialize the form with necessary fields and validators
this.form = new FormGroup({
fieldName: new FormControl('', Validators.required), // example field
});
}

private loadData(): void {
this.loadingData = true;
this.customForms$ = this.store.select(getAllForms);
this.facilityDetails$ = this.store.select(getParentLocation);
this.currentUser$ = this.store.select(getCurrentUserDetails);
this.provider$ = this.store.select(getProviderDetails);

// Fetch system settings for prescription types
this.generalPrescriptionOrderType$ =
this.systemSettingsService.getSystemSettingsByKey(
"iCare.clinic.genericPrescription.orderType"
);

this.prescriptionArrangementFields$ = this.systemSettingsService
.getSystemSettingsByKey("iCare.clinic.prescription.arrangement")
.pipe(
Expand All @@ -122,6 +120,7 @@ export class PatientHistoryComponent implements OnInit {
};
})
);

this.specificDrugConceptUuid$ = this.systemSettingsService
.getSystemSettingsByKey(
"iCare.clinic.genericPrescription.specificDrugConceptUuid"
Expand All @@ -142,16 +141,17 @@ export class PatientHistoryComponent implements OnInit {
}
})
);

this.visits$ = this.visitsService
.getAllPatientVisits(this.patient?.uuid, true)
.pipe(
map((response) => {
this.loadingData = false;
console.log('Fetched visits:',response);
console.log('Fetched visits:', response); // Debugging
if (!response?.error) {
return response?.map((visit) => {
let obs = [];
visit?.visit?.encounters.forEach((encounter) => {
visit?.visit?.encounters?.forEach((encounter) => {
(encounter?.obs || []).forEach((observation) => {
obs = [
...obs,
Expand All @@ -166,14 +166,13 @@ export class PatientHistoryComponent implements OnInit {
];
});
});
// Add service records
const serviceRecords = visit?.visit?.services || []; // Example service records
return {
visit: visit?.visit,
notes: visit?.visit?.notes || "No notes available", //Add visit notes
notes: visit?.visit?.notes || "No notes available", // Add visit notes
obs: obs,
serviceRecords: serviceRecords,
orders: [
...visit?.visit?.encounters.map((encounter) => {
...visit?.visit?.encounters?.map((encounter) => {
return (encounter?.orders || []).map((order) => {
return {
...order,
Expand All @@ -190,25 +189,8 @@ export class PatientHistoryComponent implements OnInit {
}
})
);

// this.getIPDRoundDoctorsForm();
}

// getIPDRoundDoctorsForm(): void {
// this.systemSettingsService
// .getSystemSettingsByKey("iCare.forms.doctorsIPDRound.uuid")
// .subscribe((doctorsIPDRoundFormUuid: string) => {
// if (doctorsIPDRoundFormUuid) {
// this.store.dispatch(
// loadCustomOpenMRSForm({ formUuid: doctorsIPDRoundFormUuid })
// );
// this.doctorsIPDRoundForm$ = this.store.select(
// getCustomOpenMRSFormById(doctorsIPDRoundFormUuid)
// );
// }
// });
// }

onDoctorsIPDRoundCommentsFormUpdate(formValue: FormValue): void {
console.log(formValue.getValues());
this.formData = formValue.getValues();
Expand All @@ -222,7 +204,8 @@ export class PatientHistoryComponent implements OnInit {
value: this.formData[key]?.value,
};
});
let encounterObject = {

const encounterObject = {
patient: this.patient?.uuid,
encounterType: form?.encounterType?.uuid,
location: this.location?.uuid,
Expand All @@ -243,7 +226,7 @@ export class PatientHistoryComponent implements OnInit {
.saveEncounterWithObsDetails(encounterObject)
.subscribe((res) => {
if (res) {
this.loadData();
this.loadData(); // Reload data after saving
}
});
}
Expand Down

0 comments on commit 92548e2

Please sign in to comment.