Skip to content
This repository has been archived by the owner on Jan 9, 2023. It is now read-only.

Link appointment to lab request #2184 #2243

Closed

Conversation

yosephAHMED
Copy link
Contributor

@yosephAHMED yosephAHMED commented Jul 18, 2020

Fixes #2184

Demo

Screen Shot 2020-07-18 at 2 03 46 AM

Screen Shot 2020-07-18 at 2 05 25 AM

Screen Shot 2020-07-18 at 2 00 00 AM

Screen Shot 2020-07-18 at 2 03 10 AM

Changes proposed in this pull request:

Lab.ts

  • Add a field for 'appointment' of type string in the Lab model
    When the user is making a lab request, an appointment should have been set up prior, such that they can link that specific lab request to their upcoming appointment. Furthermore, a lab request should always have a specific time when the patient will come in to get it done. Hence, I believe it is useful to update the Lab model and add a field for appointment.

Screen Shot 2020-07-18 at 12 55 36 AM

NewLabRequest.tsx

  • Imported and utilized the fetchPatientAppointments thunk inside of onPatientChange
    When the state of patient is updated after the user searches and clicks on a patient, a dispatch will be sent to retrieve that patient's appointments using the patient id. Furthermore, on line 25, appointments will be populated with appointments retrieved from the redux store. Later in the code, the appointments array will be used in the process of displaying appointments on the screen. You may have noticed the addition of a local state variable, showAppointments. This state was used to display or hide the Dropdown onscreen, as well as fix some pesky errors I ran into, which I will discuss later!

Screen Shot 2020-07-18 at 2 06 59 AM
Screen Shot 2020-07-18 at 12 52 08 AM

  • Imported and utilized the Dropdown component from hospitalrun/components
    Rather than create my own dropdown menu, I wanted to maximize code reusability and was successfully able to render the patient's appointments inside of the Dropdown component. Firstly, the appointments inside of the 'appointments' array that were retrieved from redux store needed to be reformatted so that they could match the structure set by the Dropdown's Item interface. To accomplish this, on lines 106-107, I mapped the appointments array and for each element, formatted it as an object that satisfies the requirements of the Item interface. On lines 99-104, I added a function called formatAppointment, which takes in the element aforementioned (of type Appointment), and returns an object containing an onClick and text.
    Notice how for the onClick value, the onClick will call 'onAppointmentChange' and it passes the Appointment object as an argument. This is used later when updating the appointment state and finally saving appointment with the lab request.
    These formatted objects are stored in an array, formattedAppointmentList, which is then passed in to initialize the items prop of the Dropdown on line 139.

Screen Shot 2020-07-18 at 1 04 54 AM
Screen Shot 2020-07-18 at 1 05 06 AM
How the Dropdown looks when toggled
Screen Shot 2020-07-18 at 1 06 44 AM

  • Added a function onAppointmentChange that updated the local state of appointment
    When the user is in the Dropdown menu and they click on an appointment, the onAppointmentChange function is called (lines 63-68) and it receives the selected appointment as an argument. The argument is the appointment object. Here, I update the local state of appointment to the startDateTime, as that is the only information the patient/hospital personnel would be interested in.

Screen Shot 2020-07-18 at 1 19 02 AM

  • Added a local state called showAppointments of type boolean to toggle Dropdown visibility
    The reasoning behind adding a state for dropdown visibility is simple. When a patient is not currently selected, the appointment's dropdown should not be visible. Only when a patient is successfully selected, should the dropdown be visible to the user. Therefore, only inside the onPatientChange function is the state of showAppointments updated, because inside that function is the only time the patient is being updated.
    Now, at the time, there were two errors that I was running into. The first, more complicated error being that since I was using onPatientChange to send out the dispatch for the fetchPatientAppointments thunk, each time the patient was being updated, a dispatch was being sent out, even if the patient was undefined (the case when patient was being updated after the first patient is selected). The second, less complicated error was that there needed to be a way to hide the dropdown if the state of patient was being updated. Fortunately, I was able to kill both birds with one stone by further utilizing the state of showAppointments.
    In the image below, if (!showAppointments) {} will execute assuming that the prior state of patient was the initial state. In such a case, dispatching the fetchPatientAppointments thunk will not break the code, as a correct patient was successfully selected from the patient search, and then the appointments dropdown will be made visible. The else {} will execute when the user is initially updating the state of patient. In debugging, I found that this else {} was only executing once after the user initially deleted one character from the patient name. Furthermore, by not having the dispatch in this section, I was able to address the error aforementioned.
    Finally, by updating the state of showAppointments in this section to false, I was able to accomplish hiding the dropdown once again as the patient is being updated.
    P.S. on line 57, the state of appointment is set to an empty string to fix an error I found when switching patients. Prior, if a patient selected an appointment and then patients were changed afterwards, the new patient would still have the appointment of the prior patient saved.

