init biotest web
This commit is contained in:
287
one-klinik-biotest/test/vuex/one-clinic-form/modules/patient.js
Normal file
287
one-klinik-biotest/test/vuex/one-clinic-form/modules/patient.js
Normal file
@@ -0,0 +1,287 @@
|
||||
// 1 => LOADING
|
||||
// 2 => DONE
|
||||
// 3 => ERROR
|
||||
import * as api from "../api/patient.js"
|
||||
|
||||
export default {
|
||||
namespaced: true,
|
||||
state: {
|
||||
search_dialog_is_active: false,
|
||||
search_status: 0,
|
||||
search_error_message: '',
|
||||
loading: false,
|
||||
patients: [],
|
||||
total_patient: 0,
|
||||
current_page: 1,
|
||||
noreg: '',
|
||||
search: '',
|
||||
show_more: true,
|
||||
selected_patient: {},
|
||||
errors: [],
|
||||
dialogchosee: false,
|
||||
search_nik:'',
|
||||
search_name:'',
|
||||
search_dob:'',
|
||||
search_phone:'',
|
||||
company: [],
|
||||
selected_company: {},
|
||||
nurse: [],
|
||||
selected_nurse: {},
|
||||
doctor: [],
|
||||
selected_doctor: {},
|
||||
date: moment(new Date()).format("YYYY-MM-DD"),
|
||||
save_status: 2,
|
||||
loading_save: false,
|
||||
error_message: "",
|
||||
alert_error: false,
|
||||
dialog_error: false,
|
||||
msg_success: "",
|
||||
alert_success: false,
|
||||
},
|
||||
mutations: {
|
||||
update_search_phone(state, val) {
|
||||
state.search_phone = val
|
||||
},
|
||||
update_search_dob(state, val) {
|
||||
state.search_dob = val
|
||||
},
|
||||
update_search_name(state, val) {
|
||||
state.search_name = val
|
||||
},
|
||||
update_search_nik(state, val) {
|
||||
state.search_nik = val
|
||||
},
|
||||
update_search_dialog_is_active(state, val) {
|
||||
state.search_dialog_is_active = val
|
||||
},
|
||||
update_search_status(state, val) {
|
||||
state.search_status = val
|
||||
},
|
||||
update_search_error_message(state, val) {
|
||||
state.search_error_message = val
|
||||
},
|
||||
update_loading(state, val) {
|
||||
state.loading = val
|
||||
},
|
||||
update_patients(state,data) {
|
||||
state.patients = data.records
|
||||
state.total_patient = data.total
|
||||
},
|
||||
update_current_page(state, val) {
|
||||
state.current_page = val
|
||||
},
|
||||
update_noreg(state,val) {
|
||||
state.noreg = val
|
||||
},
|
||||
update_search(state,val) {
|
||||
state.search = val
|
||||
},
|
||||
update_show_more(state,status) {
|
||||
state.show_more = status
|
||||
},
|
||||
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
|
||||
|
||||
},
|
||||
update_errors(state, val) {
|
||||
state.errors = val
|
||||
},
|
||||
update_dialogchosee(state, val) {
|
||||
state.dialogchosee = val
|
||||
},
|
||||
update_company(state, val) {
|
||||
state.company = val
|
||||
},
|
||||
update_selected_company(state, val) {
|
||||
state.selected_company = val
|
||||
},
|
||||
update_nurse(state, val) {
|
||||
state.nurse = val
|
||||
},
|
||||
update_selected_nurse(state, val) {
|
||||
state.selected_nurse = val
|
||||
},
|
||||
update_doctor(state, val) {
|
||||
state.doctor = val
|
||||
},
|
||||
update_selected_doctor(state, val) {
|
||||
state.selected_doctor = val
|
||||
},
|
||||
update_date(state, val) {
|
||||
state.date = val
|
||||
},
|
||||
update_save_status(state, val) {
|
||||
state.save_status = val
|
||||
},
|
||||
update_loading_save(state, val) {
|
||||
state.loading_save = val
|
||||
},
|
||||
update_error_message(state, val) {
|
||||
state.error_message = val
|
||||
},
|
||||
update_alert_error(state, val) {
|
||||
state.alert_error = val
|
||||
},
|
||||
update_dialog_error(state, val) {
|
||||
state.dialog_error = val
|
||||
},
|
||||
update_msg_success(state, val) {
|
||||
state.msg_success = val
|
||||
},
|
||||
update_alert_success(state, val) {
|
||||
state.alert_success = val
|
||||
},
|
||||
},
|
||||
actions: {
|
||||
async search(context) {
|
||||
context.commit("update_search_status",1)
|
||||
try {
|
||||
//context.commit("update_loading",true)
|
||||
let resp = await api.search(context.state.search_nik,context.state.search_name,context.state.search_dob,context.state.search_phone,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",false)
|
||||
context.commit("update_search_error_message","")
|
||||
let data = {
|
||||
records : resp.data,
|
||||
total: resp.data.length
|
||||
}
|
||||
context.commit("update_loading",false)
|
||||
|
||||
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})
|
||||
console.log('data_before', data_before)
|
||||
}
|
||||
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)
|
||||
}
|
||||
|
||||
}
|
||||
} catch(e) {
|
||||
context.commit("update_loading",false)
|
||||
context.commit("update_search_status",3)
|
||||
context.commit("update_search_error_message",e.message )
|
||||
}
|
||||
},
|
||||
|
||||
async getcompanyclinic(context) {
|
||||
context.commit("update_search_status", 1)
|
||||
try {
|
||||
let resp= await api.getcompanyclinic()
|
||||
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 = {
|
||||
total : resp.data.length,
|
||||
records : resp.data
|
||||
}
|
||||
context.commit("update_company", data.records)
|
||||
}
|
||||
} catch(e) {
|
||||
context.commit("update_search_status",3)
|
||||
context.commit("update_search_error_message",e.message )
|
||||
}
|
||||
},
|
||||
|
||||
async getnurseclinic(context) {
|
||||
context.commit("update_search_status", 1)
|
||||
try {
|
||||
let resp= await api.getnurseclinic()
|
||||
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 = {
|
||||
total : resp.data.length,
|
||||
records : resp.data
|
||||
}
|
||||
context.commit("update_nurse", data.records)
|
||||
}
|
||||
} catch(e) {
|
||||
context.commit("update_search_status",3)
|
||||
context.commit("update_search_error_message",e.message )
|
||||
}
|
||||
},
|
||||
|
||||
async getdoctorclinic(context) {
|
||||
context.commit("update_search_status", 1)
|
||||
try {
|
||||
let resp= await api.getdoctorclinic()
|
||||
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 = {
|
||||
total : resp.data.length,
|
||||
records : resp.data
|
||||
}
|
||||
context.commit("update_doctor", data.records)
|
||||
}
|
||||
} catch(e) {
|
||||
context.commit("update_search_status",3)
|
||||
context.commit("update_search_error_message",e.message )
|
||||
}
|
||||
},
|
||||
|
||||
async addclinic(context, prm) {
|
||||
context.commit("update_save_status", 1)
|
||||
try {
|
||||
context.commit("update_loading_save", true)
|
||||
let resp = await api.addclinic(prm)
|
||||
if (resp.status != "OK") {
|
||||
context.commit("update_save_status", 3)
|
||||
context.commit("update_loading_save", false)
|
||||
context.commit("update_error_message", resp.message)
|
||||
context.commit("update_alert_error", true)
|
||||
context.commit("update_dialog_error", true)
|
||||
// context.commit("update_errors", resp.errors)
|
||||
} else {
|
||||
context.commit("update_save_status", 2)
|
||||
context.commit("update_loading_save", false)
|
||||
context.commit("update_error_message", "")
|
||||
context.commit("update_dialog_error", false)
|
||||
var msg = "Berhasil di simpan."
|
||||
context.commit("update_msg_success", msg)
|
||||
context.commit("update_alert_success", true)
|
||||
}
|
||||
} catch (e) {
|
||||
context.commit("update_save_status", 3)
|
||||
context.commit("update_loading_save", false)
|
||||
context.commit("update_error_message", e.message)
|
||||
context.commit("update_alert_error", true)
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user