UNPKG

gcp-nrces-fhir

Version:

Google cloud healthcare api NRCES FHIR implimenataion

219 lines 8.66 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.DiagnosticReport = void 0; const ResourceMai_1 = __importDefault(require("./ResourceMai")); const diagnosticReportStatus = [ "registered", "partial", "preliminary", "final", ]; class DiagnosticReport extends ResourceMai_1.default { toHtml() { return __awaiter(this, void 0, void 0, function* () { throw new Error("Method not implemented."); }); } getFHIR(options) { try { const getText = () => { let ret = ""; if (options.labId) { ret = `${ret}<p>Lab Id: ${options.labId}</p>`; } if (options.observations) { options.observations.forEach((el) => { const res = el.text; ret = `${ret}<p>${res}</p>`; }); } else if (options.text) { ret = `${ret}<p>${options.text}</p>`; } ret = `${ret}<p>${options.conclusion}</p>`; return ret; }; const identifiers = []; const body = { resourceType: "DiagnosticReport", id: options.id || undefined, meta: { versionId: "1", lastUpdated: "2020-07-09T15:32:26.605+05:30", profile: [ "https://nrces.in/ndhm/fhir/r4/StructureDefinition/DiagnosticReportImaging", ], }, text: { status: "generated", div: `<div xmlns=\"http://www.w3.org/1999/xhtml\">${getText()}</div>`, }, status: options.status, code: options.code, issued: options.issuedDate, resultsInterpreter: options.resultsInterpreter.map((el) => { return { reference: `${el.resource}/${el.id}`, display: el.display }; }), conclusion: options.conclusion, media: options.mediaId.map((el) => { return { link: { reference: `Media/${el}` } }; }), presentedForm: [ { contentType: "application/pdf", language: "en-IN", data: options.base64Data || "", title: "Report", }, ], }; if (options.performer) { body.performer = options.performer.map((el) => { return { reference: `${el.resource}/${el.id}`, display: el.display }; }); } if (options.subject) { body.subject = { reference: `${options.subject.resource}/${options.subject.id}`, display: options.subject.display, }; } if (options.basedOn) { body.basedOn = options.basedOn.map((el) => { return { reference: `${el.resource}/${el.id}` }; }); } if (options.category) { body.category = options.category; } if (options.conclusionCode) { body.conclusionCode = options.conclusionCode; } if (options.specimenId) { body.specimen = options.specimenId.map((el) => { return { reference: `Specimen/${el}` }; }); } if (options.observationResultid) { body.result = options.observationResultid.map((el) => { return { reference: `Observation/${el}` }; }); } if (options.encounterId) { body.encounter = { reference: `Encounter/${options.encounterId}` }; } if (options.labId) { identifiers.push({ type: { coding: [ { // system: "http://terminology.hl7.org/CodeSystem/v2-0203", // code: "MR", display: "Lab Id", }, ], }, "system": "https://www.nicehms.com/labId", "value": options.labId }); } body.identifier = identifiers; return body; } catch (error) { console.log(error); } } convertFhirToObject(options) { let ret = { id: options.id, mediaId: options.media.map((el) => { return this.getIdFromReference({ ref: el.link.reference, resourceType: "Media", }); }), text: options.text.div, issuedDate: options.issued, conclusion: options.conclusion, status: options.status, code: options.code, resultsInterpreter: options.resultsInterpreter.map((el) => { return this.getFromMultResource(el); }), }; if (options.result) { ret.observationResultid = options.result.map((el) => this.getIdFromReference({ ref: el.reference, resourceType: "Observation", })); } if (options.specimen) { ret.specimenId = options.specimen.map((el) => this.getIdFromReference({ ref: el.reference, resourceType: "Specimen" })); } if (options.performer) { ret.performer = options.performer.map((el) => { return this.getFromMultResource(el); }); } if (options.subject) { ret.subject = this.getFromMultResource(options.subject); } if (options.basedOn) { ret.basedOn = options.basedOn.map((el) => { return this.getFromMultResource(el); }); } if (options.conclusionCode) { ret.conclusionCode = options.conclusionCode; } if (options.category) { ret.category = options.category; } if (options.encounter) { ret.encounterId = this.getIdFromReference({ ref: options.encounter.reference, resourceType: "Encounter", }); } if (options.identifier) { const labId = options.identifier.filter((el) => el.system == "https://www.nicehms.com/labId"); if (labId.length > 0) { ret.labId = labId[0].value; } } return ret; } statusArray() { return diagnosticReportStatus.map((el) => el); } bundlify(resource) { const copy = super.bundlify(resource); if (copy.conclusion == null || copy.conclusion == "") { delete copy.conclusion; } const presentedForm = copy.presentedForm; const correctedPresentedForm = presentedForm.filter(el => el.data != ""); if (correctedPresentedForm.length == 0) { delete copy.presentedForm; } else { copy.presentedForm = correctedPresentedForm; } return copy; } } exports.DiagnosticReport = DiagnosticReport; //# sourceMappingURL=DiagnosticReport.js.map