311 lines
12 KiB
JavaScript
311 lines
12 KiB
JavaScript
// 1 => LOADING
|
|
// 2 => DONE
|
|
// 3 => ERROR
|
|
import * as api from "../api/patient.js"
|
|
|
|
export default {
|
|
namespaced: true,
|
|
state: {
|
|
search_test: 0,
|
|
search_error_message: '',
|
|
start_date: moment(new Date()).format('YYYY-MM-DD'),
|
|
last_search_val: '',
|
|
last_search_type: '',
|
|
end_date: moment(new Date()).format('YYYY-MM-DD'),
|
|
search: '',
|
|
search_sas_code: '',
|
|
total_test: 0,
|
|
selected_test: {},
|
|
save_error_message: '',
|
|
statuses: [
|
|
{ name: 'Semua', value: 'A' },
|
|
{ name: 'Sudah Terkirim', value: 'Y' },
|
|
{ name: 'Belum Terkirim', value: 'N' }
|
|
],
|
|
selected_status: { name: 'Semua', value: 'A' },
|
|
open_alert_no_pay: false,
|
|
msg_alert_no_pay: "Loh ... Gak jadi bayar dong ?",
|
|
current_page: 1,
|
|
total_page: 0,
|
|
pay_disabled: 'Y',
|
|
autocomplete_status: 0,
|
|
companies: [{ id: 0, name: 'Semua' }],
|
|
selected_company: { id: 0, name: 'Semua' },
|
|
logs: [],
|
|
unduhan: [],
|
|
loading_download: false,
|
|
loading_send: false,
|
|
monitoring_data: [],
|
|
monitoring_status: 0,
|
|
monitoring_error_message: '',
|
|
tests: [],
|
|
transaction_log: null,
|
|
dialog_info: false,
|
|
dialog_info_message: ''
|
|
},
|
|
mutations: {
|
|
set_last_search(state, { val, type }) {
|
|
state.last_search_val = val;
|
|
state.last_search_type = type;
|
|
},
|
|
update_loading_send(state, val) {
|
|
state.loading_send = val
|
|
},
|
|
update_loading_download(state, val) {
|
|
state.loading_download = val
|
|
},
|
|
update_unduhan(state, val) {
|
|
state.unduhan = val
|
|
},
|
|
update_logs(state, val) {
|
|
state.logs = val
|
|
},
|
|
update_autocomplete_status(state, val) {
|
|
state.autocomplete_status = val
|
|
},
|
|
update_companies(state, val) {
|
|
state.companies = val
|
|
},
|
|
update_selected_company(state, val) {
|
|
state.selected_company = val
|
|
},
|
|
update_pay_disabled(state, val) {
|
|
state.pay_disabled = val
|
|
},
|
|
update_total_page(state, val) {
|
|
state.total_page = val
|
|
},
|
|
update_current_page(state, val) {
|
|
state.current_page = val
|
|
},
|
|
update_search_error_message(state, message) {
|
|
state.search_error_message = message
|
|
},
|
|
update_search_test(state, status) {
|
|
state.search_test = status
|
|
},
|
|
update_selected_test(state, val) {
|
|
state.selected_test = val
|
|
},
|
|
update_start_date(state, val) {
|
|
state.start_date = val
|
|
},
|
|
update_end_date(state, val) {
|
|
state.end_date = val
|
|
},
|
|
update_search(state, val) {
|
|
state.search = val
|
|
},
|
|
update_search_sas_code(state, val) {
|
|
state.search_sas_code = val
|
|
},
|
|
update_selected_status(state, val) {
|
|
state.selected_status = val
|
|
},
|
|
update_open_alert_no_pay(state, val) {
|
|
state.open_alert_no_pay = val
|
|
},
|
|
update_msg_alert_no_pay(state, val) {
|
|
state.msg_alert_no_pay = val
|
|
},
|
|
set_monitoring_data(state, data) {
|
|
state.monitoring_data = data;
|
|
},
|
|
set_monitoring_status(state, status) {
|
|
state.monitoring_status = status;
|
|
},
|
|
set_monitoring_error_message(state, message) {
|
|
state.monitoring_error_message = message;
|
|
},
|
|
set_transaction_log(state, payload) {
|
|
state.transaction_log = payload;
|
|
},
|
|
set_dialog_info(state, status) {
|
|
state.dialog_info = status;
|
|
},
|
|
set_dialog_info_message(state, message) {
|
|
state.dialog_info_message = message;
|
|
}
|
|
},
|
|
actions: {
|
|
async search(context, prm) {
|
|
context.commit("update_search_test", 1)
|
|
try {
|
|
prm.token = one_token()
|
|
prm.company = context.state.selected_company.id
|
|
let resp = await api.search(prm)
|
|
if (resp.status != "OK") {
|
|
context.commit("update_search_test", 3)
|
|
context.commit("update_search_error_message", resp.message)
|
|
} else {
|
|
context.commit("update_search_test", 2)
|
|
context.commit("update_search_error_message", "")
|
|
let data = {
|
|
records: resp.data.records,
|
|
total: resp.data.total
|
|
}
|
|
context.commit("update_tests", data)
|
|
context.commit("update_selected_test", {})
|
|
context.commit("update_total_page", data.total)
|
|
}
|
|
} catch (e) {
|
|
context.commit("update_search_test", 3)
|
|
context.commit("update_search_error_message", e.message)
|
|
console.log(e)
|
|
}
|
|
},
|
|
|
|
async monitoring_test(context, prm) {
|
|
context.commit("set_monitoring_status", 1);
|
|
|
|
// Sesuai dengan BE, parameter 'test_status' diganti menjadi 'status'
|
|
const params = {
|
|
...prm,
|
|
status: prm.test_status
|
|
};
|
|
delete params.test_status;
|
|
|
|
try {
|
|
let resp = await api.monitoring_test({
|
|
page: prm.page,
|
|
test_name: prm.test_name,
|
|
test_code: prm.test_code,
|
|
sas_code: prm.sas_code,
|
|
test_status: prm.test_status
|
|
});
|
|
|
|
if (resp.status !== "success") {
|
|
context.commit("set_monitoring_status", 3);
|
|
context.commit("set_monitoring_error_message", resp.message);
|
|
return;
|
|
}
|
|
|
|
const wrapped = {
|
|
data: resp.data,
|
|
total: resp.total,
|
|
page: resp.page,
|
|
limit: resp.limit,
|
|
total_page: resp.total_page
|
|
};
|
|
|
|
context.commit("set_monitoring_data", wrapped);
|
|
context.commit("set_monitoring_error_message", "");
|
|
context.commit("update_total_page", resp.total_page);
|
|
context.commit("update_current_page", resp.page);
|
|
context.commit("set_monitoring_status", 2);
|
|
|
|
} catch (err) {
|
|
context.commit("set_monitoring_status", 3);
|
|
context.commit("set_monitoring_error_message", err.message);
|
|
}
|
|
},
|
|
|
|
async get_json_response({ commit, state }) {
|
|
commit('set_transaction_log', null);
|
|
commit('set_monitoring_status', 1);
|
|
|
|
if (!state.selected_test || !state.selected_test.sas_code) {
|
|
commit('set_monitoring_status', 2);
|
|
return;
|
|
}
|
|
|
|
const params = {
|
|
sas_code: state.selected_test.sas_code
|
|
};
|
|
|
|
const response = await api.get_json_response(params);
|
|
|
|
if (response.status === 'success' && response.data) {
|
|
commit('set_transaction_log', response.data);
|
|
} else {
|
|
commit('set_transaction_log', null);
|
|
console.error("Failed to get JSON response:", response.message);
|
|
}
|
|
commit('set_monitoring_status', 2);
|
|
},
|
|
|
|
async send_test(context, prm) {
|
|
context.commit("set_monitoring_status", 1);
|
|
try {
|
|
// prm should be { sas_code: '...' }
|
|
const checkResponse = await api.get_layanan_by_code({ layanan_code: prm.sas_code });
|
|
|
|
let postResponse;
|
|
let actionMessage;
|
|
|
|
// 2. Decide to re-post or post based on the check
|
|
if (checkResponse.status === 'success' && checkResponse.data != null) {
|
|
// Data exists, use re_post (PUT request in BE)
|
|
postResponse = await api.re_post_layanan_by_code({ layanan_code: prm.sas_code });
|
|
actionMessage = "diperbarui";
|
|
} else {
|
|
// Data does not exist, use post
|
|
postResponse = await api.post_layanan_by_code({ layanan_code: prm.sas_code });
|
|
actionMessage = "dikirim";
|
|
}
|
|
|
|
// 3. Handle the response of the post/re-post action
|
|
if (postResponse.status === 'success') {
|
|
context.commit("set_dialog_info_message", `Data layanan berhasil ${actionMessage}.`);
|
|
|
|
// Refresh table and logs
|
|
await context.dispatch("monitoring_test", {
|
|
test_status: context.state.selected_status.value,
|
|
page: context.state.current_page,
|
|
...(() => {
|
|
const params = {};
|
|
const searchVal = context.state.search.trim();
|
|
if (searchVal) {
|
|
/^[a-zA-Z0-9]+$/.test(searchVal) ? params.test_code = searchVal : params.test_name = searchVal;
|
|
}
|
|
const searchSasCodeVal = (context.state.search_sas_code || '').trim();
|
|
if (searchSasCodeVal) {
|
|
/^[a-zA-Z0-9]+$/.test(searchSasCodeVal) ? params.sas_code = searchSasCodeVal : params.sas_name = searchSasCodeVal;
|
|
}
|
|
return params;
|
|
})()
|
|
});
|
|
|
|
const updatedItem = context.state.monitoring_data.data?.find(
|
|
item => item.sas_code === prm.sas_code
|
|
);
|
|
if (updatedItem) {
|
|
context.commit("update_selected_test", updatedItem);
|
|
await context.dispatch("get_json_response");
|
|
}
|
|
} else {
|
|
const errorMessage = postResponse.message || `Gagal ${actionMessage} data layanan.`;
|
|
context.commit("set_dialog_info_message", errorMessage);
|
|
}
|
|
|
|
} catch (e) {
|
|
context.commit("set_dialog_info_message", "Terjadi kesalahan pada sistem: " + e.message);
|
|
} finally {
|
|
context.commit("set_dialog_info", true);
|
|
context.commit("set_monitoring_status", 2);
|
|
}
|
|
},
|
|
|
|
async all_layanan_post(context) {
|
|
context.commit("set_monitoring_status", 1);
|
|
try {
|
|
const response = await api.all_layanan_post({});
|
|
|
|
if (response.status === 'success') {
|
|
context.commit("set_dialog_info_message", response.message || "Berhasil mengirim semua layanan.");
|
|
await context.dispatch("monitoring_test", {
|
|
test_status: context.state.selected_status.value,
|
|
page: 1
|
|
});
|
|
} else {
|
|
context.commit("set_dialog_info_message", response.message || "Gagal mengirim semua layanan.");
|
|
}
|
|
} catch (e) {
|
|
context.commit("set_dialog_info_message", "Terjadi kesalahan pada sistem: " + e.message);
|
|
} finally {
|
|
context.commit("set_dialog_info", true);
|
|
context.commit("set_monitoring_status", 2);
|
|
}
|
|
}
|
|
}
|
|
} |