first commit
This commit is contained in:
42
server/api/practitioner/basic.post.ts
Normal file
42
server/api/practitioner/basic.post.ts
Normal 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
|
||||
})
|
||||
65
server/api/practitioner/index.get.ts
Normal file
65
server/api/practitioner/index.get.ts
Normal 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,
|
||||
},
|
||||
}
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user