Skip to main content

Define clinic facilities for clinicedc/edc projects

Project description

pypi actions codecov downloads

edc-facility

Loading holidays

To load the list of holidays into the system:

python manage.py import_holidays

Customizing appointment scheduling by Facility

Appointment scheduling can be customized per facility or clinic:

Add each facility to app_config.facilities specifying the facility name, days open and the maximum number of slots available per day:

from edc_facility.apps import AppConfig as EdcAppointmentAppConfig

class AppConfig(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:

from edc_utils import get_utcnow
from .facility import Facility

suggested_datetime = get_utcnow()
available_datetime = facility.available_datetime(suggested_datetime)

If holidays are entered (in model Holiday) and the appointment lands on a holiday, the appointment date is incremented forward to an allowed weekday. Assuming facility is configured in app_config to only schedule appointments on [TU, TH]:

from datetime import datetime
from dateutil.relativedelta import TU, TH
from django.conf import settings
from django.utils import timezone
from zoneifo import ZoneInfo

from .facility import Facility
from .models import Holiday

Holiday.objects.create(
    name='Id-ul-Adha (Feast of the Sacrifice)',
    date=date(2015, 9, 24)
)
suggested_datetime = datetime(2015, 9, 24, tzinfo=ZoneInfo("UTC"))  # TH
available_datetime = facility.available_datetime(suggested_datetime)
print(available_datetime)  # 2015-09-29 00:00:00, TU

The maximum number of possible scheduling slots per day is configured in app_config. As with the holiday example above, the appointment date will be incremented forward to a day with an available slot.

System checks

  • edc_facility.001 Holiday file not set! settings.HOLIDAY_FILE not defined.

  • edc_facility.002 Holiday file not found.

  • edc_facility.003 Holiday table is empty. Run management command ‘import_holidays’.

  • edc_facility.004 No Holidays have been defined for this country.

HealthFacility model

The HealthFacility model is used by edc-next-appointment when 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 also edc-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 update settings to tell edc_facility where the custom model is:

EDC_FACILITY_HEALTH_FACILITY_MODEL = "myapp.healthfacility"

For example:

# models.py
class HealthFacility(SiteModelMixin, HealthFacilityModelMixin, BaseUuidModel):

    objects = Manager()
    on_site = CurrentSiteManager()
    history = HistoricalRecords()

    class Meta(SiteModelMixin.Meta, BaseUuidModel.Meta):
        verbose_name = "Health Facility"
        verbose_name_plural = "Health Facilities"
# forms.py
class HealthFacilityForm(FormValidatorMixin, forms.ModelForm):
    form_validator_cls = HealthFacilityFormValidator

    class Meta:
        model = HealthFacility
        fields = "__all__"
# admin.py
@admin.register(HealthFacility, site=intecomm_facility_admin)
class HealthFacilityAdmin(
    HealthFacilityModelAdminMixin,
    SiteModelAdminMixin,
    BaseModelAdminMixin,
):
    form = HealthFacilityForm

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

edc-facility-0.3.28.tar.gz (45.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

edc_facility-0.3.28-py3-none-any.whl (54.8 kB view details)

Uploaded Python 3

File details

Details for the file edc-facility-0.3.28.tar.gz.

File metadata

  • Download URL: edc-facility-0.3.28.tar.gz
  • Upload date:
  • Size: 45.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.4

File hashes

Hashes for edc-facility-0.3.28.tar.gz
Algorithm Hash digest
SHA256 530ca8dc6aeb811b6f788329d10d6fda15134966ccd79435c216967685aff9c7
MD5 968f5ebbc62975825a553515ec3306cd
BLAKE2b-256 a8ef238a3cca7feaa5333b78dc52bee5e0f404b7a5ac0adb98aff7e5b90e8519

See more details on using hashes here.

File details

Details for the file edc_facility-0.3.28-py3-none-any.whl.

File metadata

  • Download URL: edc_facility-0.3.28-py3-none-any.whl
  • Upload date:
  • Size: 54.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.4

File hashes

Hashes for edc_facility-0.3.28-py3-none-any.whl
Algorithm Hash digest
SHA256 95e2bbbd3c0871457775d30ceec6e6a1b9804436303a087e81978830dcdbd43e
MD5 a4a971b4058b671a3f3f98576b2dba02
BLAKE2b-256 fa45e1c889dd137f297545c69bf354c776b9ccc08732370f18cb4961e50b7140

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page