first commit

This commit is contained in:
2025-04-22 10:56:56 +07:00
commit af123c091b
147 changed files with 778063 additions and 0 deletions

View File

@@ -0,0 +1,42 @@
export default defineEventHandler(async (event) => {
const body = await readBody(event)
// return body
const data = await prisma.practitioner.create({
data: {
active: body.active ? true : false,
identifier: body.identifier.map((i) => {
return {
name: i.name,
value: i.value,
}
}),
name: body.name.map((n) => ({
use: n.use || 'usual',
...(n.family && { family: n.family }),
...(n.given && { given: n.given }),
...(n.prefix && { prefix: n.prefix }),
...(n.suffix && { suffix: n.suffix }),
...(n.period &&
(n.period.start || n.period.end) && {
period: Object.fromEntries(
Object.entries({
start: n.period.start ? new Date(n.period.start) : undefined,
end: n.period.end ? new Date(n.period.end) : undefined,
}).filter(([, value]) => value !== undefined),
),
}),
})),
gender: body.gender,
birthDate: body.birthDate ? new Date(body.birthDate) : null,
birthPlace: body.birthPlace,
address: body.address,
communication: body.communication.map((c) => {
return {
preferred: c.preferred ? true : false,
language: c.language,
}
}),
},
})
return data
})

View File

@@ -0,0 +1,65 @@
import { useToString } from '@vueuse/core'
import { take } from 'echarts/types/src/component/helper/interactionMutex.js'
export default defineEventHandler(async (event) => {
const query = getQuery(event)
const name = useToString(query.name).value.split(' ')
function pipelineFilter(keywords) {
var result = [{}]
keywords.forEach((keyword, index) => {
result[index] = {
$match: {
$or: [
{
'name.family': {
$regex: (index === 0 ? '^' : '') + keyword,
$options: 'i',
},
},
{
'name.given': {
$regex: (index === 0 ? '^' : '') + keyword,
$options: 'i',
},
},
],
},
}
})
return result
}
try {
if (Object.keys(query).length === 0) {
return await prisma.practitioner.aggregateRaw({
pipeline: [{ $limit: 100 }],
})
}
const practitioners = await prisma.practitioner.aggregateRaw({
pipeline: [
// { $unwind: { path: '$name.family' } },
...pipelineFilter(name),
{
$limit: 10,
},
// {
// $project: {
// id: 1,
// name: 1,
// },
// },
],
})
return practitioners
} catch (error) {
return {
status: 500,
body: {
messages: 'failed to fetch practitioners',
code: error,
},
}
}
})