diff --git a/app/components/content/encounter/process-next.vue b/app/components/content/encounter/process-next.vue
new file mode 100644
index 00000000..22db3536
--- /dev/null
+++ b/app/components/content/encounter/process-next.vue
@@ -0,0 +1,290 @@
+
+
+
+
+
diff --git a/app/components/content/encounter/process-previous.vue b/app/components/content/encounter/process-previous.vue
deleted file mode 100644
index 23640af7..00000000
--- a/app/components/content/encounter/process-previous.vue
+++ /dev/null
@@ -1,94 +0,0 @@
-
-
-
-
-
diff --git a/app/handlers/encounter-process.handler.ts b/app/handlers/encounter-process.handler.ts
index 4d500368..665cae04 100644
--- a/app/handlers/encounter-process.handler.ts
+++ b/app/handlers/encounter-process.handler.ts
@@ -1,11 +1,19 @@
-import { medicalPositions } from "~/lib/roles"
+import { isValidDate } from '~/lib/date'
+import { medicalPositions } from '~/lib/roles'
export interface EncounterItem {
id: string
title: string
classCode?: string[]
- unit?: string,
+ unit?: string
afterId?: string
+ component?: any
+ props?: Record
+}
+
+export interface EncounterProps {
+ classCode: 'ambulatory' | 'emergency' | 'inpatient' | 'outpatient'
+ subClassCode: 'reg' | 'rehab' | 'chemo' | 'emg' | 'eon' | 'op' | 'icu' | 'hcu' | 'vk'
}
export const defaultItems: EncounterItem[] = [
@@ -174,11 +182,11 @@ const getItemsByUnit = (unit: string, items: EncounterItem[]) => {
return items.filter((item) => item.unit === unit)
}
-const getItemsByIds = (ids: string[], items: EncounterItem[]) => {
+export const getItemsByIds = (ids: string[], items: EncounterItem[]) => {
return items.filter((item) => ids.includes(item.id))
}
-const getIndexById = (id: string, items: EncounterItem[]) => {
+export const getIndexById = (id: string, items: EncounterItem[]) => {
return items.findIndex((item) => item.id === id)
}
@@ -189,17 +197,13 @@ export function insertItemByAfterId(id: string, items: EncounterItem[], newItem:
}
}
-export function mergeArrayAt(
- arraysOne: T[],
- arraysTwo: T[] | T,
- deleteCount = 0,
-): T[] {
+export function mergeArrayAt(arraysOne: T[], arraysTwo: T[] | T, deleteCount = 0): T[] {
const prevItems = arraysOne.slice()
if (!prevItems) return prevItems
const nextItems = Array.isArray(arraysTwo) ? arraysTwo : [arraysTwo]
if (nextItems.length === 0) return prevItems
// determine insertion position using the first item's `id` if available
- const firstId = (nextItems[0] as any)?.afterId || (prevItems[0] as any)?.id
+ const firstId = (nextItems[0] as any)?.afterId || (prevItems[0] as any)?.id
let pos = prevItems.length
if (typeof firstId === 'string') {
const index = prevItems.findIndex((item: any) => item.id === firstId)
@@ -216,6 +220,66 @@ export const getItemsAll = (classCode: string, unit: string, items: EncounterIte
return updateItems
}
+// Function to map API response to Encounter structure
+export function mapResponseToEncounter(result: any): any {
+ if (!result) return null
+
+ // Check if patient and patient.person exist (minimal validation)
+ if (!result.patient || !result.patient.person) {
+ return null
+ }
+
+ const mapped: any = {
+ id: result.id || 0,
+ patient_id: result.patient_id || result.patient?.id || 0,
+ patient: {
+ id: result.patient?.id || 0,
+ number: result.patient?.number || '',
+ person: {
+ id: result.patient?.person?.id || 0,
+ name: result.patient?.person?.name || '',
+ birthDate: result.patient?.person?.birthDate || null,
+ gender_code: result.patient?.person?.gender_code || '',
+ residentIdentityNumber: result.patient?.person?.residentIdentityNumber || null,
+ frontTitle: result.patient?.person?.frontTitle || '',
+ endTitle: result.patient?.person?.endTitle || '',
+ addresses: result.patient?.person?.addresses || [],
+ },
+ },
+ registeredAt: result.registeredAt || result.patient?.registeredAt || null,
+ class_code: result.class_code || '',
+ unit_id: result.unit_id || 0,
+ unit: result.unit || null,
+ specialist_id: result.specialist_id || null,
+ subspecialist_id: result.subspecialist_id || null,
+ visitDate: isValidDate(result.visitDate)
+ ? result.visitDate
+ : result.registeredAt || result.patient?.registeredAt || null,
+ adm_employee_id: result.adm_employee_id || 0,
+ appointment_doctor_id: result.appointment_doctor_id || null,
+ responsible_doctor_id: result.responsible_doctor_id || null,
+ appointment_doctor: result.appointment_doctor || null,
+ responsible_doctor: result.responsible_doctor || null,
+ refSource_name: result.refSource_name || null,
+ appointment_id: result.appointment_id || null,
+ earlyEducation: result.earlyEducation || null,
+ medicalDischargeEducation: result.medicalDischargeEducation || '',
+ admDischargeEducation: result.admDischargeEducation || null,
+ discharge_method_code: result.discharge_method_code || null,
+ discharge_reason: result.dischargeReason || result.discharge_reason || null,
+ discharge_date: result.discharge_date || null,
+ status_code: result.status_code || '',
+ // Payment related fields
+ paymentMethod_code:
+ result.paymentMethod_code && result.paymentMethod_code.trim() !== '' ? result.paymentMethod_code : null,
+ trx_number: result.trx_number || null,
+ member_number: result.member_number || null,
+ ref_number: result.ref_number || null,
+ }
+
+ return mapped
+}
+
const listItemsForOutpatientRehab = mergeArrayAt(
getItemsAll('ambulatory', 'all', defaultItems),
getItemsAll('ambulatory', 'rehab', defaultItems),
@@ -226,22 +290,22 @@ const listItemsForOutpatientChemo = mergeArrayAt(
getItemsAll('ambulatory', 'chemo', defaultItems),
)
-export const listItems = {
+export const listItems: Record>> = {
'installation|outpatient': {
'unit|rehab': {
- 'items': listItemsForOutpatientRehab,
- 'roles': medicalPositions,
+ items: listItemsForOutpatientRehab,
+ roles: medicalPositions,
},
'unit|chemo': {
- 'items': listItemsForOutpatientChemo,
- 'roles': medicalPositions,
+ items: listItemsForOutpatientChemo,
+ roles: medicalPositions,
},
- 'all': getItemsAll('ambulatory', 'all', defaultItems),
+ all: getItemsAll('ambulatory', 'all', defaultItems),
},
'installation|emergency': {
- 'all': getItemsAll('emergency', 'all', defaultItems),
+ all: getItemsAll('emergency', 'all', defaultItems),
},
'installation|inpatient': {
- 'all': getItemsAll('inpatient', 'all', defaultItems),
- }
+ all: getItemsAll('inpatient', 'all', defaultItems),
+ },
}
diff --git a/app/lib/date.ts b/app/lib/date.ts
index 4abfc6d8..982c3c5b 100644
--- a/app/lib/date.ts
+++ b/app/lib/date.ts
@@ -73,3 +73,16 @@ export function formatDateYyyyMmDd(isoDateString: string): string {
const day = String(date.getDate()).padStart(2, '0');
return `${year}-${month}-${day}`;
}
+
+// Function to check if date is invalid (like "0001-01-01T00:00:00Z")
+export function isValidDate(dateString: string | null | undefined): boolean {
+ if (!dateString) return false
+ // Check for invalid date patterns
+ if (dateString.startsWith('0001-01-01')) return false
+ try {
+ const date = new Date(dateString)
+ return !isNaN(date.getTime())
+ } catch {
+ return false
+ }
+}
diff --git a/app/pages/(features)/outpatient/encounter/[id]/process.vue b/app/pages/(features)/outpatient/encounter/[id]/process.vue
index 0b048ec5..8a44a130 100644
--- a/app/pages/(features)/outpatient/encounter/[id]/process.vue
+++ b/app/pages/(features)/outpatient/encounter/[id]/process.vue
@@ -2,6 +2,7 @@
import type { PagePermission } from '~/models/role'
import Error from '~/components/pub/my-ui/error/error.vue'
import { PAGE_PERMISSIONS } from '~/lib/page-permission'
+import EncounterProcess from '~/components/content/encounter/process-next.vue'
definePageMeta({
middleware: ['rbac'],
@@ -35,7 +36,7 @@ const canCreate = hasCreateAccess(roleAccess)
-
+