UNPKG

gcp-nrces-fhir

Version:

Google cloud healthcare api NRCES FHIR implimenataion

390 lines 20.3 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.emptySign = exports.Composition = exports.compositionTypeArrey = void 0; const uuid_1 = require("uuid"); const Encounter_1 = require("../Encounter"); const Patient_1 = require("../Patient"); const Organization_1 = require("../Organization"); const ResourceMai_1 = __importDefault(require("../ResourceMai")); const date_age_1 = require("date-age"); const __1 = require("../.."); const Practitioner_1 = require("../Practitioner"); const js_ts_report_1 = require("js-ts-report"); exports.compositionTypeArrey = [ { type: "OPConsultation", system: "https://ndhm.gov.in/sct", url: "https://nrces.in/ndhm/fhir/r4/StructureDefinition/OPConsultRecord", code: "371530004", text: "Clinical consultation report", }, { type: "DischargeSummary", system: "https://ndhm.gov.in/sct", url: "https://nrces.in/ndhm/fhir/r4/StructureDefinition/DischargeSummaryRecord", code: "373942005", text: "Discharge summary", }, { type: "ImmunizationRecord", system: "https://ndhm.gov.in/sct", url: "https://nrces.in/ndhm/fhir/r4/StructureDefinition/ImmunizationRecord", code: "41000179103", text: "Immunization record", }, { type: "Prescription", system: "https://ndhm.gov.in/sct", url: "https://nrces.in/ndhm/fhir/r4/StructureDefinition/PrescriptionRecord", code: "440545006", text: "Prescription record", }, { type: "DiagnosticReport", system: "https://ndhm.gov.in/sct", url: "https://nrces.in/ndhm/fhir/r4/StructureDefinition/DiagnosticReportRecord", code: "721981007", text: "Diagnostic studies report", }, ]; const onlyType = exports.compositionTypeArrey.map((el) => el.type); const compositionStatusArrey = [ "preliminary", "final", "amended", "entered-in-error", ]; class Composition extends ResourceMai_1.default { constructor() { super(...arguments); /** * This are persons who interpt the result in care of diagnostic report and in care of the others these who treat patinets */ this._practitioner = []; /** * This is for diagnostic reporting enity requesting the services */ this.requeter = ""; this.performer = []; /** * service requested by could be patient , organization, patient him or herself * this is applicable diagnostic report */ this.setRequester = (options) => { if (options.reesource == "Patient") { this.requeter = "Self"; } else { this.requeter = `${options.display}`; } }; this.setPerformer = (options) => { this.performer.push(options.display); }; /** * this function return the all resources of copistion namely Patient, Author/Practioner, Encounter and entries in section * @param id composition id * @returns */ this.getWithIncludes = (id) => __awaiter(this, void 0, void 0, function* () { const gcpFhirSearch = new __1.GcpFhirSearch(); const res = yield gcpFhirSearch.search("Composition", `_id=${id}&_include=Composition:patient&_include=Composition:author&_include=Composition:author&_include=Composition:encounter&_include=Composition:entry`); return res; }); /** * This function returns all the compositions of patient * @param id of patient * @returns */ this.getCompositionsByPatient = (id) => __awaiter(this, void 0, void 0, function* () { const gcpFhirSearch = new __1.GcpFhirSearch(); const res = yield gcpFhirSearch.search("Patient", `_id=${id}&_revinclude=Composition:patient`); return res; }); this.getPdf = (options) => __awaiter(this, void 0, void 0, function* () { const pdf = new js_ts_report_1.CreatePdf(); const retPdf = yield pdf.create(options.html, { paragraphSpace: options.paragraphSpace || 6, base64: options.base64, header: options.header, footer: options.footer, topMargin: options.topMargin, bottomMargin: options.bottomMargin, esign: { image: options.composition.status == "final" ? options.signBase64 : exports.emptySign, nameLine1: options.nameLine1, nameLine2: options.nameLine2 || "", }, qrcode: options.qrCode, qrCodeWidth: options.qrCodeWidth, paperSize: options.paperSize, headerbase64Image: options.headerbase64Image, }); return retPdf; }); } mapCompositionType(type) { this.compType = exports.compositionTypeArrey.filter((comp) => comp.type == type)[0]; } get patient() { return this._patient; } get organization() { return this._organization; } get practitioner() { return this._practitioner; } get encounter() { return this._encounter; } setEncounter(id) { return __awaiter(this, void 0, void 0, function* () { let curClass = new Encounter_1.Encounter(); const res = yield new __1.GcpFhirCRUD().getFhirResource(id, "Encounter"); this._encounter = curClass.convertFhirToObject(res.data); }); } setPatient(id) { return __awaiter(this, void 0, void 0, function* () { let curClass = new Patient_1.Patient(); const res = yield new __1.GcpFhirCRUD().getFhirResource(id, "Patient"); this._patient = curClass.convertFhirToObject(res.data); }); } setOrganization(id) { return __awaiter(this, void 0, void 0, function* () { let curClass = new Organization_1.Organization(); const res = yield new __1.GcpFhirCRUD().getFhirResource(id, "Organization"); this._organization = curClass.convertFhirToObject(res.data); }); } setPractitioner(id) { return __awaiter(this, void 0, void 0, function* () { let curClass = new Practitioner_1.Practitioner(); const res = yield new __1.GcpFhirCRUD().getFhirResource(id, "Practitioner"); this._practitioner.push({ reference: `Practitioner/${res.data.id}}`, display: curClass.convertFhirToObject(res.data).name, }); }); } getFHIR(options) { const getpatientdetails = () => { let ret = `<div>Patient:- ${options.patient.name}.</div>`; ret += `<div>MRN:- ${options.patient.MRN} </div>`; ret += `${options.patient.phrAddress ? `<div>ABHA Address : ${options.patient.phrAddress}. ${options.patient.healthNumber ? `ABHA Number ${options.patient.healthNumber}` : ""}</div>` : ""}`; ret += `<div>Gender/Age: ${options.patient.gender}/${new date_age_1.Age().dobToAge(new Date(options.patient.dob))} ph: ${options.patient.mobile}</div>`; return ret.trim(); }; /** * This is for doctors who authored the document or who interpreted the results * @returns */ const getDoctors = () => { let str = ""; options.author.forEach((el, i) => { if (i > 0) { str = str + `<div>${el.display}</div>`; } else { str = `<div><b>Signed By :- ${el.display}</b></div>`; } }); return str; }; const getHtmlText = () => __awaiter(this, void 0, void 0, function* () { let html = `<div xmlns="http://www.w3.org/1999/xhtml">`; html += `<div style="text-align: right">`; html += `Date:-${new Date(options.date).toDateString()}`; html += `</div>`; html += `<div style="text-align: right; font-size: 9px">`; html += `Docurment Status :${options.status}`; html += `</div>`; html += `<div style="text-align: right; font-size: 9px">`; html += `Docurment Type :${options.type}`; html += `</div>`; html += `<table data-pdfmake="{'widths':['60%','40%']}">`; html += `<tr>`; html += `<td>${getpatientdetails()}</td>`; html += `<td>${getDoctors()}`; html += `${this.performer.length > 0 ? `<div>Performed By :${this.performer.reduce((pr, cu) => (pr += `${cu}<\br>`))}</div>` : ""}`; html += `</td>`; html += `</tr>`; html += `${this.requeter || options.patient.internalId ? `<tr><td>${this.requeter ? `Requested By : ${this.requeter}` : ""}</td><td>${options.patient.internalId ? `Internal Id : ${options.patient.internalId}` : ""}</td></tr>` : ""}`; html += `</table>`; html += `<div>${options.documentDatahtml}</div`; html += `</div>`; // html = `<span style="font-size: 10px;">${html}</span>` return html.trim(); }); const extensions = []; if (options.user && options.user.length > 0) { options.user.forEach(el => { extensions.push({ url: "https://www.nicehms.com/user", valueString: JSON.stringify(el), }); }); } this.mapCompositionType(options.type); const body = { resourceType: "Composition", id: options.id || undefined, meta: { versionId: "1", lastUpdated: new Date().toISOString(), profile: [this.compType.url], }, language: "en-IN", text: { status: "generated", div: getHtmlText(), }, extension: extensions, identifier: { system: "https://ndhm.in/phr", value: options.identifier || (0, uuid_1.v4)(), }, status: options.status, type: { coding: [ { system: "https://ndhm.gov.in/sct", code: this.compType.code, display: this.compType.text, }, ], text: this.compType.text, }, subject: { reference: `Patient/${options.patientId}`, // "display": options.patient.name }, encounter: { reference: `Encounter/${options.encounterId}`, }, date: options.date, author: options.author, title: options.type, custodian: { reference: `Organization/${options.organizationId}`, // "display": options.organization.name }, section: [ { title: this.compType.type, code: { coding: [ { system: "https://ndhm.gov.in/sct", code: this.compType.code, display: options.type, }, ], }, entry: options.section, }, ], }; return body; } convertFhirToObject(options) { let ret = { patient: undefined, patientId: this.getIdFromReference({ ref: options.subject.reference, resourceType: "Patient", }), encounter: undefined, encounterId: this.getIdFromReference({ ref: options.encounter.reference, resourceType: "Encounter", }), date: options.date, organization: undefined, // organizationId: `${options.custodian.reference}`.substring(13), organizationId: this.getIdFromReference({ ref: options.custodian.reference, resourceType: "Organization", }), status: options.status, type: options.title, section: options.section, id: options.id, identifier: options.identifier.value, author: options.author, documentDatahtml: options.text.div.trim(), }; if (ret.patient == undefined) { delete ret.patient; } if (ret.encounter == undefined) { delete ret.encounter; } if (ret.organization == undefined) { delete ret.organization; } if (options.extension) { const user = options.extension.filter((el) => { if ((el.url = "https://www.nicehms.com/user")) { return el; } }).map((pl) => { return JSON.parse(pl.valueString); }); ret.user = user; } return ret; } /** * This returns the diagnosis from encounter * @param encounter * @returns */ getDiagnosisFromEnconter(encounter) { return __awaiter(this, void 0, void 0, function* () { let ret = []; if ((encounter === null || encounter === void 0 ? void 0 : encounter.diagnosis) && encounter.diagnosis.length > 0) { encounter.diagnosis.forEach((el) => __awaiter(this, void 0, void 0, function* () { const id = this.getFromMultResource({ "reference": el.condition.reference }).id; ret.push((yield new __1.GcpFhirCRUD().getFhirResource(id, el.condition.type)).data.text.div); })); } return ret; }); } statusArray() { return compositionStatusArrey.map((el) => el); } typeArray() { return onlyType.map((el) => el); } } exports.Composition = Composition; exports.emptySign = `data:image/gif;base64,iVBORw0KGgoAAAANSUhEUgAAAUoAAACZCAMAAAB+KoMCAAAAMFBMVEX////n5ubm5eXl5OTz8/P6+vrw7+/s6+v39vb//Pnu7e3q6en5+fn//fvz8e/39PJx9eXWAAAMj0lEQVR4nO1diZazrBJUNCYu6Pu/7dDdbCIKGjNigv+55+s7qcxAidhbaVHA0bCyLJ9o9sJiNZoVmANYL/i8ioIOBlqD2aP5hM8bA32B9XCgJZod01BmoPCt6uGDdmiWeiwWFIfN9LAldO8MGwc6OFA1wyJT+eVUdpnK86jkd6WyYqyib5dMmPIPgUnfRtNA6dt9tQ2tDfQJZmOgkp8ZlJUG2nG+CSV+OoSiyZxhE5XOsP0z3ID2zrA3ySgaOOoXHGiiVXvNELSJh9bO5zPoNE1j1zVNNwUGUMeP9ehYdsyQTufGIukAYJ15C2pOJ3OhwTMP0LVF0vJ2klBOZ15CexZeJ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