Skip to content

Commit

Permalink
[Closes #132] Add additional information for the results of the Physi…
Browse files Browse the repository at this point in the history
…cian search (#135)

* include hospital data for each physician

* display name of hospital with each physician in form dropdrown

* Displays physician followed by hospital name only if it exists

* Format selected value

* Fixed format issues with Prettier

* Fixed bug related to pagination headers

* Formatted with Prettier

* Modify pagination parameters to avoid conflicts

* Update display of dropdown values

* Include hospitals in physician query

* Restore to previous approach of paginating results

* Refactored data mapping to hospital name

* Update initial physician input

* Modified component with hospital data

* Reformatted physician input value

* Add nullish operator to prevent accessing undefined properties

Without the use of the nullish operator here, the app would crash when a search for physicians is made where some of the fields are null.

* Modify string creation logic to remove extra characters

* Remove passing initial hospital data prop as it is unused

* Display physician name and their hospital if patient has that information stored already

* Separate out the pieces for string construction of physician details

* Display physician name, hospital, and phone number in combobox drop down

* Format files

---------

Co-authored-by: Wendy <[email protected]>
Co-authored-by: samau3 <[email protected]>
  • Loading branch information
3 people authored Oct 25, 2024
1 parent 63bb8e7 commit 1fd9b26
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 9 deletions.
1 change: 1 addition & 0 deletions client/src/pages/patients/LifelineAPI.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export default class LifelineAPI {
return {
...item,
name: `${item.firstName} ${item.lastName}`,
hospital: item.hospitals[0]?.name,
};
});
}
Expand Down
12 changes: 9 additions & 3 deletions client/src/pages/patients/register/PatientRegistration.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,15 @@ export default function PatientRegistration() {

setInitialHospitalData(hospital ? hospital.name : '');

setInitialPhysicianData(
physician ? `${physician.firstName} ${physician.lastName}` : '',
);
if (physician) {
const fullName = `${physician.firstName}${physician.middleName ? ` ${physician.middleName}` : ''} ${physician.lastName}`;
const hospital = physician.hospitals[0]
? physician.hospitals[0].name
: '';
const phone = physician.phone ? `${physician.phone} ` : '';
const physicianDetails = `${fullName}${hospital ? ` (${hospital})` : ''}${phone ? ` - ${phone}` : ''}`;
setInitialPhysicianData(physicianDetails);
}

const patientData = {
firstName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,16 @@ export default function HealthcareChoicesSearch({ form, choice, initialData }) {

const handleSelectValue = (id, key) => {
const name = key.children;
// setValue({ id, name });
setSearch(name);
setSearch(name.join(''));
form.setFieldValue(`healthcareChoices.${choice}Id`, id);
combobox.closeDropdown();
};

const options = (data || []).map((item) => (
<Combobox.Option value={item.id} key={item.id}>
{item.name}
{item.hospital ? ` (${item.hospital})` : ''}
{item.phone ? ` - ${item.phone}` : ''}
</Combobox.Option>
));

Expand Down
9 changes: 7 additions & 2 deletions server/prisma/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,17 @@ const prisma = new PrismaClient({
name: 'paginate',
model: {
$allModels: {
async paginate({ page, perPage, ...options }) {
async paginate({ page, perPage, include, ...options }) {
const take = parseInt(perPage, 10);
const skip = (parseInt(page, 10) - 1) * take;
const context = Prisma.getExtensionContext(this);
const total = await context.count(options);
const records = await context.findMany({ ...options, skip, take });
const records = await context.findMany({
...options,
include,
skip,
take,
});
return { records, total };
},
},
Expand Down
19 changes: 18 additions & 1 deletion server/routes/api/v1/patients/get.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,19 @@ export default async function (fastify, _opts) {
lastName: { type: 'string' },
phone: { type: 'string' },
email: { type: 'string' },
hospitals: {
type: 'array',
items: {
type: 'object',
properties: {
id: { type: 'string' },
name: { type: 'string' },
address: { type: 'string' },
phone: { type: 'string' },
email: { type: 'string' },
},
},
},
},
},
updatedById: { type: 'string' },
Expand Down Expand Up @@ -98,7 +111,11 @@ export default async function (fastify, _opts) {
orderBy: { sortOrder: 'asc' },
},
hospital: true,
physician: true,
physician: {
include: {
hospitals: true,
},
},
},
});
if (!patient) throw new Error('Patient not found');
Expand Down
12 changes: 11 additions & 1 deletion server/routes/api/v1/physicians/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,16 @@ export default async function (fastify) {
phone: { type: 'string' },
firstName: { type: 'string' },
lastName: { type: 'string' },
hospitals: {
type: 'array',
items: {
type: 'object',
properties: {
id: { type: 'string' },
name: { type: 'string' },
},
},
},
},
},
},
Expand Down Expand Up @@ -71,12 +81,12 @@ export default async function (fastify) {
],
};
}

const options = {
page,
perPage,
orderBy: [{ firstName: 'asc' }, { lastName: 'asc' }],
where: whereClase,
include: { hospitals: true },
};

const { records, total } =
Expand Down

0 comments on commit 1fd9b26

Please sign in to comment.