58 lines
1.7 KiB
TypeScript
58 lines
1.7 KiB
TypeScript
export default defineEventHandler(async (event) => {
|
|
const marital = {
|
|
'M': 'Menikah',
|
|
'U': 'Belum Menikah',
|
|
'jawa': 'Jawa',
|
|
'sunda': 'Sunda'
|
|
};
|
|
const body = await readBody(event)
|
|
const data = await prisma.patient.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,
|
|
maritalStatus: body.maritalStatus.map((m) => {
|
|
const coding = m.coding[0];
|
|
return {
|
|
preferred: coding.system ? true : false,
|
|
// coding: coding.system
|
|
code: coding.select,
|
|
display: marital[coding.select],
|
|
};
|
|
}),
|
|
communication: body.communication.map((c) => {
|
|
const language = c.language[0]
|
|
return {
|
|
preferred: c.preferred ? true : false,
|
|
language: [{ text: language.text }],
|
|
}
|
|
}),
|
|
},
|
|
})
|
|
return data
|
|
})
|