From c6757355627f1fbf7143996ecd66aacf1d0cff42 Mon Sep 17 00:00:00 2001 From: 5Amogh Date: Thu, 12 Feb 2026 15:43:56 +0530 Subject: [PATCH] fix: amm-2174 n-1 date issues and habit field refelction issues fixed --- .../nurse-doctor/anc/anc.component.ts | 50 ++++++++++++++ .../personal-history.component.ts | 68 +++++++++++++------ .../nurse-doctor/pnc/pnc.component.ts | 22 +++++- .../shared/services/nurse.service.ts | 58 +++++++++++++--- 4 files changed, 167 insertions(+), 31 deletions(-) diff --git a/src/app/app-modules/nurse-doctor/anc/anc.component.ts b/src/app/app-modules/nurse-doctor/anc/anc.component.ts index 17d68ec..82e3ed3 100644 --- a/src/app/app-modules/nurse-doctor/anc/anc.component.ts +++ b/src/app/app-modules/nurse-doctor/anc/anc.component.ts @@ -134,6 +134,46 @@ export class AncComponent implements OnInit, OnChanges, OnDestroy, DoCheck { visitCode: this.sessionstorage.getItem('visitCode'), }; + const immunizationForm = patientANCForm.get('patientANCImmunizationForm'); + + if (immunizationForm) { + const ttDateFields = [ + 'dateReceivedForTT_1', + 'dateReceivedForTT_2', + 'dateReceivedForTT_3', + ]; + + ttDateFields.forEach((field) => { + const value = immunizationForm.get(field)?.value; + + if (value) { + immunizationForm.patchValue({ + [field]: this.normalizeToUTCMidnight(new Date(value)), + }); + } + }); + } + + const ancDetailsForm = patientANCForm.get('patientANCDetailsForm'); + + if (ancDetailsForm) { + const lmpDateValue = ancDetailsForm.get('lmpDate')?.value; + + if (lmpDateValue) { + ancDetailsForm.patchValue({ + lmpDate: this.normalizeToUTCMidnight(new Date(lmpDateValue)), + }); + } + + const expDelDtValue = ancDetailsForm.get('expDelDt')?.value; + + if (expDelDtValue) { + ancDetailsForm.patchValue({ + expDelDt: this.normalizeToUTCMidnight(new Date(expDelDtValue)), + }); + } + } + this.updateANCDetailsSubs = this.doctorService .updateANCDetails(patientANCForm, temp) .subscribe( @@ -152,6 +192,16 @@ export class AncComponent implements OnInit, OnChanges, OnDestroy, DoCheck { ); } + private normalizeToUTCMidnight(date: Date | null | undefined): string | null { + if (!date) return null; + + const d = new Date(date); + const utcDate = new Date( + Date.UTC(d.getFullYear(), d.getMonth(), d.getDate(), 0, 0, 0, 0) + ); + return utcDate.toISOString(); + } + getHRPDetails() { const beneficiaryRegID = this.sessionstorage.getItem('beneficiaryRegID'); const visitCode = this.sessionstorage.getItem('visitCode'); diff --git a/src/app/app-modules/nurse-doctor/history/general-opd-history/personal-history/personal-history.component.ts b/src/app/app-modules/nurse-doctor/history/general-opd-history/personal-history/personal-history.component.ts index 1817385..89290fb 100644 --- a/src/app/app-modules/nurse-doctor/history/general-opd-history/personal-history/personal-history.component.ts +++ b/src/app/app-modules/nurse-doctor/history/general-opd-history/personal-history/personal-history.component.ts @@ -213,6 +213,15 @@ export class GeneralPersonalHistoryComponent history.data.PersonalHistory ) { this.personalHistoryData = history.data.PersonalHistory; + if ( + this.personalHistoryData && + this.personalHistoryData.riskySexualPracticesStatus !== null + ) { + this.personalHistoryData.riskySexualPracticesStatus = + this.personalHistoryData.riskySexualPracticesStatus == '1' + ? true + : false; + } this.generalPersonalHistoryForm.patchValue(this.personalHistoryData); this.handlePersonalTobaccoHistoryData(); this.handlePersonalAlcoholHistoryData(); @@ -420,44 +429,63 @@ export class GeneralPersonalHistoryComponent const formArray = this.generalPersonalHistoryForm.controls[ 'allergicList' ] as FormArray; + if (this.personalHistoryData && this.personalHistoryData.allergicList) { const temp = this.personalHistoryData.allergicList.slice(); + while (formArray.length > 0) { + formArray.removeAt(0); + } + + for (let i = 0; i < temp.length; i++) { + formArray.push(this.initAllergyList()); + } + + this.allerySelectList = []; + this.previousSelectedAlleryList = []; + for (let i = 0; i < temp.length; i++) { const allergyType = this.allergyMasterData.filter((item) => { return item.allergyType === temp[i].allergyType; }); + if (allergyType.length > 0) temp[i].allergyType = allergyType[0]; - if (this.masterData.AllergicReactionTypes !== undefined) { - temp[i].typeOfAllergicReactions = - this.masterData.AllergicReactionTypes.filter((item: any) => { - let flag = false; - temp[i].typeOfAllergicReactions.forEach((element: any) => { - if (element.name === item.name) flag = true; - }); - return flag; + temp[i].typeOfAllergicReactions = + this.masterData.AllergicReactionTypes.filter((item: any) => { + let flag = false; + temp[i].typeOfAllergicReactions.forEach((element: any) => { + if (element.name === item.name) flag = true; }); - } + return flag; + }); if (temp[i].otherAllergicReaction) temp[i].enableOtherAllergy = true; + const selectedAllergies = temp + .filter((t: any, idx: any) => idx !== i && t.allergyType) + .map((t: any) => t.allergyType.allergyType); + + const availableAllergies = this.allergyMasterData.filter( + (item) => !selectedAllergies.includes(item.allergyType), + ); + + this.allerySelectList.push(availableAllergies.slice()); + if (temp[i].allergyType) { - const k: any = formArray.get('' + i); + this.previousSelectedAlleryList[i] = temp[i].allergyType; + } + + const k: any = formArray.get('' + i); + if (k) { k.patchValue(temp[i]); k.markAsTouched(); - k.markAsDirty(); - this.filterAlleryList(temp[i].allergyType, i); - if ( - k?.get('snomedTerm')?.value !== null && - k?.get('typeOfAllergicReactions')?.value !== null - ) { - k?.get('snomedTerm')?.enable(); - k?.get('typeOfAllergicReactions')?.enable(); + + if (temp[i].allergyType) { + k.get('snomedTerm')?.enable(); + k.get('typeOfAllergicReactions')?.enable(); } } - - if (i + 1 < temp.length) this.addAllergy(); } } } diff --git a/src/app/app-modules/nurse-doctor/pnc/pnc.component.ts b/src/app/app-modules/nurse-doctor/pnc/pnc.component.ts index 13e14f6..49bed08 100644 --- a/src/app/app-modules/nurse-doctor/pnc/pnc.component.ts +++ b/src/app/app-modules/nurse-doctor/pnc/pnc.component.ts @@ -158,13 +158,25 @@ export class PncComponent implements OnInit, DoCheck, OnChanges, OnDestroy { })[0]; } - tempPNCData.dDate = new Date(tempPNCData.dateOfDelivery); + tempPNCData.dDate = this.normalizeToUTCMidnight( + new Date(tempPNCData.dateOfDelivery), + ); const patchPNCdata = Object.assign({}, tempPNCData); this.patientPNCForm.patchValue(tempPNCData); }); } + private normalizeToUTCMidnight(date: Date | null | undefined): string | null { + if (!date) return null; + + const d = new Date(date); + const utcDate = new Date( + Date.UTC(d.getFullYear(), d.getMonth(), d.getDate(), 0, 0, 0, 0) + ); + return utcDate.toISOString(); + } + updatePatientPNC(patientPNCForm: any) { const temp = { beneficiaryRegID: this.sessionstorage.getItem('beneficiaryRegID'), @@ -174,6 +186,14 @@ export class PncComponent implements OnInit, DoCheck, OnChanges, OnDestroy { visitCode: this.sessionstorage.getItem('visitCode'), }; + const dDate = patientPNCForm.get('dDate')?.value; + if (dDate) { + patientPNCForm.patchValue({ + dateOfDelivery: this.normalizeToUTCMidnight(new Date(dDate)), + dDate: this.normalizeToUTCMidnight(new Date(dDate)), + }); + } + this.doctorService.updatePNCDetails(patientPNCForm, temp).subscribe( (res: any) => { if (res.statusCode === 200 && res.data !== null) { diff --git a/src/app/app-modules/nurse-doctor/shared/services/nurse.service.ts b/src/app/app-modules/nurse-doctor/shared/services/nurse.service.ts index 9dcdb4a..b73a8d5 100644 --- a/src/app/app-modules/nurse-doctor/shared/services/nurse.service.ts +++ b/src/app/app-modules/nurse-doctor/shared/services/nurse.service.ts @@ -694,6 +694,17 @@ export class NurseService { }; } + private normalizeToUTCMidnight(date: Date | null | undefined): string | null { + if (!date) return null; + + const d = new Date(date); + + const utcDate = new Date( + Date.UTC(d.getFullYear(), d.getMonth(), d.getDate(), 0, 0, 0, 0) + ); + return utcDate.toISOString(); + } + postANCDetailForm(patientANCForm: any, benVisitID: any) { const detailedANC = JSON.parse( JSON.stringify(patientANCForm.controls.patientANCDetailsForm.value), @@ -702,11 +713,15 @@ export class NurseService { JSON.stringify(patientANCForm.controls.obstetricFormulaForm.value), ); if (detailedANC.lmpDate) { - const lmpDate = new Date(detailedANC.lmpDate); - const adjustedDate = new Date( - lmpDate.getTime() - lmpDate.getTimezoneOffset() * 60000, + detailedANC.lmpDate = this.normalizeToUTCMidnight( + new Date(detailedANC.lmpDate) + ); + } + + if (detailedANC.expDelDt) { + detailedANC.expDelDt = this.normalizeToUTCMidnight( + new Date(detailedANC.expDelDt) ); - detailedANC.lmpDate = adjustedDate.toISOString(); } const combinedANCForm = Object.assign({}, detailedANC, { @@ -726,7 +741,29 @@ export class NurseService { } postANCImmunizationForm(patientANCImmunizationForm: any, benVisitID: any) { - const immunizationForm = Object.assign({}, patientANCImmunizationForm, { + const immunizationFormValue = JSON.parse( + JSON.stringify(patientANCImmunizationForm) + ); + + if (immunizationFormValue.dateReceivedForTT_1) { + immunizationFormValue.dateReceivedForTT_1 = this.normalizeToUTCMidnight( + new Date(immunizationFormValue.dateReceivedForTT_1) + ); + } + + if (immunizationFormValue.dateReceivedForTT_2) { + immunizationFormValue.dateReceivedForTT_2 = this.normalizeToUTCMidnight( + new Date(immunizationFormValue.dateReceivedForTT_2) + ); + } + + if (immunizationFormValue.dateReceivedForTT_3) { + immunizationFormValue.dateReceivedForTT_3 = this.normalizeToUTCMidnight( + new Date(immunizationFormValue.dateReceivedForTT_3) + ); + } + + const immunizationForm = Object.assign({}, immunizationFormValue, { beneficiaryRegID: this.sessionstorage.getItem('beneficiaryRegID'), benVisitID: benVisitID, providerServiceMapID: this.sessionstorage.getItem('providerServiceID'), @@ -1264,11 +1301,7 @@ export class NurseService { if (!temp.lMPDate) { temp.lMPDate = undefined; } else { - const lmpDate = new Date(temp.lMPDate); - const adjustedDate = new Date( - lmpDate.getTime() - lmpDate.getTimezoneOffset() * 60000, - ); - temp.lMPDate = adjustedDate.toISOString(); + temp.lMPDate = this.normalizeToUTCMidnight(new Date(temp.lMPDate)); } const menstrualHistoryData = Object.assign({}, temp, otherDetails); @@ -1894,6 +1927,11 @@ export class NurseService { temp.newBornHealthStatus = temp.newBornHealthStatus.newBornHealthStatus; } + if (temp.dDate) { + temp.dateOfDelivery = this.normalizeToUTCMidnight(new Date(temp.dDate)); + temp.dDate = temp.dateOfDelivery; + } + const patientPNCDetails = Object.assign({}, temp, { beneficiaryRegID: this.sessionstorage.getItem('beneficiaryRegID'), benVisitID: benVisitID,