UNPKG

gcp-nrces-fhir

Version:

Google cloud healthcare api NRCES FHIR implimenataion

244 lines 10.2 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.CoverageEligibilityRequest = void 0; const gcp_1 = __importDefault(require("../classess/gcp")); const Location_1 = require("../resources/Location"); const ResourceMai_1 = __importDefault(require("../resources/ResourceMai")); const TimeZone_1 = require("../TimeZone"); const CoverageEligibilityRequestStatus = [ "active", "cancelled", "draft", "entered-in-error", ]; const CoverageEligibilityRequestPurpose = [ "auth-requirements", "benefits", "discovery", "validation", ]; class CoverageEligibilityRequest extends ResourceMai_1.default { constructor() { super(...arguments); this.statusArray = () => { return CoverageEligibilityRequestStatus.map((el) => el); }; this.Purpose = () => { return CoverageEligibilityRequestPurpose.map((el) => el); }; } toHtml(option) { return __awaiter(this, void 0, void 0, function* () { let ret = ""; const body = this.convertFhirToObject(option.body); if (option.addResourceType) { ret += `<h1>Coverage Eligibility Request</h1>`; } ret += `Date : ${new TimeZone_1.TimeZone().convertTZ(body.createdDateTime, "Asia/Kolkata", false)}`; if (option.body.text) { ret += `<h2>Text</h2>`; ret += `<p>${option.body.text} </p>`; } if (body.purpose) { ret += body.purpose && `Purpose : ${body.purpose}</br>`; } if (option.body.identifier && option.body.identifier.length > 0) { ret += `<h4>Identifiers</h4>`; ret += this.identifierToHtml(body.identifier); } if (option.body.priority) { ret += `<b>Priority</b> : ${this.codeableConceptToHtml(option.body.priority)}<br/>`; } if (option.body.locationId) { try { const locationRes = yield new gcp_1.default().getFhirResource(option.body.locationId, "Location"); if (locationRes && locationRes.data) { const location = new Location_1.Location(); const locationObj = location.convertFhirToObject(locationRes.data); ret += `<h3>Location</h3> ${yield location.toHtml({ body: locationObj })}`; } } catch (error) { } } if (body.insurance) { ret += yield this.insuranceToHtml({ "val": Array.isArray(body.insurance) ? body.insurance : [body.insurance], "coverage": option.coverages || [], "patient": option.patient, "payerCode": option.payerCode, "payerName": option.payerName }); } if (body.item && body.item.length > 0) { ret += `<table> <tr> <th>category</th> <th>diagnosis</th> <th>productOrService</th> </tr>`; for (let index = 0; index < body.item.length; index++) { const el = body.item[index]; ret += `<tr>`; if (el.category) { ret += `<td>`; ret += this.codeableConceptToHtml(el.category); ret += `</td>`; } if (el.diagnosis) { ret += `<td>`; el.diagnosis.forEach((dia) => { if (dia.diagnosisCodeableConcept) { ret += `${this.codeableConceptToHtml(dia.diagnosisCodeableConcept)}`; } }); ret += `</td>`; } if (el.productOrService) { ret += `<td>`; ret += this.codeableConceptToHtml(el.productOrService); ret += `</td>`; } ret += `</tr>`; } ret += `</table>`; } return ret; }); } getFHIR(options) { const getText = () => { let ret = ""; ret += options.text; return ret; }; const body = { resourceType: "CoverageEligibilityRequest", id: options.id, meta: { profile: options.hcx == "nhcx" ? [ "https://nrces.in/ndhm/fhir/r4/StructureDefinition/CoverageEligibilityRequest", ] : [ "https://ig.hcxprotocol.io/v0.7.1/StructureDefinition-CoverageEligibilityRequest.html", ], }, language: "en", text: { status: "generated", div: getText(), }, servicedDate: options.servicedDate, supportingInfo: options.supportingInfo, identifier: options.identifier, priority: options.priority, purpose: options.purpose, patient: { reference: `Patient/${options.patientId}`, }, created: options.createdDateTime, enterer: { reference: `${options.enterer.resource}/${options.enterer.id}`, "display": options.enterer && options.enterer.display, identifier: options.enterer && options.enterer.identifier }, provider: { reference: options.provider && `${options.provider.resource}/${options.provider.id}`, "display": options.provider && options.provider.display, identifier: options.provider && options.provider.identifier }, insurer: { reference: options.insurerOrganizationId && `Organization/${options.insurerOrganizationId}`, identifier: options.insurerParticipantId && { "system": "NHCX", "value": options.insurerParticipantId }, display: options.insurerName, }, facility: { reference: `Location/${options.locationId}`, }, insurance: options.insurance, item: options.item, detail: options.detail, status: options.status, }; const keys = Object.keys(body); keys.forEach((el) => { if (el == undefined) { delete body[`${el}`]; } }); return body; } convertFhirToObject(options) { let ret = { id: options.id, status: options.status, text: options.text && options.text.div, identifier: options.identifier, priority: options.priority, purpose: options.purpose, patientId: this.getIdFromReference({ ref: options.patient.reference, resourceType: "Patient", }), createdDateTime: options.created, // enterer: options.enterer, enterer: Object.assign({ "identifier": options.enterer.identifier }, this.getFromMultResource(options.enterer)), // provider: options.provider, provider: Object.assign({ "identifier": options.provider.identifier }, this.getFromMultResource(options.provider)), insurance: options.insurance, resourceType: "CoverageEligibilityRequest" }; if (options.insurer && options.insurer.reference) { ret.insurerOrganizationId = this.getIdFromReference({ ref: options.insurer.reference, resourceType: "Organization" }); } if (options.insurer && options.insurer.display) { ret.insurerName = options.insurer.display; } if (options.insurer && options.insurer.identifier) { ret.insurerParticipantId = options.insurer.identifier.value; } if (options.item) { ret.item = options.item; } if (options.facility) { ret.locationId = this.getIdFromReference({ ref: options.facility.reference, resourceType: "Location", }); } if (options.supportingInfo) { ret.supportingInfo = options.supportingInfo; } if (options.servicedPeriod) { ret.servicedPeriod = options.servicedPeriod; } if (options.servicedDate) { ret.servicedDate = options.servicedDate; } if (options.detail) { ret.detail = options.detail; } return ret; } } exports.CoverageEligibilityRequest = CoverageEligibilityRequest; //# sourceMappingURL=CoverageEligibilityRequest.js.map