gcp-nrces-fhir
Version:
Google cloud healthcare api NRCES FHIR implimenataion
193 lines • 7.03 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.Procedure = exports.procedureStatusArray = void 0;
const ResourceMai_1 = __importDefault(require("./ResourceMai"));
const html_to_text_1 = require("html-to-text");
exports.procedureStatusArray = [
"preparation",
"in-progress",
"not-done",
"on-hold",
"stopped",
"completed",
"entered-in-error",
"unknown",
];
class Procedure extends ResourceMai_1.default {
constructor() {
super(...arguments);
this.statusArray = () => {
return exports.procedureStatusArray.map((el) => el);
};
}
toHtml() {
return __awaiter(this, void 0, void 0, function* () {
throw new Error("Method not implemented.");
});
}
getFHIR(options) {
const getText = () => {
let ret = "";
if (options.text == "" || options.text == undefined) {
return "";
}
if (options.performer) {
ret = `<div>Performer : ${options.performer.name}</div>`;
}
if (options.asserter) {
ret = `${ret}<div>Asserted By : ${options.asserter.name}</div>`;
}
if (options.recorder) {
ret = `${ret}<div>Recorded By : ${options.recorder.name}</div>`;
}
// ret = `${ret}<div>Procedure Notes</div>`;
ret = `${ret}${options.text}`;
if (options.outcome) {
ret = `${ret}<div>Outcome</div>`;
ret = `${ret}<div>${options.outcome.text}</div>`;
}
if (options.followUp) {
ret = `${ret}<div>Follow Up</div>`;
options.followUp.forEach((el) => {
ret = `${ret} <div>${el}</div>`;
});
}
ret = ret.trim();
return ret;
};
options.code = {
coding: options.code.coding,
text: (0, html_to_text_1.htmlToText)(options.text),
};
const body = {
resourceType: "Procedure",
id: options.id || undefined,
meta: {
profile: [
"https://nrces.in/ndhm/fhir/r4/StructureDefinition/Procedure",
],
},
text: {
status: "generated",
div: getText(),
},
status: options.status,
code: options.code,
subject: { reference: `Patient/${options.patientID}` },
performedDateTime: options.procedureDate,
encounter: {
reference: `Encounter/${options.encounterId}`,
},
note: [{ text: options.text }],
outcome: options.outcome,
};
if (options.performer) {
body.performer = [
{
actor: {
reference: `Practitioner/${options.performer.id}`,
display: options.performer.name,
},
},
];
}
if (options.recorder) {
body.recorder = {
reference: `Practitioner/${options.recorder.id}`,
display: options.recorder.name,
};
}
if (options.asserter) {
body.asserter = {
reference: `Practitioner/${options.asserter.id}`,
display: options.asserter.name,
};
}
if (options.report && options.report.length > 0) {
body.report = options.report.map((el) => {
return { reference: `DiagnosticReport/${el}` };
});
}
if (options.followUp) {
body.followUp = options.followUp.map((el) => {
return {
text: el,
};
});
}
return body;
}
convertFhirToObject(options) {
let ret = {
status: options.status,
text: options.text.div,
code: options.code,
patientID: `${options.subject.reference}`.substring(8),
procedureDate: options.performedDateTime,
id: options.id,
encounterId: this.getIdFromReference({
ref: options.encounter.reference,
resourceType: "Encounter",
}),
note: options.note.map((el) => {
return el.text;
}),
};
if (options.performer) {
ret.performer = {
id: this.getIdFromReference({
ref: options.performer[0].actor.reference,
resourceType: "Practitioner",
}),
name: options.performer[0].actor.display,
};
}
if (options.followUp) {
ret.followUp = options.followUp.map((el) => el.text);
}
if (options.outcome) {
ret.outcome = options.outcome;
}
if (options.report) {
ret.report = options.report.map((el) => {
return this.getIdFromReference({
ref: el.reference,
resourceType: "DiagnosticReport",
});
});
}
if (options.asserter) {
ret.asserter = {
id: this.getIdFromReference({
ref: options.asserter.reference,
resourceType: "Practitioner",
}),
name: options.asserter.display,
};
}
if (options.recorder) {
ret.recorder = {
id: this.getIdFromReference({
ref: options.recorder.reference,
resourceType: "Practitioner",
}),
name: options.recorder.display,
};
}
return ret;
}
}
exports.Procedure = Procedure;
//# sourceMappingURL=Procedure.js.map