101 lines
5.0 KiB
JavaScript
101 lines
5.0 KiB
JavaScript
"use strict";
|
|
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());
|
|
});
|
|
};
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.sendConditionService = void 0;
|
|
const config_1 = require("../../../../utils/config");
|
|
const generate_token_service_1 = require("../../generate-token/generate-token.service");
|
|
const condition_repository_1 = require("./condition.repository");
|
|
const axiosClient_1 = require("../../../../utils/axiosClient");
|
|
const date_fns_tz_1 = require("date-fns-tz");
|
|
const date = new Date();
|
|
const timeZone = config_1.environment.timezone;
|
|
const formattedUtcDate = new Date((0, date_fns_tz_1.format)(date, "yyyy-MM-dd HH:mm:ss", { timeZone }) + " UTC");
|
|
const baseUrl = config_1.environment.satusehat.url_base;
|
|
const orgId = config_1.environment.satusehat.org_id;
|
|
const sendConditionService = (limit) => __awaiter(void 0, void 0, void 0, function* () {
|
|
var _a;
|
|
const tokenService = yield (0, generate_token_service_1.checkTokenService)();
|
|
if ((tokenService === null || tokenService === void 0 ? void 0 : tokenService.code) !== 200) {
|
|
throw new Error("Generate Token Failed");
|
|
}
|
|
let token = (_a = tokenService === null || tokenService === void 0 ? void 0 : tokenService.data) === null || _a === void 0 ? void 0 : _a.access_token;
|
|
const getDataConditionReady = yield (0, condition_repository_1.getDataCondition)(limit);
|
|
const resultPush = [];
|
|
if (getDataConditionReady.length > 0) {
|
|
const promises = getDataConditionReady.map((element) => __awaiter(void 0, void 0, void 0, function* () {
|
|
const headersData = {
|
|
"Content-Type": "application/json",
|
|
Authorization: `Bearer ${token}`,
|
|
};
|
|
const url = `${baseUrl}/Condition`;
|
|
const method = "POST";
|
|
const tglLayanan = element.input_time_emr;
|
|
const payload = {
|
|
resourceType: "Condition",
|
|
clinicalStatus: {
|
|
coding: [
|
|
{
|
|
system: "http://terminology.hl7.org/CodeSystem/condition-clinical",
|
|
code: "active",
|
|
display: "Active",
|
|
},
|
|
],
|
|
},
|
|
category: [
|
|
{
|
|
coding: [
|
|
{
|
|
system: "http://terminology.hl7.org/CodeSystem/condition-category",
|
|
code: "encounter-diagnosis",
|
|
display: "Encounter Diagnosis",
|
|
},
|
|
],
|
|
},
|
|
],
|
|
code: {
|
|
coding: [
|
|
{
|
|
system: "http://hl7.org/fhir/sid/icd-10",
|
|
code: `${element.kode_diagnosa}`,
|
|
display: `${element.nama_diagnosa}`,
|
|
},
|
|
],
|
|
},
|
|
subject: {
|
|
reference: `Patient/${element.patient_id}`,
|
|
display: `${element.patient_name}`,
|
|
},
|
|
encounter: {
|
|
reference: `Encounter/${element.encounter_id}`,
|
|
},
|
|
onsetDateTime: `${tglLayanan
|
|
.toISOString()
|
|
.replace(".000Z", "+00:00")}`,
|
|
recordedDate: `${tglLayanan
|
|
.toISOString()
|
|
.replace(".000Z", "+00:00")}`,
|
|
};
|
|
const response = yield (0, axiosClient_1.requestAxios)(headersData, url, method, payload);
|
|
if (response.status === 201) {
|
|
const updateInsertIdPatient = (0, condition_repository_1.updateInsertIdConditionRepo)(element.emr_detail_id, payload, response.data, response.data.id, response.data.resourceType);
|
|
resultPush.push(Object.assign(Object.assign({}, element), { status: "sukses" }));
|
|
}
|
|
else {
|
|
const updateInsertIdPatient = (0, condition_repository_1.updateInsertIdConditionRepo)(element.emr_detail_id, payload, response.data, "0", "Condition", 1);
|
|
resultPush.push(Object.assign(Object.assign({}, element), { status: "gagal", response: response.data }));
|
|
}
|
|
}));
|
|
yield Promise.all(promises);
|
|
}
|
|
return resultPush;
|
|
});
|
|
exports.sendConditionService = sendConditionService;
|