Files
api-kedungdoro/ui/10.9.9.2/one-process-resultentry-v106/modules/re_patient.js

256 lines
7.4 KiB
JavaScript

// 1 => LOADING
// 2 => DONE
// 3 => ERROR
import * as api from "../api/re_patient.js"
window.api = api
export default {
namespaced: true,
state: {
order_id: 0,
search: '',
nolab: '',
sdate: new Date().toISOString().substr(0, 10),
edate: null,
search_status: 0,
search_error_message: '',
search_dialog_is_active: false,
patients: [],
total_patient: 0,
total_patient_page: 0,
curr_patient_page: 1,
selected_patient: {},
// PX
total_px: 0,
pxs: [],
langs: [],
lang_code: "ID",
lang_id: 0,
lang_si: "N",
dialog_req: false,
dialog_note: false,
result_note: '',
info_req: { req_fo: [], req_spec_col: [], req_spec_ver: [], req_samp_ver: [], req_pre_an: [] },
// ITF
Itf: "",
BrnListBarcode: ""
},
mutations: {
// ITF
update_Itf(state, val) {
state.Itf = val
},
update_BrnListBarcode(state, val) {
state.BrnListBarcode = val
},
update_search_dialog_is_active(state, status) {
state.search_dialog_is_active = status
},
update_search_error_message(state, status) {
state.search_error_message = status
},
update_search(state, val) {
state.search = val
},
update_nolab(state, val) {
state.nolab = val
},
update_search_status(state, status) {
state.search_status = status
},
update_patients(state, data) {
state.patients = data.records
state.total_patient = data.total
state.total_patient_page = data.total_page
},
update_curr_patient_page(state, data) {
state.curr_patient_page = data
},
update_selected_patient(state, val) {
state.selected_patient = val
if (val) {
state.langs = val.lang
state.lang_code = val.lang[0].code
state.lang_id = val.lang[0].id
state.lang_si = val.lang[0].is_si
state.result_note = val.T_OrderHeaderResultNote
} else {
state.langs = []
state.lang_code =
state.lang_id =
state.lang_si = null
state.result_note = ""
}
},
update_id(state, id) {
state.order_id = id
},
update_pxs(state, pxs) {
state.pxs = pxs.records
},
update_sdate(state, date) {
state.sdate = date
},
update_edate(state, date) {
state.edate = date
},
update_lang(state, lang) {
state.lang_code = lang.code
state.lang_id = lang.id
state.lang_si = lang.is_si
},
update_dialog_note(state, v) {
state.dialog_note = v
},
update_result_note(state, v) {
state.result_note = v
},
update_info_req(state, v) {
state.info_req = v
},
update_dialog_req(state, v) {
state.dialog_req = v
}
},
actions: {
async search(context) {
context.commit("update_search_status", 1)
try {
let g_id = 0
if (context.rootState.re_px.selected_group)
g_id = context.rootState.re_px.selected_group.group_id
let inp_no = context.state.search
if (inp_no.length == 9 && inp_no.substr(0, 2) == "ZL") {
inp_no = await window.xno(inp_no)
}
let company_id = 0
if (context.rootState.company.company) {
company_id = context.rootState.company.company.M_CompanyID
}
let resp = await api.search(one_token(), context.state.sdate, inp_no, g_id, context.state.curr_patient_page, company_id)
if (resp.status != "OK") {
context.commit("update_search_status", 3)
context.commit("update_search_error_message", resp.message)
} else {
context.commit("update_search_status", 2)
context.commit("update_search_error_message", "")
let data = {
records: resp.data.records,
total: resp.data.total,
total_page: resp.data.total_page
}
// attachment obj
let objAttachment = resp.data.attachment;
console.log("DARI SERVER ATTACHMENT RE_PATIENT ", resp.data.attachment)
// update object attachment
context.commit("re_px/update_obj_attachment", objAttachment, { root: true })
context.commit("update_patients", data)
if (data.records.length < 1) {
context.commit('update_selected_patient', null)
context.commit('re_px/update_pxs', [], { root: true })
// update order_id state jika data tidak ada
context.commit('re_px/update_id', 0, { root: true })
}
else {
context.commit('update_selected_patient', data.records[0])
context.commit('re_px/update_id', data.records[0].T_OrderHeaderID, { root: true })
context.dispatch('re_px/search', null, { root: true })
context.dispatch('info_req')
}
}
} catch (e) {
context.commit("update_search_status", 3)
context.commit("update_search_error_message", e.message)
}
},
async save_note(context) {
context.commit("update_search_status", 1)
try {
let resp = await api.save_note(one_token(), context.state.selected_patient.T_OrderHeaderID, context.state.result_note)
if (resp.status != "OK") {
context.commit("update_search_status", 3)
context.commit("update_search_error_message", resp.message)
} else {
context.commit("update_search_status", 2)
context.commit("update_search_error_message", "")
console.log(resp)
context.commit('update_dialog_note', false)
let x = context.state.selected_patient
let y = context.state.patients
for (let i in y)
if (x.T_OrderHeaderID == y[i].T_OrderHeaderID)
y[i].T_OrderHeaderResultNote = context.state.result_note
context.commit("update_patients", {
records: y,
total: context.state.total_patient,
total_page: context.state.total_patient_page
})
}
} catch (e) {
context.commit("update_search_status", 3)
context.commit("update_search_error_message", e.message)
}
},
async info_req(context) {
context.commit("update_search_status", 1)
try {
let resp = await api.info_req(one_token(), context.state.selected_patient.T_OrderHeaderID)
if (resp.status != "OK") {
context.commit("update_search_status", 3)
context.commit("update_search_error_message", resp.message)
} else {
context.commit("update_search_status", 2)
context.commit("update_search_error_message", "")
context.commit('update_info_req', resp.data)
}
} catch (e) {
context.commit("update_search_status", 3)
context.commit("update_search_error_message", e.message)
}
}
}
}