import { differenceInYears } from "date-fns"; import { SharedPDFService } from "../../shared/shared-pdf.service"; import { MyDate } from "../../utils/my-date"; import { TrUtils } from "../../utils/tr-utils"; export class ConsultationPDFService { static GetConsultationPrint(CnstData: any, Remarks: any) { let dd: any = { info: { title: 'Consultation', }, footer: SharedPDFService.FooterContent(CnstData), header: function (currentPage: any, pageCount: any, pageSize: any) { return { text: currentPage.toString() + ' of ' + pageCount, alignment: 'right', marginRight: 25, fontSize: 8, marginTop: 2 }; }, pageMargins: [35, 15, 15, 80], pageSize: 'A4', content: [ // { text: CnstData.Entity.CName, style: ['headerstyle'], alignment: 'center', fontSize: 20 }, // { text: 'Expiring Drugs (' + this.GetDate(DatesDetails) + ')', style: ['headerstyle'], alignment: 'center', fontSize: 12 }, this.GetMainHeaderDetails(CnstData, CnstData.Entity, CnstData.HeaderName, CnstData.Image, CnstData.HColor, CnstData.AColor, null), { columns: [this.GetHeight(CnstData), this.GetWeight(CnstData), this.GetBP(CnstData), this.GetTemperature(CnstData) , this.GetSPO2(CnstData), this.GetPulse(CnstData)], fontSize: 8, marginTop: 5 }, this.GetComplaintsTable(CnstData.Comps, 'Complaints:'), this.GetDiagnosisTable(CnstData.Diags, 'Diagnosis:'), this.GetRxTable(CnstData.Rx, Remarks), this.GetComplaintsTable(CnstData.Tests, 'Lab Investigations:'), this.GetDiagnosisTable(CnstData.Advice, 'Advices:'), // { text: 'Complaints:', bold: true, marginTop: 5, fontSize: 12 }, // { text: this.GetComplaints(CnstData.Comps), fontSize: 9, marginTop: 5, marginBottom: 10 }, // { text: 'Diagnosis:', bold: true, marginTop: 5, fontSize: 12 }, // { text: this.GetDiagnosis(CnstData.Diags), fontSize: 9, marginTop: 5, marginBottom: 10 }, // { text: 'Rx:', bold: true, fontSize: 12 }, // this.GetItemsTable(CnstData.Rx, Remarks), // { text: 'Lab Investigations:', bold: true, marginTop: 5, fontSize: 12 }, // { text: this.GetComplaints(CnstData.Tests), fontSize: 9, marginTop: 5, marginBottom: 10 }, // { text: 'Advices:', bold: true, marginTop: 5, fontSize: 12 }, // { text: this.GetDiagnosis(CnstData.Advice), fontSize: 9, marginTop: 5, marginBottom: 10 }, this.CustomSection(CnstData.Sections) // this.GetSignatures(CnstData.Entity.CName, CnstData.Type, CnstData.For), ], styles: { temp2header: { fontSize: 15, bold: true, alignment: 'left', // margin: [0, 10, 0, 0], }, headerstyle: { fontSize: 9 }, Sign: { fontSize: 8, margin: [0, 30, 0, 5] }, forCompany: { marginRight: 5, marginTop: 10, fontSize: 9, alignment: 'left' }, tableheader: { bold: true, margin: [0, 1, 0, 5], alignment: 'center' }, tableheader1: { bold: true, margin: [0, 2, 0, 2], alignment: 'center' }, tableExample: { fontSize: 9 }, ws_adrs_left: { fontSize: 8, alignment: 'left', } } }; return dd; } static GetRxTable(Rx: any, Remarks: any) { if (!TrUtils.IsNull(Rx) && Rx.length !== 0) { return { stack: [ { text: 'Rx:', bold: true, fontSize: 12 }, this.GetItemsTable(Rx, Remarks),] } } else { return {}; } } static GetDiagnosisTable(diagnosis: any, heading: any) { if (!TrUtils.IsNull(diagnosis) && diagnosis.length !== 0) { return { stack: [ { text: heading, bold: true, marginTop: 5, fontSize: 12 }, { text: this.GetDiagnosis(diagnosis), fontSize: 9, marginTop: 5, marginBottom: 10 }, ] } } else { return {}; } } static GetComplaintsTable(complaints: any, heading: any) { if (!TrUtils.IsNull(complaints) && complaints.length !== 0) { return { stack: [ { text: heading, bold: true, marginTop: 5, fontSize: 12 }, { text: this.GetComplaints(complaints), fontSize: 9, marginTop: 5, marginBottom: 10 }, ] } } else { return {}; } } static CustomSection(sections: any) { let Sec: any = []; sections?.forEach((sec: any) => { Sec.push({ text: sec.Name + ' :', bold: true, style: 'header', marginTop: 5, marginBottom: 5 }); let UnOrderlist: any = []; sec.Items?.forEach((item: any) => { UnOrderlist.push({ style: 'tableExample', table: { body: [ [{ text: item.Desc, bold: true }, '-', { text: item.Notes }] ] }, layout: 'noBorders' }); }); Sec.push({ ul: UnOrderlist, fontSize: 10 }); }); return Sec; } static GetWeight(CnstData: any) { if (!TrUtils.IsNull(CnstData?.Vitals?.Weight) && !TrUtils.IsNull(CnstData?.Vitals?.Weight?.V)) { return { text: 'Weight :' + CnstData?.Vitals?.Weight?.V + ' kg', Width: 80 }; } else { return { text: 'Weight :', Width: 80 }; } } static GetTemperature(CnstData: any) { if (!TrUtils.IsNull(CnstData?.Vitals?.Temp) && !TrUtils.IsNull(CnstData?.Vitals?.Temp?.V)) { return { text: 'Temperature :' + CnstData?.Vitals?.Temp?.V + ' F', Width: 80 }; } else { return { text: 'Temperature :', Width: 80 }; } } static GetSPO2(CnstData: any) { if (!TrUtils.IsNull(CnstData?.Vitals?.SPO2) && !TrUtils.IsNull(CnstData?.Vitals?.SPO2?.V)) { return { text: 'SPO2 :' + CnstData?.Vitals?.SPO2?.V + ' mmHg', Width: 80 }; } else { return { text: 'SPO2 :', Width: 80 }; } } static GetPulse(CnstData: any) { if (!TrUtils.IsNull(CnstData?.Vitals?.Pulse) && !TrUtils.IsNull(CnstData?.Vitals?.Pulse?.V)) { return { text: 'Pulse :' + CnstData?.Vitals?.Pulse?.V + ' bpm', Width: 80 }; } else { return { text: 'Pulse :', Width: 80 }; } } static GetHeight(CnstData: any) { if (!TrUtils.IsNull(CnstData?.Vitals?.Height) && !TrUtils.IsNull(CnstData?.Vitals?.Height?.V)) { return { text: 'Height :' + CnstData?.Vitals?.Height?.V + ' '+ CnstData?.Vitals?.Height?.U, Width: 80 }; } else { return { text: 'Height :', Width: 80 }; } } static GetBP(CnstData: any) { if (!TrUtils.IsNull(CnstData?.Vitals?.BP) && !TrUtils.IsNull(CnstData?.Vitals?.Height?.U)) { return { text: 'BP :' + CnstData?.Vitals?.BP?.V + ' mmHg', Width: 80 }; } else { return { text: 'BP :', Width: 80 }; } } static GetMainHeaderDetails(CnstData: any, Entity: any, HeaderName: any, Image: any, HColor: any, AColor: any, text: any) { return [ this.GetHeaderBasedOnCondition(CnstData, Entity, HeaderName, Image, HColor, AColor, text), SharedPDFService.HeaderAfterLine1(), { columns: [{ stack: [{ text: CnstData.Pat.Name, fontSize: 10, marginTop: 5, bold: true }, { text: CnstData.Pat.Code + ' | ' + this.DifferenceInYears(CnstData.Pat.DOB, Entity.User.TZ) + ' | ' + CnstData.Pat.Sex + this.GetPhoneNumber(CnstData?.Pat?.Ph), fontSize: 10, marginBottom: 5 }] }, { stack: [ { text: this.GetCnsltDate(CnstData, Entity.User), style: ['headerstyle'] }], marginTop: 5, width: 120 } ] } // { text: CnstData.Pat.Name, fontSize: 10, marginTop: 5 }, // { text: CnstData.Pat.Code + ' | ' + this.DifferenceInYears(CnstData.Pat.DOB) + ' | ' + CnstData.Pat.Sex + this.GetPhoneNumber(CnstData?.Pat?.Ph), fontSize: 10, marginBottom: 5 }, ]; } static GetCnsltDate(CnstData: any, User: any) { if (!TrUtils.IsNull(CnstData.ClDate)) { return MyDate.GetWeekDateAndTime(CnstData.ClDate, User.TZ); } else { return MyDate.GetWeekDateAndTime(CnstData.CrDate, User.TZ); } } static GetHeaderBasedOnCondition(CnstData: any, Entity: any, HeaderName: any, Image: any, HColor: any, AColor: any, text: any) { if (Entity.Header === 2) { return { columns: [ SharedPDFService.GetConsultationMainHeader(Entity, null, AColor, HColor, text), { stack: [{ text: CnstData?.Doc?.Sltn + ' ' + CnstData?.Doc?.Name, fontSize: 15, bold: true, alignment: 'right' }, { text: CnstData?.Doc?.Intro1, fontSize: 9, alignment: 'right' }, { text: CnstData?.Doc?.Intro2, fontSize: 9, alignment: 'right' }, { text: CnstData?.Doc?.Intro3, fontSize: 9, alignment: 'right' }, { text: 'Registration ID- ' + CnstData?.Doc?.CounReg, fontSize: 9, alignment: 'right', marginBottom: 5 }], width: '40%', marginTop: 15 } ] }; } else { return { columns: [SharedPDFService.GetImage(Image, Entity.Header.ShowLogo), { stack: [{ text: CnstData?.Doc?.Sltn + ' ' + CnstData?.Doc?.Name, fontSize: 15, alignment: 'right', bold: true }, { text: CnstData?.Doc?.Intro1, fontSize: 9, alignment: 'right' }, { text: CnstData?.Doc?.Intro2, fontSize: 9, alignment: 'right' }, { text: CnstData?.Doc?.Intro3, fontSize: 9, alignment: 'right' }, { text: 'Registration ID- ' + CnstData?.Doc?.CounReg, fontSize: 9, alignment: 'right', marginBottom: 5 }], marginTop: 25 }] }; } } static GetPhoneNumber(phone: any) { if (!TrUtils.IsNull(phone)) { return ' | ' + phone; } else { return ''; } } static DifferenceInYears(DOB: any, TZ: any) { if (TrUtils.IsNull(DOB)) { return 'DOB Not Specified'; } let Datei: any = MyDate.GetDateTimeNowInUTC(TZ); const result = differenceInYears(Datei, new Date(DOB)); return result + ' Years'; } static GetDiagnosis(Diags: any) { let Diagnosis: any = ''; Diags?.forEach((item: any, index: any) => { Diagnosis = Diagnosis + item.Desc; if ((index + 1) !== Diags.length) { Diagnosis = Diagnosis + ', '; } }); return Diagnosis; } static GetComplaints(Comps: any) { let Complaints: any = ''; Comps?.forEach((item: any, index: any) => { Complaints = Complaints + item.Desc; if ((index + 1) !== Comps.length) { Complaints = Complaints + ', '; } }); return Complaints; } // static GetDate(DatesDetails: any) { // if (DatesDetails.Date === 'CustomRange') { // return MyDate.GetWeekAndDate(DatesDetails.StDate) + ' - ' + MyDate.GetWeekAndDate(DatesDetails.EnDate); // } else { // return 'till ' + MyDate.GetWeekAndDate(DatesDetails.EnDate); // } // } static CustomerAndVehicleDetailsAfterLine() { return { canvas: [ { type: 'line', lineColor: 'gray', x1: 0, y1: 0, x2: 575, y2: 0, lineWidth: 1 } ] }; } static GetSignatures(CName: any, For: any, Type: any) { return { columns: [{ stack: [ this.CompanyName(CName), ] }], }; } static CompanyName(CName: any) { return { style: 'forCompany', text: ['For ', { text: CName, }], }; } static GetItemsTable(Items: any, Remarks: any) { if (!TrUtils.IsNull(Items)) { return { style: 'tableExample', marginTop: 3, marginBottom: 5, table: { widths: [20, '*', 45, 50, 200], headerRows: 1, body: this.BuildTableBodyForLaborAndParts(Items, Remarks) }, layout: { hLineWidth: function (i: any, node: any) { return (i === 0 || i === 1 || i === node.table.body.length) ? 1 : 0.5; }, vLineWidth: function (i: any, node: any) { return (i === 0 || i === node.table.widths.length) ? 1 : 0.5; }, // hLineStyle: function (i, node) { // return (i === 0 || i === 1) ? { dash: { length: 5, space: 5 } } : null; // }, hLineColor: function (i: any, node: any) { return (i === 0 || i === 1 || i === node.table.body.length) ? 'gray' : 'lightgrey'; }, vLineColor: function (i: any, node: any) { return 'gray'; }, } }; } else { return {}; } } static BuildTableBodyForLaborAndParts(Items: any, Remarks: any) { let body: any = this.GetHeaderNames(); Items?.forEach((item: any, index: any) => { let dataRow: any = []; dataRow.push({ text: index + 1, rowSpan: item.Dosage.length }); dataRow.push({ text: item.Desc, bold: true, rowSpan: item.Dosage.length }); item.Dosage.forEach((dose: any, index: any) => { if (index === 0) { dataRow.push({ text: dose.Dose, alignment: 'left', style: ['headerstyle'], }); dataRow.push({ text: dose.Dur, alignment: 'left', style: ['headerstyle'], }); dataRow.push({ text: Remarks[dose.Dose], alignment: 'left', style: ['headerstyle'], }); body.push(dataRow); } else { let dataRow1: any = []; dataRow1.push({ text: dose.Dose, alignment: 'left', style: ['headerstyle'], }); dataRow1.push({ text: dose.Dur, alignment: 'left', style: ['headerstyle'], }); dataRow1.push({ text: dose.Dose, alignment: 'left', style: ['headerstyle'], }); dataRow1.push({ text: dose.Dur, alignment: 'left', style: ['headerstyle'], }); dataRow1.push({ text: Remarks[dose.Dose], alignment: 'left', style: ['headerstyle'], fontFamily: 'telugu' }); body.push(dataRow1); } }) }); return body; } static GetHeaderNames() { let HeadingNames: any; HeadingNames = [[{ text: 'SNo', style: 'tableheader1', Field: 'SNo', alignment: 'left', line: true }, { text: 'Medicine', style: 'tableheader1', Field: 'Name', alignment: 'left', line: true }, { text: 'Dosage', style: 'tableheader1', Field: 'Dosage', alignment: 'left' }, { text: 'Duration', style: 'tableheader1', Field: 'Freq', alignment: 'left' }, { text: 'Remarks', style: 'tableheader1', Field: 'Freq', alignment: 'left' }, ]]; return HeadingNames; } }