gcp-nrces-fhir
Version:
Google cloud healthcare api NRCES FHIR implimenataion
228 lines (225 loc) • 10.4 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.InsurancePlan = void 0;
const ResourceMai_1 = __importDefault(require("../resources/ResourceMai"));
class InsurancePlan extends ResourceMai_1.default {
getFHIR(options) {
const body = {
resourceType: "InsurancePlan",
id: options.id,
meta: {
versionId: "1",
profile: [
"https://nrces.in/ndhm/fhir/r4/StructureDefinition/InsurancePlan",
],
},
text: {
status: "extensions",
div: options.text,
},
alias: options.alias,
extension: options.extension,
identifier: options.identifier,
status: options.status,
type: options.type,
name: options.name,
period: options.period,
ownedBy: options.ownedBy && {
reference: options.ownedBy.resource &&
options.ownedBy.id &&
`${options.ownedBy.resource}/${options.ownedBy.id}`,
identifier: options.ownedBy.identifier,
display: options.ownedBy.display,
type: options.ownedBy.type,
},
administeredBy: options.administeredBy && {
reference: options.administeredBy.resource &&
options.administeredBy.id &&
`${options.administeredBy.resource}/${options.administeredBy.id}`,
identifier: options.administeredBy.identifier,
display: options.administeredBy.display,
type: options.administeredBy.type,
},
coverage: options.coverage,
plan: options.plan,
};
return body;
}
convertFhirToObject(options) {
const ret = {
id: options.id,
text: options.text && options.text.div,
resourceType: "InsurancePlan",
identifier: options.identifier,
extension: options.extension,
status: options.status,
type: options.type,
period: options.period,
name: options.name,
ownedBy: options.oownedBy &&
((options.ownedBy.reference &&
this.getFromMultResource(options.ownedBy)) ||
options.ownedBy),
administeredBy: options.administeredBy &&
((options.administeredBy.reference &&
this.getFromMultResource(options.administeredBy)) ||
options.administeredBy),
alias: options.alias,
coverage: options.coverage,
plan: options.plan,
};
// Remove keys with null or undefined values
Object.keys(ret).forEach((key) => {
if (ret[key] === null ||
ret[key] === undefined) {
delete ret[key];
}
});
return ret;
}
toHtml(option) {
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
return __awaiter(this, void 0, void 0, function* () {
option.body = this.convertFhirToObject(option.body);
const getLimit = (limit) => {
const limitRet = limit &&
limit.map((el) => {
let ret = `<tr><td>${el.code && this.codeableConceptToHtml(el.code)}</td>`;
ret += `<td>${el.value && el.value.value || ""}</td></tr>`;
return ret;
});
let tablest = `<table data-pdfmake="{'widths':['60%','40%']}">
<tr>
<th>
Item
</th>
<th>
Value
</th>
</tr>
${limitRet === null || limitRet === void 0 ? void 0 : limitRet.join("")}
</table>
`;
return tablest;
};
const getBenfit = (benefit) => {
const benefitRet = benefit.map((el) => {
let ret = `<b>${el.type && this.codeableConceptToHtml(el.type)}</b>`;
ret += el.requirement && `<p>${el.requirement}</p>`;
ret += getLimit(el.limit);
return ret;
});
return benefitRet.join("</br/>");
};
const getCoverage = () => {
const coveragedstr = data.coverage &&
data.coverage.map((el) => {
let ret = `<h3>${this.codeableConceptToHtml(el.type)}</h3>`;
ret += el.requirement && `<p>${el.requirement}</p>`;
ret += getBenfit(el.benefit);
return ret;
});
return coveragedstr.join("</br/>");
};
const data = option.body;
return `
<div>
<h1>Insurance Plan</h1>
<p><strong>Resource Type:</strong> ${data.resourceType}</p>
<p><strong>ID:</strong> ${data.id || "N/A"}</p>
<p><strong>Status:</strong> ${data.status}</p>
<p><strong>Name:</strong> ${data.name}</p>
<p><strong>Text:</strong> ${data.text || "N/A"}</p>
<p><strong>Type:</strong> ${((_a = data.type) === null || _a === void 0 ? void 0 : _a.text) || "N/A"}</p>
<p><strong>Period:</strong> ${((_b = data.period) === null || _b === void 0 ? void 0 : _b.start)
? new Date(data.period.start).toLocaleDateString()
: "N/A"} to ${((_c = data.period) === null || _c === void 0 ? void 0 : _c.end) ? new Date(data.period.end).toLocaleDateString() : "N/A"}</p>
<p><strong>Owned By:</strong> ${((_d = data.ownedBy) === null || _d === void 0 ? void 0 : _d.display) || "N/A"} (${((_e = data.ownedBy) === null || _e === void 0 ? void 0 : _e.reference) || "N/A"})</p>
<p><strong>Administered By:</strong> ${((_f = data.administeredBy) === null || _f === void 0 ? void 0 : _f.display) || "N/A"} (${((_g = data.administeredBy) === null || _g === void 0 ? void 0 : _g.reference) || "N/A"})</p>
<p><strong>Alias:</strong> ${((_h = data.alias) === null || _h === void 0 ? void 0 : _h.join(", ")) || "None"}</p>
<h2>Identifiers</h2>
<ul>
${((_j = data.identifier) === null || _j === void 0 ? void 0 : _j.map((id) => `
<li>
<strong>System:</strong> ${id.system || "N/A"},
<strong>Value:</strong> ${id.value || "N/A"}
</li>
`).join("")) || "<li>None</li>"}
</ul>
<h2>Coverage</h2>
${getCoverage()}
<h2>Plans</h2>
<table border="1" cellspacing="0" cellpadding="5">
<thead>
<tr>
<th>Type</th>
<th>Coverage Areas</th>
<th>General Costs</th>
<th>Networks</th>
</tr>
</thead>
<tbody>
${((_k = data.plan) === null || _k === void 0 ? void 0 : _k.map((plan) => {
var _a, _b, _c, _d;
return `
<tr>
<td>${((_a = plan.type) === null || _a === void 0 ? void 0 : _a.text) || "N/A"}</td>
<td>
<ul>
${((_b = plan.coverageArea) === null || _b === void 0 ? void 0 : _b.map((area) => `
<li>
<strong>Resource:</strong> ${area.resource || "N/A"}<br>
<strong>Reference:</strong> ${area.reference || "N/A"}
</li>
`).join("")) || "<li>None</li>"}
</ul>
</td>
<td>
<ul>
${((_c = plan.generalCost) === null || _c === void 0 ? void 0 : _c.map((cost) => {
var _a, _b, _c;
return `
<li>
<strong>Type:</strong> ${((_a = cost.type) === null || _a === void 0 ? void 0 : _a.text) || "N/A"}<br>
<strong>Group Size:</strong> ${cost.groupSize || "N/A"}<br>
<strong>Cost:</strong> ${((_b = cost.cost) === null || _b === void 0 ? void 0 : _b.value) || "N/A"} ${((_c = cost.cost) === null || _c === void 0 ? void 0 : _c.currency) || ""}<br>
<strong>Comment:</strong> ${cost.comment || "N/A"}
</li>
`;
}).join("")) || "<li>None</li>"}
</ul>
</td>
<td>
<ul>
${((_d = plan.network) === null || _d === void 0 ? void 0 : _d.map((network) => `
<li>
<strong>Resource:</strong> ${network.resource || "N/A"}<br>
<strong>Display:</strong> ${network.display || "N/A"}
</li>
`).join("")) || "<li>None</li>"}
</ul>
</td>
</tr>
`;
}).join("")) || "<tr><td colspan='4'>No Plans Available</td></tr>"}
</tbody>
</table>
</div>
`;
});
}
}
exports.InsurancePlan = InsurancePlan;
//# sourceMappingURL=Insuranceplan.js.map