Flatten nested repos
This commit is contained in:
221
test/vuex/cpone-card-reader/modules/patient.js
Normal file
221
test/vuex/cpone-card-reader/modules/patient.js
Normal file
@@ -0,0 +1,221 @@
|
||||
// 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: {},
|
||||
current_page:1,
|
||||
edit: false,
|
||||
dialog_birthday:false,
|
||||
show_more:true,
|
||||
loading:false
|
||||
},
|
||||
mutations: {
|
||||
update_loading(state,status) {
|
||||
state.loading = 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)
|
||||
} 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 )
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user