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
|
||||
|
||||
Reference in New Issue
Block a user