-
Notifications
You must be signed in to change notification settings - Fork 203
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
(feat) O3-2180 & O3-2300: Allow creating past visits and set visit stop date and time in the form #1704
Open
vasharma05
wants to merge
19
commits into
main
Choose a base branch
from
O3-2180
base: main
Could not load branches
Branch not found: {{ refName }}
Could not load tags
Nothing to show
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
(feat) O3-2180 & O3-2300: Allow creating past visits and set visit stop date and time in the form #1704
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
af55d0b
Avoid passing minDate and maxDate in the visit start and end date giv…
vasharma05 2fc0c0d
Merge branch 'main' of https://www.github.com/openmrs/openmrs-esm-pat…
vasharma05 a364a0a
Added zod validations for visit start and stop date
vasharma05 c3bd130
Updated translations
vasharma05 7957752
Updated headers
vasharma05 9074f82
Cleanup
vasharma05 63f1d22
Merge branch 'main' of https://www.github.com/openmrs/openmrs-esm-pat…
vasharma05 7efdeed
Merge branch 'main' into fix/O3-2720
denniskigen d411683
Merge branch 'main' of https://www.github.com/openmrs/openmrs-esm-pat…
vasharma05 d80adb9
Allow user creating past visit
vasharma05 c1769f2
Updated translations
vasharma05 f979935
Updated tests
vasharma05 861d4da
Updated default values for visit stop date time
vasharma05 afb2d59
Merge branch 'fix/O3-2720' of https://www.github.com/openmrs/openmrs-…
vasharma05 1ae0391
Merge branch 'fix/O3-2720' into O3-2180
vasharma05 f51677c
Merge branch 'main' of https://www.github.com/openmrs/openmrs-esm-pat…
vasharma05 c76f460
Merge branch 'main' of https://www.github.com/openmrs/openmrs-esm-pat…
vasharma05 6753495
Merge branch 'main' of https://www.github.com/openmrs/openmrs-esm-pat…
vasharma05 d2338d0
Updated translations
vasharma05 File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -2,13 +2,13 @@ import React from 'react'; | |||||
import AddPastVisitOverflowMenuItem from './add-past-visit.component'; | ||||||
import { screen, render } from '@testing-library/react'; | ||||||
import userEvent from '@testing-library/user-event'; | ||||||
import { showModal } from '@openmrs/esm-framework'; | ||||||
import { launchPatientWorkspace } from '@openmrs/esm-patient-common-lib'; | ||||||
|
||||||
const mockShowModal = showModal as jest.Mock; | ||||||
const mockLaunchPatientWorkspace = launchPatientWorkspace as jest.Mock; | ||||||
|
||||||
jest.mock('@openmrs/esm-framework', () => { | ||||||
const originalModule = jest.requireActual('@openmrs/esm-framework'); | ||||||
return { originalModule, showModal: jest.fn() }; | ||||||
jest.mock('@openmrs/esm-patient-common-lib', () => { | ||||||
const originalModule = jest.requireActual('@openmrs/esm-patient-common-lib'); | ||||||
return { originalModule, launchPatientWorkspace: jest.fn() }; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
}); | ||||||
|
||||||
describe('AddPastVisitOverflowMenuItem', () => { | ||||||
|
@@ -23,6 +23,9 @@ describe('AddPastVisitOverflowMenuItem', () => { | |||||
// should launch the form | ||||||
await user.click(addPastVisitButton); | ||||||
|
||||||
expect(mockShowModal).toHaveBeenCalled(); | ||||||
expect(mockLaunchPatientWorkspace).toHaveBeenCalledWith('start-visit-workspace-form', { | ||||||
isCreatingVisit: true, | ||||||
workspaceTitle: 'Add past visit', | ||||||
}); | ||||||
}); | ||||||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,41 +2,38 @@ import React from 'react'; | |
import styles from './visit-form.scss'; | ||
import { Controller, useFormContext } from 'react-hook-form'; | ||
import { type VisitFormData } from './visit-form.resource'; | ||
import { DatePicker, DatePickerInput, SelectItem, TimePicker, TimePickerSelect } from '@carbon/react'; | ||
import { | ||
DatePicker, | ||
DatePickerInput, | ||
SelectItem, | ||
TimePicker, | ||
TimePickerSelect, | ||
InlineNotification, | ||
} from '@carbon/react'; | ||
import classNames from 'classnames'; | ||
import { useLayoutType, ResponsiveWrapper } from '@openmrs/esm-framework'; | ||
import { useTranslation } from 'react-i18next'; | ||
import { type amPm } from '@openmrs/esm-patient-common-lib'; | ||
|
||
interface VisitDateTimeFieldProps { | ||
visitDatetimeLabel: string; | ||
dateFieldName: 'visitStartDate' | 'visitStopDate'; | ||
timeFieldName: 'visitStartTime' | 'visitStopTime'; | ||
timeFormatFieldName: 'visitStartTimeFormat' | 'visitStopTimeFormat'; | ||
minDate?: number; | ||
maxDate?: number; | ||
datetimeFieldName: 'visitStartDatetime' | 'visitStopDatetime'; | ||
} | ||
|
||
const VisitDateTimeField: React.FC<VisitDateTimeFieldProps> = ({ | ||
visitDatetimeLabel, | ||
dateFieldName, | ||
timeFieldName, | ||
timeFormatFieldName, | ||
minDate, | ||
maxDate, | ||
}) => { | ||
const VisitDateTimeField: React.FC<VisitDateTimeFieldProps> = ({ visitDatetimeLabel, datetimeFieldName }) => { | ||
const { t } = useTranslation(); | ||
const isTablet = useLayoutType() === 'tablet'; | ||
const { | ||
control, | ||
formState: { errors }, | ||
setError, | ||
} = useFormContext<VisitFormData>(); | ||
|
||
// Since we have the separate date and time fields, the final validation needs to be done at the form | ||
// submission, hence just using the min date with hours/ minutes/ seconds set to 0 and max date set to | ||
// last second of the day. We want to just compare dates and not time. | ||
minDate = minDate ? new Date(minDate).setHours(0, 0, 0, 0) : null; | ||
maxDate = maxDate ? new Date(maxDate).setHours(23, 59, 59, 59) : null; | ||
const dateFieldName: 'visitStartDatetime.date' | 'visitStopDatetime.date' = `${datetimeFieldName}.date`; | ||
const timeFieldName: 'visitStartDatetime.time' | 'visitStopDatetime.time' = `${datetimeFieldName}.time`; | ||
const timeFormatFieldName: | ||
| 'visitStartDatetime.timeFormat' | ||
| 'visitStopDatetime.timeFormat' = `${datetimeFieldName}.timeFormat`; | ||
|
||
return ( | ||
<section> | ||
|
@@ -45,25 +42,23 @@ const VisitDateTimeField: React.FC<VisitDateTimeFieldProps> = ({ | |
<Controller | ||
name={dateFieldName} | ||
control={control} | ||
render={({ field: { onBlur, onChange, value } }) => ( | ||
render={({ field: dateField }) => ( | ||
<ResponsiveWrapper> | ||
<DatePicker | ||
{...dateField} | ||
dateFormat="d/m/Y" | ||
datePickerType="single" | ||
id={dateFieldName} | ||
style={{ paddingBottom: '1rem' }} | ||
minDate={minDate} | ||
maxDate={maxDate} | ||
onChange={([date]) => onChange(date)} | ||
value={value} | ||
onChange={([date]) => dateField.onChange(date)} | ||
invalid={errors?.[datetimeFieldName]?.date?.message} | ||
invalidText={errors?.[datetimeFieldName]?.date?.message} | ||
> | ||
<DatePickerInput | ||
id={`${dateFieldName}Input`} | ||
labelText={t('date', 'Date')} | ||
placeholder="dd/mm/yyyy" | ||
style={{ width: '100%' }} | ||
invalid={errors[dateFieldName]?.message} | ||
invalidText={errors[dateFieldName]?.message} | ||
/> | ||
</DatePicker> | ||
</ResponsiveWrapper> | ||
|
@@ -73,32 +68,31 @@ const VisitDateTimeField: React.FC<VisitDateTimeFieldProps> = ({ | |
<Controller | ||
name={timeFieldName} | ||
control={control} | ||
render={({ field: { onBlur, onChange, value } }) => ( | ||
render={({ field: timeField }) => ( | ||
<TimePicker | ||
{...timeField} | ||
id={timeFieldName} | ||
labelText={t('time', 'Time')} | ||
onChange={(event) => onChange(event.target.value as amPm)} | ||
onChange={(event) => timeField.onChange(event.target.value as amPm)} | ||
pattern="^(1[0-2]|0?[1-9]):([0-5]?[0-9])$" | ||
style={{ marginLeft: '0.125rem', flex: 'none' }} | ||
value={value} | ||
onBlur={onBlur} | ||
invalid={errors[timeFieldName]?.message} | ||
invalidText={errors[timeFieldName]?.message} | ||
invalid={errors?.[datetimeFieldName]?.time?.message} | ||
invalidText={errors?.[datetimeFieldName]?.time?.message} | ||
> | ||
<Controller | ||
name={timeFormatFieldName} | ||
control={control} | ||
render={({ field: { onChange, value } }) => ( | ||
render={({ field: timeFormatField }) => ( | ||
<TimePickerSelect | ||
{...timeFormatField} | ||
id={`${timeFormatFieldName}Input`} | ||
onChange={(event) => onChange(event.target.value as amPm)} | ||
value={value} | ||
onChange={(event) => timeFormatField.onChange(event.target.value as amPm)} | ||
aria-label={t('timeFormat ', 'Time Format')} | ||
invalid={errors[timeFormatFieldName]?.message} | ||
invalidText={errors[timeFormatFieldName]?.message} | ||
invalid={errors?.[datetimeFieldName]?.timeFormat?.message} | ||
invalidText={errors?.[datetimeFieldName]?.timeFormat?.message} | ||
> | ||
<SelectItem value="AM" text="AM" /> | ||
<SelectItem value="PM" text="PM" /> | ||
<SelectItem value="AM" text={t('AM', 'AM')} /> | ||
<SelectItem value="PM" text={t('PM', 'PM')} /> | ||
</TimePickerSelect> | ||
)} | ||
/> | ||
|
@@ -107,6 +101,17 @@ const VisitDateTimeField: React.FC<VisitDateTimeFieldProps> = ({ | |
/> | ||
</ResponsiveWrapper> | ||
</div> | ||
{errors?.[datetimeFieldName]?.root && ( | ||
<InlineNotification | ||
aria-label="Close notification" | ||
kind="error" | ||
onClose={() => setError(datetimeFieldName, null)} | ||
statusIconDescription="notification" | ||
subtitle={errors?.[datetimeFieldName]?.root?.message} | ||
title={t('datetimeOutOfRange', 'Selected time is out of range')} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would seem useful here to tell the user what the time range is? |
||
lowContrast | ||
/> | ||
)} | ||
</section> | ||
); | ||
}; | ||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This dependency array no longer seems accurate.