233 lines
9.1 KiB
JavaScript
233 lines
9.1 KiB
JavaScript
// 1 => LOADING
|
|
// 2 => DONE
|
|
// 3 => ERROR
|
|
import * as api from "../api/mcu.js"
|
|
|
|
export default {
|
|
namespaced: true,
|
|
state: {
|
|
order_id: 0,
|
|
|
|
// Statuses
|
|
ajax_status: 0,
|
|
ajax_error_message: ''
|
|
},
|
|
mutations: {
|
|
update_ajax_status(state, v) {
|
|
state.ajax_status = v
|
|
},
|
|
|
|
update_ajax_error_message(state, v) {
|
|
state.ajax_error_message = v
|
|
},
|
|
|
|
update_order_id(state, v) {
|
|
state.order_id = v
|
|
}
|
|
},
|
|
actions: {
|
|
|
|
async load(context) {
|
|
|
|
try {
|
|
let resp = await api.load(one_token())
|
|
|
|
if (resp.status != "200") {
|
|
context.commit("update_ajax_status", 3)
|
|
context.commit("update_ajax_error_message", resp.message)
|
|
alert('error')
|
|
} else {
|
|
if (resp.data.status != "OK") {
|
|
alert(resp.data.message)
|
|
return;
|
|
}
|
|
|
|
let data = resp.data.data
|
|
context.commit('update_order_id', data.pre_id)
|
|
|
|
// BEGIN Load
|
|
// Load PATIENT
|
|
context.commit('patient/update_noreg', data.patient.patient_number, {root:true})
|
|
context.commit('patient/update_search', '', {root:true})
|
|
|
|
context.dispatch('patient/search', {use:true, use_idx:0}, {root:true})
|
|
|
|
// Load COMPANY
|
|
context.commit("company/update_companies", {records:data.company, total:1}, {root:true})
|
|
context.commit("company/update_selected_company", data.company[0], {root:true})
|
|
|
|
for(let i in data.company[0].mou) {
|
|
let cmou = data.company[0].mou[i]
|
|
if (cmou.M_MouIsDefault == "Y") {
|
|
context.commit("company/update_selected_mou", cmou, {root:true})
|
|
|
|
if (cmou.M_MouEmail != "" && cmou.M_MouEmailIsDefault == "Y") {
|
|
let dlv = context.rootState.delivery.checked_id
|
|
// if (dlv == undefined) dlv = []
|
|
|
|
if (dlv.indexOf(cmou.delivery_email_code) < 0) {
|
|
|
|
// console.log(cid)
|
|
dlv.push(cmou.delivery_email_code)
|
|
console.log(dlv)
|
|
context.commit('delivery/update_checked_id', dlv, {root:true})
|
|
}
|
|
}
|
|
|
|
context.commit("delivery/update_params", {m_id:cmou.M_MouID}, {root:true})
|
|
context.dispatch("delivery/search", null, {root:true})
|
|
}
|
|
|
|
}
|
|
|
|
context.dispatch('load_pxs', data.pre_id)
|
|
}
|
|
} catch(e) {
|
|
context.commit("update_ajax_status", 3)
|
|
context.commit("update_ajax_error_message", resp.message)
|
|
}
|
|
},
|
|
|
|
async load_pxs(context, id) {
|
|
context.commit("update_ajax_status", 1)
|
|
|
|
// LOADING
|
|
context.commit('update_dialog_loading', true, {root:true})
|
|
try {
|
|
let mouCompanyID = 0
|
|
if (context.rootState.company.selected_mou.M_MouID) {
|
|
mouCompanyID = context.rootState.company.selected_mou.M_MouID
|
|
}
|
|
|
|
let resp = await api.load_pxs(mouCompanyID, id)
|
|
if (resp.status != "OK") {
|
|
context.commit("update_ajax_status", 3)
|
|
context.commit("update_ajax_error_message", resp.message)
|
|
|
|
// LOADING
|
|
context.commit('update_dialog_loading', false, {root:true})
|
|
} else {
|
|
context.commit("update_ajax_status", 2)
|
|
context.commit("update_ajax_error_message", "")
|
|
|
|
let x = resp.data.records
|
|
let cpx = context.rootState.px
|
|
|
|
for (let k in x) {
|
|
// SEARCH NAT TEST
|
|
let px = x[k]
|
|
let nt = cpx.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)
|
|
continue
|
|
|
|
let selected_test = cpx.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)
|
|
}
|
|
context.commit('px/update_selected_test', selected_test, {root:true})
|
|
|
|
let req = px.requirement
|
|
let reqs = cpx.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.commit('px/update_nat_test', null, {root:true})
|
|
// END LOADING
|
|
|
|
}
|
|
|
|
context.dispatch('px/appx_schedule', null, {root:true})
|
|
context.commit('update_dialog_loading', false, {root:true})
|
|
context.commit('history/update_history_dialog', false, {root:true})
|
|
// context.commit('change_tab', '02', {root:true})
|
|
|
|
context.dispatch('load_doctor')
|
|
}
|
|
} catch(e) {
|
|
context.commit("update_ajax_status", 3)
|
|
context.commit("update_ajax_error_message", e.message )
|
|
console.log(e)
|
|
}
|
|
},
|
|
|
|
async load_doctor(context) {
|
|
context.commit("update_ajax_status", 1)
|
|
|
|
try {
|
|
|
|
let resp = await api.load_doctor()
|
|
if (resp.status != "OK") {
|
|
context.commit("update_ajax_status", 3)
|
|
context.commit("update_ajax_error_message", resp.message)
|
|
|
|
} else {
|
|
context.commit("update_ajax_status", 2)
|
|
context.commit("update_ajax_error_message", "")
|
|
|
|
let data = {
|
|
total : resp.data.total,
|
|
records : resp.data.records
|
|
}
|
|
|
|
context.commit("doctor/update_doctors", data, {root:true})
|
|
context.commit("doctor/update_selected_doctor", data.records[0], {root:true})
|
|
|
|
// Auto CHECKED
|
|
let cdoc = data.records[0]
|
|
if (cdoc.email_default == "Y") {
|
|
let dlv = context.rootState.delivery.checked_id
|
|
if (dlv.indexOf(cdoc.delivery_email_code) < 0) {
|
|
dlv.push(cdoc.delivery_email_code)
|
|
context.commit('delivery/update_checked_id', dlv, {root:true})
|
|
}
|
|
}
|
|
|
|
context.commit('delivery/update_params', {d_id:cdoc.M_DoctorID}, {root:true})
|
|
context.dispatch('delivery/search', null, {root:true})
|
|
}
|
|
} catch(e) {
|
|
context.commit("update_ajax_status", 3)
|
|
context.commit("update_ajax_error_message", e.message )
|
|
console.log(e)
|
|
}
|
|
}
|
|
}
|
|
}
|