UNPKG

gcp-nrces-fhir

Version:

Google cloud healthcare api NRCES FHIR implimenataion

159 lines 7.84 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.BundelMain = void 0; const ResourceFactory_1 = __importDefault(require("../../classess/ResourceFactory")); const Composition_1 = require("../Composition"); const gcp_1 = __importDefault(require("../../classess/gcp")); const ResourceMai_1 = __importDefault(require("../ResourceMai")); const js_ts_report_1 = require("js-ts-report"); const DocumentReference_1 = require("../DocumentReference"); const Patient_1 = require("../Patient"); const Encounter_1 = require("../Encounter"); const Organization_1 = require("../Organization"); const MedicationRequest_1 = require("../MedicationRequest"); class BundelMain extends ResourceMai_1.default { constructor(gcpCredetials, gcpPath) { super(); this.entry = []; this.getAllSectionAndAllEntries = (index, sections) => __awaiter(this, void 0, void 0, function* () { if (index >= sections.length) { return; } yield this.getEntriesPerSection(0, sections[index].entry); index = index + 1; yield this.getAllSectionAndAllEntries(index, sections); }); this.getEntriesPerSection = (index, sectionEntries) => __awaiter(this, void 0, void 0, function* () { if (index >= sectionEntries.length) { return; } const curSectionEntryObj = this.getFromMultResource({ reference: sectionEntries[index].reference, }); const curSectionEntry = yield new gcp_1.default(this.gcpCredetials, this.gcpPath).getFhirResource(curSectionEntryObj.id, curSectionEntryObj.resource); if (curSectionEntryObj.resource == "MedicationRequest") { const medicationRequest = new MedicationRequest_1.MedicationRequest().bundlify(curSectionEntry.data); medicationRequest.forEach((el, i) => { this.entry.push(el); }); } else { this.entry.push({ fullUrl: `${curSectionEntryObj.resource}/${curSectionEntryObj.id}`, resource: new ResourceFactory_1.default(curSectionEntryObj.resource).bundlefy(curSectionEntry.data), }); } curSectionEntry.data; index = index + 1; yield this.getEntriesPerSection(index, sectionEntries); }); this.gcpCredetials = gcpCredetials; this.gcpPath = gcpPath; } getentries(composition, pdfData) { return __awaiter(this, void 0, void 0, function* () { const compositionObj = new ResourceFactory_1.default("Composition").convertFhirToObject(composition); const gcpGcpFhir = new gcp_1.default(this.gcpCredetials, this.gcpPath); const authors = yield Promise.all(compositionObj.author.map((el) => __awaiter(this, void 0, void 0, function* () { const id = this.getIdFromReference({ ref: el.reference, resourceType: "Practitioner", }); const url = el.reference; const resource = yield gcpGcpFhir .getFhirResource(id, "Practitioner") .then((res) => res.data); return { fullUrl: url, resource: resource, }; }))).then((res) => res); const entry = [ { fullUrl: `Composition/${compositionObj.id}`, resource: new Composition_1.Composition().bundlify(composition), }, { fullUrl: `Patient/${compositionObj.patientId}`, resource: new Patient_1.Patient().bundlify((yield gcpGcpFhir.getFhirResource(compositionObj.patientId, "Patient")).data), }, { fullUrl: `Encounter/${compositionObj.encounterId}`, resource: new Encounter_1.Encounter().bundlify((yield gcpGcpFhir.getFhirResource(compositionObj.encounterId, "Encounter")).data), }, { fullUrl: `Organization/${compositionObj.organizationId}`, resource: new Organization_1.Organization().bundlify((yield gcpGcpFhir.getFhirResource(compositionObj.organizationId, "Organization")).data), }, { fullUrl: `DocumentReference/${compositionObj.id}`, resource: new DocumentReference_1.DocumentReference().bundlify(new DocumentReference_1.DocumentReference().getFHIR({ "id": compositionObj.id, "patientId": compositionObj.patientId, "pdf": pdfData, "docStatus": compositionObj.status, "title": composition.title, "type": composition.type, status: "current" })) } ]; authors.forEach((el) => { entry.push(el); }); return { entry, compositionObj }; }); } getpdf(options) { return __awaiter(this, void 0, void 0, function* () { const composition = new Composition_1.Composition(); const mediaContent = []; if (options.compositionRes) { const section = composition.convertFhirToObject(options.compositionRes).section; const mediaId = section[0].entry.filter((el) => { if (el.type == "Media") { return el; } }).map((el) => { const id = this.getIdFromReference({ ref: el.reference, resourceType: "Media", }); return id; }); if (mediaId.length > 0) { yield composition.getMediaComposition(0, mediaId, mediaContent); } } let pdf = new js_ts_report_1.CreatePdf(); const ret = yield pdf.create(options.html, { base64: true, paperSize: "A4", qrcode: options.qrCode, esign: { image: Composition_1.emptySign, nameLine1: "Scan QR code to get full document", }, media: mediaContent.length > 0 ? { "content": mediaContent, singleImagePerPage: options.singleImagePerPage || false } : undefined }); return ret; }); } } exports.BundelMain = BundelMain; //# sourceMappingURL=index.js.map