UNPKG

gcp-nrces-fhir

Version:

Google cloud healthcare api NRCES FHIR implimenataion

118 lines 6.76 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.InvoiceRecordBundle = void 0; const _1 = require("."); const gcp_1 = __importDefault(require("../../classess/gcp")); const PdfGenerator_1 = __importDefault(require("../../classess/PdfGenerator")); class InvoiceRecordBundle extends _1.BundelMain { toHtml() { return __awaiter(this, void 0, void 0, function* () { throw new Error("Method not implemented."); }); } getFHIR(options) { var _a, _b; return __awaiter(this, void 0, void 0, function* () { const bundlemain = yield new _1.BundelMain(this.gcpCredetials, this.gcpPath).getentries(options.composition, options.pdfData || ""); this.entry = bundlemain.entry; const compObj = bundlemain.compositionObj; // Add Invoice and ChargeItem resources from section entries const gcpFhirCrud = new gcp_1.default(this.gcpCredetials, this.gcpPath); if (options.composition.section) { for (const section of options.composition.section) { if (section.entry) { for (const entry of section.entry) { try { const refParts = (_a = entry.reference) === null || _a === void 0 ? void 0 : _a.split("/"); if (refParts && refParts.length === 2) { const [resourceType, resourceId] = refParts; if (resourceType === "Invoice") { const invRes = yield gcpFhirCrud.getFhirResource(resourceId, "Invoice"); if (invRes === null || invRes === void 0 ? void 0 : invRes.data) { this.entry.push({ fullUrl: entry.reference, resource: invRes.data, }); // Also fetch ChargeItems referenced by this Invoice if (invRes.data.lineItem) { for (const lineItem of invRes.data.lineItem) { const ciRef = ((_b = lineItem.chargeItemReference) === null || _b === void 0 ? void 0 : _b.reference) || lineItem.chargeItemReference; if (ciRef) { try { const ciRefParts = ciRef.split("/"); if (ciRefParts && ciRefParts.length === 2) { const [ciType, ciId] = ciRefParts; if (ciType === "ChargeItem") { const ciRes = yield gcpFhirCrud.getFhirResource(ciId, "ChargeItem"); if (ciRes === null || ciRes === void 0 ? void 0 : ciRes.data) { this.entry.push({ fullUrl: ciRef, resource: ciRes.data, }); } } } } catch (_c) { // ChargeItem may not be stored in FHIR store; skip } } } } } } } } catch (err) { // Entry not found; skip } } } } } const body = { resourceType: "Bundle", id: options.id, meta: { lastUpdated: new Date().toISOString(), profile: ["https://nrces.in/ndhm/fhir/r4/StructureDefinition/DocumentBundle"], }, identifier: { system: "https://www.nicehms.com/bundle", value: options.id, }, type: "document", timestamp: options.composition.date || new Date().toISOString(), entry: this.entry, }; return body; }); } getpdf(options) { return __awaiter(this, void 0, void 0, function* () { const pdf = yield (0, PdfGenerator_1.default)(options.html, { base64: true, paperSize: "A4", qrcode: options.qrCode, }); return pdf; }); } convertFhirToObject(options) { throw new Error("Method not implemented."); } } exports.InvoiceRecordBundle = InvoiceRecordBundle; //# sourceMappingURL=InvoiceRecord.js.map