Skip to content

Commit

Permalink
Format code to resolve prettier issues
Browse files Browse the repository at this point in the history
  • Loading branch information
samau3 committed Aug 15, 2024
1 parent 9d6d5e4 commit 9cf39b9
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 39 deletions.
33 changes: 20 additions & 13 deletions server/routes/api/v1/patients/update.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export default async function (fastify, _opts) {
middleName: { type: 'string' },
lastName: { type: 'string' },
dateOfBirth: { type: 'string', format: 'date' },
}
},
},
contactData: {
type: 'object',
Expand Down Expand Up @@ -79,7 +79,7 @@ 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' },
Expand Down Expand Up @@ -107,19 +107,24 @@ export default async function (fastify, _opts) {
},
async (request, reply) => {
const { patientId } = request.params;
const { patientData, 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 = {}
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);

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,
Expand All @@ -128,10 +133,12 @@ export default async function (fastify, _opts) {
});
}
if (contactData) {
const existingContact = (await tx.patient.findUnique({
where: { id: patientId },
include: { emergencyContact: true }
})).emergencyContact;
const existingContact = (
await tx.patient.findUnique({
where: { id: patientId },
include: { emergencyContact: true },
})
).emergencyContact;

if (existingContact) {
await tx.contact.update({
Expand Down
4 changes: 2 additions & 2 deletions server/test/fixtures/db/Patient.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ items:
firstName: John
middleName: A
lastName: Doe
dateOfBirth: "2000-10-05T00:00:00.000Z"
dateOfBirth: '2000-10-05T00:00:00.000Z'
createdBy: '@user1'
updatedBy: '@user1'
updatedBy: '@user1'
69 changes: 45 additions & 24 deletions server/test/routes/api/v1/patients.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,12 @@ describe('/api/v1/patients', () => {
const app = await build(t);
await t.loadFixtures();

let reply = await app
.inject()
.post('/api/v1/patients/register')
.payload({
firstName: 'John',
middleName: 'A',
lastName: 'Doe',
dateOfBirth: '1990-01-01',
});
let reply = await app.inject().post('/api/v1/patients/register').payload({
firstName: 'John',
middleName: 'A',
lastName: 'Doe',
dateOfBirth: '1990-01-01',
});

assert.deepStrictEqual(reply.statusCode, StatusCodes.UNAUTHORIZED);

Expand Down Expand Up @@ -143,9 +140,11 @@ describe('/api/v1/patients', () => {

assert.deepStrictEqual(reply.statusCode, StatusCodes.BAD_REQUEST);
const result = JSON.parse(reply.body);
assert.deepStrictEqual(result.message, "body must have required property 'firstName'");
assert.deepStrictEqual(
result.message,
"body must have required property 'firstName'",
);
});

});

describe('PATCH /update/:patientId', () => {
Expand Down Expand Up @@ -196,8 +195,10 @@ describe('/api/v1/patients', () => {
.headers(headers);

assert.deepStrictEqual(reply.statusCode, StatusCodes.OK);
const { id, firstName, middleName, lastName, dateOfBirth } = JSON.parse(reply.body);
assert.deepStrictEqual(id, "27963f68-ebc1-408a-8bb5-8fbe54671064");
const { id, firstName, middleName, lastName, dateOfBirth } = JSON.parse(
reply.body,
);
assert.deepStrictEqual(id, '27963f68-ebc1-408a-8bb5-8fbe54671064');
assert.deepStrictEqual(firstName, 'Jane');
assert.deepStrictEqual(middleName, 'A');
assert.deepStrictEqual(lastName, 'Doe');
Expand All @@ -220,8 +221,10 @@ describe('/api/v1/patients', () => {
.headers(headers);

assert.deepStrictEqual(reply.statusCode, StatusCodes.OK);
const { id, firstName, middleName, lastName, dateOfBirth } = JSON.parse(reply.body);
assert.deepStrictEqual(id, "27963f68-ebc1-408a-8bb5-8fbe54671064");
const { id, firstName, middleName, lastName, dateOfBirth } = JSON.parse(
reply.body,
);
assert.deepStrictEqual(id, '27963f68-ebc1-408a-8bb5-8fbe54671064');
assert.deepStrictEqual(firstName, 'Jack');
assert.deepStrictEqual(middleName, 'A');
assert.deepStrictEqual(lastName, 'Doe');
Expand All @@ -244,8 +247,10 @@ describe('/api/v1/patients', () => {
.headers(headers);

assert.deepStrictEqual(reply.statusCode, StatusCodes.OK);
const { id, firstName, middleName, lastName, dateOfBirth } = JSON.parse(reply.body);
assert.deepStrictEqual(id, "27963f68-ebc1-408a-8bb5-8fbe54671064");
const { id, firstName, middleName, lastName, dateOfBirth } = JSON.parse(
reply.body,
);
assert.deepStrictEqual(id, '27963f68-ebc1-408a-8bb5-8fbe54671064');
assert.deepStrictEqual(firstName, 'Jill');
assert.deepStrictEqual(middleName, 'A');
assert.deepStrictEqual(lastName, 'Doe');
Expand Down Expand Up @@ -279,7 +284,6 @@ describe('/api/v1/patients', () => {
phone: '123-456-7890',
relationship: 'Mother',
});

});

it('should allow ADMIN to update a patient with medical data', async (t) => {
Expand Down Expand Up @@ -311,16 +315,33 @@ describe('/api/v1/patients', () => {
.headers(headers);

assert.deepStrictEqual(reply.statusCode, StatusCodes.OK);
const { id, firstName, middleName, lastName, dateOfBirth, allergies, medications, conditions } = JSON.parse(reply.body);
assert.deepStrictEqual(id, "27963f68-ebc1-408a-8bb5-8fbe54671064");
const {
id,
firstName,
middleName,
lastName,
dateOfBirth,
allergies,
medications,
conditions,
} = JSON.parse(reply.body);
assert.deepStrictEqual(id, '27963f68-ebc1-408a-8bb5-8fbe54671064');
assert.deepStrictEqual(firstName, 'John');
assert.deepStrictEqual(middleName, 'A');
assert.deepStrictEqual(lastName, 'Doe');
assert.deepStrictEqual(dateOfBirth, '2000-10-05');
assert.deepStrictEqual(allergies[0].id, '5c057fc3-15d2-40fc-b664-707d04ba66c2');
assert.deepStrictEqual(medications[0].id, '583c7775-9466-4dab-8a4d-edf1056f097f');
assert.deepStrictEqual(conditions[0].id, '471c8529-81fc-4129-8ca0-f1b7406ed90c');
assert.deepStrictEqual(
allergies[0].id,
'5c057fc3-15d2-40fc-b664-707d04ba66c2',
);
assert.deepStrictEqual(
medications[0].id,
'583c7775-9466-4dab-8a4d-edf1056f097f',
);
assert.deepStrictEqual(
conditions[0].id,
'471c8529-81fc-4129-8ca0-f1b7406ed90c',
);
});

});
});

0 comments on commit 9cf39b9

Please sign in to comment.