325 lines
16 KiB
JavaScript
325 lines
16 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.sendEncounterRegistrasiService = exports.getEncounterSubjectService = exports.getEncounterIdService = exports.sendEncounterService = void 0;
|
|
const config_1 = require("../../../../utils/config");
|
|
const generate_token_service_1 = require("../../generate-token/generate-token.service");
|
|
const encounter_repository_1 = require("./encounter.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 getEncounterIdService = (id) => __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 headersData = {
|
|
"Content-Type": "application/json",
|
|
Authorization: `Bearer ${token}`,
|
|
};
|
|
const url = `${baseUrl}/Encounter/${id}`;
|
|
const method = "GET";
|
|
const payload = null;
|
|
const response = yield (0, axiosClient_1.requestAxios)(headersData, url, method, payload);
|
|
return response;
|
|
});
|
|
exports.getEncounterIdService = getEncounterIdService;
|
|
const getEncounterSubjectService = (subject) => __awaiter(void 0, void 0, void 0, function* () {
|
|
var _b;
|
|
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 = (_b = tokenService === null || tokenService === void 0 ? void 0 : tokenService.data) === null || _b === void 0 ? void 0 : _b.access_token;
|
|
const headersData = {
|
|
"Content-Type": "application/json",
|
|
Authorization: `Bearer ${token}`,
|
|
};
|
|
const url = `${baseUrl}/Encounter?subject=${subject}`;
|
|
const method = "GET";
|
|
const payload = null;
|
|
const response = yield (0, axiosClient_1.requestAxios)(headersData, url, method, payload);
|
|
return response;
|
|
});
|
|
exports.getEncounterSubjectService = getEncounterSubjectService;
|
|
const sendEncounterService = (limit) => __awaiter(void 0, void 0, void 0, function* () {
|
|
var _c;
|
|
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 = (_c = tokenService === null || tokenService === void 0 ? void 0 : tokenService.data) === null || _c === void 0 ? void 0 : _c.access_token;
|
|
const getDataEncounterReady = yield (0, encounter_repository_1.getDataEncounter)(limit);
|
|
const resultPush = [];
|
|
if (getDataEncounterReady.length > 0) {
|
|
const promises = getDataEncounterReady.map((element) => __awaiter(void 0, void 0, void 0, function* () {
|
|
const headersData = {
|
|
"Content-Type": "application/json",
|
|
Authorization: `Bearer ${token}`,
|
|
};
|
|
const url = `${baseUrl}/Encounter`;
|
|
const method = "POST";
|
|
const tglLayanan = element.tgl_urut;
|
|
const payload = {
|
|
resourceType: "Encounter",
|
|
identifier: [
|
|
{
|
|
system: `http://sys-ids.kemkes.go.id/encounter/${orgId}`,
|
|
value: `${element.registration_id}`,
|
|
},
|
|
],
|
|
status: "arrived",
|
|
class: {
|
|
system: "http://terminology.hl7.org/CodeSystem/v3-ActCode",
|
|
code: "AMB",
|
|
display: "ambulatory",
|
|
},
|
|
subject: {
|
|
reference: `Patient/${element.patient_id}`,
|
|
display: `${element.patient_name}`,
|
|
},
|
|
participant: [
|
|
{
|
|
type: [
|
|
{
|
|
coding: [
|
|
{
|
|
system: "http://terminology.hl7.org/CodeSystem/v3-ParticipationType",
|
|
code: "ATND",
|
|
display: "attender",
|
|
},
|
|
],
|
|
},
|
|
],
|
|
individual: {
|
|
reference: `Practitioner/${element.practitioner_id}`,
|
|
display: `${element.practitioner_name}`,
|
|
},
|
|
},
|
|
],
|
|
period: {
|
|
start: `${tglLayanan
|
|
.toISOString()
|
|
.replace(".000Z", "+00:00")}`,
|
|
},
|
|
location: [
|
|
{
|
|
location: {
|
|
reference: `Location/${element.location_poli_id}`,
|
|
display: `${element.location_poli_name}`,
|
|
},
|
|
period: {
|
|
start: `${tglLayanan
|
|
.toISOString()
|
|
.replace(".000Z", "+00:00")}`,
|
|
},
|
|
extension: [
|
|
{
|
|
url: "https://fhir.kemkes.go.id/r4/StructureDefinition/ServiceClass",
|
|
extension: [
|
|
{
|
|
url: "value",
|
|
valueCodeableConcept: {
|
|
coding: [
|
|
{
|
|
system: "http://terminology.kemkes.go.id/CodeSystem/locationServiceClass-Outpatient",
|
|
code: "reguler",
|
|
display: "Kelas Reguler",
|
|
},
|
|
],
|
|
},
|
|
},
|
|
{
|
|
url: "upgradeClassIndicator",
|
|
valueCodeableConcept: {
|
|
coding: [
|
|
{
|
|
system: "http://terminology.kemkes.go.id/CodeSystem/locationUpgradeClass",
|
|
code: "kelas-tetap",
|
|
display: "Kelas Tetap Perawatan",
|
|
},
|
|
],
|
|
},
|
|
},
|
|
],
|
|
},
|
|
],
|
|
},
|
|
],
|
|
statusHistory: [
|
|
{
|
|
status: "arrived",
|
|
period: {
|
|
start: `${tglLayanan
|
|
.toISOString()
|
|
.replace(".000Z", "+00:00")}`,
|
|
},
|
|
},
|
|
],
|
|
serviceProvider: {
|
|
reference: `Organization/${orgId}`,
|
|
},
|
|
};
|
|
const response = yield (0, axiosClient_1.requestAxios)(headersData, url, method, payload);
|
|
if (response.status === 201) {
|
|
const updateInsertIdPatient = (0, encounter_repository_1.updateInsertIdEncounterRepo)(element.registration_id, payload, response.data, response.data.id, response.data.resourceType);
|
|
resultPush.push(Object.assign(Object.assign({}, element), { status: "sukses" }));
|
|
}
|
|
else {
|
|
const updateInsertIdPatient = (0, encounter_repository_1.updateInsertIdEncounterRepo)(element.registration_id, payload, response.data, "0", "Encounter", 1);
|
|
resultPush.push(Object.assign(Object.assign({}, element), { status: "gagal", response: response.data }));
|
|
}
|
|
}));
|
|
yield Promise.all(promises);
|
|
}
|
|
return resultPush;
|
|
});
|
|
exports.sendEncounterService = sendEncounterService;
|
|
const sendEncounterRegistrasiService = (registrasi_id) => __awaiter(void 0, void 0, void 0, function* () {
|
|
var _d;
|
|
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 = (_d = tokenService === null || tokenService === void 0 ? void 0 : tokenService.data) === null || _d === void 0 ? void 0 : _d.access_token;
|
|
const getDataEncounterReady = yield (0, encounter_repository_1.getDataEncounter)('1', registrasi_id);
|
|
const resultPush = [];
|
|
if (getDataEncounterReady.length > 0) {
|
|
const promises = getDataEncounterReady.map((element) => __awaiter(void 0, void 0, void 0, function* () {
|
|
const headersData = {
|
|
"Content-Type": "application/json",
|
|
Authorization: `Bearer ${token}`,
|
|
};
|
|
const url = `${baseUrl}/Encounter`;
|
|
const method = "POST";
|
|
const tglLayanan = element.tgl_urut;
|
|
const payload = {
|
|
resourceType: "Encounter",
|
|
identifier: [
|
|
{
|
|
system: `http://sys-ids.kemkes.go.id/encounter/${orgId}`,
|
|
value: `${element.registration_id}`,
|
|
},
|
|
],
|
|
status: "arrived",
|
|
class: {
|
|
system: "http://terminology.hl7.org/CodeSystem/v3-ActCode",
|
|
code: "AMB",
|
|
display: "ambulatory",
|
|
},
|
|
subject: {
|
|
reference: `Patient/${element.patient_id}`,
|
|
display: `${element.patient_name}`,
|
|
},
|
|
participant: [
|
|
{
|
|
type: [
|
|
{
|
|
coding: [
|
|
{
|
|
system: "http://terminology.hl7.org/CodeSystem/v3-ParticipationType",
|
|
code: "ATND",
|
|
display: "attender",
|
|
},
|
|
],
|
|
},
|
|
],
|
|
individual: {
|
|
reference: `Practitioner/${element.practitioner_id}`,
|
|
display: `${element.practitioner_name}`,
|
|
},
|
|
},
|
|
],
|
|
period: {
|
|
start: `${tglLayanan
|
|
.toISOString()
|
|
.replace(".000Z", "+00:00")}`,
|
|
},
|
|
location: [
|
|
{
|
|
location: {
|
|
reference: `Location/${element.location_poli_id}`,
|
|
display: `${element.location_poli_name}`,
|
|
},
|
|
period: {
|
|
start: `${tglLayanan
|
|
.toISOString()
|
|
.replace(".000Z", "+00:00")}`,
|
|
},
|
|
extension: [
|
|
{
|
|
url: "https://fhir.kemkes.go.id/r4/StructureDefinition/ServiceClass",
|
|
extension: [
|
|
{
|
|
url: "value",
|
|
valueCodeableConcept: {
|
|
coding: [
|
|
{
|
|
system: "http://terminology.kemkes.go.id/CodeSystem/locationServiceClass-Outpatient",
|
|
code: "reguler",
|
|
display: "Kelas Reguler",
|
|
},
|
|
],
|
|
},
|
|
},
|
|
{
|
|
url: "upgradeClassIndicator",
|
|
valueCodeableConcept: {
|
|
coding: [
|
|
{
|
|
system: "http://terminology.kemkes.go.id/CodeSystem/locationUpgradeClass",
|
|
code: "kelas-tetap",
|
|
display: "Kelas Tetap Perawatan",
|
|
},
|
|
],
|
|
},
|
|
},
|
|
],
|
|
},
|
|
],
|
|
},
|
|
],
|
|
statusHistory: [
|
|
{
|
|
status: "arrived",
|
|
period: {
|
|
start: `${tglLayanan
|
|
.toISOString()
|
|
.replace(".000Z", "+00:00")}`,
|
|
},
|
|
},
|
|
],
|
|
serviceProvider: {
|
|
reference: `Organization/${orgId}`,
|
|
},
|
|
};
|
|
const response = yield (0, axiosClient_1.requestAxios)(headersData, url, method, payload);
|
|
if (response.status === 201) {
|
|
const updateInsertIdPatient = (0, encounter_repository_1.updateInsertIdEncounterRepo)(element.registration_id, payload, response.data, response.data.id, response.data.resourceType);
|
|
resultPush.push(Object.assign(Object.assign({}, element), { status: "sukses" }));
|
|
}
|
|
else {
|
|
const updateInsertIdPatient = (0, encounter_repository_1.updateInsertIdEncounterRepo)(element.registration_id, payload, response.data, "0", "Encounter", 1);
|
|
resultPush.push(Object.assign(Object.assign({}, element), { status: "gagal", response: response.data }));
|
|
}
|
|
}));
|
|
yield Promise.all(promises);
|
|
}
|
|
return resultPush;
|
|
});
|
|
exports.sendEncounterRegistrasiService = sendEncounterRegistrasiService;
|