Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changed to current date time instead of date time at which app was loaded. #6791

Merged
7 changes: 7 additions & 0 deletions src/Components/Facility/ConsultationForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,13 @@ export const ConsultationForm = (props: any) => {
fetchPatientName();
}, [dispatchAction, patientId]);

useEffect(() => {
dispatch({
type: "set_form",
form: { ...state.form, admission_date: new Date() },
});
}, []);

Copy link
Member

Choose a reason for hiding this comment

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

this would be quite similar, this date would be generated when the component is initialized, i.e., if a user opens the form and moves away for some reason, this wouldn't be accurate if time is tracked.

Copy link
Member

Choose a reason for hiding this comment

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

You could do this while submitting, something like

onSubmit(() => {
  apiCall({...state, admission_date: (() => new Date())()})
})

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@khavinshankar but the user should be able to see the current date and time in the field of date of admission rather than the date at which the app was loaded. The user can also edit the date so if we take the new Date() when onSubmit then there will be no use of the custom date field which is displayed to the user.

Copy link
Member

@rithviknishad rithviknishad Dec 9, 2023

Choose a reason for hiding this comment

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

He meant more like:

admission_date: state.form.admission_date ?? new Date() // API call

And in the date time input field, you can have something like this to always show current time while the form state's admission_date being null. It would be non-null only when onChange is triggered.

value={state.form.admission_date ?? new Date()}

Copy link
Member

Choose a reason for hiding this comment

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

@khavinshankar but I don't think that's a good way. It could mess up with the draft forms right?

Say the user wanted to create an admission consultation at 11 AM. But had to put the app in background for some reason, bought the app back, form drafts restored the form, but the form drafts would have saved admission_date as null. This would cause the admission date to be time at which the submit button was clicked although user may not have intended that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@rithviknishad @khavinshankar can you suggest me the final changes?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@khavinshankar @Ashesh3 final changes ?

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 it should be left to be done on component mount, so that drafts play nice with it. In any case, the user should correctly set and verify the admission date before submission. I do see the issue of the "time" part not being pin point accurate in this solution, but it's manually configurable and they do see it while filling out the form. (correct me here if admission_date is a hidden field)

cc: @rithviknishad @khavinshankar

const hasSymptoms =
!!state.form.symptoms.length && !state.form.symptoms.includes(1);
const isOtherSymptomsSelected = state.form.symptoms.includes(9);
Expand Down
Loading