Merge branch 'dev' into fe-prescription-56

This commit is contained in:
Andrian Roshandy
2025-10-07 03:10:19 +07:00
71 changed files with 963 additions and 3006 deletions
+15 -15
View File
@@ -1,6 +1,6 @@
import { xfetch } from '~/composables/useXfetch'
export async function create(path: string, data: any) {
export async function create(path: string, data: any, name: string = 'item') {
try {
const resp = await xfetch(path, 'POST', data)
const result: any = {}
@@ -8,12 +8,12 @@ export async function create(path: string, data: any) {
result.body = (resp.body as Record<string, any>) || {}
return result
} catch (error) {
console.error('Error posting division:', error)
throw new Error('Failed to post division')
console.error(`Error posting ${name}:`, error)
throw new Error(`Failed to post ${name}`)
}
}
export async function getList(path: string, params: any = null) {
export async function getList(path: string, params: any = null, name: string = 'item') {
try {
let url = path
if (params && typeof params === 'object' && Object.keys(params).length > 0) {
@@ -32,12 +32,12 @@ export async function getList(path: string, params: any = null) {
result.body = (resp.body as Record<string, any>) || {}
return result
} catch (error) {
console.error('Error fetching divisions:', error)
throw new Error('Failed to fetch divisions')
console.error(`Error fetching ${name}s:`, error)
throw new Error(`Failed to fetch ${name}s`)
}
}
export async function getDetail(path: string, id: number | string) {
export async function getDetail(path: string, id: number | string, name: string = 'item') {
try {
const resp = await xfetch(`${path}/${id}`, 'GET')
const result: any = {}
@@ -45,12 +45,12 @@ export async function getDetail(path: string, id: number | string) {
result.body = (resp.body as Record<string, any>) || {}
return result
} catch (error) {
console.error('Error fetching division detail:', error)
throw new Error('Failed to get division detail')
console.error(`Error fetching ${name} detail:`, error)
throw new Error(`Failed to get ${name} detail`)
}
}
export async function update(path: string, id: number | string, data: any) {
export async function update(path: string, id: number | string, data: any, name: string = 'item') {
try {
const resp = await xfetch(`${path}/${id}`, 'PATCH', data)
const result: any = {}
@@ -58,12 +58,12 @@ export async function update(path: string, id: number | string, data: any) {
result.body = (resp.body as Record<string, any>) || {}
return result
} catch (error) {
console.error('Error putting division:', error)
throw new Error('Failed to put division')
console.error(`Error putting ${name}:`, error)
throw new Error(`Failed to put ${name}`)
}
}
export async function remove(path: string, id: number | string) {
export async function remove(path: string, id: number | string, name: string = 'item') {
try {
const resp = await xfetch(`${path}/${id}`, 'DELETE')
const result: any = {}
@@ -71,7 +71,7 @@ export async function remove(path: string, id: number | string) {
result.body = (resp.body as Record<string, any>) || {}
return result
} catch (error) {
console.error('Error deleting data:', error)
throw new Error('Failed to delete division')
console.error(`Error deleting ${name}:`, error)
throw new Error(`Failed to delete ${name}`)
}
}
+14 -68
View File
@@ -1,79 +1,25 @@
import { xfetch } from '~/composables/useXfetch'
// Base
import * as base from './_crud-base'
const mainUrl = '/api/v1/device'
const path = '/api/v1/device'
const name = 'device'
export async function getDevices(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 devices:', error)
throw new Error('Failed to fetch devices')
}
export function create(data: any) {
return base.create(path, data, name)
}
export async function getDeviceDetail(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 device detail:', error)
throw new Error('Failed to fetch device detail')
}
export function getList(params: any = null) {
return base.getList(path, params, name)
}
export async function postDevice(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 device:', error)
throw new Error('Failed to create device')
}
export function getDetail(id: number | string) {
return base.getDetail(path, id, name)
}
export async function patchDevice(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 device:', error)
throw new Error('Failed to update device')
}
export function update(id: number | string, data: any) {
return base.update(path, id, data, name)
}
export async function removeDevice(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 device:', error)
throw new Error('Failed to delete device')
}
export function remove(id: number | string) {
return base.remove(path, id, name)
}
+14 -68
View File
@@ -1,79 +1,25 @@
import { xfetch } from '~/composables/useXfetch'
// Base
import * as base from './_crud-base'
const mainUrl = '/api/v1/division-position'
const path = '/api/v1/division-position'
const name = 'division-position'
export async function getDivisionPositions(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(mainUrl, 'GET')
const result: any = {}
result.success = resp.success
result.body = (resp.body as Record<string, any>) || {}
return result
} catch (error) {
console.error('Error fetching division-positions:', error)
throw new Error('Failed to fetch division-positions')
}
export function create(data: any) {
return base.create(path, data, name)
}
export async function getDivisionPositionDetail(id: number | string) {
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 division-position detail:', error)
throw new Error('Failed to get division-position detail')
}
export function getList(params: any = null) {
return base.getList(path, params, name)
}
export async function postDivisionPosition(record: any) {
try {
const resp = await xfetch(mainUrl, 'POST', record)
const result: any = {}
result.success = resp.success
result.body = (resp.body as Record<string, any>) || {}
return result
} catch (error) {
console.error('Error posting division-position:', error)
throw new Error('Failed to post division-position')
}
export function getDetail(id: number | string) {
return base.getDetail(path, id, name)
}
export async function patchDivisionPosition(id: number | string, record: any) {
try {
const resp = await xfetch(`${mainUrl}/${id}`, 'PATCH', record)
const result: any = {}
result.success = resp.success
result.body = (resp.body as Record<string, any>) || {}
return result
} catch (error) {
console.error('Error putting division-position:', error)
throw new Error('Failed to put division-position')
}
export function update(id: number | string, data: any) {
return base.update(path, id, data, name)
}
export async function removeDivisionPosition(id: number | string) {
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 record:', error)
throw new Error('Failed to delete division-position')
}
export function remove(id: number | string) {
return base.remove(path, id, name)
}
+50 -68
View File
@@ -1,79 +1,61 @@
import { xfetch } from '~/composables/useXfetch'
// Base
import * as base from './_crud-base'
const mainUrl = '/api/v1/division'
// Types
import type { Division } from '~/models/division'
import type { TreeItem } from '~/models/_model'
export async function getDivisions(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(mainUrl, 'GET')
const result: any = {}
result.success = resp.success
result.body = (resp.body as Record<string, any>) || {}
return result
} catch (error) {
console.error('Error fetching divisions:', error)
throw new Error('Failed to fetch divisions')
}
const path = '/api/v1/division'
const name = 'division'
export function create(data: any) {
return base.create(path, data, name)
}
export async function getDivisionDetail(id: number | string) {
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 division detail:', error)
throw new Error('Failed to get division detail')
}
export function getList(params: any = null) {
return base.getList(path, params, name)
}
export async function postDivision(record: any) {
try {
const resp = await xfetch(mainUrl, 'POST', record)
const result: any = {}
result.success = resp.success
result.body = (resp.body as Record<string, any>) || {}
return result
} catch (error) {
console.error('Error posting division:', error)
throw new Error('Failed to post division')
}
export function getDetail(id: number | string) {
return base.getDetail(path, id, name)
}
export async function patchDivision(id: number | string, record: any) {
try {
const resp = await xfetch(`${mainUrl}/${id}`, 'PATCH', record)
const result: any = {}
result.success = resp.success
result.body = (resp.body as Record<string, any>) || {}
return result
} catch (error) {
console.error('Error putting division:', error)
throw new Error('Failed to put division')
}
export function update(id: number | string, data: any) {
return base.update(path, id, data, name)
}
export async function removeDivision(id: number | string) {
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 record:', error)
throw new Error('Failed to delete division')
}
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
}
/**
* Convert division response (with childrens) to TreeItem[]
* @param divisions Array of division objects from API
* @returns TreeItem[]
*/
export function getValueTreeItems(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
? getValueTreeItems(division.childrens)
: undefined,
}))
}
+48
View File
@@ -0,0 +1,48 @@
// Base
import * as base from './_crud-base'
// Constants
import { encounterClassCodes } from '~/lib/constants'
const path = '/api/v1/encounter'
const name = 'encounter'
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: 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 }))
}
+30 -68
View File
@@ -1,79 +1,41 @@
import { xfetch } from '~/composables/useXfetch'
// Base
import * as base from './_crud-base'
const mainUrl = '/api/v1/installation'
// Types
import type { Installation } from '~/models/installation'
export async function getInstallations(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(mainUrl, 'GET')
const result: any = {}
result.success = resp.success
result.body = (resp.body as Record<string, any>) || {}
return result
} catch (error) {
console.error('Error fetching installations:', error)
throw new Error('Failed to fetch installations')
}
const path = '/api/v1/installation'
const name = 'installation'
export function create(data: any) {
return base.create(path, data, name)
}
export async function getInstallationDetail(id: number | string) {
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 installation detail:', error)
throw new Error('Failed to get installation detail')
}
export function getList(params: any = null) {
return base.getList(path, params, name)
}
export async function postInstallation(record: any) {
try {
const resp = await xfetch(mainUrl, 'POST', record)
const result: any = {}
result.success = resp.success
result.body = (resp.body as Record<string, any>) || {}
return result
} catch (error) {
console.error('Error posting installation:', error)
throw new Error('Failed to post installation')
}
export function getDetail(id: number | string) {
return base.getDetail(path, id, name)
}
export async function patchInstallation(id: number | string, record: any) {
try {
const resp = await xfetch(`${mainUrl}/${id}`, 'PATCH', record)
const result: any = {}
result.success = resp.success
result.body = (resp.body as Record<string, any>) || {}
return result
} catch (error) {
console.error('Error putting installation:', error)
throw new Error('Failed to put installation')
}
export function update(id: number | string, data: any) {
return base.update(path, id, data, name)
}
export async function removeInstallation(id: number | string) {
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 record:', error)
throw new Error('Failed to delete installation')
}
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
}
+14 -68
View File
@@ -1,79 +1,25 @@
import { xfetch } from '~/composables/useXfetch'
// Base
import * as base from './_crud-base'
const mainUrl = '/api/v1/material'
const path = '/api/v1/material'
const name = 'material'
export async function getMaterials(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 materials:', error)
throw new Error('Failed to fetch materials')
}
export function create(data: any) {
return base.create(path, data, name)
}
export async function getMaterialDetail(id: number | string) {
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 material detail:', error)
throw new Error('Failed to get material detail')
}
export function getList(params: any = null) {
return base.getList(path, params, name)
}
export async function postMaterial(record: any) {
try {
const resp = await xfetch(mainUrl, 'POST', record)
const result: any = {}
result.success = resp.success
result.body = (resp.body as Record<string, any>) || {}
return result
} catch (error) {
console.error('Error posting material:', error)
throw new Error('Failed to post material')
}
export function getDetail(id: number | string) {
return base.getDetail(path, id, name)
}
export async function patchMaterial(id: number | string, record: any) {
try {
const resp = await xfetch(`${mainUrl}/${id}`, 'PATCH', record)
const result: any = {}
result.success = resp.success
result.body = (resp.body as Record<string, any>) || {}
return result
} catch (error) {
console.error('Error putting material:', error)
throw new Error('Failed to put material')
}
export function update(id: number | string, data: any) {
return base.update(path, id, data, name)
}
export async function removeMaterial(id: number | string) {
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 record:', error)
throw new Error('Failed to delete material')
}
export function remove(id: number | string) {
return base.remove(path, id, name)
}
+30 -68
View File
@@ -1,79 +1,41 @@
import { xfetch } from '~/composables/useXfetch'
// Base
import * as base from './_crud-base'
const mainUrl = '/api/v1/medicine-group'
// Types
import type { MedicineGroup } from '~/models/medicine-group'
export async function getMedicineGroups(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(mainUrl, 'GET')
const result: any = {}
result.success = resp.success
result.body = (resp.body as Record<string, any>) || {}
return result
} catch (error) {
console.error('Error fetching medicine groups:', error)
throw new Error('Failed to fetch medicine groups')
}
const path = '/api/v1/medicine-group'
const name = 'medicine-group'
export function create(data: any) {
return base.create(path, data, name)
}
export async function getMedicineGroupDetail(id: number | string) {
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 medicine group detail:', error)
throw new Error('Failed to get medicine group detail')
}
export function getList(params: any = null) {
return base.getList(path, params, name)
}
export async function postMedicineGroup(record: any) {
try {
const resp = await xfetch(mainUrl, 'POST', record)
const result: any = {}
result.success = resp.success
result.body = (resp.body as Record<string, any>) || {}
return result
} catch (error) {
console.error('Error posting medicine group:', error)
throw new Error('Failed to post medicine group')
}
export function getDetail(id: number | string) {
return base.getDetail(path, id, name)
}
export async function patchMedicineGroup(id: number | string, record: any) {
try {
const resp = await xfetch(`${mainUrl}/${id}`, 'PATCH', record)
const result: any = {}
result.success = resp.success
result.body = (resp.body as Record<string, any>) || {}
return result
} catch (error) {
console.error('Error putting medicine group:', error)
throw new Error('Failed to put medicine group')
}
export function update(id: number | string, data: any) {
return base.update(path, id, data, name)
}
export async function removeMedicineGroup(id: number | string) {
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 record:', error)
throw new Error('Failed to delete medicine group')
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: MedicineGroup) => ({
value: item.code,
label: item.name,
}))
}
}
return data
}
+27 -73
View File
@@ -1,87 +1,41 @@
import { xfetch } from '~/composables/useXfetch'
// Base
import * as base from './_crud-base'
const mainUrl = '/api/v1/medicine-method'
// Types
import type { MedicineMethod } from '~/models/medicine-method'
export async function getMedicineMethodsPrev() {
const resp = await xfetch('/api/v1/medicine-method')
if (resp.success) {
return (resp.body as Record<string, any>).data
}
throw new Error('Failed to fetch medicine methods')
const path = '/api/v1/medicine-method'
const name = 'medicine-method'
export function create(data: any) {
return base.create(path, data, name)
}
export async function getMedicineMethods(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(mainUrl, 'GET')
const result: any = {}
result.success = resp.success
result.body = (resp.body as Record<string, any>) || {}
return result
} catch (error) {
console.error('Error fetching medicine methods:', error)
throw new Error('Failed to fetch medicine methods')
}
export function getList(params: any = null) {
return base.getList(path, params, name)
}
export async function getMedicineMethodDetail(id: number | string) {
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 medicine method detail:', error)
throw new Error('Failed to get medicine method detail')
}
export function getDetail(id: number | string) {
return base.getDetail(path, id, name)
}
export async function postMedicineMethod(record: any) {
try {
const resp = await xfetch(mainUrl, 'POST', record)
const result: any = {}
result.success = resp.success
result.body = (resp.body as Record<string, any>) || {}
return result
} catch (error) {
console.error('Error posting medicine method:', error)
throw new Error('Failed to post medicine method')
}
export function update(id: number | string, data: any) {
return base.update(path, id, data, name)
}
export async function patchMedicineMethod(id: number | string, record: any) {
try {
const resp = await xfetch(`${mainUrl}/${id}`, 'PATCH', record)
const result: any = {}
result.success = resp.success
result.body = (resp.body as Record<string, any>) || {}
return result
} catch (error) {
console.error('Error putting medicine method:', error)
throw new Error('Failed to put medicine method')
}
export function remove(id: number | string) {
return base.remove(path, id, name)
}
export async function removeMedicineMethod(id: number | string) {
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 record:', error)
throw new Error('Failed to delete medicine method')
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: MedicineMethod) => ({
value: item.code,
label: item.name,
}))
}
return data
}
+14 -68
View File
@@ -1,79 +1,25 @@
import { xfetch } from '~/composables/useXfetch'
// Base
import * as base from './_crud-base'
const mainUrl = '/api/v1/medicine'
const path = '/api/v1/medicine'
const name = 'medicine'
export async function getMedicines(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 medicines:', error)
throw new Error('Failed to fetch medicines')
}
export function create(data: any) {
return base.create(path, data, name)
}
export async function getMedicineDetail(id: number | string) {
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 medicine detail:', error)
throw new Error('Failed to get medicine detail')
}
export function getList(params: any = null) {
return base.getList(path, params, name)
}
export async function postMedicine(record: any) {
try {
const resp = await xfetch(mainUrl, 'POST', record)
const result: any = {}
result.success = resp.success
result.body = (resp.body as Record<string, any>) || {}
return result
} catch (error) {
console.error('Error posting medicine:', error)
throw new Error('Failed to post medicine')
}
export function getDetail(id: number | string) {
return base.getDetail(path, id, name)
}
export async function patchMedicine(id: number | string, record: any) {
try {
const resp = await xfetch(`${mainUrl}/${id}`, 'PATCH', record)
const result: any = {}
result.success = resp.success
result.body = (resp.body as Record<string, any>) || {}
return result
} catch (error) {
console.error('Error patching medicine:', error)
throw new Error('Failed to patch medicine')
}
export function update(id: number | string, data: any) {
return base.update(path, id, data, name)
}
export async function removeMedicine(id: number | string) {
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 medicine:', error)
throw new Error('Failed to delete medicine')
}
export function remove(id: number | string) {
return base.remove(path, id, name)
}
+30 -68
View File
@@ -1,79 +1,41 @@
import { xfetch } from '~/composables/useXfetch'
// Base
import * as base from './_crud-base'
const mainUrl = '/api/v1/specialist'
// Types
import type { Specialist } from '~/models/specialist'
export async function getSpecialists(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(mainUrl, 'GET')
const result: any = {}
result.success = resp.success
result.body = (resp.body as Record<string, any>) || {}
return result
} catch (error) {
console.error('Error fetching specialists:', error)
throw new Error('Failed to fetch specialists')
}
const path = '/api/v1/specialist'
const name = 'specialist'
export function create(data: any) {
return base.create(path, data, name)
}
export async function getSpecialistDetail(id: number | string) {
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 specialist detail:', error)
throw new Error('Failed to get specialist detail')
}
export function getList(params: any = null) {
return base.getList(path, params, name)
}
export async function postSpecialist(record: any) {
try {
const resp = await xfetch(mainUrl, 'POST', record)
const result: any = {}
result.success = resp.success
result.body = (resp.body as Record<string, any>) || {}
return result
} catch (error) {
console.error('Error posting specialist:', error)
throw new Error('Failed to post specialist')
}
export function getDetail(id: number | string) {
return base.getDetail(path, id, name)
}
export async function patchSpecialist(id: number | string, record: any) {
try {
const resp = await xfetch(`${mainUrl}/${id}`, 'PATCH', record)
const result: any = {}
result.success = resp.success
result.body = (resp.body as Record<string, any>) || {}
return result
} catch (error) {
console.error('Error putting specialist:', error)
throw new Error('Failed to put specialist')
}
export function update(id: number | string, data: any) {
return base.update(path, id, data, name)
}
export async function removeSpecialist(id: number | string) {
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 record:', error)
throw new Error('Failed to delete specialist')
}
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
}
+30 -68
View File
@@ -1,79 +1,41 @@
import { xfetch } from '~/composables/useXfetch'
// Base
import * as base from './_crud-base'
const mainUrl = '/api/v1/subspecialist'
// Types
import type { Subspecialist } from '~/models/subspecialist'
export async function getSubspecialists(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(mainUrl, 'GET')
const result: any = {}
result.success = resp.success
result.body = (resp.body as Record<string, any>) || {}
return result
} catch (error) {
console.error('Error fetching subspecialists:', error)
throw new Error('Failed to fetch subspecialists')
}
const path = '/api/v1/subspecialist'
const name = 'subspecialist'
export function create(data: any) {
return base.create(path, data, name)
}
export async function getSubspecialistDetail(id: number | string) {
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 subspecialist detail:', error)
throw new Error('Failed to get subspecialist detail')
}
export function getList(params: any = null) {
return base.getList(path, params, name)
}
export async function postSubspecialist(record: any) {
try {
const resp = await xfetch(mainUrl, 'POST', record)
const result: any = {}
result.success = resp.success
result.body = (resp.body as Record<string, any>) || {}
return result
} catch (error) {
console.error('Error posting subspecialist:', error)
throw new Error('Failed to post subspecialist')
}
export function getDetail(id: number | string) {
return base.getDetail(path, id, name)
}
export async function patchSubspecialist(id: number | string, record: any) {
try {
const resp = await xfetch(`${mainUrl}/${id}`, 'PATCH', record)
const result: any = {}
result.success = resp.success
result.body = (resp.body as Record<string, any>) || {}
return result
} catch (error) {
console.error('Error putting subspecialist:', error)
throw new Error('Failed to put subspecialist')
}
export function update(id: number | string, data: any) {
return base.update(path, id, data, name)
}
export async function removeSubspecialist(id: number | string) {
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 record:', error)
throw new Error('Failed to delete subspecialist')
}
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
}
+30 -68
View File
@@ -1,79 +1,41 @@
import { xfetch } from '~/composables/useXfetch'
// Base
import * as base from './_crud-base'
const mainUrl = '/api/v1/unit'
// Types
import type { Unit } from "~/models/unit";
export async function getUnits(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(mainUrl, 'GET')
const result: any = {}
result.success = resp.success
result.body = (resp.body as Record<string, any>) || {}
return result
} catch (error) {
console.error('Error fetching units:', error)
throw new Error('Failed to fetch units')
}
const path = '/api/v1/unit'
const name = 'unit'
export function create(data: any) {
return base.create(path, data, name)
}
export async function getUnitDetail(id: number | string) {
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 unit detail:', error)
throw new Error('Failed to get unit detail')
}
export function getList(params: any = null) {
return base.getList(path, params, name)
}
export async function postUnit(record: any) {
try {
const resp = await xfetch(mainUrl, 'POST', record)
const result: any = {}
result.success = resp.success
result.body = (resp.body as Record<string, any>) || {}
return result
} catch (error) {
console.error('Error posting unit:', error)
throw new Error('Failed to post unit')
}
export function getDetail(id: number | string) {
return base.getDetail(path, id, name)
}
export async function patchUnit(id: number | string, record: any) {
try {
const resp = await xfetch(`${mainUrl}/${id}`, 'PATCH', record)
const result: any = {}
result.success = resp.success
result.body = (resp.body as Record<string, any>) || {}
return result
} catch (error) {
console.error('Error putting unit:', error)
throw new Error('Failed to put unit')
}
export function update(id: number | string, data: any) {
return base.update(path, id, data, name)
}
export async function removeUnit(id: number | string) {
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 record:', error)
throw new Error('Failed to delete unit')
}
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: Unit) => ({
value: item.id,
label: item.name,
}))
}
return data
}
+30 -68
View File
@@ -1,79 +1,41 @@
import { xfetch } from '~/composables/useXfetch'
// Base
import * as base from './_crud-base'
const mainUrl = '/api/v1/uom'
// Types
import type { Uom } from '~/models/uom'
export async function getUoms(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(mainUrl, 'GET')
const result: any = {}
result.success = resp.success
result.body = (resp.body as Record<string, any>) || {}
return result
} catch (error) {
console.error('Error fetching uoms:', error)
throw new Error('Failed to fetch uoms')
}
const path = '/api/v1/uom'
const name = 'uom'
export function create(data: any) {
return base.create(path, data, name)
}
export async function getUomDetail(id: number | string) {
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 uom detail:', error)
throw new Error('Failed to get uom detail')
}
export function getList(params: any = null) {
return base.getList(path, params, name)
}
export async function postUom(record: any) {
try {
const resp = await xfetch(mainUrl, 'POST', record)
const result: any = {}
result.success = resp.success
result.body = (resp.body as Record<string, any>) || {}
return result
} catch (error) {
console.error('Error posting uom:', error)
throw new Error('Failed to post uom')
}
export function getDetail(id: number | string) {
return base.getDetail(path, id, name)
}
export async function patchUom(id: number | string, record: any) {
try {
const resp = await xfetch(`${mainUrl}/${id}`, 'PATCH', record)
const result: any = {}
result.success = resp.success
result.body = (resp.body as Record<string, any>) || {}
return result
} catch (error) {
console.error('Error putting uom:', error)
throw new Error('Failed to put uom')
}
export function update(id: number | string, data: any) {
return base.update(path, id, data, name)
}
export async function removeUom(id: number | string) {
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 record:', error)
throw new Error('Failed to delete uom')
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: Uom) => ({
value: item.code || item.erp_id,
label: item.name,
}))
}
}
return data
}