diff --git a/app/handlers/_shared.handler.ts b/app/handlers/_shared.handler.ts index 0face19c..14204b9a 100644 --- a/app/handlers/_shared.handler.ts +++ b/app/handlers/_shared.handler.ts @@ -1,24 +1,7 @@ // types -import type { MedicineGroup } from '~/models/medicine-group' -import type { MedicineMethod } from '~/models/medicine-method' import type { Division } from '~/models/division' -import type { Installation } from '~/models/installation' -import type { Specialist } from '~/models/specialist' -import type { Uom } from '~/models/uom' -import type { Unit } from '~/models/unit' import type { TreeItem } from '~/models/_model' -// constants -import { encounterClassCodes } from '~/lib/constants' - -// services -import { getMedicineGroups } from '~/services/medicine-group.service' -import { getMedicineMethods } from '~/services/medicine-method.service' -import { getEncounters } from '~/services/encounter.service' -import { getDivisions } from '~/services/division.service' -import { getInstallations } from '~/services/installation.service' -import { getSpecialists } from '~/services/specialist.service' - // variables export const medicineGroups = ref<{ value: string; label: string }[]>([]) export const medicineMethods = ref<{ value: string; label: string }[]>([]) @@ -29,85 +12,6 @@ export const specialists = ref<{ value: string | number; label: string }[]>([]) export const uoms = ref<{ value: string; label: string }[]>([]) export const units = ref<{ value: string | number; label: string }[]>([]) -export const getMedicineGroupList = async () => { - const result = await getMedicineGroups() - if (result.success) { - const currentMedicineGroups = result.body?.data || [] - medicineGroups.value = currentMedicineGroups.map((medicineGroup: MedicineGroup) => ({ - value: medicineGroup.code, - label: medicineGroup.name, - })) - } -} - -export const getMedicineMethodList = async () => { - const result = await getMedicineMethods() - if (result.success) { - const currentMedicineMethods = result.body?.data || [] - medicineMethods.value = currentMedicineMethods.map((medicineMethod: MedicineMethod) => ({ - value: medicineMethod.code, - label: medicineMethod.name, - })) - } -} - -export const getDivisionParentList = async (isFetch = true, externalDivisions: any[] = []) => { - if (isFetch) { - const result = await getDivisions() - if (result.success) { - const currentDivisions = result.body?.data || [] - divisions.value = currentDivisions.map((division: Division) => ({ - value: division.id ? Number(division.id) : String(division.code), - label: division.name, - })) - } - } - divisions.value = externalDivisions.map((division: Division) => ({ - value: division.id ? Number(division.id) : String(division.code), - label: division.name, - })) -} - -export const getEncounterClassList = async () => { - const result = await getEncounters() - if (result.success) { - const currentValues = result.body?.data || [] - encounterClasses.value = currentValues.map((item: any) => ({ - value: item.class_code || item.id, - label: item.class_code, - })) - } -} - -export function getEncounterClassConstants() { - const allowed = ['ambulatory', 'emergency', 'inpatient'] - encounterClasses.value = Object.entries(encounterClassCodes) - .filter(([key]) => allowed.includes(key)) - .map(([key, value]) => ({ value: key, label: value })) -} - -export const getInstallationList = async () => { - const result = await getInstallations() - if (result.success) { - const currentInstallations = result.body?.data || [] - installations.value = currentInstallations.map((item: Installation) => ({ - value: item.id ? Number(item.id) : item.code, - label: item.name, - })) - } -} - -export const getSpecialistsList = async () => { - const result = await getSpecialists() - if (result.success) { - const currentSpecialists = result.body?.data || [] - specialists.value = currentSpecialists.map((item: Specialist) => ({ - value: item.id ? Number(item.id) : item.code, - label: item.name, - })) - } -} - /** * Convert division response (with childrens) to TreeItem[] * @param divisions Array of division objects from API diff --git a/app/models/subspecialist.ts b/app/models/subspecialist.ts index 32591ab3..911603ae 100644 --- a/app/models/subspecialist.ts +++ b/app/models/subspecialist.ts @@ -1,4 +1,5 @@ export interface Subspecialist { + id?: number code: string name: string specialist_id: number | string diff --git a/app/services/device.service.ts b/app/services/device.service.ts index 5e6a7b1f..8ad00b2b 100644 --- a/app/services/device.service.ts +++ b/app/services/device.service.ts @@ -1,3 +1,4 @@ +// Base import * as base from './_crud-base' const path = '/api/v1/device' diff --git a/app/services/division-position.service.ts b/app/services/division-position.service.ts index 6006e572..dc3929f8 100644 --- a/app/services/division-position.service.ts +++ b/app/services/division-position.service.ts @@ -1,3 +1,4 @@ +// Base import * as base from './_crud-base' const path = '/api/v1/division-position' diff --git a/app/services/division.service.ts b/app/services/division.service.ts index 707337d0..422b99fa 100644 --- a/app/services/division.service.ts +++ b/app/services/division.service.ts @@ -1,5 +1,9 @@ +// Base import * as base from './_crud-base' +// Types +import type { Division } from '~/models/division' + const path = '/api/v1/division' const name = 'division' @@ -22,3 +26,16 @@ export function update(id: number | string, data: any) { export function remove(id: number | string) { return base.remove(path, id, name) } + +export async function getValueLabelList(params: any = null): Promise<{ value: string; label: string }[]> { + let data: { value: string; label: string }[] = [] + const result = await getList(params) + if (result.success) { + const resultData = result.body?.data || [] + data = resultData.map((item: Division) => ({ + value: item.id ? Number(item.id) : item.code, + label: item.name, + })) + } + return data +} diff --git a/app/services/encounter.service.ts b/app/services/encounter.service.ts index 51f0b060..bf83c843 100644 --- a/app/services/encounter.service.ts +++ b/app/services/encounter.service.ts @@ -1,79 +1,48 @@ -import { xfetch } from '~/composables/useXfetch' +// Base +import * as base from './_crud-base' -const mainUrl = '/api/v1/encounter' +// Constants +import { encounterClassCodes } from '~/lib/constants' -export async function getEncounters(params: any = null) { - try { - let url = mainUrl - if (params && typeof params === 'object' && Object.keys(params).length > 0) { - const searchParams = new URLSearchParams() - for (const key in params) { - if (params[key] !== null && params[key] !== undefined && params[key] !== '') { - searchParams.append(key, params[key]) - } - } - const queryString = searchParams.toString() - if (queryString) url += `?${queryString}` - } - const resp = await xfetch(url, 'GET') - const result: any = {} - result.success = resp.success - result.body = (resp.body as Record) || {} - return result - } catch (error) { - console.error('Error fetching encounters:', error) - throw new Error('Failed to fetch encounters') - } +const path = '/api/v1/encounter' +const name = 'encounter' + +export function create(data: any) { + return base.create(path, data, name) } -export async function getEncounterDetail(id: string | number) { - try { - const resp = await xfetch(`${mainUrl}/${id}`, 'GET') - const result: any = {} - result.success = resp.success - result.body = (resp.body as Record) || {} - return result - } catch (error) { - console.error('Error fetching encounter detail:', error) - throw new Error('Failed to fetch encounter detail') - } +export function getList(params: any = null) { + return base.getList(path, params, name) } -export async function postEncounter(data: any) { - try { - const resp = await xfetch(mainUrl, 'POST', data) - const result: any = {} - result.success = resp.success - result.body = (resp.body as Record) || {} - return result - } catch (error) { - console.error('Error creating encounter:', error) - throw new Error('Failed to create encounter') - } +export function getDetail(id: number | string) { + return base.getDetail(path, id, name) } -export async function patchEncounter(id: string | number, data: any) { - try { - const resp = await xfetch(`${mainUrl}/${id}`, 'PATCH', data) - const result: any = {} - result.success = resp.success - result.body = (resp.body as Record) || {} - return result - } catch (error) { - console.error('Error updating encounter:', error) - throw new Error('Failed to update encounter') - } +export function update(id: number | string, data: any) { + return base.update(path, id, data, name) } -export async function removeEncounter(id: string | number) { - try { - const resp = await xfetch(`${mainUrl}/${id}`, 'DELETE') - const result: any = {} - result.success = resp.success - result.body = (resp.body as Record) || {} - return result - } catch (error) { - console.error('Error deleting encounter:', error) - throw new Error('Failed to delete encounter') - } +export function remove(id: number | string) { + return base.remove(path, id, name) +} + +export async function getValueLabelList(params: any = null): Promise<{ value: string; label: string }[]> { + let data: { value: string; label: string }[] = [] + const result = await getList(params) + if (result.success) { + const resultData = result.body?.data || [] + data = resultData.map((item: any) => ({ + value: item.id ? Number(item.id) : item.code, + label: item.name, + })) + } + return data +} + +export function getValueLabelListConstants() { + const allowed = ['ambulatory', 'emergency', 'inpatient'] + return Object.entries(encounterClassCodes) + .filter(([key]) => allowed.includes(key)) + .map(([key, value]) => ({ value: key, label: value })) } diff --git a/app/services/installation.service.ts b/app/services/installation.service.ts index 3a85568e..1f1975f5 100644 --- a/app/services/installation.service.ts +++ b/app/services/installation.service.ts @@ -1,5 +1,9 @@ +// Base import * as base from './_crud-base' +// Types +import type { Installation } from '~/models/installation' + const path = '/api/v1/installation' const name = 'installation' @@ -22,3 +26,16 @@ export function update(id: number | string, data: any) { export function remove(id: number | string) { return base.remove(path, id, name) } + +export async function getValueLabelList(params: any = null): Promise<{ value: string; label: string }[]> { + let data: { value: string; label: string }[] = [] + const result = await getList(params) + if (result.success) { + const resultData = result.body?.data || [] + data = resultData.map((item: Installation) => ({ + value: item.id ? Number(item.id) : item.code, + label: item.name, + })) + } + return data +} diff --git a/app/services/material.service.ts b/app/services/material.service.ts index 242b0ad7..f8e8c013 100644 --- a/app/services/material.service.ts +++ b/app/services/material.service.ts @@ -1,3 +1,4 @@ +// Base import * as base from './_crud-base' const path = '/api/v1/material' diff --git a/app/services/medicine.service.ts b/app/services/medicine.service.ts index e889d2ee..57a52103 100644 --- a/app/services/medicine.service.ts +++ b/app/services/medicine.service.ts @@ -1,3 +1,4 @@ +// Base import * as base from './_crud-base' const path = '/api/v1/medicine' diff --git a/app/services/specialist.service.ts b/app/services/specialist.service.ts index e2531bb2..d0be9657 100644 --- a/app/services/specialist.service.ts +++ b/app/services/specialist.service.ts @@ -1,20 +1,41 @@ +// Base import * as base from './_crud-base' +// Types +import type { Specialist } from '~/models/specialist' + const path = '/api/v1/specialist' const name = 'specialist' export function create(data: any) { return base.create(path, data, name) } + export function getList(params: any = null) { return base.getList(path, params, name) } + export function getDetail(id: number | string) { return base.getDetail(path, id, name) } + export function update(id: number | string, data: any) { return base.update(path, id, data, name) } + export function remove(id: number | string) { return base.remove(path, id, name) } + +export async function getValueLabelList(params: any = null): Promise<{ value: string; label: string }[]> { + let data: { value: string; label: string }[] = [] + const result = await getList(params) + if (result.success) { + const resultData = result.body?.data || [] + data = resultData.map((item: Specialist) => ({ + value: item.id ? Number(item.id) : item.code, + label: item.name, + })) + } + return data +} diff --git a/app/services/subspecialist.service.ts b/app/services/subspecialist.service.ts index 6b427d43..59c1d57a 100644 --- a/app/services/subspecialist.service.ts +++ b/app/services/subspecialist.service.ts @@ -1,20 +1,41 @@ +// Base import * as base from './_crud-base' +// Types +import type { Subspecialist } from '~/models/subspecialist' + const path = '/api/v1/subspecialist' const name = 'subspecialist' export function create(data: any) { return base.create(path, data, name) } + export function getList(params: any = null) { return base.getList(path, params, name) } + export function getDetail(id: number | string) { return base.getDetail(path, id, name) } + export function update(id: number | string, data: any) { return base.update(path, id, data, name) } + export function remove(id: number | string) { return base.remove(path, id, name) } + +export async function getValueLabelList(params: any = null): Promise<{ value: string; label: string }[]> { + let data: { value: string; label: string }[] = [] + const result = await getList(params) + if (result.success) { + const resultData = result.body?.data || [] + data = resultData.map((item: Subspecialist) => ({ + value: item.id ? Number(item.id) : item.code, + label: item.name, + })) + } + return data +}