Skip to content

Commit

Permalink
Add demo businessTime
Browse files Browse the repository at this point in the history
  • Loading branch information
projkov committed Oct 4, 2023
1 parent a8efe37 commit c97e305
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 5 deletions.
22 changes: 21 additions & 1 deletion resources/seeds/PractitionerRole/practitioner1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,28 @@ specialty:
display: Endocrinology
availableTime:
- daysOfWeek:
- mon
- sat
availableEndTime: '10:00:00'
availableStartTime: '08:00:00'
- daysOfWeek:
- fri
availableEndTime: '17:00:00'
availableStartTime: '14:00:00'
- daysOfWeek:
- thu
availableEndTime: '17:00:00'
availableStartTime: '14:00:00'
- daysOfWeek:
- wed
availableEndTime: '14:00:00'
availableStartTime: '08:00:00'
- daysOfWeek:
- tue
availableEndTime: '14:00:00'
availableStartTime: '08:00:00'
- daysOfWeek:
- mon
availableEndTime: '14:00:00'
availableStartTime: '08:00:00'
practitioner:
id: practitioner1
Expand Down
22 changes: 21 additions & 1 deletion resources/seeds/PractitionerRole/practitioner2.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,30 @@ specialty:
system: http://snomed.info/sct
display: Endocrinology
availableTime:
- daysOfWeek:
- sat
availableEndTime: '12:00:00'
availableStartTime: '08:00:00'
- daysOfWeek:
- fri
availableEndTime: '14:00:00'
availableStartTime: '08:00:00'
- daysOfWeek:
- thu
availableEndTime: '14:00:00'
availableStartTime: '08:00:00'
- daysOfWeek:
- wed
availableEndTime: '17:00:00'
availableStartTime: '14:00:00'
- daysOfWeek:
- mon
availableEndTime: '17:00:00'
availableStartTime: '14:00:00'
- daysOfWeek:
- tue
availableEndTime: '17:00:00'
availableStartTime: '08:00:00'
availableStartTime: '14:00:00'
practitioner:
id: practitioner2
resourceType: Practitioner
Expand Down
6 changes: 4 additions & 2 deletions src/containers/OrganizationScheduling/hooks.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Appointment, HealthcareService, Patient, Practitioner, PractitionerRole } from 'fhir/r4b';
import _ from 'lodash';
import React from 'react';

import { useService } from 'fhir-react/lib/hooks/service';
Expand Down Expand Up @@ -61,15 +62,16 @@ export function useOrganizationSchedulingSlots({
return mapSuccess(response, (bundle) => {
const resMap = extractBundleResources(bundle);
const practitionerRoles = resMap.PractitionerRole;
const practitionerRolesWithAvailableTime = practitionerRoles.filter((pr) => !!pr.availableTime);

return practitionerRoles.map((practitionerRole) => {
return practitionerRolesWithAvailableTime.map((practitionerRole) => {
const availableTime = practitionerRole.availableTime?.map((item) => ({
daysOfWeek: item.daysOfWeek?.map((dow) => days.indexOf(dow) + 1),
startTime: item.availableStartTime,
endTime: item.availableEndTime,
}));

return availableTime;
return availableTime?.filter((aTime) => !_.isUndefined(aTime.daysOfWeek));
});
});
}, [practitionerRoleId, healthcareServiceId]);
Expand Down
13 changes: 12 additions & 1 deletion src/containers/OrganizationScheduling/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,17 @@ export function OrganizationScheduling() {
): boolean => !!appointmentData && !!selectedPractitionerRole && !!selectedHealthcareService;
const isSelectable = (selectedPractitionerRole: SelectOption, selectedHealthcareService: SelectOption): boolean =>
!!selectedPractitionerRole && !!selectedHealthcareService;
// NOTE: In case we don't have business hours (didn't set up for practitioner
// empty filters results, etc.) We should show the visual sign to the receptionist
// that there is no available time. By default, the calendar can get false as businessHours property.
// But in this case, it looks like all day is available.
const emptyBusinessHours = [
{
daysOfWeek: [1, 2, 3, 4, 5, 6, 7],
startTime: '08:00',
endTime: '08:00',
},
];

return (
<>
Expand Down Expand Up @@ -95,7 +106,7 @@ export function OrganizationScheduling() {
center: 'title',
right: 'timeGridWeek,timeGridDay',
}}
businessHours={businessHours.flat()}
businessHours={businessHours.length ? businessHours.flat() : emptyBusinessHours}
initialView="timeGridWeek"
editable={true}
selectable={isSelectable(selectedHealthcareService, selectedPractitionerRole)}
Expand Down

0 comments on commit c97e305

Please sign in to comment.