From c97e305c705eeef668a1eb81849488539efd797f Mon Sep 17 00:00:00 2001 From: Pavel R Date: Wed, 4 Oct 2023 15:21:43 +0200 Subject: [PATCH] Add demo businessTime --- .../seeds/PractitionerRole/practitioner1.yaml | 22 ++++++++++++++++++- .../seeds/PractitionerRole/practitioner2.yaml | 22 ++++++++++++++++++- .../OrganizationScheduling/hooks.ts | 6 +++-- .../OrganizationScheduling/index.tsx | 13 ++++++++++- 4 files changed, 58 insertions(+), 5 deletions(-) diff --git a/resources/seeds/PractitionerRole/practitioner1.yaml b/resources/seeds/PractitionerRole/practitioner1.yaml index 2907aae6..d7a55116 100644 --- a/resources/seeds/PractitionerRole/practitioner1.yaml +++ b/resources/seeds/PractitionerRole/practitioner1.yaml @@ -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 diff --git a/resources/seeds/PractitionerRole/practitioner2.yaml b/resources/seeds/PractitionerRole/practitioner2.yaml index 322e7cc8..5bda7fa6 100644 --- a/resources/seeds/PractitionerRole/practitioner2.yaml +++ b/resources/seeds/PractitionerRole/practitioner2.yaml @@ -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 diff --git a/src/containers/OrganizationScheduling/hooks.ts b/src/containers/OrganizationScheduling/hooks.ts index 0ce31e1a..42842606 100644 --- a/src/containers/OrganizationScheduling/hooks.ts +++ b/src/containers/OrganizationScheduling/hooks.ts @@ -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'; @@ -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]); diff --git a/src/containers/OrganizationScheduling/index.tsx b/src/containers/OrganizationScheduling/index.tsx index b87ef553..aadd3187 100644 --- a/src/containers/OrganizationScheduling/index.tsx +++ b/src/containers/OrganizationScheduling/index.tsx @@ -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 ( <> @@ -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)}