Files
2026-04-27 10:13:31 +07:00

58 lines
1.7 KiB
JavaScript

// 1 => LOADING
// 2 => DONE
// 3 => ERROR
import * as api from "../api/helper.js"
export default {
namespaced: true,
state: {
loading:false,
error:'',
open_print: false
},
mutations: {
update_calc_age_status(state,value) {
state.loading= value
},
update_error(state,value) {
state.error= value
},
update_loading(state,value) {
state.loading = value
},
update_open_print(state, value) {
state.open_print = value
}
},
actions: {
async calc_age(context,orderID) {
context.commit("update_loading", true)
try {
let prm = { orderID }
prm["token"] = one_token()
let resp = await api.calc_age(prm)
if (resp.status != "OK") {
context.commit("update_error", resp.message)
} else {
context.commit("update_error", "")
let patient = context.rootState.re_patient.selected_patient
let dob = resp.data.M_PatientDOB
let age = resp.data.T_OrderHeaderM_PatientAge
patient.M_PatientDOB = dob
patient.T_OrderHeaderM_PatientAge = age
context.rootState.commit("re_patient/update_selected_patient", patient)
let patients = context.rootState.patients
for( let idx =0; idx < patients.length ; idx++) {
if (patients[idx].M_PatientID = patient.M_PatientID ) {
patients[idx] = patient
}
}
context.rootState.commit('re_patient/update_patients',patients)
}
} catch (e) {
context.commit("update_error", e.message)
}
}
}
}