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

(feat) Edit Patient #1806

Merged
merged 22 commits into from
Feb 8, 2020
Merged

(feat) Edit Patient #1806

merged 22 commits into from
Feb 8, 2020

Conversation

MatthewDorner
Copy link
Contributor

Fixes #1765

  • Implement Edit Patient functionality
  • Refactor New Patient and View Patient so that New, Edit and View Patient functions all use the same GeneralInformation form.
  • Changed behavior of isEditable prop in input components to make it false by default, as this seems to make more sense for boolean
  • Moved createPatient into patient slice instead of patients

Right now the tests should all pass but I still need to add the tests for Edit Patient and improve some other tests. I think I also need to add error handling back into the new form since I lost it when I deleted NewPatientForm.

@vercel
Copy link

vercel bot commented Feb 6, 2020

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

🔍 Inspect: https://zeit.co/hospitalrun/hospitalrun-frontend/an1yuurn8
✅ Preview: https://hospitalrun-frontend-git-fork-matthewdorner-edit-patient.hospitalrun.now.sh

)}
</form>
</Panel>
{isEditable ? (
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like some of the stylings may have accidentally changed here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Github thinks this file is NewPatientForm.tsx (which didn't have panels) renamed to GeneralInformation.tsx, when in fact I deleted NewPatientForm.tsx, so that's why it thinks I put panels in.

const dispatch = useDispatch()

const [patient, setPatient] = useState({} as Patient)
const { patient: reduxPatient } = useSelector((state: RootState) => state.patient)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that we could add isLoading to this restructured object so that we can use it for displaying the loading spinner.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

}

// see comment in ViewPatient
if (!reduxPatient) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could change this check to something like isLoading || !reduxPatient.id so that the loading spinner properly appears

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isLoading makes sense to me, but what does the check for !reduxPatient.id add? or should it be !id, like if there's no parameter? but that seems like it would be handled separately with an error or something

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so far I've just used isLoading which seems to work. Now, you actually see the loading icon when you change patients, etc.

@@ -34,6 +37,8 @@ const ViewPatient = () => {
}
}, [dispatch, id])

// this check doesn't work as an empty object isn't falsy. would it be more correct to display
// the spinner when the Redux patient state isLoading is true?
if (!patient) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that we can change this check to something like isLoading || !patient.id when we display the loading spinner.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in this one, test fails unless you use isLoading || !patient since it uses patient.id to render the tabs

@@ -130,6 +237,7 @@ describe('patients slice', () => {
})
})

// should check for the Toast
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does a test still need to be written to check for the Toast?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah. I added a toast for updating a Patient and made it redirect history to /patients/${newPatient.id}, since saving on Edit Patient ought to redirect to that. as a side effect of that, adding a new Related Person now moves you off the Related Persons tab and back onto the General Information tab, but I'm not sure if should do anything else about that now.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added this test

@@ -39,11 +39,11 @@ export default class Repository<T extends AbstractDBModel> {
}

