UNPKG

gcp-nrces-fhir

Version:

Google cloud healthcare api NRCES FHIR implimenataion

137 lines 8.08 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.ImmunizationRecordComp = void 0; const TimeZone_1 = require("../../TimeZone"); const _1 = require("."); const gcp_1 = __importDefault(require("../../classess/gcp")); class ImmunizationRecordComp extends _1.Composition { constructor() { super(...arguments); this.create = (options, Credentials, DatabasePath) => __awaiter(this, void 0, void 0, function* () { options = yield this.getOptions(options); const body = this.getFHIR(options.composition); body.section = options.composition.section; let gcpFhirCrud; if (Credentials) { gcpFhirCrud = new gcp_1.default(Credentials, DatabasePath); } else { gcpFhirCrud = new gcp_1.default(); } const res = yield gcpFhirCrud.createFhirResource(body, "Composition"); return res; }); this.update = (options, Credentials, DatabasePath) => __awaiter(this, void 0, void 0, function* () { if (!options.composition.id) { throw new Error("id of composition is required"); } options = yield this.getOptions(options); const body = this.getFHIR(options.composition); body.section = options.composition.section; let gcpFhirCrud; if (Credentials) { gcpFhirCrud = new gcp_1.default(Credentials, DatabasePath); } else { gcpFhirCrud = new gcp_1.default(); } const res = yield gcpFhirCrud.updateFhirResource(body, options.composition.id || "", "Composition"); return res; }); this.getOptions = (options) => __awaiter(this, void 0, void 0, function* () { var _a; let docHtml = ""; docHtml += `<h3 style="text-align: center;">Immunization Record</h3>`; const sectionTitle = options.title || "Immunization record"; const sectionEntry = []; // Section 0: Immunization entries if (options.immunization && options.immunization.length > 0) { docHtml += `<p><b>Vaccines Administered</b></p>`; docHtml += `<table style="border-collapse: collapse; width: 100%;" border="1">`; docHtml += `<tr><th>Vaccine</th><th>Dose #</th><th>Date</th><th>Brand</th><th>Lot #</th><th>Status</th></tr>`; options.immunization.forEach((imm) => { var _a, _b, _c, _d, _e, _f, _g, _h, _j; sectionEntry.push({ reference: `Immunization/${imm.id}`, type: "Immunization", }); const vaccineName = ((_a = imm.vaccineCode) === null || _a === void 0 ? void 0 : _a.text) || ((_d = (_c = (_b = imm.vaccineCode) === null || _b === void 0 ? void 0 : _b.coding) === null || _c === void 0 ? void 0 : _c[0]) === null || _d === void 0 ? void 0 : _d.display) || ""; const doseNumber = ((_f = (_e = imm.protocolApplied) === null || _e === void 0 ? void 0 : _e[0]) === null || _f === void 0 ? void 0 : _f.doseNumberPositiveInt) || ""; const date = imm.occurrenceDateTime ? new TimeZone_1.TimeZone().convertTZ(imm.occurrenceDateTime, process.env.TZ, false) : ""; const brand = ((_g = imm.manufacturer) === null || _g === void 0 ? void 0 : _g.display) || ((_j = (_h = imm.extension) === null || _h === void 0 ? void 0 : _h[0]) === null || _j === void 0 ? void 0 : _j.valueString) || ""; const lot = imm.lotNumber || ""; const status = imm.status || ""; docHtml += `<tr><td>${vaccineName}</td><td>${doseNumber}</td><td>${date}</td><td>${brand}</td><td>${lot}</td><td>${status}</td></tr>`; }); docHtml += `</table>`; } // Section 1 (entries): ImmunizationRecommendation if (options.immunizationRecommendation) { docHtml += `<p><b>Next Due Dates</b></p>`; docHtml += `<table style="border-collapse: collapse; width: 100%;" border="1">`; docHtml += `<tr><th>Vaccine</th><th>Dose #</th><th>Due Date</th><th>Notes</th></tr>`; sectionEntry.push({ reference: `ImmunizationRecommendation/${options.immunizationRecommendation.id}`, type: "ImmunizationRecommendation", }); (_a = options.immunizationRecommendation.recommendation) === null || _a === void 0 ? void 0 : _a.forEach((rec) => { var _a, _b, _c, _d, _e, _f, _g, _h; const vaccineName = ((_b = (_a = rec.vaccineCode) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.text) || ((_f = (_e = (_d = (_c = rec.vaccineCode) === null || _c === void 0 ? void 0 : _c[0]) === null || _d === void 0 ? void 0 : _d.coding) === null || _e === void 0 ? void 0 : _e[0]) === null || _f === void 0 ? void 0 : _f.display) || ""; const doseNumber = rec.doseNumberPositiveInt || ""; const dueDate = ((_h = (_g = rec.dateCriterion) === null || _g === void 0 ? void 0 : _g[0]) === null || _h === void 0 ? void 0 : _h.value) ? new TimeZone_1.TimeZone().convertTZ(rec.dateCriterion[0].value, process.env.TZ, false) : ""; const notes = rec.description || ""; docHtml += `<tr><td>${vaccineName}</td><td>${doseNumber}</td><td>${dueDate}</td><td>${notes}</td></tr>`; }); docHtml += `</table>`; } // Section 2 (entries): DocumentReference (optional) if (options.documentReference && options.documentReference.length > 0) { options.documentReference.forEach((dr) => { sectionEntry.push({ reference: `DocumentReference/${dr.id}`, type: "DocumentReference", }); }); } options.composition.section = [ { title: sectionTitle, code: { coding: [ { system: "http://snomed.info/sct", code: "41000179103", display: "Immunization record", }, ], }, entry: sectionEntry, }, ]; options.composition.documentDatahtml = docHtml; return options; }); } } exports.ImmunizationRecordComp = ImmunizationRecordComp; //# sourceMappingURL=ImmunizationRecord.js.map