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

feat(patients): add no patients exist #2235

Merged
merged 8 commits into from
Aug 5, 2020
Merged

feat(patients): add no patients exist #2235

merged 8 commits into from
Aug 5, 2020

Conversation

Fibii
Copy link
Contributor

@Fibii Fibii commented Jul 13, 2020

Fixes #2231

Changes proposed in this pull request:

@jsf-clabot
Copy link

jsf-clabot commented Jul 13, 2020

CLA assistant check
All committers have signed the CLA.

@gitpod-io
Copy link

gitpod-io bot commented Jul 13, 2020

add missing useEffect dependency in ViewPatients.tsx
@vercel
Copy link

vercel bot commented Jul 13, 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/rdymsc2nf
✅ Preview: https://hospitalrun-fr-git-fork-fibii-featpatients-implement-nop-eaebe0.hospitalrun.vercel.app

@matteovivona matteovivona added the in progress indicates that issue/pull request is currently being worked on label Jul 14, 2020
@matteovivona matteovivona added this to In progress in Version 2.0 via automation Jul 14, 2020
@matteovivona matteovivona added this to the v2.0 milestone Jul 14, 2020
@Fibii
Copy link
Contributor Author

Fibii commented Jul 14, 2020

so for some reason i added a patient to the vercel build to check if the "add new patient" shows up when patients exist (even tho the tests passed) and i couldn't find a way to remove the patient, which means my commit won't be displayed (because there's a patient) so whomever reviews the code in vercel have to remove that test patient.

<div style={{ display: 'flex', justifyContent: 'center' }}>
<div style={{ display: 'flex', flexDirection: 'column' }}>
<div style={{ display: 'flex', justifyContent: 'center' }}>
<Icon icon="patient" outline={false} size="6x" />
Copy link
Member

Choose a reason for hiding this comment

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

lets use the patients icon rather than patient.

Comment on lines 120 to 121
outlined
color="success"
Copy link
Member

Choose a reason for hiding this comment

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

rather than using a success and outlined button, I think a primary button makes more sense here since it is the call to action on the page.

</Button>,
])

if (patients && patients.length > 0) {
Copy link
Member

Choose a reason for hiding this comment

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

this patients variable represents the current patients in state.

This could be the default page of patients or a search result. When searching for patients and my search results return 0, I would not expect the new icon to appear.

I think that we should implement a new function called count in Repository that returns the number of documents that are available for a type.

Then here, we use that count function to determine if the new icon should display or not.

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 get it, what i don't get is why do we need to implement count?

it seems like PatientRepository.findAll() returns all the existing patients in the db, we can use it as:

  1. implement a state called count
  2. at initial load, setCount(PatientRepository.findAll().length)
  3. if (count == 0) show addNewPations component, else show the table

but it seems that implementing a count in Repository seems like a better solution here, since it makes Repository more flexible for future issues/enhancements

Comment on lines 106 to 129
return (
<div style={{ display: 'flex', justifyContent: 'center' }}>
<div style={{ display: 'flex', flexDirection: 'column' }}>
<div style={{ display: 'flex', justifyContent: 'center' }}>
<Icon icon="patient" outline={false} size="6x" />
</div>
<div style={{ display: 'flex', justifyContent: 'center' }}>
<div style={{ textAlign: 'center', width: '60%', margin: 16 }}>
<Typography variant="h5">{t('patients.noPatients')}</Typography>
</div>
</div>
<div style={{ display: 'flex', justifyContent: 'center' }}>
<Button
key="newPatientButton"
outlined
color="success"
icon="patient-add"
onClick={() => history.push('/patients/new')}
>
{t('patients.newPatient')}
</Button>
</div>
</div>
</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 that we should move this to its own component to:

  • keep components smaller and easier to understand
  • make it easier to test

@jackcmeyer
Copy link
Member

@Fibii please let me know if you have any questions or need help addressing the code review feedback.

@Fibii
Copy link
Contributor Author

Fibii commented Jul 22, 2020

@jackcmeyer how would i add count to patient-slice, should i even do that ?

i already added count to Repository as

async count(): Promise<number> {
    const result = await this.findAll()
    return result.length
  }

what i want to do now is use it in ViewPatients.tsx as

  const { patients, isLoading, count } = useSelector((state: RootState) => state.patients)

but i couldn't figure it out. I updated the interface in patients-slice.ts to be

interface PatientsState {
  isLoading: boolean
  patients: Patient[]
  count: number
}

and called Repository#count in fetchPatients

export const fetchPatients = (sortRequest: SortRequest = Unsorted): AppThunk => async (
  dispatch,
) => {
  dispatch(fetchPatientsStart())
  const patients = await PatientRepository.findAll(sortRequest)
  const count = await PatientRepository.count()
  // dispatch(fetchPatientsSuccess(... ? ))
}

but i couldn't figure what to dispatch there. I need a little bit of help here.

@matteovivona
Copy link
Contributor

@fox1t some advice?

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.

Few more code related comments.

One other thing:
The AddNewPatient component should not display because a search result has no results.

It should show up when there are no patients in the database.

Comment on lines 85 to 107
it('should render no patients exists when no patients exist', () => {
const wrapper = setup(false, [], 0)

const addNewPatient = wrapper.find(AddNewPatient)
expect(addNewPatient).toHaveLength(1)

const icon = wrapper.find(Icon).first()
const typography = wrapper.find(Typography)
const button = wrapper.find(Button)
const iconType = icon.prop('icon')
const iconSize = icon.prop('size')
const typographyText = typography.prop('children')
const typographyVariant = typography.prop('variant')
const buttonIcon = button.prop('icon')
const buttonText = button.prop('children')

expect(iconType).toEqual('patients')
expect(iconSize).toEqual('6x')
expect(typographyText).toEqual('patients.noPatients')
expect(typographyVariant).toEqual('h5')
expect(buttonIcon).toEqual('patient-add')
expect(buttonText).toEqual('patients.newPatient')
})
Copy link
Member

Choose a reason for hiding this comment

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

This test is testing behavior inside the AddNewPatient component. I think instead, this test should test that the AddNewPatient component gets rendered and then this current test should be moved to an AddNewPatient test.


import useTranslator from '../../shared/hooks/useTranslator'

const AddNewPatient = () => {
Copy link
Member

Choose a reason for hiding this comment

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

Thoughts on NoPatientsExist for this component name? AddNewPatient could potentially be confusing with NewPatient component.

@matteovivona matteovivona added the 🚀enhancement an issue/pull request that adds a feature to the application label Jul 30, 2020
@Fibii Fibii requested a review from jackcmeyer July 31, 2020 11:43
@jackcmeyer jackcmeyer merged commit 886163a into HospitalRun:master Aug 5, 2020
Version 2.0 automation moved this from In progress to Done Aug 5, 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 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.

Implement "no patients" state on the /patients route
4 participants