Package: edc-facility
edc-facilityLoading holidaysTo load the list of holidays into the system:pythonmanage.pyimport_holidaysCustomizing appointment scheduling byFacilityAppointment scheduling can be customized perfacilityor clinic:Add each facility toapp_config.facilitiesspecifying the facilityname,daysopen and the maximum number ofslotsavailable per day:fromedc_facility.appsimportAppConfigasEdcAppointmentAppConfigclassAppConfig(EdcAppointmentAppConfig):facilities={'clinic1':Facility(name='clinic',days=[MO,TU,WE,TH,FR],slots=[100,100,100,100,100])}'clinic2':Facility(name='clinic',days=[MO,WE,FR],slots=[30,30,30])}To schedule an appointment that falls on a day that the clinic is open, isn’t a holiday and isn’t already over-booked:fromedc_utilsimportget_utcnowfrom.facilityimportFacilitysuggested_datetime=get_utcnow()available_datetime=facility.available_datetime(suggested_datetime)If holidays are entered (in modelHoliday) and the appointment lands on a holiday, the appointment date is incremented forward to an allowed weekday. Assumingfacilityis configured inapp_configto only schedule appointments on [TU, TH]:fromdatetimeimportdatetimefromdateutil.relativedeltaimportTU,THfromdjango.confimportsettingsfromdjango.utilsimporttimezonefromzoneifoimportZoneInfofrom.facilityimportFacilityfrom.modelsimportHolidayHoliday.objects.create(name='Id-ul-Adha (Feast of the Sacrifice)',date=date(2015,9,24))suggested_datetime=datetime(2015,9,24,tzinfo=ZoneInfo("UTC"))# THavailable_datetime=facility.available_datetime(suggested_datetime)print(available_datetime)# 2015-09-29 00:00:00, TUThe maximum number of possible scheduling slots per day is configured inapp_config. As with the holiday example above, the appointment date will be incremented forward to a day with an available slot.System checksedc_facility.001Holiday file not set! settings.HOLIDAY_FILE not defined.edc_facility.002Holiday file not found.edc_facility.003Holiday table is empty. Run management command ‘import_holidays’.edc_facility.004No Holidays have been defined for this country.HealthFacility modelTheHealthFacilitymodel is used byedc-next-appointmentwhen reporting the next routine
appointment for a participant. This is important for trials that collect data at routine clinic appointments
not set by the research staff or defined by the protocol.See alsoedc-next-appointment.If you need to customize the model, declare the concrete model locally in your app. You can use the mixins to build
your own classes.You’ll also need to updatesettingsto telledc_facilitywhere the custom model is:EDC_FACILITY_HEALTH_FACILITY_MODEL = "myapp.healthfacility"For example:# models.pyclassHealthFacility(SiteModelMixin,HealthFacilityModelMixin,BaseUuidModel):objects=Manager()on_site=CurrentSiteManager()history=HistoricalRecords()classMeta(SiteModelMixin.Meta,BaseUuidModel.Meta):verbose_name="Health Facility"verbose_name_plural="Health Facilities"# forms.pyclassHealthFacilityForm(FormValidatorMixin,forms.ModelForm):form_validator_cls=HealthFacilityFormValidatorclassMeta:model=HealthFacilityfields="__all__"# admin.py@admin.register(HealthFacility,site=intecomm_facility_admin)classHealthFacilityAdmin(HealthFacilityModelAdminMixin,SiteModelAdminMixin,BaseModelAdminMixin,):form=HealthFacilityForm