From 4ef01561817ac88aaa7d919e5b367f0e237c4da6 Mon Sep 17 00:00:00 2001 From: riefive Date: Mon, 17 Nov 2025 13:16:01 +0700 Subject: [PATCH] fix: refactors date range handling to use a formatted, reactive approach --- app/components/app/sep/entry-form.vue | 3 + app/components/app/sep/list.vue | 3 +- app/components/content/sep/list.vue | 55 ++++++++++++---- app/lib/date.ts | 95 +++++++++++++++++---------- app/services/vclaim-sep.service.ts | 2 +- 5 files changed, 107 insertions(+), 51 deletions(-) diff --git a/app/components/app/sep/entry-form.vue b/app/components/app/sep/entry-form.vue index 4e9bed2c..0aa33178 100644 --- a/app/components/app/sep/entry-form.vue +++ b/app/components/app/sep/entry-form.vue @@ -180,6 +180,9 @@ onMounted(() => { if (!isService.value) { serviceType.value = '2' } + if (!admissionType.value) { + admissionType.value = '1' + } }) diff --git a/app/components/app/sep/list.vue b/app/components/app/sep/list.vue index 2afaa2cc..78a0b740 100644 --- a/app/components/app/sep/list.vue +++ b/app/components/app/sep/list.vue @@ -11,7 +11,8 @@ const props = defineProps<{ diff --git a/app/components/content/sep/list.vue b/app/components/content/sep/list.vue index 013b076a..a7f09284 100644 --- a/app/components/content/sep/list.vue +++ b/app/components/content/sep/list.vue @@ -18,17 +18,33 @@ import { X, Check } from 'lucide-vue-next' // Types import type { VclaimSepData } from '~/models/vclaim' +// Libraries +import { getFormatDateId } from '~/lib/date' + // Services import { getList as geMonitoringVisitList } from '~/services/vclaim-monitoring-visit.service' const search = ref('') -const dateRange = ref('12 Agustus 2025 - 31 Agustus 2025') + +const today = new Date() +const dateSelection = ref<[Date, Date]>([today, today]) +const dateRange = ref(`${getFormatDateId(today)} - ${getFormatDateId(today)}`) const open = ref(false) -const sepData = { - no_sep: 'SP23311224', - kartu: '001234', - nama: 'Kenzie', +const sepData = ref({ + sepNumber: '', + cardNumber: '', + patientName: '', +}) + +function onRowSelected(row: any) { + if (!row) return + // map possible property names from API / table rows + sepData.value.sepNumber = row.letterNumber || '' + sepData.value.cardNumber = row.cardNumber || '' + sepData.value.patientName = row.patientName || '' + recItem.value = row + recId.value = (row && (row.id || row.recId)) || 0 } const paginationMeta = reactive({ @@ -81,7 +97,7 @@ async function getMonitoringVisitMappers() { isLoading.dataListLoading = true data.value = [] - const dateFirst = new Date() + const dateFirst = (dateSelection.value && dateSelection.value[0]) ? dateSelection.value[0] : new Date() const result = await geMonitoringVisitList({ date: dateFirst.toISOString().substring(0, 10), serviceType: 1, @@ -157,6 +173,18 @@ onMounted(() => { getSepList() }) +// When date selection changes, update display and re-fetch +watch( + () => dateSelection.value, + (val) => { + if (!val) return + const [start, end] = val + dateRange.value = `${getFormatDateId(start)} - ${getFormatDateId(end)}` + getSepList() + }, + { deep: true }, +) + provide('rec_id', recId) provide('rec_action', recAction) provide('rec_item', recItem) @@ -216,10 +244,11 @@ provide('table_data_loader', isLoading)
- +
@@ -244,9 +273,9 @@ provide('table_data_loader', isLoading) Apakah anda yakin ingin menghapus SEP dengan data:
-

No. SEP : {{ sepData.no_sep }}

-

No. Kartu BPJS : {{ sepData.kartu }}

-

Nama Pasien : {{ sepData.nama }}

+

No. SEP : {{ sepData.sepNumber }}

+

No. Kartu BPJS : {{ sepData.cardNumber }}

+

Nama Pasien : {{ sepData.patientName }}

diff --git a/app/lib/date.ts b/app/lib/date.ts index 502a6cfb..6bbfff7b 100644 --- a/app/lib/date.ts +++ b/app/lib/date.ts @@ -1,44 +1,67 @@ +const monthsInId = [ + 'Januari', + 'Februari', + 'Maret', + 'April', + 'Mei', + 'Juni', + 'Juli', + 'Agustus', + 'September', + 'Oktober', + 'November', + 'Desember', +] + export function getAge(dateString: string, comparedDate?: string): { idFormat: string; extFormat: string } { - const birthDate = new Date(dateString); - const today = new Date(); + const birthDate = new Date(dateString) + const today = new Date() - if (comparedDate) { - const comparedDateObj = new Date(comparedDate); - today.setFullYear(comparedDateObj.getFullYear()); - today.setMonth(comparedDateObj.getMonth()); - today.setDate(comparedDateObj.getDate()); - } + if (comparedDate) { + const comparedDateObj = new Date(comparedDate) + today.setFullYear(comparedDateObj.getFullYear()) + today.setMonth(comparedDateObj.getMonth()) + today.setDate(comparedDateObj.getDate()) + } - // Format the date part - const options: Intl.DateTimeFormatOptions = { day: 'numeric', month: 'long', year: 'numeric' }; - const idFormat = birthDate.toLocaleDateString('id-ID', options); + // Format the date part + const options: Intl.DateTimeFormatOptions = { day: 'numeric', month: 'long', year: 'numeric' } + const idFormat = birthDate.toLocaleDateString('id-ID', options) - // Calculate age - let years = today.getFullYear() - birthDate.getFullYear(); - let months = today.getMonth() - birthDate.getMonth(); - let days = today.getDate() - birthDate.getDate(); + // Calculate age + let years = today.getFullYear() - birthDate.getFullYear() + let months = today.getMonth() - birthDate.getMonth() + let days = today.getDate() - birthDate.getDate() - if (months < 0 || (months === 0 && days < 0)) { - years--; - months += 12; - } + if (months < 0 || (months === 0 && days < 0)) { + years-- + months += 12 + } - if (days < 0) { - const prevMonth = new Date(today.getFullYear(), today.getMonth() - 1, 0); - days += prevMonth.getDate(); - months--; - } + if (days < 0) { + const prevMonth = new Date(today.getFullYear(), today.getMonth() - 1, 0) + days += prevMonth.getDate() + months-- + } - // Format the age part - let extFormat = ''; - if ([years, months, days].filter(Boolean).join(' ')) { - extFormat = `${years} Tahun ${months} Bulan ${days} Hari`; - } else { - extFormat = '0'; - } + // Format the age part + let extFormat = '' + if ([years, months, days].filter(Boolean).join(' ')) { + extFormat = `${years} Tahun ${months} Bulan ${days} Hari` + } else { + extFormat = '0' + } - return { - idFormat, - extFormat - }; -} \ No newline at end of file + return { + idFormat, + extFormat, + } +} + +// Date selection: default to today - today +export function getFormatDateId(date: Date) { + const dd = String(date.getDate()).padStart(2, '0') + const mm = monthsInId[date.getMonth()] + const yyyy = date.getFullYear() + return `${dd} ${mm} ${yyyy}` +} diff --git a/app/services/vclaim-sep.service.ts b/app/services/vclaim-sep.service.ts index 7d54d771..258c08dc 100644 --- a/app/services/vclaim-sep.service.ts +++ b/app/services/vclaim-sep.service.ts @@ -32,7 +32,7 @@ export function makeSepData( noKartu: data.cardNumber || '', tglSep: data.sepDate, ppkPelayanan: data.fromClinic || '', - jnsPelayanan: data.admissionType ? String(data.admissionType) : '1', + jnsPelayanan: data.serviceType ? String(data.serviceType) : '2', noMR: data.medicalRecordNumber || '', catatan: data.note || '', diagAwal: data.initialDiagnosis || '',