UNPKG

gcp-nrces-fhir

Version:

Google cloud healthcare api NRCES FHIR implimenataion

207 lines 10 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.CommunicationRequest = void 0; const ReseorcetToHtml_1 = __importDefault(require("../classess/ReseorcetToHtml")); const ResourceMai_1 = __importDefault(require("../resources/ResourceMai")); class CommunicationRequest extends ResourceMai_1.default { getFHIR(options) { var _a, _b; const body = { resourceType: "CommunicationRequest", id: options.id || undefined, status: options.status, meta: { versionId: "1", lastUpdated: "2023-09-07T14:58:58.181+05:30", profile: options.hcx == "swasth" ? [ "https://ig.hcxprotocol.io/v0.8/StructureDefinition-CommunicationRequest.html", ] : [ "https://nrces.in/ndhm/fhir/r4/StructureDefinition/CommunicationRequest", ], }, text: { status: "generated", div: options.text || "", }, identifier: options.identifiers, replaces: options.replaces && options.replaces.map((el) => { return { reference: el.resource && `${el.resource}/${el.id}`, type: el.type, identifier: el.identifier, display: el.display, }; }), basedOn: options.basedOn && options.basedOn.map((el) => { return { reference: el.resource && `${el.resource}/${el.id}`, type: el.type, identifier: el.identifier, display: el.display, }; }), category: options.category, priority: options.priority, subject: { reference: options.subject && `${(_a = options.subject) === null || _a === void 0 ? void 0 : _a.resource}/${(_b = options.subject) === null || _b === void 0 ? void 0 : _b.id}`, }, doNotPerform: options.doNotPerform, statusReason: options.statusReason, encounter: { reference: `Encounter/${options.encounterId}` }, payload: options.payload, authoredOn: options.authoredOn, requester: { reference: options.requester && `${options.requester.resource}/${options.requester.id}`, }, recipient: options.recipient && options.recipient.map((el) => { return { reference: `${el.resource}/${el.id}` }; }), sender: options.sender && { reference: `${options.sender.resource}/${options.sender.id}`, }, reasonCode: options.reasonCode && options.reasonCode, reasonReference: options.reasonReference && options.reasonReference.map((el) => { return { reference: `${el.resource}/${el.id}` }; }), note: options.note, }; return body; } convertFhirToObject(options) { var _a, _b, _c; const ret = { text: (options.text && options.text.div) || "", identifiers: options.identifier, status: options.status, category: options.category, priority: options.priority, reasonReference: options.reasonReference && options.reasonReference.map((el) => { return this.getFromMultResource(Object.assign(Object.assign({}, el), { reference: el === null || el === void 0 ? void 0 : el.reference })); }), statusReason: options.statusReason, authoredOn: options.authoredOn, requester: options.requester && this.getFromMultResource(Object.assign(Object.assign({}, options.requester), { reference: options === null || options === void 0 ? void 0 : options.requester })), recipient: options.recipient && options.recipient.map((el) => { return this.getFromMultResource(Object.assign(Object.assign({}, el), { reference: el === null || el === void 0 ? void 0 : el.reference })); }), reasonCode: options.reasonCode, doNotPerform: options.doNotPerform, note: options.note, subject: options.subject && this.getFromMultResource({ reference: options.subject.reference, display: options.subject.display, }), encounterId: options.encounter && this.getIdFromReference({ ref: options.encounter.reference, resourceType: "Encounter", }), about: options.about && this.getFromMultResource(Object.assign(Object.assign({}, options.about), { reference: (_a = options.about) === null || _a === void 0 ? void 0 : _a.reference })), sender: options.sender && this.getFromMultResource(Object.assign(Object.assign({}, options.sender), { reference: (_b = options.sender) === null || _b === void 0 ? void 0 : _b.reference })), resourceType: "CommunicationRequest", basedOn: options.basedOn.map((el) => { var _a; return this.getFromMultResource(Object.assign(Object.assign({}, el), { reference: (_a = el.basedOn) === null || _a === void 0 ? void 0 : _a.reference })); }) }; if (options.payload) { ret.payload = (_c = options.payload) === null || _c === void 0 ? void 0 : _c.map((el) => { const ret = {}; if (el.id) ret.id = el.id; if (el.extension) ret.extension = el.extension; if (el.modifierExtension) ret.modifierExtension = el.modifierExtension; if (el.contentAttachment) { ret.content = {}; ret.content.contentAttachment = el.contentAttachment; } else if (el.contentString) { ret.content = {}; ret.content.contentString = el.contentString; } else if (el.content.contentReference) { ret.content = {}; ret.content.contentReference = this.getFromMultResource(el.contentReference); } return ret; }); } return ret; } toHtml(option) { return __awaiter(this, void 0, void 0, function* () { let ret = ""; const body = this.convertFhirToObject(option.body); ret += `<html><body>`; ret += `<h1>Communication Request</h1>`; ret += `<p><strong>ID:</strong> ${body.id || "N/A"}</p>`; ret += `<p><strong>Status:</strong> ${body.status}</p>`; ret += `<p><strong>Priority:</strong> ${body.priority}</p>`; ret += `<p><strong>Authored On:</strong> ${body.authoredOn}</p>`; ret += body.text; if (body.identifiers) { ret += `<p><strong>Identifiers</strong></p>`; body.identifiers.forEach(el => { ret += this.identifierToHtml(el); }); } if (body.subject) { ret += `<p><strong>Subject:</strong></p>`; ret += this.multiResourceToHtml(body.subject, "Subject"); } if (body.requester) { ret += this.multiResourceToHtml(body.requester, "Requester"); } if (body.recipient && body.recipient.length > 0) { ret += this.multiResourceToHtml(body.recipient, "Recipient"); } if (body.reasonCode && body.reasonCode.length > 0) { ret += `<p><strong>ReasonCode</strong></p>`; ret += this.codeableConceptToHtml(body.reasonCode); } if (body.reasonReference && body.reasonReference.length > 0) { ret += this.multiResourceToHtml(body.reasonReference, "ReasonReference"); } if (body.payload && body.payload.length > 0) { ret += `<h2>Payload</h2>`; ret += new ReseorcetToHtml_1.default().payloadToHtml(body.payload); } if (body.note) { ret += `<h2>Notes</h2>`; ret += `<p>${body.note.text}</p>`; } ret += `</body></html>`; return ret; }); } } exports.CommunicationRequest = CommunicationRequest; //# sourceMappingURL=CommunicationRequest.js.map