gcp-nrces-fhir
Version:
Google cloud healthcare api NRCES FHIR implimenataion
302 lines • 14.3 kB
JavaScript
;
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.Communication = void 0;
const ResourceMai_1 = __importDefault(require("../resources/ResourceMai"));
const ReseorcetToHtml_1 = __importDefault(require("../classess/ReseorcetToHtml"));
const statusArray = [
"preparation",
"in-progress",
"not-done",
"on-hold",
"stopped",
"completed",
"entered-in-error",
"unknown",
];
class Communication extends ResourceMai_1.default {
toHtml(options) {
var _a, _b, _c, _d;
return __awaiter(this, void 0, void 0, function* () {
const body = this.convertFhirToObject(options.body);
const getReference = (resource, name) => this.multiResourceToHtml(resource, name);
const getCategories = () => { var _a; return ((_a = body.category) === null || _a === void 0 ? void 0 : _a.map(c => c.text).filter(Boolean).join(', ')) || ''; };
const getRecipients = () => { var _a; return ((_a = body.recipient) === null || _a === void 0 ? void 0 : _a.map(r => getReference(r, "Recipient")).join(',<br>')) || ''; };
const getInResponseTo = () => { var _a; return ((_a = body.inResponseTo) === null || _a === void 0 ? void 0 : _a.map(ir => getReference(ir, "InResponseTo")).join(',<br>')) || ''; };
const getReasonReferences = () => { var _a; return ((_a = body.reasonReference) === null || _a === void 0 ? void 0 : _a.map(rr => getReference(rr, "ReasonReference")).join(',<br>')) || ''; };
const html = `
<div class="communication">
<h1>Communication</h1>
<table data-pdfmake="{'widths':['40%','60%']}">
<tbody>
${body.id ? `<tr><th>ID</th><td>${body.id}</td></tr>` : ''}
${body.status ? `<tr><th>Status</th><td>${body.status}</td></tr>` : ''}
${body.priority ? `<tr><th>Priority</th><td>${body.priority}</td></tr>` : ''}
${body.category ? `<tr><th>Category</th><td>${getCategories()}</td></tr>` : ''}
${body.subject ? `<tr><th>Subject</th><td>${getReference(body.subject, "Subject")}</td></tr>` : ''}
${body.encounter ? `<tr><th>Encounter</th><td>${getReference(body.encounter, "Encounter")}</td></tr>` : ''}
${body.sentDate ? `<tr><th>Sent Date</th><td>${body.sentDate}</td></tr>` : ''}
${body.receivedDate ? `<tr><th>Received Date</th><td>${body.receivedDate}</td></tr>` : ''}
${body.topic ? `<tr><th>Topic</th><td>${body.topic.text}</td></tr>` : ''}
${((_a = body.reasonCode) === null || _a === void 0 ? void 0 : _a.length) ? `<tr><th>Reason Code</th><td>${body.reasonCode.map(rc => rc.text).join(', ')}</td></tr>` : ''}
${((_b = body.reasonReference) === null || _b === void 0 ? void 0 : _b.length) ? `<tr><th>Reason Reference</th><td>${getReasonReferences()}</td></tr>` : ''}
${((_c = body.inResponseTo) === null || _c === void 0 ? void 0 : _c.length) ? `<tr><th>In Response To</th><td>${getInResponseTo()}</td></tr>` : ''}
${((_d = body.payload) === null || _d === void 0 ? void 0 : _d.length) ? `
<tr>
<th>Payloads</th>
<td>
<ul style="list-style-type: none; padding-left: 0;">
${new ReseorcetToHtml_1.default().payloadToHtml(body.payload)}
</ul>
</td>
</tr>` : ''}
</tbody>
</table>
</div>
`;
return html;
});
}
getFHIR(options) {
const body = {
resourceType: "Communication",
identifier: options.identifier,
topic: options.topic,
id: options.id ? options.id : undefined,
implicitRules: options.implicitRulesLink,
medium: options.medium,
subject: options.subject && {
reference: options.subject.resource &&
`${options.subject.resource}/${options.subject.id}`,
type: options.subject.type,
identifier: options.subject.identifier,
display: options.subject.display,
},
meta: {
versionId: "1",
lastUpdated: "2023-09-07T14:58:58.181+05:30",
profile: options.hcx == "nhcx"
? [
"https://nrces.in/ndhm/fhir/r4/StructureDefinition/Communication",
]
: [
"https://ig.hcxprotocol.io/v0.8/StructureDefinition-Communication.html",
],
},
text: {
status: "generated",
div: options.text,
},
basedOn: options.basedOn &&
options.basedOn.map((el) => {
return {
reference: el.resource && `${el.resource}/${el.id}`,
type: el.type,
identifier: el.identifier,
display: el.display,
};
}),
about: options.about &&
options.about.map((el) => {
return {
reference: el.resource && `${el.resource}/${el.id}`,
type: el.type,
identifier: el.identifier,
display: el.display,
};
}),
partOf: options.partOf &&
options.partOf.map((el) => {
return {
reference: el.resource && `${el.resource}/${el.id}`,
type: el.type,
identifier: el.identifier,
display: el.display,
};
}),
status: options.status,
category: options.category,
priority: options.priority,
recipient: options.recipient &&
options.recipient.map((el) => {
return {
reference: el.resource && `${el.resource}/${el.id}`,
type: el.type,
identifier: el.identifier,
display: el.display,
};
}),
sender: options.sender && {
reference: options.sender.resource &&
`${options.sender.resource}/${options.sender.id}`,
type: options.sender.type,
identifier: options.sender.identifier,
display: options.sender.display,
},
payload: options.payload &&
options.payload.map((el) => {
let ret = {};
if (el.id) {
ret.id = el.id;
}
if (el.extension) {
ret.extension = el.extension;
}
if (el.modifierExtension) {
ret.modifierExtension = ret.modifierExtension;
}
if (el.content) {
if (el.content.contentAttachment) {
ret.contentAttachment = el.content.contentAttachment;
}
else if (el.content.contentString) {
ret.contentString = el.content.contentString;
}
else if (el.content.contentReference) {
ret.contentReference = {
reference: `${el.content.contentReference.resource}/${el.content.contentReference.id}`,
type: el.content.contentReference.type,
identifier: el.content.contentReference.identifier,
display: el.content.contentReference.display,
};
}
}
return ret;
}),
received: options.receivedDate,
sent: options.sentDate,
reasonCode: options.reasonCode,
reasonReference: options.reasonReference &&
options.reasonReference.map((el) => {
return {
reference: el.resource && `${el.resource}/${el.id}`,
type: el.type,
identifier: el.identifier,
display: el.display,
};
}),
encounter: options.encounter && {
reference: options.encounter.resource &&
`${options.encounter.resource}/${options.encounter.id}`,
type: options.encounter.type,
identifier: options.encounter.identifier,
display: options.encounter.display,
},
inResponseTo: options.inResponseTo &&
options.inResponseTo.map((el) => {
return {
reference: el.resource && `${el.resource}/${el.id}`,
type: el.type,
identifier: el.identifier,
display: el.display,
};
}),
};
return body;
}
convertFhirToObject(options) {
var _a, _b;
const ret = {
text: ((_a = options === null || options === void 0 ? void 0 : options.text) === null || _a === void 0 ? void 0 : _a.div) || "",
status: options.status,
category: options.category,
resourceType: "Communication",
priority: options.priority
};
if (options.recipient) {
ret.recipient = options.recipient.map((el) => this.getFromMultResource(el));
}
if (options.identifier) {
ret.identifier = options.identifier;
}
if (options.subject) {
ret.subject = this.getFromMultResource(options.subject);
}
if (options.basedOn) {
ret.basedOn = options.basedOn.map((el) => this.getFromMultResource(el));
}
if (options.about) {
ret.about = options.about.map((el) => this.getFromMultResource(el));
}
if (options.topic) {
ret.topic = options.topic;
}
if (options.partOf) {
ret.partOf = options.partOf.map((el) => this.getFromMultResource(el));
}
if (options.recipient) {
ret.recipient = options.recipient.map((el) => this.getFromMultResource(el));
}
if (options.medium) {
ret.medium = options.medium;
}
if (options.implicitRules) {
ret.implicitRulesLink = options.implicitRules;
}
if (options.reasonCode) {
ret.reasonCode = options.reasonCode;
}
if (options.reasonReference) {
ret.reasonReference = options.reasonReference.map((el) => this.getFromMultResource(el));
}
if (options.inResponseTo) {
ret.inResponseTo = options.inResponseTo.map((el) => this.getFromMultResource(el));
}
if (options.sender) {
ret.sender = this.getFromMultResource(options.sender);
}
if (options.encounter) {
ret.encounter = this.getFromMultResource(options.encounter);
}
if (options.id) {
ret.id = options.id;
}
if (options.sent) {
ret.sentDate = options.sent;
}
if (options.received) {
ret.receivedDate = options.received;
}
if (options.payload) {
ret.payload = (_b = options.payload) === null || _b === void 0 ? void 0 : _b.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;
}
statusArray() {
return statusArray.map((el) => el);
}
}
exports.Communication = Communication;
//# sourceMappingURL=Communication.js.map