127 lines
4.6 KiB
TypeScript
127 lines
4.6 KiB
TypeScript
// 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 }[]>([])
|
|
export const encounterClasses = ref<{ value: string; label: string }[]>([])
|
|
export const divisions = ref<{ value: string | number; label: string }[]>([])
|
|
export const installations = ref<{ value: string; label: string }[]>([])
|
|
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
|
|
* @returns TreeItem[]
|
|
*/
|
|
export function convertDivisionToTreeItems(divisions: any[]): TreeItem[] {
|
|
return divisions.filter((division: Division) => !division.parent_id).map((division: Division) => ({
|
|
value: division.id ? String(division.id) : division.code,
|
|
label: division.name,
|
|
hasChildren: Array.isArray(division.childrens) && division.childrens.length > 0,
|
|
children:
|
|
Array.isArray(division.childrens) && division.childrens.length > 0
|
|
? convertDivisionToTreeItems(division.childrens)
|
|
: undefined,
|
|
}))
|
|
}
|