async findAll(): Promise<T[]> {
const allPatients = await this.db.allDocs({
const allDocs = await this.db.allDocs({
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for renaming these :)

src/clients/db/Repository.ts Outdated Show resolved Hide resolved
@@ -3,12 +3,13 @@ import { useDispatch, useSelector } from 'react-redux'
import { useParams, withRouter, Route, useHistory, useLocation } from 'react-router-dom'
import { Panel, Spinner, TabsHeader, Tab } from '@hospitalrun/components'
import { useTranslation } from 'react-i18next'

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extra whitespace here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just thought it helped to separate the types of imports

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really like separating type of imports:external deps -> 1 empty line -> internal deps
:)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there's an eslint setting for this, that's why I instinctively did it.

const wrapper = setup()

const dateOfBirthInput = wrapper.findWhere((w) => w.prop('name') === 'address')
const dateOfBirthInput = wrapper.findWhere((w: any) => w.prop('name') === 'address')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this variable name should be addressTextField. This is probably my bad, copy paste :(

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

const wrapper = setup()

const dateOfBirthInput = wrapper.findWhere((w) => w.prop('name') === 'occupation')
const dateOfBirthInput = wrapper.findWhere((w: any) => w.prop('name') === 'occupation')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should probably be occupationInput

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

const wrapper = setup()

const dateOfBirthInput = wrapper.findWhere((w) => w.prop('name') === 'preferredLanguage')
const dateOfBirthInput = wrapper.findWhere((w: any) => w.prop('name') === 'preferredLanguage')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

preferredLanguageInput

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

const wrapper = setup()

const dateOfBirthInput = wrapper.findWhere((w) => w.prop('name') === 'phoneNumber')
const dateOfBirthInput = wrapper.findWhere((w: any) => w.prop('name') === 'phoneNumber')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

phoneNumberInput

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment on lines +46 to +54
<PrivateRoute
isAuthenticated={
permissions.includes(Permissions.WritePatients) &&
permissions.includes(Permissions.ReadPatients)
}
exact
path="/patients/edit/:id"
component={EditPatient}
/>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that we need some tests in HospitalRun.test.tsx surrounding this new route, especially for permissions.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added these

@jackcmeyer jackcmeyer added 🚀enhancement an issue/pull request that adds a feature to the application patients issue/pull request that interacts with patients module labels Feb 6, 2020
@jackcmeyer jackcmeyer added this to In progress in Version 2.0 via automation Feb 6, 2020
@jackcmeyer jackcmeyer added this to the v2.0.0 milestone Feb 6, 2020
Copy link
Member

@jackcmeyer jackcmeyer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

UI Styling comment:

Edit button should be in the top right corner, outlined success variant, and a pencil icon.

@MatthewDorner
Copy link
Contributor Author

  • Made the requested UI changes.
  • Brought some of the tests from NewPatientForm.test.tsx back into GeneralInformation.test.tsx though probably still need more.
  • Fixed other tests.
  • Fixed the logic to display spinner in EditPatient and ViewPatient
  • Added error handling and test for error handling back in.

Still need to add tests for the new route in HospitalRun component, and the actual tests for EditPatient.

Comment on lines -282 to -291
{isEditable && (
<div className="row float-right">
<div className="btn-group btn-group-lg">
<Button className="mr-2" color="success" onClick={onSaveButtonClick}>
{t('actions.save')}
</Button>
<Button color="danger" onClick={() => onCancel()}>
{t('actions.cancel')}
</Button>
</div>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we want to keep these buttons

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's where the buttons were in NewPatientForm, the entire file is deleted but Github thinks I renamed it to GeneralInformation and deleted GeneralInformation. The buttons are still there, they're just slightly further down. GeneralInformation has a different layout than NewPatientForm because it has the panels.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, I restored the previous style of buttons

@MatthewDorner
Copy link
Contributor Author

Added tests for EditPatient component and the patients/edit route, still having some test failures and not exactly sure why. Also couldn't figure out how to mock useParams (see the commented out test in EditPatient.test.tsx)

@vercel vercel bot temporarily deployed to Preview February 7, 2020 15:15 Inactive
fox1t
fox1t previously approved these changes Feb 7, 2020
@matteovivona
Copy link
Contributor

@MatthewDorner this afternoon we fixed an annoying bug with husky/lint. Could you Resolve conflicts and errors? thank you!

@matteovivona matteovivona self-assigned this Feb 7, 2020
@matteovivona matteovivona removed their request for review February 7, 2020 20:12
Comment on lines +249 to +253
onChange={
(event: React.ChangeEvent<HTMLTextAreaElement>) =>
onFieldChange && onFieldChange('address', event.currentTarget.value)
// eslint-disable-next-line react/jsx-curly-newline
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't get eslint to accept this any way I can think to format it, or via the eslint automatic fix. There must be two conflicting rules.

Instead of conditionally rendering buttons in GeneralInformation, render them in their parent
components (New/View/Edit Patient).
@MatthewDorner
Copy link
Contributor Author

  • Fixed merge conflicts
  • Moved buttons out of GeneralInformation form and into the parent forms (NewPatient, EditPatient, ViewPatient)
  • Fixed some tests

@MatthewDorner
Copy link
Contributor Author

Tests passing now. Looks like I should add some more tests, although I was thinking of going through the tests more thoroughly after this gets merged anyway.

@@ -3,12 +3,13 @@ import { useDispatch, useSelector } from 'react-redux'
import { useParams, withRouter, Route, useHistory, useLocation } from 'react-router-dom'
import { Panel, Spinner, TabsHeader, Tab } from '@hospitalrun/components'
import { useTranslation } from 'react-i18next'

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really like separating type of imports:external deps -> 1 empty line -> internal deps
:)

@fox1t
Copy link
Member

fox1t commented Feb 8, 2020

@MatthewDorner Great PR!

@fox1t
Copy link
Member

fox1t commented Feb 8, 2020

LGTM

@fox1t fox1t merged commit 3626609 into HospitalRun:master Feb 8, 2020
Version 2.0 automation moved this from In progress to Done Feb 8, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
🚀enhancement an issue/pull request that adds a feature to the application patients issue/pull request that interacts with patients module
Projects
Version 2.0
  
Done
Development

Successfully merging this pull request may close these issues.

Edit patient details
4 participants