kunjungan pasien
This commit is contained in:
@@ -149,7 +149,65 @@ export const useDataLogAPIGet = defineStore("DataLogAPI", () => {
|
||||
dataLogAPI,
|
||||
loadDataLogAPI,
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
export const useDataKunjunganPasien = defineStore("DataKunjunganPasien", () => {
|
||||
const dataKunjunganPasien = ref<any[]>([]);
|
||||
|
||||
const calculateAge = (tanggalLahir: string) => {
|
||||
const today = new Date();
|
||||
const birthDate = new Date(tanggalLahir);
|
||||
|
||||
if (isNaN(birthDate.getTime())) {
|
||||
console.error("Tanggal lahir tidak valid:", tanggalLahir);
|
||||
return null;
|
||||
}
|
||||
|
||||
let age = today.getFullYear() - birthDate.getFullYear();
|
||||
const m = today.getMonth() - birthDate.getMonth();
|
||||
|
||||
|
||||
if (m < 0 || (m === 0 && today.getDate() < birthDate.getDate())) {
|
||||
age--;
|
||||
}
|
||||
|
||||
return age;
|
||||
};
|
||||
|
||||
|
||||
const loadDataKunjunganPasien = async (reqDataKunjunganPasien: Record<string, any>) => {
|
||||
try {
|
||||
console.log("REQ", reqDataKunjunganPasien);
|
||||
const response = await $fetch("/api/satu_rssa/kunjungan_pasien", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify(reqDataKunjunganPasien),
|
||||
});
|
||||
|
||||
console.log("Response Data:", response);
|
||||
|
||||
|
||||
dataKunjunganPasien.value = response.map((item: any) => {
|
||||
const tanggalLahir = item.tanggallahir;
|
||||
const umur = tanggalLahir ? calculateAge(tanggalLahir) : null;
|
||||
|
||||
|
||||
return { ...item, umur };
|
||||
});
|
||||
|
||||
console.log("Data Kunjungan Pasien dengan Umur:", dataKunjunganPasien.value);
|
||||
} catch (error) {
|
||||
console.error("Failed to load data log api:", error);
|
||||
}
|
||||
};
|
||||
|
||||
return {
|
||||
dataKunjunganPasien,
|
||||
loadDataKunjunganPasien,
|
||||
};
|
||||
});
|
||||
|
||||
//Path:stores/users.ts
|
||||
if (import.meta.hot) {
|
||||
|
||||
Reference in New Issue
Block a user