kunjungan pasien

This commit is contained in:
ahdan15
2024-12-18 10:05:57 +07:00
parent 9999faa387
commit a069659fec
6 changed files with 322 additions and 142 deletions

View File

@@ -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) {