535 lines
18 KiB
JavaScript
535 lines
18 KiB
JavaScript
// 1 => LOADING
|
|
// 2 => DONE
|
|
// 3 => ERROR
|
|
import * as api from "../api/patient.js"
|
|
window.api = api
|
|
|
|
export default {
|
|
namespaced: true,
|
|
state: {
|
|
noreg:'',
|
|
search: '',
|
|
search_status:0,
|
|
search_error_message:'',
|
|
search_dialog_is_active: false,
|
|
patients: [],
|
|
total_patient: 0,
|
|
total_display: 0,
|
|
selected_patient: {},
|
|
xdob:'',
|
|
patient_new: {},
|
|
patient_new_dialog_is_active: false,
|
|
|
|
idtypes: [],
|
|
selected_idtype: {},
|
|
current_page:1,
|
|
edit: false,
|
|
dialog_birthday:false,
|
|
show_more:true,
|
|
loading:false,
|
|
s_patient:[],
|
|
s_address:[],
|
|
pdefault: {patient:[]},
|
|
pdefault_patient: "N",
|
|
hs_date:moment(new Date()).format('YYYY-MM-DD'),
|
|
hs_time:'',
|
|
hs_times: [],
|
|
selected_hs_time: {},
|
|
hs_name:'',
|
|
hs_hp:'',
|
|
hs_addressid: 0,
|
|
hspatientid: 0,
|
|
hslabel:'',
|
|
hsaddress:'',
|
|
hsdetailaddress:'',
|
|
hsisutama: false,
|
|
dialog_hsaddress: false,
|
|
hs_price: 0,
|
|
hs_priceminimal: 0,
|
|
hs_priceother: 0,
|
|
hs_config:[],
|
|
hs_distance_km: 0,
|
|
hs_addressidlist: 0,
|
|
isnewpatient : 'N'
|
|
},
|
|
mutations: {
|
|
update_isnewpatient(state, val) {
|
|
state.isnewpatient = val
|
|
},
|
|
update_hs_distance_km(state, val) {
|
|
state.hs_distance_km = val
|
|
},
|
|
update_hs_config(state, val) {
|
|
state.hs_config = val
|
|
},
|
|
update_hs_times(state, val) {
|
|
state.hs_times = val.records
|
|
},
|
|
update_selected_hs_time(state, val) {
|
|
state.selected_hs_time = val
|
|
},
|
|
|
|
update_hs_addressid(state, val) {
|
|
state.hs_addressid = val
|
|
},
|
|
update_hs_addressidlist(state, val) {
|
|
state.hs_addressidlist = val
|
|
},
|
|
update_hs_price(state, val) {
|
|
state.hs_price = val
|
|
},
|
|
update_hs_priceminimal(state, val) {
|
|
state.hs_priceminimal = val
|
|
},
|
|
update_hs_priceother(state, val) {
|
|
state.hs_priceother = val
|
|
},
|
|
update_dialog_hsaddress(state, val) {
|
|
state.dialog_hsaddress = val
|
|
},
|
|
update_hslabel(state, val) {
|
|
state.hslabel = val
|
|
},
|
|
update_hsaddress(state, val) {
|
|
state.hsaddress = val
|
|
},
|
|
update_hsdetailaddress(state, val) {
|
|
state.hsdetailaddress = val
|
|
},
|
|
update_hsisutama(state, val) {
|
|
state.hsisutama = val
|
|
},
|
|
update_hspatientid(state, val) {
|
|
state.hspatientid = val
|
|
},
|
|
update_hs_date(state, val) {
|
|
state.hs_date = val
|
|
},
|
|
update_hs_time(state, val) {
|
|
state.hs_time = val
|
|
},
|
|
update_hs_name(state, val) {
|
|
state.hs_name = val
|
|
},
|
|
update_hs_hp(state, val) {
|
|
state.hs_hp = val
|
|
},
|
|
update_pdefault(state, val) {
|
|
let patient = state.selected_patient
|
|
console.log(patient)
|
|
let pdefault = state.pdefault
|
|
// if (val.length > 0) {
|
|
|
|
for (var i in patient) {
|
|
patient[i]['M_PatientIsDefault'] = 'N'
|
|
if (val.v.indexOf(patient[i]['M_PatientD']) > -1)
|
|
patient[i]['M_PatientIsDefault'] = 'Y'
|
|
}
|
|
|
|
// }
|
|
|
|
pdefault[val.t] = val.v
|
|
console.log(pdefault)
|
|
state.pdefault = pdefault
|
|
state.selected_patient = patient
|
|
},
|
|
update_pdefault_patient(state, val) {
|
|
state.pdefault_patient = val
|
|
},
|
|
update_s_address(state,status) {
|
|
state.s_address = status
|
|
},
|
|
update_s_patient(state,status) {
|
|
state.s_patient = status
|
|
},
|
|
update_loading(state,status) {
|
|
state.loading = status
|
|
},
|
|
update_xdob(state,status) {
|
|
state.xdob = status
|
|
},
|
|
update_show_more(state,status) {
|
|
state.show_more = status
|
|
},
|
|
update_current_page(state,status) {
|
|
state.current_page = status
|
|
},
|
|
update_dialog_birthday(state,status) {
|
|
state.dialog_birthday = status
|
|
},
|
|
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_noreg(state,val) {
|
|
state.noreg=val
|
|
},
|
|
update_search(state,val) {
|
|
state.search=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_display = data.total_display
|
|
},
|
|
update_selected_patient(state,val) {
|
|
var now = moment(new Date())
|
|
var dob = moment(new Date(val.M_PatientDOB))
|
|
var year = now.diff(dob,'years')
|
|
dob.add(year,'years')
|
|
var month = now.diff(dob,'months')
|
|
dob.add(month,'months')
|
|
var day = now.diff(dob,'days')
|
|
if (isNaN(year)) val.patient_age = ''
|
|
else val.patient_age = `${year} tahun ${month} bulan ${day} hari`
|
|
|
|
state.selected_patient=val
|
|
// store.state.patientaddress.patient_id = val.M_PatientID
|
|
|
|
// photo
|
|
|
|
},
|
|
|
|
update_patient_new(state, v) {
|
|
state.patient_new = v
|
|
},
|
|
|
|
update_patient_new_dialog_is_active(state, v) {
|
|
state.patient_new_dialog_is_active = v
|
|
},
|
|
|
|
update_idtypes(state, v) {
|
|
state.idtypes = v.records
|
|
},
|
|
|
|
update_selected_idtype(state, v) {
|
|
state.selected_idtype = v
|
|
},
|
|
|
|
update_edit(state, v) {
|
|
state.edit = v
|
|
}
|
|
},
|
|
actions: {
|
|
async search(context, prm) {
|
|
context.commit("update_search_status",1)
|
|
try {
|
|
//context.commit("update_loading",true)
|
|
let resp= await api.search(context.state.noreg,context.state.search,context.state.current_page)
|
|
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
|
|
}
|
|
context.commit("update_loading",false)
|
|
if (prm && prm.use)
|
|
context.commit("update_patients",{records : [],total:0})
|
|
|
|
if(data.records.length > 0){
|
|
if(context.state.patients.length > 0){
|
|
var data_before = context.state.patients
|
|
var idx_last = data_before.length - 1
|
|
data_before[idx_last].divider = 'Y'
|
|
data.records.forEach(function(entry) {
|
|
data_before.push(entry)
|
|
})
|
|
context.commit("update_patients",{records : data_before,total:data_before.length})
|
|
}
|
|
else{
|
|
context.commit("update_patients",data)
|
|
}
|
|
|
|
context.commit("update_show_more",true)
|
|
}
|
|
else{
|
|
context.commit("update_show_more",false)
|
|
context.commit("update_current_page",1)
|
|
}
|
|
|
|
if (prm)
|
|
if (prm.use) {
|
|
let pat = context.state.patients[prm.use_idx]
|
|
console.log(pat)
|
|
context.commit('update_selected_patient', pat)
|
|
if(pat.info.birthday == 'Y')
|
|
context.commit('update_dialog_birthday', true)
|
|
|
|
context.commit('order/update_patient_note', pat.M_PatientNote, {root:true})
|
|
context.dispatch('delivery/search_deliveries',{type:'patient',id:pat.M_PatientID},{root:true})
|
|
|
|
context.commit('photo/update_patient_id', pat.M_PatientID, {root: true})
|
|
}
|
|
}
|
|
} catch(e) {
|
|
context.commit("update_loading",false)
|
|
context.commit("update_search_status",3)
|
|
context.commit("update_search_error_message",e.message )
|
|
}
|
|
},
|
|
|
|
async add_new(context, prm) {
|
|
context.commit("update_search_status",1)
|
|
try {
|
|
|
|
let resp
|
|
if (context.state.edit){
|
|
resp = await api.edit(prm, context.state.selected_patient.M_PatientID)
|
|
|
|
}
|
|
else
|
|
resp = await api.add_new(prm)
|
|
|
|
if (resp.status != "OK") {
|
|
context.commit("update_search_status",3)
|
|
context.commit("update_search_error_message", resp.message)
|
|
alert(resp.message)
|
|
} else {
|
|
context.commit("update_search_status",2)
|
|
context.commit("update_search_error_message","")
|
|
|
|
if (prm.use) {
|
|
context.commit('update_noreg', resp.data.noreg)
|
|
context.commit('update_search', '')
|
|
|
|
context.dispatch('search', {use:true, use_idx:0})
|
|
context.commit('update_isnewpatient', 'N')
|
|
|
|
}
|
|
|
|
// commit("patientaddress/test", "X", { root: true })
|
|
}
|
|
} catch(e) {
|
|
context.commit("update_search_status",3)
|
|
context.commit("update_search_error_message",e.message )
|
|
}
|
|
},
|
|
async add_new_hs(context, prm) {
|
|
context.commit("update_search_status",1)
|
|
try {
|
|
|
|
let resp = await api.add_new_hs(prm)
|
|
|
|
if (resp.status != "OK") {
|
|
context.commit("update_search_status",3)
|
|
context.commit("update_search_error_message", resp.message)
|
|
} else {
|
|
let data = {
|
|
idhs : resp.data.idhs
|
|
}
|
|
context.commit("update_search_status",2)
|
|
context.commit("update_search_error_message","")
|
|
//alert(data.idhs)
|
|
let spatient = context.state.s_patient
|
|
spatient.forEach(function (t, idx) {
|
|
if (t.M_PatientID == prm.M_PatientID) {
|
|
let p_pasien = spatient[idx]
|
|
p_pasien.patientidhs = data.idhs
|
|
}
|
|
|
|
})
|
|
console.log(spatient)
|
|
// commit("patientaddress/test", "X", { root: true })
|
|
}
|
|
} catch(e) {
|
|
context.commit("update_search_status",3)
|
|
context.commit("update_search_error_message",e.message )
|
|
}
|
|
},
|
|
async save_hsaddress(context, prm) {
|
|
context.commit("update_search_status",1)
|
|
try {
|
|
|
|
let resp
|
|
prm.token = one_token()
|
|
resp = await api.save_hsaddress(prm)
|
|
|
|
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.dispatch('search_hsaddress', {patientid:prm.patientid})
|
|
context.commit("update_dialog_hsaddress", false)
|
|
}
|
|
} catch(e) {
|
|
context.commit("update_search_status",3)
|
|
context.commit("update_search_error_message",e.message )
|
|
}
|
|
},
|
|
async search_idtype(context) {
|
|
context.commit("update_search_status",1)
|
|
try {
|
|
let resp= await api.search_idtype()
|
|
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
|
|
}
|
|
|
|
context.commit("update_idtypes", data)
|
|
}
|
|
} catch(e) {
|
|
context.commit("update_search_status",3)
|
|
context.commit("update_search_error_message",e.message )
|
|
}
|
|
},
|
|
delete_patient(context, patient) {
|
|
console.log(patient)
|
|
let sel = context.state.s_patient
|
|
sel.forEach(function(t, idx) {
|
|
if(t.M_PatientID == patient.M_PatientID) {
|
|
sel.splice(idx,1)
|
|
}
|
|
})
|
|
context.commit("update_s_patient", sel)
|
|
|
|
let addr = context.state.s_address
|
|
console.log(addr)
|
|
addr.forEach(function(t, idx) {
|
|
if(t.HS_AddressM_PatientID == patient.patientidhs) {
|
|
addr.splice(idx,1)
|
|
}
|
|
})
|
|
context.commit("update_s_address", addr)
|
|
|
|
},
|
|
update_testpatient(context, patient) {
|
|
console.log(patient)
|
|
let sel = context.state.s_patient
|
|
sel.forEach(function(t, idx) {
|
|
if(t.M_PatientID == patient.M_PatientID) {
|
|
sel.splice(idx,1)
|
|
}
|
|
})
|
|
context.commit("update_s_patient", sel)
|
|
},
|
|
async search_hsaddress(context, prm) {
|
|
context.commit("update_search_status",1)
|
|
try {
|
|
//context.commit("update_loading",true)
|
|
let resp= await api.search_hsaddress(prm)
|
|
|
|
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
|
|
}
|
|
let saddress = context.state.s_address
|
|
let arr = data.records
|
|
if(data.total != 0){
|
|
saddress.push(data.records)
|
|
context.commit('update_s_address', arr)
|
|
console.log('search_hsaddress')
|
|
let addr = context.state.s_address
|
|
let p_idx = -1
|
|
let hprice = 0
|
|
addr.forEach(function(t, idx) {
|
|
if(t.HS_AddressIsUtama == 'Y') {
|
|
p_idx = idx
|
|
}
|
|
})
|
|
console.log(arr[p_idx])
|
|
// context.commit("update_hs_price", arr[p_idx].hsprice)
|
|
context.commit("update_hs_addressid", arr[p_idx].HS_AddressID)
|
|
context.commit("order/update_hs_lat", arr[p_idx].HS_AddressLat, {root:true})
|
|
context.commit("order/update_hs_lang", arr[p_idx].HS_AddressLng, {root:true})
|
|
context.commit("update_hs_addressidlist", arr[p_idx].HS_AddressID)
|
|
|
|
}else{
|
|
console.log('tidak ada array')
|
|
}
|
|
|
|
|
|
|
|
}
|
|
} catch(e) {
|
|
context.commit("update_search_status",3)
|
|
context.commit("update_search_error_message",e.message )
|
|
}
|
|
},
|
|
async gettimekuota(context, prm) {
|
|
context.commit("update_search_status",1)
|
|
try {
|
|
//context.commit("update_loading",true)
|
|
let resp= await api.gettimekuota(prm)
|
|
|
|
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
|
|
}
|
|
if(data.total != 0){
|
|
context.commit("update_hs_times", data)
|
|
console.log(data)
|
|
}else{
|
|
console.log('tidak ada array')
|
|
}
|
|
|
|
|
|
|
|
}
|
|
} catch(e) {
|
|
context.commit("update_search_status",3)
|
|
context.commit("update_search_error_message",e.message )
|
|
}
|
|
},
|
|
async getconfig(context, prm) {
|
|
context.commit("update_search_status",1)
|
|
try {
|
|
//context.commit("update_loading",true)
|
|
let resp= await api.getconfig(prm)
|
|
|
|
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
|
|
}
|
|
if(data.total != 0){
|
|
context.commit("update_hs_config", data.records[0])
|
|
console.log(data)
|
|
}else{
|
|
console.log('tidak ada array')
|
|
}
|
|
|
|
|
|
|
|
}
|
|
} catch(e) {
|
|
context.commit("update_search_status",3)
|
|
context.commit("update_search_error_message",e.message )
|
|
}
|
|
}
|
|
}
|
|
}
|