gcp-nrces-fhir
Version:
Google cloud healthcare api NRCES FHIR implimenataion
232 lines • 8.33 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.ServiceRequest = exports.serviceRequestCategoryArray = void 0;
const ResourceMai_1 = __importDefault(require("./ResourceMai"));
const ServiceRequestStatusArray = [
"draft",
"active",
"on-hold",
"revoked",
"completed",
"entered-in-error",
"unknown",
];
const ServiceRequestIntentArray = [
"proposal",
"plan",
"directive",
"order",
"original-order",
"reflex-order",
"filler-order",
"instance-order",
"option",
];
exports.serviceRequestCategoryArray = [
{ code: "108252007", display: "Laboratory procedure" },
{ code: "363679005", display: "Imaging" },
{ code: "409063005", display: "Counselling" },
{ code: "409073007", display: "Education" },
{ code: "387713003", display: "Surgical procedure" },
];
const serviceRequestPriority = ["routine", "urgent", "asap", "stat"];
class ServiceRequest extends ResourceMai_1.default {
constructor() {
super(...arguments);
this.statusArray = () => {
return ServiceRequestStatusArray.map((el) => el);
};
this.itentArray = () => {
return ServiceRequestIntentArray.map((el) => el);
};
this.category = () => {
return exports.serviceRequestCategoryArray.map((el) => el);
};
this.priority = () => {
return serviceRequestPriority.map((el) => el);
};
}
toHtml() {
return __awaiter(this, void 0, void 0, function* () {
throw new Error("Method not implemented.");
});
}
getFHIR(options) {
const getText = () => {
let services = "";
if (options.services && options.services.length > 0) {
options.services.forEach((el) => {
services = `${services}, ${el.display}`;
});
}
let ret = services;
return ret;
};
const body = {
resourceType: "ServiceRequest",
id: options.id || undefined,
meta: {
profile: [
"https://nrces.in/ndhm/fhir/r4/StructureDefinition/ServiceRequest",
],
},
text: {
status: "generated",
div: `<div xmlns=\"http://www.w3.org/1999/xhtml\">${getText()}</div>`,
},
specimen: options.specimanIds &&
options.specimanIds.map((el) => {
return {
reference: `Specimen/${el}`,
};
}),
status: options.status,
intent: options.intent,
code: {
coding: options.services,
},
subject: {
reference: `Patient/${options.patientId}`,
display: options.patientName,
},
occurrenceDateTime: options.date,
};
if (options.priority) {
body.priority = options.priority;
}
if (options.category) {
body.category = [
{
coding: [
{
system: "http://snomed.info/sct",
code: options.category.code,
display: options.category.display,
},
],
},
];
}
if (options.requester) {
body.requester = {
reference: `${options.requester.resource}/${options.requester.id}`,
display: options.requester.display,
};
}
if (options.performer) {
body.performer = options.performer.map((el) => {
return {
reference: `${el.resource}/${el.id}`,
display: el.display,
};
});
}
if (options.encounterId) {
body.encounter = { reference: `Encounter/${options.encounterId}` };
}
if (options.note) {
body.note = options.note;
}
if (options.extension) {
body.extension = options.extension;
}
if (options.reasonCode) {
body.reasonCode = options.reasonCode;
}
return body;
}
convertFhirToObject(options) {
const requester = () => {
const resource = `${options.requester.reference}`.substring(0, `${options.requester.reference}`.indexOf("/"));
const id = this.getIdFromReference({
ref: options.requester.reference,
resourceType: resource,
});
let ret = {
display: options.requester.display,
id: id,
resource: resource,
};
return ret;
};
const performer = () => {
let ret = [];
options.performer.forEach((el) => {
const resource = `${el.reference}`.substring(0, `${el.reference}`.indexOf("/"));
const id = this.getIdFromReference({
ref: el.reference,
resourceType: resource,
});
ret.push({
display: el.display,
id: id,
resource: resource,
});
});
return ret;
};
let ret = {
status: options.status,
intent: options.intent,
patientId: this.getIdFromReference({
ref: options.subject.reference,
resourceType: "Patient",
}),
patientName: options.subject.display,
date: options.occurrenceDateTime,
id: options.id,
requester: requester(),
};
if (options.priority) {
ret.priority = options.priority;
}
if (options.category) {
ret.category = {
code: options.category[0].coding[0].code,
display: options.category[0].coding[0].display,
};
}
if (options.reasonCode) {
ret.reasonCode = options.reasonCode;
}
if (options.specimen && options.specimen.length > 0) {
ret.specimanIds = options.specimen.map((el) => this.getIdFromReference({ ref: el.reference, resourceType: "Specimen" }));
}
if (options.code && options.code.coding) {
ret.services = options.code.coding;
}
if (options.performer) {
ret.performer = performer();
}
if (options.encounter) {
ret.encounterId = this.getIdFromReference({
ref: options.encounter.reference,
resourceType: "Encounter",
});
}
if (options.extension) {
ret.extension = options.extension;
}
if (options.note) {
ret.note = options.note;
}
if (ret.performer == undefined) {
delete ret.performer;
}
return ret;
}
}
exports.ServiceRequest = ServiceRequest;
//# sourceMappingURL=ServiceRequest.js.map