diff --git a/src/app/etl-api/family-testing-resource.service.ts b/src/app/etl-api/family-testing-resource.service.ts index 923e0b159..612a80462 100644 --- a/src/app/etl-api/family-testing-resource.service.ts +++ b/src/app/etl-api/family-testing-resource.service.ts @@ -130,9 +130,13 @@ export class FamilyTestingService { ); } - public getPatientEncounters(patientUuid: string) { - const familyTestingEncounterTypeUuid = - '975ae894-7660-4224-b777-468c2e710a2a'; + public getPatientEncounters( + patientUuid: string, + isFamilyTestingEncounter: boolean + ) { + const familyTestingEncounterTypeUuid = isFamilyTestingEncounter + ? '3fbc8512-b37b-4bc2-a0f4-8d0ac7955127' + : '5a58f6f5-f5a6-47eb-a644-626abd83f83b'; return this.http.get( `${this.amrsUrl()}encounter?patient=${patientUuid}&encounterType=${familyTestingEncounterTypeUuid}` ); diff --git a/src/app/patient-dashboard/common/patient-banner/patient-banner.component.ts b/src/app/patient-dashboard/common/patient-banner/patient-banner.component.ts index 6b90d1e65..81349130a 100644 --- a/src/app/patient-dashboard/common/patient-banner/patient-banner.component.ts +++ b/src/app/patient-dashboard/common/patient-banner/patient-banner.component.ts @@ -52,6 +52,7 @@ export class PatientBannerComponent implements OnInit, OnDestroy, OnChanges { public isPatientEligibleForOtz = false; public isPatientVerified = false; public verificationStatus = false; + private isFamilyTestingEncounter = false; modalRef: BsModalRef; modalConfig = { backdrop: true, @@ -121,11 +122,32 @@ export class PatientBannerComponent implements OnInit, OnDestroy, OnChanges { ); this.getHIVPatient(_.filter(patient.enrolledPrograms, 'isEnrolled')); this.familyTestingService - .getPatientEncounters(this.patient.uuid) + .getPatientEncounters(this.patient.uuid, true) .subscribe((response: any) => { - this.familyTestingEncounterUuid = _.first(response.results); + if (response.results && response.results.length > 0) { + this.isFamilyTestingEncounter = true; + this.familyTestingEncounterUuid = _.first( + response.results + ); + } else { + this.isFamilyTestingEncounter = false; + } }); - this.getPatientEncounters(); + + setTimeout(async () => { + if (!this.isFamilyTestingEncounter) { + this.familyTestingService + .getPatientEncounters(this.patient.uuid, false) + .subscribe((response: any) => { + if (response.results && response.results.length > 0) { + this.familyTestingEncounterUuid = _.first( + response.results + ); + } + }); + } + this.getPatientEncounters(this.isFamilyTestingEncounter); + }, 4000); } else { this.searchIdentifiers = undefined; this.birthdate = undefined; @@ -347,7 +369,6 @@ export class PatientBannerComponent implements OnInit, OnDestroy, OnChanges { this.displayContacts = false; } public updateContacts() { - console.log('this.patient.uuid ', this.patient.uuid); const encounterUuid = _.first(this.patientEncounters).uuid; const familyPartnerHistoryForm = `3fbc8512-b37b-4bc2-a0f4-8d0ac7955127`; const url = `/patient-dashboard/patient/${this.patient.uuid}/general/general/formentry/${familyPartnerHistoryForm}`; @@ -361,9 +382,10 @@ export class PatientBannerComponent implements OnInit, OnDestroy, OnChanges { this.displayContacts = false; } - public getPatientEncounters() { - const familyAndPartnerTestingFormUuid = - '3fbc8512-b37b-4bc2-a0f4-8d0ac7955127'; + public getPatientEncounters(isFamilyTestingEncounter: boolean) { + const familyAndPartnerTestingFormUuid = isFamilyTestingEncounter + ? '3fbc8512-b37b-4bc2-a0f4-8d0ac7955127' + : '8b196bad-6ee5-4290-b1be-101539e04290'; this.encounterResourceService .getEncountersByPatientUuid(this.patient.uuid, false, null) .pipe(take(1))