Screen Shot 2020-07-18 at 1 29 13 AM

  • Implemented conditional rendering for Dropdown text and showing Dropdown in return
    When the patient has not selected an appointment in the dropdown, the default text will be "Appointments". After an appointment is selected, the text changes to match the local state of appointment. I found that this approach was overall better for user experience when utilizing the dropdown. Also, I added the conditional rendering needed for displaying/hiding the dropdown menu.

Screen Shot 2020-07-18 at 1 49 23 AM

  • Display Patient field and Appointment field in the same row of the form
    I was able to accomplish this by using bootstrap. I put the patient section and appointment section under a parent div called 'row', then separated the patient section and appointment section into two divs called 'col'. This separates patient and appointment section into two 50/50 parts.

Screen Shot 2020-07-18 at 2 01 07 AM

ViewLab.tsx

  • Implemented a very minimal method for displaying appointment details when viewing patient lab
    To ensure that appointment details were being saved properly with the lab,
    on line 188-193, I added a Column and all it does is display labToView.appointment.

Screen Shot 2020-07-18 at 1 52 08 AM

Thank you to the maintainers and everyone involved

It was a blast working on this issue! I learned a great deal since I was assigned to it.

A lab request should always have a specific appointment when the patient will come to get it done
…ange patient

prior dropdown would always show and changing patient would break code
conditional rendering for dropdown text. shows selected appointment
@jsf-clabot
Copy link

jsf-clabot commented Jul 18, 2020

CLA assistant check
All committers have signed the CLA.

@gitpod-io
Copy link

gitpod-io bot commented Jul 18, 2020

@jackcmeyer jackcmeyer self-requested a review July 18, 2020 19:53
@jackcmeyer jackcmeyer assigned fox1t and ghost Jul 18, 2020
@vercel
Copy link

vercel bot commented Jul 18, 2020

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/hospitalrun/hospitalrun-frontend/ay84v9m44
✅ Preview: https://hospitalrun-fr-git-fork-yosephahmed-enhancement-lab-appo-edc04d.hospitalrun.vercel.app

[update for 4efcfd1 failed]

@mkcode
Copy link

mkcode commented Jul 20, 2020

@yosephAHMED - Appreciate the detailed PR description here.

It looks like the linter failed in some cases. Please run npm run lint locally and do your best to fix any issues that it reports: https://github.com/HospitalRun/hospitalrun-frontend/blob/master/package.json#L119

@yosephAHMED
Copy link
Contributor Author

yosephAHMED commented Jul 24, 2020

@jackcmeyer

  • Completed
    I was able to address the changes you requested regarding the SelectWithLabelFormGroup and using the state of newLabRequest.patient to control displaying the appointments box

  • In progress
    Test cases for the files aforementioned and updating PouchDB schema

  • Questions
    Should there be a one to many relationship between an appointment and a lab? My reasoning is that a patient can schedule many labs to be done during one appointment.

Screen Shot 2020-07-24 at 10 08 06 AM

@jackcmeyer jackcmeyer unassigned fox1t and ghost Jul 26, 2020
@jackcmeyer jackcmeyer requested review from fox1t and a user July 26, 2020 03:11
@jackcmeyer
Copy link
Member

@yosephAHMED this is starting to look great!

  • I think you are definitely right with the one to many relationship.

Other:

  • Looks like some tests are still failing, let me know if you want/need help resolving them!

@yosephAHMED
Copy link
Contributor Author

@jackcmeyer @fox1t @kumikokashii

Help Requested

  • With the little experience I have with writing tests, I am unable to figure out how to implement the test cases required in NewLabRequest.test.tsx

  • PouchDB schema needs to be updated for a one to many relationship between an appointment and labs.

Furthermore, I am asking that someone else steps in and works on these final steps in my place
I would like to focus more on the infographic widgets issue that I was assigned to

@jackcmeyer
Copy link
Member

@yosephAHMED sounds good, we can take this PR from here!

@lgtm-com
Copy link

lgtm-com bot commented Aug 12, 2020

This pull request introduces 1 alert when merging 1c92ccd into c601262 - view on LGTM.com

new alerts:

  • 1 for Unused variable, import, function or class

@lgtm-com
Copy link

lgtm-com bot commented Sep 7, 2020

This pull request introduces 1 alert when merging 4efcfd1 into 08d7965 - view on LGTM.com

new alerts:

  • 1 for Invocation of non-function

@jackcmeyer jackcmeyer closed this Sep 8, 2020
Version 2.0 automation moved this from In progress to Done Sep 8, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
in progress indicates that issue/pull request is currently being worked on
Projects
Version 2.0
  
Done
Development

Successfully merging this pull request may close these issues.

Link visit to lab request
8 participants