Files
FE_CPONE/test/vuex/cpone-card-reader/modules/order.js
2026-04-27 10:13:31 +07:00

791 lines
29 KiB
JavaScript

// 1 => LOADING
// 2 => DONE
// 3 => ERROR
import * as api from "../api/order.js"
export default {
namespaced: true,
state: {
order_id: 0,
queue: "",
is_from_clinic: false,
catatan_fo: '',
diagnosa: '',
patient_note: '',
finish_dialog_is_active: false,
current_order: {},
received_sample: 'N',
tabs: [
{ "label": "DEMOGRAFI", "icon": "opacity", "code": "01", "enabled": true },
{ "label": "PEMERIKSAAN", "icon": "verified_user", "code": "02", "enabled": true },
{ "label": "PEMBAYARAN", "icon": "motorcycle", "code": "03", "enabled": false }
],
print_dialog_is_active: false,
rpt_url: window.BASE_URL + '/one-ui/test/vuex/common/under-cons.pdf',
dialog_start: true,
status_start: 'Y',
time_start: undefined,
elapsedTime: 0,
show_time: null,
loading_process: false,
stest: [],
mcuid: 0,
preid: 0,
patientBarcode: [],
url_preregister : '',
url_register: '',
in_saving: false,
loading_data_patient: false
},
mutations: {
update_loading_data_patient(state, val) {
state.loading_data_patient = val
},
update_in_saving(state, val) {
state.in_saving = val
},
update_url_preregister(state, val) {
state.url_preregister = val
},
update_url_register(state, val) {
state.url_register = val
},
update_patientBarcode(state, val) {
state.patientBarcode = val
},
update_preid(state, val) {
state.preid = val
},
update_mcuid(state, val) {
state.mcuid = val
},
update_stest(state, val) {
state.stest = val
},
update_loading_process(state, val) {
state.loading_process = val
},
update_show_time(state, val) {
state.show_time = val
},
update_elapsedTime(state, val) {
state.elapsedTime = val
},
update_dialog_start(state, val) {
state.dialog_start = val
},
update_status_start(state, val) {
state.status_start = val
},
update_time_start(state, val) {
state.time_start = val
},
update_patient_note(state, val) {
state.patient_note = val
},
update_catatan_fo(state, val) {
state.catatan_fo = val
},
update_diagnosa(state, val) {
state.diagnosa = val
},
update_finish_dialog_is_active(state, val) {
state.finish_dialog_is_active = val
},
update_current_order(state, val) {
state.current_order = val
},
update_received_sample(state, val) {
state.received_sample = val
},
update_tab_enable(state, v) {
state.tabs[v[0]].enabled = v[1]
},
update_from_clinic(state, v) {
state.is_from_clinic = v
},
update_queue(state, v) {
state.queue = v
},
update_order_id(state, v) {
state.order_id = v
},
reset_form(state) {
state.order_id = 0
state.queue = ""
state.is_from_clinic = false
state.catatan_fo = ""
state.diagnosa = ""
state.patient_note = ""
},
update_print_dialog_is_active(state, val) {
state.print_dialog_is_active = val
},
update_rpt_url(state, v) {
state.rpt_url = v
}
},
actions: {
async save(context) {
var order_id = context.state.order_id;
var preid = context.state.preid;
var mcuid = context.state.mcuid;
console.log(mcuid);
var delivery = [];
var delivery_note = [];
var detail = [];
var req = [];
var test_detail = [];
var tests = context.state.stest;
console.log('lang_2')
console.log(context.rootState.language.selected_language_2)
var header = {
patient_id: context.rootState.patient.selected_patient.M_PatientID,
age: context.rootState.patient.selected_patient.patient_age,
alias_doctor: context.rootState.doctor.doctor_alias,
alias_doctor_address: context.rootState.doctor.doctor_alias_address,
sender_doctor_id: context.rootState.doctor.selected_doctor.M_DoctorID,
sender_address_id: 0,
pj_doctor_id: context.rootState.doctor.selected_doctor_pj.M_DoctorID,
lang_id: context.rootState.language.selected_language.id,
lang_si: context.rootState.language.selected_language.is_si,
lang_id_2: context.rootState.language.selected_language_2 ? context.rootState.language.selected_language_2.id : 0,
lang_si_2: context.rootState.language.selected_language_2 ? context.rootState.language.selected_language_2.is_si : "N",
doctor_note: "",
fo_note: context.state.catatan_fo,
patient_note: context.state.patient_note,
company_id: context.rootState.company.selected_company.CorporateID,
mou_id: 0,
received_sample: context.rootState.order.received_sample,
queue: context.state.queue,
diagnose: context.state.diagnosa,
is_cito: context.rootState.px.is_cito,
cito_id: context.rootState.px.selected_cito ? context.rootState.px.selected_cito.Nat_CitoID : 0,
mcu_pre_id: order_id,
branch_id: context.rootState.patient.selected_patient.branch_id
};
let xxdlv = context.rootState.delivery.data_deliveries
let xdlv = _.filter(xxdlv, function (o) { return o.chex === 'Y' })
let dlv = _.filter(xdlv, function (o) { return o.typeform === 'origin' })
delivery_note = _.filter(xdlv, function (o) { return o.typeform === 'additional' })
dlv.forEach(function (value) {
delivery.push({
delivery_id: value.delivery_id,
delivery_code: value.delivery_code,
delivery_type_id: value.delivery_type,
address_id: value.address_id,
note: value.description,
noteplus: value.note,
kelurahan: value.kelurahan
})
})
var px_tmp = [];
var st = context.rootState.px.selected_test;
for (let i in st) {
let x = {
ss_price_id: st[i]['Ss_PriceMouID'],
t_id: st[i]['T_TestID'],
t_price: st[i]['T_PriceAmount'],
t_disc: st[i]['T_PriceDisc'],
t_discrp: st[i]['T_PriceDiscRp'],
t_cito: st[i]['T_TestIsCito'],
t_req: 'N',
t_reqnote: '',
t_ispacket: st[i]['is_packet'],
t_packetid: st[i]['packet_id'],
t_packettype: st[i]['px_type']
}
let rq = context.rootState.px.requirement
for (let j in rq) {
if (rq[j].label == st[i].T_TestRequirement) {
x.t_req = (rq[j].checked ? 'Y' : 'N')
x.t_reqnote = rq[j].note
}
}
px_tmp.push(x)
}
detail = px_tmp;
// let _req = context.rootState.px.requirement
// for (let _i in _req) {
// req.push({req_id:_req[_i].req_id, req_label:_req[_i].label, checked:(_req[_i].checked?"Y":"N"), note:_req[_i].note, px_id:_req[_i].px_id})
// }
let req_status = context.rootState.px.req_status
req = {
status: req_status,
reqs: req_status == 'Y' ? [] : context.rootState.px.reqs
}
// context.commit("update_search_status",1)
try {
let resp = await api.save(one_token(), mcuid, preid, order_id, header, delivery, delivery_note, detail, req, tests)
console.log('save respon' , resp.data)
if (resp.status != "200") {
// context.commit("update_search_status",3)
// context.commit("update_search_error_message",resp.message)
alert('error')
} else {
// Dialog loading
context.commit('update_loading_process', false)
context.commit('update_dialog_loading', false, { root: true })
if(resp.data.data.tipe == 'new'){
context.commit("update_current_order", resp.data.data)
context.commit('update_finish_dialog_is_active', true)
context.commit('payment/update_order_id', resp.data.data.id, { root: true })
context.commit("payment/update_order", resp.data, { root: true })
}else{
alert('Data telah terdaftar')
var p_url = resp.data.data.url
var url_string = window.location.href
var url = new URL(url_string);
var mcuid = url.searchParams.get("mcuid")
location.replace("/one-ui/" + p_url +"?mcuid="+mcuid)
}
//context.dispatch('payment/get_order', resp.data.data.id, {root:true})
// store.commit('change_tab', '03');
}
} catch (e) {
// context.commit("update_search_status",3)
// context.commit("update_search_error_message",e.message )
}
},
async load_from_clinic(context) {
let queue = context.state.queue;
try {
let resp = await api.load_from_clinic(queue)
if (resp.status != "200") {
// context.commit("update_search_status",3)
// context.commit("update_search_error_message",resp.message)
alert('error')
} else {
if (resp.data.status != "OK") {
return;
}
let data = resp.data.data
context.commit('update_from_clinic', true)
context.commit('patient/update_selected_patient', data.patient, { root: true })
context.commit('doctor/update_doctors', { records: [data.doctor], total: 1 }, { root: true })
context.commit('doctor/update_selected_doctor', data.doctor, { root: true })
context.commit('doctor/update_search', data.doctor.search, { root: true })
// Delivery
context.commit('delivery/update_params', { p_id: data.patient.M_PatientID }, { root: true })
context.commit('delivery/update_params', { d_id: data.doctor.M_DoctorID }, { root: true })
// Company
let search = data.company.search
delete (data.company.search)
setTimeout(function () { context.commit('company/update_companies', { records: [data.company], total: 1 }, { root: true }) }, 0)
setTimeout(function () { context.commit('company/update_search', search, { root: true }) }, 0)
setTimeout(function () { context.commit('company/update_selected_company', data.company, { root: true }) }, 0)
setTimeout(function () { context.commit('company/update_selected_mou', data.company.mou[0], { root: true }) }, 0)
// setTimeout(function() { context.commit('company/selected_xx', data.company.mou[0], {root:true}) }, 0)
// PX
// context.commit("px/update_selected_test", data.test, {root:true})
// context.commit("px/update_requirement", data.req, {root:true})
// Delivery
context.dispatch('delivery/search', null, { root: true })
// PX
context.dispatch('px/search_pxs_clinic', data.order_id, { root: true })
}
} catch (e) {
// context.commit("update_search_status",3)
// context.commit("update_search_error_message",e.message )
}
},
async load(context) {
let id = context.state.order_id;
try {
let resp = await api.load(id)
if (resp.status != "200") {
// context.commit("update_search_status",3)
// context.commit("update_search_error_message",resp.message)
alert('error')
} else {
if (resp.data.status != "OK") {
return;
}
let data = resp.data.data
if (id !== -1)
context.commit('patient/update_selected_patient', data.patient, { root: true })
context.commit('doctor/update_doctors', { records: [data.doctor], total: 1 }, { root: true })
context.commit('doctor/update_selected_doctor', data.doctor, { root: true })
context.commit('doctor/update_search', data.doctor.search, { root: true })
// Delivery
context.commit('delivery/update_params', { p_id: data.patient.M_PatientID }, { root: true })
context.commit('delivery/update_params', { d_id: data.doctor.M_DoctorID }, { root: true })
// Company
let search = data.company.search
delete (data.company.search)
setTimeout(function () { context.commit('company/update_companies', { records: [data.company], total: 1 }, { root: true }) }, 0)
setTimeout(function () { context.commit('company/update_search', search, { root: true }) }, 0)
setTimeout(function () { context.commit('company/update_selected_company', data.company, { root: true }) }, 0)
setTimeout(function () { context.commit('company/update_selected_mou', data.company.mou[0], { root: true }) }, 0)
// setTimeout(function() { context.commit('company/selected_xx', data.company.mou[0], {root:true}) }, 0)
context.commit('update_received_sample', data.order.rec_sample);
// PX
context.commit("px/update_selected_test", data.test, { root: true })
context.commit("px/update_requirement", data.req, { root: true })
// Delivery
context.dispatch('delivery/search', null, { root: true })
// Enable tab
context.commit('update_tab_enable', [2, true])
setTimeout(function () {
context.commit('update_from_clinic', false)
}, 15000)
}
} catch (e) {
// context.commit("update_search_status",3)
// context.commit("update_search_error_message",e.message )
}
},
async reset_form(context) {
context.commit("reset_form")
context.commit("patient/update_selected_patient", {}, { root: true })
context.commit("doctor/update_doctors", { records: [], total: 0 }, { root: true })
context.commit("doctor/update_selected_doctor", {}, { root: true })
context.commit("doctor/update_selected_doctor_pj", {}, { root: true })
// context.commit("delivery/update_deliveries", [], {root:true})
// context.commit("delivery/update_selected_delivery", {}, {root:true})
context.commit("delivery/update_params", { p_id: 0, d_id: 0, o_id: 0 }, { root: true })
context.dispatch("delivery/search", null, { root: true })
context.commit("px/update_selected_test", [], { root: true })
context.commit("px/update_requirement", [], { root: true })
// Company
context.commit("company/reset_company")
},
async load_preregister(context, prm) {
//context.commit("update_search_status",1)
try {
prm.token = one_token()
let resp = await api.load_preregister(prm)
//alert("dasdasd")
// console.log(resp)
// context.commit("update_search_status",2)
// context.commit("update_search_error_message","")
// alert("aaaaaaaaaaaaaa")
//console.log("dasdasdasd")
let data = {
records: resp.data.records
}
console.log(resp)
var rst = resp.data.data.records
console.log(rst)
context.commit('patient/update_selected_patient', rst['patient'], { root: true })
if (rst['patient']['M_PatientPhoto']) {
context.commit('photo/update_photo_url', rst['patient']['M_PatientPhoto'], { root: true })
}
let doctors = []
doctors.push(rst['selected_doctor'])
console.log(doctors)
context.commit('doctor/update_doctors', { records: doctors, total: doctors.length }, { root: true })
context.commit('doctor/update_selected_doctor', doctors[0], { root: true })
context.commit('doctor/update_selected_address', rst['selected_address'], { root: true })
console.log('selesai doctor')
console.log(rst['companies'])
context.commit('company/update_companies', { records: rst['companies'], total: 1 }, { root: true })
console.log(context.rootState.company.companies)
context.commit('company/update_selected_company', rst['selected_company'], { root: true })
context.commit('company/update_selected_mou', rst['selected_mou'], { root: true })
console.log('selesai company')
context.commit('delivery/update_data_deliveries', rst['data_deliveries'], { root: true })
console.log('selesai delivery')
context.commit('update_stest', rst['tests'])
console.log('selesai test 1')
//context.commit('history/update_history_dialog',false,{root:true})
//context.dispatch('px/search', {}, { root: true })
if (rst['tests']) {
rst['tests'].forEach(function (test) {
context.dispatch('selectPx', test)
});
}
console.log('selesai load')
} catch (e) {
// context.commit("update_search_status",3)
// context.commit("update_search_error_message",e.message )
}
},
async selectPx(context, px) {
// console.log(context)
var in_selectPx = false
console.log(px)
//debugger
console.log("start select px")
if (!window.one_token()) {
//context.commit('update_message_error', 'Maaf, koneksi Anda sempat terputus silahkan Log Out dan Login kembali',{root:true})
//context.commit('update_dialog_error', true,{root:true})
return
}
try {
console.log(in_selectPx)
// START LOADING
//context.commit('update_dialog_loading', true)
console.log('px type ' + px.px_type)
// IF PROFILE
if (px.px_type == "PR" || px.px_type == "PXR")
return context.dispatch('selectProfile', px)
// SEARCH NAT TEST
let nt = context.rootState.px.nat_test
let found_nt = false
for (let i in px.nat_test) {
if (nt.indexOf(px.nat_test[i]) > -1)
found_nt = true
}
if (found_nt) {
alert('Pemeriksaan tersebut sudah ada !')
// END LOADING
//context.commit('update_dialog_loading', false,{root:true})
return
}
//if (in_selectPx) return
in_selectPx = true
let selected_test = context.rootState.px.selected_test
let flag_found = false
selected_test.forEach(function (t, idx) {
if (t.T_TestID == px.T_TestID) {
selected_test[idx] = px
flag_found = true
}
})
if (!flag_found) {
selected_test.push(px)
let tests = context.rootState.px.tests
let p_idx = -1
tests.forEach(function (t, idx) {
if (t.T_TestID == px.T_TestID) {
p_idx = idx
}
})
if (p_idx >= 0) {
_.pullAt(tests, [p_idx])
let dt = {
records: tests,
total: tests.length
}
context.commit('px/update_tests', dt, { root: true })
}
}
context.commit('px/update_selected_test', selected_test, { root: true })
console.log('load data patient px')
context.commit('update_loading_data_patient', true)
if (px.px_type !== "PN") {
let req = px.requirement
let reqs = context.rootState.px.requirement
if (req.length > 0) {
for (let i in req) {
let found = false
for (let j in reqs) {
if (reqs[j]['req_id'] == req[i]['req_id'])
found = j
}
if (!found)
reqs.push({
px_id: [px.T_TestID],
label: req[i]['req_name'],
error_message: 'Hasil harus di isi',
is_error: true,
checked: false,
note: '',
req_id: req[i]['req_id']
})
else
reqs[found].px_id.push(px.T_TestID)
}
context.commit('px/update_requirement', reqs, { root: true })
}
}
context.dispatch('px/appx_schedule', {}, { root: true })
in_selectPx = false
context.commit('px/update_nat_test', {}, { root: true })
context.commit('update_loading_data_patient', true)
console.log('load data patient px')
// END LOADING
if (px.px_type == "PN")
//context.commit('update_loading_data_patient', false)
context.dispatch('px/packet_reqs', { pxs: px.child_test }, { root: true })
//context.commit('update_dialog_loading', false,{root:true})
} catch (e) {
console.log(e)
in_selectPx = false
}
},
async selectProfile(context, px) {
try {
var in_selectPx = false
// SEARCH NAT TEST
let nt = context.rootState.px.nat_test
let found_nt = false
for (let i in px.nat_test) {
if (nt.indexOf(px.nat_test[i]) > -1)
found_nt = true
}
if (found_nt) {
alert('Pemeriksaan tersebut sudah ada !')
// END LOADING
// context.commit('update_dialog_loading', false,{root:true})
return
}
let pxs = px.child_test
for (let i in pxs) {
px = pxs[i]
let selected_test = context.rootState.px.selected_test
let flag_found = false
selected_test.push(px)
let tests = context.rootState.px.tests
let p_idx = -1
tests.forEach(function (t, idx) {
if (t.T_TestID == px.T_TestID) {
p_idx = idx
}
})
if (p_idx >= 0) {
_.pullAt(tests, [p_idx])
let dt = {
records: tests,
total: tests.length
}
context.commit('px/update_tests', dt, { root: true })
}
context.commit('px/update_selected_test', selected_test, { root: true })
let req = px.requirement
let reqs = context.rootState.px.requirement
if (req.length > 0) {
for (let i in req) {
let found = false
for (let j in reqs) {
if (reqs[j]['req_id'] == req[i]['req_id'])
found = j
}
if (!found)
reqs.push({
px_id: [px.T_TestID],
label: req[i]['req_name'],
error_message: 'Hasil harus di isi',
is_error: true,
checked: false,
note: '',
req_id: req[i]['req_id']
})
else
reqs[found].px_id.push(px.T_TestID)
}
context.commit('px/update_requirement', reqs, { root: true })
}
}
context.dispatch('px/appx_schedule', { root: true })
//in_selectPx = false
context.commit('px/update_nat_test', { root: true })
console.log('load data patient profile')
context.commit('update_loading_data_patient', true)
// END LOADING
//context.commit('update_dialog_loading', false,{root:true})
} catch (e) {
console.log(e)
// END LOADING
//context.commit('update_dialog_loading', false,{root:true})
// in_selectPx = false
}
},
async get_time_start(context, prm) {
try {
prm.token = one_token()
let resp = await api.get_time_start(prm)
if (resp.data.status != "OK") {
} else {
var t_orderid = resp.data.data.orderid
var url_preregister = resp.data.data.url_preregister
var url_register = resp.data.data.url_register
console.log(t_orderid)
console.log(url_preregister)
console.log(url_register)
context.commit('update_url_preregister', url_preregister)
context.commit('update_url_register', url_register)
if(t_orderid > 0){
alert('Data telah terdaftar !!!')
var url_string = window.location.href
var url = new URL(url_string);
var mcuid = url.searchParams.get("mcuid")
location.replace("/one-ui/" +url_preregister +"?mcuid="+mcuid)
}else{
context.commit('update_dialog_start', false)
context.commit('update_show_time', resp.data.data.records)
context.commit('update_status_start', 'Y')
if (prm.pre_id) {
context.dispatch("load_preregister", { id: context.state.order_id })
}
}
}
} catch (e) {
}
},
async getbarcode(context, prm) {
context.commit("update_get_data_status", 1)
try {
prm.token = one_token();
console.log(prm);
let resp = await api.lookupbarcodes(prm)
if (resp.status != "OK") {
// context.commit("update_get_data_status", 3)
var snackbar = context.state.snackbar
snackbar.color = 'red'
snackbar.value = true
snackbar.multi_line = 'single-line'
snackbar.text = 'Gagal get barcode'
context.commit("update_snackbar", snackbar)
} else {
context.commit("update_get_data_status", 2)
let data = {
records: resp.data.records,
total: resp.data.total
}
let barcodes = resp.data.records
context.commit("update_patientBarcode", data.records)
let arrprm = [];
let arrprmst = [];
for (let index = 0; index < barcodes.length; index++) {
const e = barcodes[index];
arrprm.push(e.T_BarcodeLabBarcode)
if (e.type === 'nonlab') {
arrprmst.push(e.T_SampleTypeID)
console.log('print so')
console.log("nolab so ganti group")
console.log("param ganti")
console.log("balik lagi")
// one_print_barcode_so(e.T_SampleTypeID)
}
}
if (arrprm.length > 0) {
//one_print_barcode_pk(arrprm.join(","));
}
if (arrprmst.length > 0) {
one_print_barcode_sov1(arrprmst.join(","));
}
// let inp = {};
// inp.id = prm.id;
// inp.no_lab = prm.no_lab;
// inp.name = prm.name;
// inp.register_date = prm.register_date;
// one_print_qrcode(inp);
// // console.log("Input prm")
// // console.log(inp)
// console.log("print barcode new")
// console.log(inp)
// one_print_qrcode_patient(inp);
}
} catch (e) {
console.log(e)
// context.commit("update_get_data_status", 3)
}
}
}
}