Files
FE_CPONE/test/vuex/one-fo-supervisor/modules/patient.js
2026-04-27 10:13:31 +07:00

127 lines
5.2 KiB
JavaScript

// 1 => LOADING
// 2 => DONE
// 3 => ERROR
import * as api from "../api/patient.js"
export default {
namespaced: true,
state: {
search_patient: 0,
search_error_message: '',
search:'',
patients: [],
total_patient: 0,
selected_patient: {},
notes:[],
save_error_message: '',
statuses:[{name:'Belum selesai',value:'N'},{name:'Sudah selesai',value:'Y'},{name:'Adhoc',value:'adhoc'}],
selected_status:{name:'Belum selesai',value:'N'},
message_type:'',
status_act:'',
dialogerrormsg:false,
errormsg:'',
last_id:-1,
snackbar:{value:false,timeout:4000,text:''}
},
mutations: {
update_snackbar(state, val) {
state.snackbar = val
},
update_last_id(state, val) {
state.last_id = val
},
update_dialogerrormsg(state, patient) {
state.dialogerrormsg = patient
},
update_errormsg(state, patient) {
state.errormsg = patient
},
update_search_error_message(state, patient) {
state.search_error_message = patient
},
update_search_patient(state, patient) {
state.search_patient = patient
},
update_patients(state, data) {
state.patients = data.records
state.total_patient = data.total
},
update_selected_patient(state, val) {
state.selected_patient = val
},
update_start_date(state, val) {
state.start_date = val
},
update_end_date(state, val) {
state.end_date = val
},
update_search(state, val) {
state.search = val
},
update_selected_status(state, val) {
state.selected_status = val
},
update_notes(state, val) {
state.notes = val
},
update_message_type(state, val) {
state.message_type = val
},
update_status_act(state, val) {
state.status_act = val
}
},
actions: {
async search(context, prm) {
context.commit("update_search_patient", 1)
try {
prm.token = one_token()
let resp = await api.search(prm)
if (resp.status != "OK") {
context.commit("update_search_patient", 3)
context.commit("update_search_error_message", resp.message)
} else {
context.commit("update_search_patient", 2)
context.commit("update_search_error_message", "")
let data = {
records: resp.data.records,
total: resp.data.total
}
context.commit("update_patients", data)
if(data.records.length > 0){
if(prm.lastidx === -1){
context.commit("update_selected_patient", data.records[0])
context.commit("update_notes",data.records[0].notes)
context.commit("update_message_type",data.records[0].message_type)
context.commit("update_status_act",data.records[0].status)
context.dispatch("supplies/lookup",{orderid:data.records[0].orderid},{root:true})
context.dispatch("barcode/lookup",{orderid:data.records[0].orderid},{root:true})
context.dispatch("delivery/lookup",{orderid:data.records[0].orderid},{root:true})
//context.commit("payment/update_notes",data.records[0].notes,{root:true})
}
else{
context.commit("update_selected_patient", data.records[prm.lastidx])
context.commit("update_notes",data.records[prm.lastidx].notes)
context.commit("update_message_type",data.records[prm.lastidx].message_type)
context.commit("update_status_act",data.records[prm.lastidx].status)
context.dispatch("supplies/lookup",{orderid:data.records[prm.lastidx].orderid},{root:true})
context.dispatch("barcode/lookup",{orderid:data.records[prm.lastidx].orderid},{root:true})
context.dispatch("delivery/lookup",{orderid:data.records[prm.lastidx].orderid},{root:true})
//context.commit("payment/update_notes",data.records[prm.lastidx].notes,{root:true})
}
}else{
context.commit("update_selected_patient", {})
context.commit("update_notes",[])
context.dispatch("delivery/lookup",{orderid:0},{root:true})
}
context.dispatch("test/getcitos",{},{root:true})
}
} catch (e) {
context.commit("update_search_patient", 3)
context.commit("update_search_error_message", e.message)
console.log(e)
}
}
}
}