gcp-nrces-fhir
Version:
Google cloud healthcare api NRCES FHIR implimenataion
157 lines • 6.89 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.AllergyIntolerance = exports.allergyVerificationStatusArray = exports.allergyClinicalStatusArray = void 0;
const gcpSearch_1 = __importDefault(require("../classess/gcpSearch"));
const ResourceMai_1 = __importDefault(require("./ResourceMai"));
exports.allergyClinicalStatusArray = [
"active",
"inactive",
"resolved",
];
exports.allergyVerificationStatusArray = [
"unconfirmed",
"confirmed",
"refuted",
"entered-in-error",
];
class AllergyIntolerance extends ResourceMai_1.default {
constructor() {
super(...arguments);
this.getClinicalStatusArray = () => {
return exports.allergyClinicalStatusArray.map((el) => el);
};
this.getVerificationStatus = () => {
return exports.allergyVerificationStatusArray.map((el) => el);
};
this.getPatientPerEncounterAllergyIntolerances = (patientId, encounterId) => __awaiter(this, void 0, void 0, function* () {
let ret = [];
const gcpFhirSearch = new gcpSearch_1.default();
try {
// Perform search for AllergyIntolerance resources by patient ID
const res = yield gcpFhirSearch.search("AllergyIntolerance", `patient=${patientId}`);
// Check if the response contains valid data entries
if (res.data && res.data.entry && res.data.entry.length > 0) {
// Filter entries to only include those with a matching encounter ID
ret = res.data.entry
.filter((el) => {
// Attempt to extract Encounter ID from the resource reference
const id = this.getIdFromReference({ ref: el.resource.encounter.reference, resourceType: "Encounter" });
return id === encounterId;
})
// Convert each filtered FHIR resource to ALLERGY_INTOLERANCE object
.map((el) => this.convertFhirToObject(el.resource));
}
}
catch (error) {
console.error("Error fetching AllergyIntolerance data:", error);
// Optional: Handle errors, log, or throw to propagate further
}
return ret;
});
this.gettAllergyIntolerancesText = (allergyIntolerances) => {
let ret = '';
allergyIntolerances.forEach((el, i) => {
ret += `<div>${i + 1} ${el.text}</div`;
});
return ret;
};
}
toHtml() {
return __awaiter(this, void 0, void 0, function* () {
throw new Error("Method not implemented.");
});
}
getFHIR(options) {
var _a, _b;
const getText = () => {
let ret = "";
ret = `Agent:${options.code.text}, clinical status:${options.clinicalStatus}, verification status:${options.verificationStatus}`;
if (options.note && options.note.length > 0) {
ret += `<div>${options.note.map(el => el.text).join(". ")}</div>`;
}
return ret;
};
const body = {
resourceType: "AllergyIntolerance",
id: options.id || undefined,
meta: {
profile: [
"https://nrces.in/ndhm/fhir/r4/StructureDefinition/AllergyIntolerance",
],
},
text: {
status: "generated",
div: getText(),
},
clinicalStatus: {
coding: [
{
system: "http://terminology.hl7.org/CodeSystem/allergyintolerance-clinical",
code: options.clinicalStatus,
display: options.clinicalStatus,
},
],
},
verificationStatus: {
coding: [
{
system: "http://terminology.hl7.org/CodeSystem/allergyintolerance-verification",
code: options.verificationStatus,
display: options.verificationStatus,
},
],
},
code: options.code,
patient: { reference: `Patient/${options.patientId}` },
recordedDate: options.date,
};
if (options.encounterId) {
body.encounter = {
"reference": `Encounter/${options.encounterId}`
};
}
if (options.note) {
body.note = options.note;
}
if (options.recorder) {
body.recorder = { "reference": `${(_a = options.recorder) === null || _a === void 0 ? void 0 : _a.resource}/${(_b = options.recorder) === null || _b === void 0 ? void 0 : _b.id}` };
}
return body;
}
convertFhirToObject(options) {
let ret = {
clinicalStatus: options.clinicalStatus.coding[0].code,
verificationStatus: options.verificationStatus.coding[0].code,
code: options.code,
text: options.text.div,
patientId: `${options.patient.reference}`.substring(8),
date: options.recordedDate,
id: options.id,
};
if (options.encounter) {
ret.encounterId = this.getIdFromReference({ "ref": options.encounter.reference, "resourceType": "Encounter" });
}
if (options.recorder) {
ret.recorder = this.getFromMultResource({ "reference": options.recorder.reference });
}
if (options.note) {
ret.note = options.note;
}
// note: options.note,
return ret;
}
}
exports.AllergyIntolerance = AllergyIntolerance;
//# sourceMappingURL=AllergyIntolerance.js.map