Skip to content

Commit

Permalink
Enable updating patientData and fix bug in conditions schema
Browse files Browse the repository at this point in the history
  • Loading branch information
samau3 committed Aug 15, 2024
1 parent d29f166 commit 43d6ff8
Showing 1 changed file with 32 additions and 7 deletions.
39 changes: 32 additions & 7 deletions server/routes/api/v1/patients/update.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@ export default async function (fastify, _opts) {
body: {
type: 'object',
properties: {
patientData: {
type: 'object',
properties: {
firstName: { type: 'string' },
middleName: { type: 'string' },
lastName: { type: 'string' },
dateOfBirth: { type: 'string', format: 'date' },
}
},
contactData: {
type: 'object',
required: ['firstName', 'lastName', 'phone', 'relationship'],
Expand Down Expand Up @@ -47,12 +56,9 @@ export default async function (fastify, _opts) {
type: 'array',
items: {
type: 'object',
required: ['name'],
required: ['id'],
properties: {
name: { type: 'string' },
category: { type: 'string' },
system: { type: 'string' },
code: { type: 'string' },
id: { type: 'string' },
},
},
},
Expand All @@ -73,7 +79,11 @@ export default async function (fastify, _opts) {
[StatusCodes.OK]: {
type: 'object',
properties: {
id: { type: 'string' },
id: { type: 'string'},
firstName: { type: 'string' },
middleName: { type: 'string' },
lastName: { type: 'string' },
dateOfBirth: { type: 'string', format: 'date' },
emergencyContact: {
type: 'object',
properties: {
Expand All @@ -97,11 +107,26 @@ export default async function (fastify, _opts) {
},
async (request, reply) => {
const { patientId } = request.params;
const { contactData, medicalData, healthcareChoices } = request.body;
const { patientData, contactData, medicalData, healthcareChoices } = request.body;

const userId = request.user.id;

const updatedPatient = await fastify.prisma.$transaction(async (tx) => {
if (patientData) {
const newPatientData = {}

if (patientData.firstName) newPatientData.firstName = patientData.firstName;
if (patientData.middleName) newPatientData.middleName = patientData.middleName;
if (patientData.lastName) newPatientData.lastName = patientData.lastName;
if (patientData.dateOfBirth) newPatientData.dateOfBirth = new Date(patientData.dateOfBirth);

await tx.patient.update({
where: {
id: patientId,
},
data: newPatientData,
});
}
if (contactData) {
const existingContact = (await tx.patient.findUnique({
where: { id: patientId },
Expand Down

0 comments on commit 43d6ff8

Please sign in to comment.