fix: update some service
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
export interface Subspecialist {
|
||||
id?: number
|
||||
code: string
|
||||
name: string
|
||||
specialist_id: number | string
|
||||
|
||||
@@ -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'
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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 }))
|
||||
}
|
||||
|
||||
@@ -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,3 +1,4 @@
|
||||
// Base
|
||||
import * as base from './_crud-base'
|
||||
|
||||
const path = '/api/v1/material'
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
// Base
|
||||
import * as base from './_crud-base'
|
||||
|
||||
const path = '/api/v1/medicine'
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user