gcp-nrces-fhir
Version:
Google cloud healthcare api NRCES FHIR implimenataion
303 lines • 12 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.Observation = void 0;
const html_to_text_1 = require("html-to-text");
const gcp_1 = __importDefault(require("../classess/gcp"));
const ResourceMai_1 = __importDefault(require("./ResourceMai"));
const statusArray = ["registered", "preliminary", "final", "amended"];
class Observation extends ResourceMai_1.default {
toHtml() {
return __awaiter(this, void 0, void 0, function* () {
throw new Error("Method not implemented.");
});
}
getFHIR(options) {
const extensions = [];
if (options.orgPanel) {
extensions.push({
url: "https://www.nicehms.com/orgPanel",
valueString: JSON.stringify(options.orgPanel),
});
}
const getText = () => {
let ret = "";
if (options.hasMember) {
options.hasMember.forEach((el) => __awaiter(this, void 0, void 0, function* () {
const res = (yield new gcp_1.default().getFhirResource(el.id, el.resource)).data;
ret = `${ret}<br/>${res.text.div}`;
}));
}
else {
ret = options.text;
}
return ret;
};
if (options.valueWithType) {
options.value = options.valueWithType;
}
const body = {
resourceType: "Observation",
id: options.id,
meta: {
profile: [
"https://nrces.in/ndhm/fhir/r4/StructureDefinition/ObservationBodyMeasurement",
],
},
text: {
status: "generated",
div: getText(),
},
status: options.status,
extension: extensions,
code: options.code,
subject: {
reference: `Patient/${options.patientId}`,
},
};
if (options.category) {
body.category = options.category;
}
if (options.effectiveDateTime) {
body.effectiveDateTime = options.effectiveDateTime;
}
if (options.effectivePeriod) {
body.effectivePeriod = options.effectivePeriod;
}
if (options.encounterId) {
body.encounter = { reference: `Encounter/${options.encounterId}` };
}
if (options.basedOn) {
body.basedOn = options.basedOn.map((el) => {
return { reference: `${el.resource}/${el.id}` };
});
}
if (options.partOf) {
body.partOf = options.partOf.map((el) => {
return { reference: `${el.resource}/${el.id}` };
});
}
if (options.hasMember) {
body.hasMember = options.hasMember.map((el) => {
return { reference: `${el.resource}/${el.id}` };
});
}
if (options.performer) {
body.performer = options.performer.map((el) => {
return { reference: `${el.resource}/${el.id}` };
});
}
if (options.referenceRange) {
body.referenceRange = options.referenceRange;
}
if (options.specimenId) {
body.specimen = { reference: `Specimen/${options.specimenId}` };
}
if (options.value) {
body[Object.keys(options.value)[0]] = Object.values(options.value)[0];
}
if (options.interpretation) {
body.interpretation = options.interpretation;
}
if (options.bodySite) {
body.bodySite = options.bodySite;
}
if (options.component) {
body.component = options.component;
}
return body;
}
convertFhirToObject(options) {
let ret = {
status: options.status,
code: options.code,
patientId: this.getIdFromReference({
ref: options.subject.reference,
resourceType: "Patient",
}),
id: options.id,
value: options.valueQuantity ||
options.valueCodeableConcept ||
options.valueString ||
options.valueBoolean ||
options.valueInteger ||
options.valueRange ||
options.valueRatio ||
options.valueSampledData ||
options.valueTime ||
options.valueDateTime ||
options.valuePeriod,
text: options.text.div,
referenceRange: options.referenceRange,
};
if (options.valueQuantity) {
ret.valueWithType = { "valueQuantity": options.valueQuantity };
}
else if (options.valueCodeableConcept) {
ret.valueWithType = { "valueCodeableConcept": options.valueCodeableConcept };
}
else if (options.valueString) {
ret.valueWithType = { "valueString": options.valueString };
}
else if (options.valueBoolean) {
ret.valueWithType = { "valueBoolean": options.valueBoolean };
}
else if (options.valueInteger) {
ret.valueWithType = { "valueInteger": options.valueInteger };
}
else if (options.valueRange) {
ret.valueWithType = { "valueRange": options.valueRange };
}
else if (options.valueRatio) {
ret.valueWithType = { "valueRatio": options.valueRatio };
}
else if (options.valueSampledData) {
ret.valueWithType = { "valueSampledData": options.valueSampledData };
}
else if (options.valueTime) {
ret.valueWithType = { "valueTime": options.valueTime };
}
else if (options.valueDateTime) {
ret.valueWithType = { "valueDateTime": options.valueDateTime };
}
else if (options.valuePeriod) {
ret.valueWithType = { "valuePeriod": options.valuePeriod };
}
if (options.category) {
ret.category = options.category;
}
if (options.component) {
ret.component = options.component;
}
if (ret.value == undefined) {
delete ret.value;
}
if (options.effectiveDateTime) {
ret.effectiveDateTime = options.effectiveDateTime;
}
if (options.effectivePeriod) {
ret.effectivePeriod = options.effectivePeriod;
}
if (options.interpretation) {
ret.interpretation = options.interpretation;
}
if (options.bodySite) {
ret.bodySite = options.bodySite;
}
if (options.hasMember) {
ret.hasMember = options.hasMember.map((el) => {
return this.getFromMultResource(el);
});
}
if (options.basedOn) {
ret.basedOn = options.basedOn.map((el) => {
return this.getFromMultResource(el);
});
}
if (options.partOf) {
ret.partOf = options.partOf.map((el) => {
return this.getFromMultResource(el);
});
}
if (options.encounterId) {
ret.encounterId = this.getIdFromReference({
ref: options.encounter.reference,
resourceType: "Encounter",
});
}
if (options.performer) {
ret.performer = options.performer.map((el) => {
return this.getFromMultResource(el);
});
}
if (ret.referenceRange == undefined) {
delete ret.referenceRange;
}
if (options.specimenId) {
ret.specimenId = this.getIdFromReference({
ref: options.specimen.reference,
resourceType: "Specimen",
});
}
if (options.dataAbsentReason) {
ret.dataAbsentReason = options.dataAbsentReason;
}
if (options.extension) {
const orgPanel = options.extension.filter((el) => {
if ((el.url = "https://www.nicehms.com/orgPanel")) {
return el;
}
});
ret.orgPanel = JSON.parse(orgPanel[0].valueString);
}
return ret;
}
statusArray() {
return statusArray.map((el) => el);
}
bundlify(resource) {
var _a, _b;
const copy = super.bundlify(resource);
if (copy.valueString) {
copy.valueString = (0, html_to_text_1.htmlToText)(copy.valueString);
return copy;
}
else if (copy.valueQuantity) {
if (!copy.valueQuantity.value) {
delete copy.valueQuantity;
delete copy.referenceRange;
copy.valueString = "Not Done";
return copy;
}
let valueString = `${copy.valueQuantity.value} ${copy.valueQuantity.unit} `;
if (copy.referenceRange) {
const lessThan = copy.referenceRange.filter((el) => el.high).length > 0 ? copy.referenceRange.filter((el) => el.high)[0].high.value : "";
const morethan = copy.referenceRange.filter((el) => el.low).length > 0 ? copy.referenceRange.filter((el) => el.low)[0].low.value : "";
if (lessThan == "" && morethan == "") {
}
else if (lessThan != "" && morethan != "") {
valueString = `${valueString} Reference Range ${morethan}-${lessThan}`;
}
else if (lessThan == "") {
valueString = `${valueString} Reference Range more than ${morethan}`;
}
else if (morethan == "") {
valueString = `${valueString} Reference Range less than ${lessThan}`;
}
delete copy.referenceRange;
}
delete copy.valueQuantity;
copy.valueString = valueString;
}
else if (copy.valueCodeableConcept) {
copy.valueString = copy.valueCodeableConcept.text ||
((_b = (_a = copy.valueCodeableConcept.coding) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.display) || "";
delete copy.valueCodeableConcept;
}
else if (copy.valueBoolean != null) {
copy.valueString = copy.valueBoolean ? "Yes" : "No";
delete copy.valueBoolean;
}
else if (copy.valueInteger != null) {
copy.valueString = String(copy.valueInteger);
delete copy.valueInteger;
}
else {
copy.valueString = "Panel";
}
return copy;
}
}
exports.Observation = Observation;
//# sourceMappingURL=Observation.js.map