169 lines
5.4 KiB
JavaScript
169 lines
5.4 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: {},
|
|
|
|
patient_new: {},
|
|
patient_new_dialog_is_active: false,
|
|
|
|
idtypes: [],
|
|
selected_idtype: {}
|
|
},
|
|
mutations: {
|
|
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
|
|
}
|
|
},
|
|
actions: {
|
|
async search(context, prm) {
|
|
context.commit("update_search_status",1)
|
|
try {
|
|
let resp= await api.search(context.state.noreg,context.state.search)
|
|
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_display: resp.data.total_display
|
|
}
|
|
context.commit("update_patients",data)
|
|
|
|
if (prm)
|
|
if (prm.use) {
|
|
let pat = context.state.patients[prm.use_idx]
|
|
context.commit('update_selected_patient', pat)
|
|
context.commit('order/update_patient_note', pat.M_PatientNote, {root:true})
|
|
context.commit('delivery/update_params', {p_id:pat.M_PatientID}, { root: true })
|
|
context.dispatch('delivery/search', null, { root: true })
|
|
|
|
context.commit('photo/update_patient_id', pat.M_PatientID, {root: true})
|
|
}
|
|
|
|
// 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(context, prm) {
|
|
context.commit("update_search_status",1)
|
|
try {
|
|
|
|
let resp= await api.add_new(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","")
|
|
|
|
if (prm.use) {
|
|
context.commit('update_noreg', resp.data.noreg)
|
|
context.commit('update_search', '')
|
|
|
|
context.dispatch('search', {use:true, use_idx:0})
|
|
}
|
|
|
|
// commit("patientaddress/test", "X", { root: true })
|
|
}
|
|
} 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 )
|
|
}
|
|
}
|
|
}
|
|
}
|