fix: update some service

This commit is contained in:
riefive
2025-10-06 10:38:10 +07:00
parent 78ae8a8aa0
commit d1bcd6e66c
11 changed files with 118 additions and 164 deletions
+1
View File
@@ -1,3 +1,4 @@
// Base
import * as base from './_crud-base'
const path = '/api/v1/device'
@@ -1,3 +1,4 @@
// Base
import * as base from './_crud-base'
const path = '/api/v1/division-position'
+17
View File
@@ -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
}
+37 -68
View File
@@ -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<string, any>) || {}
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<string, any>) || {}
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<string, any>) || {}
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<string, any>) || {}
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<string, any>) || {}
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 }))
}
+17
View File
@@ -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
}
+1
View File
@@ -1,3 +1,4 @@
// Base
import * as base from './_crud-base'
const path = '/api/v1/material'
+1
View File
@@ -1,3 +1,4 @@
// Base
import * as base from './_crud-base'
const path = '/api/v1/medicine'
+21
View File
@@ -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
}
+21
View File
@@ -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
}