Skip to main content

Lock a timepoint from further editing once data is cleaned and reviewed in clinicedc/edc projects

Project description

pypi actions codecov downloads

edc-timepoint

Lock a “timepoint” from further editing once data is cleaned and reviewed.

With module edc_timepoint a data manager or supervisor is able to flag a model instance, that represents a timepoint, as closed to further edit. A good candidate for a “timepoint” model is one that is used to cover other data collection, such as an edc_appointment.Appointment. When the appointment status is set to something like ‘complete’ the timepoint status is set to closed and no further edits are allowed for data covered by that appointment.

Configuring the Timepoint Model

Select a model that represent a timepoint. The model should at least have a datetime field and a status field. For example Appointment:

class Appointment(TimepointModelMixin, BaseUuidModel):

    appt_datetime = models.DateTimeField(
        verbose_name='Appointment date and time')

    appt_status = models.CharField(
        verbose_name='Status',
        choices=APPT_STATUS,
        max_length=25,
        default='NEW')

The TimepointModelMixin adds fields and methods prefixed as timepoint_<something>. There is also a signal that is loaded in the AppConfig.ready that resets the timepoint attributes should Appointment.appt_status change from DONE.

Only field timepoint_status is meant to be edited by the user. The other timepoint_<something> are managed automatically.

In your projects apps.py subclass edc_timepoint.apps.AppConfig and declare Appointment as a timepoint model by creating a Timepoint instance and appending it to AppConfig.timepoints:

from django.apps import AppConfig as DjangoAppConfig

from edc_timepoint.apps import AppConfig as EdcTimepointAppConfigParent
from edc_timepoint.timepoint import Timepoint


class AppConfig(DjangoAppConfig):
    name = 'example'

class EdcTimepointAppConfig(EdcTimepointAppConfigParent):
    timepoints = TimepointCollection(
        timepoints=[Timepoint(
            model='example.appointment',
            datetime_field='appt_datetime',
            status_field='appt_status',
            closed_status='DONE')])

The user updates the Appointment normally closing it when the appointment is done. Then a data manager or supervisor can close the Appointment to further edit once the data has been reviewed.

To close the Appointment to further edit the code needs to call the timepoint_close_timepoint method:

appointment = Appointment.objects.create(**options)
appointment.appt_status = 'DONE'
appointment.timepoint_close_timepoint()

If the appointment.appt_status is not DONE when timepoint_close_timepoint is called, a TimepointError is raised.

If the appointment is successfully closed to further edit, any attempts to call appointment.save() will raise a TimepointError.

The Appointment may be re-opened for edit by calling method timepoint_open_timepoint.

Configuring others to use the Timepoint Model

Continuing with the example above where Appointment is the timepoint model.

To prevent further edits to models related to Appointment, configure the model with the TimepointLookupModelMixin and the TimepointLookup class. These models will refer to the timepoint model on save.

For example:

class VisitTimepointLookup(TimepointLookup):
    timepoint_related_model_lookup = 'appointment'

class VisitModel(TimepointLookupModelMixin, BaseUuidModel):

    timepoint_lookup_cls = VisitTimepointLookup

    appointment = models.ForeignKey(Appointment)

    report_datetime = models.DateTimeField(
        default=timezone.now)

If the timepoint model’s timepoint_status is closed, any attempt to create or modify VisitModel will raise a TimepointClosed exception.

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-timepoint-0.3.18.tar.gz (33.5 kB view details)

Uploaded Source

Built Distribution

edc_timepoint-0.3.18-py3-none-any.whl (32.6 kB view details)

Uploaded Python 3

File details

Details for the file edc-timepoint-0.3.18.tar.gz.

File metadata

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

File hashes

Hashes for edc-timepoint-0.3.18.tar.gz
Algorithm Hash digest
SHA256 87298d62310465ab8befe9d6d14e8f92838b3047ce61e8bd03600f2574459a04
MD5 08f432cd0d7eede468ed8adf0e42dc7b
BLAKE2b-256 43a67311ed6d31b3d86d553f70cdbcfc30ba69f3e131a5fb6303f6d6e6e9dacb

See more details on using hashes here.

File details

Details for the file edc_timepoint-0.3.18-py3-none-any.whl.

File metadata

File hashes

Hashes for edc_timepoint-0.3.18-py3-none-any.whl
Algorithm Hash digest
SHA256 84833c9e47d6a09daa148f75b5eef26aff0572468afe469fa22ac211887b4b12
MD5 2788f3ed21c7cee3711b7b1036ca82ed
BLAKE2b-256 54ba6598def18b551f0706f2c4fea9326eabe00f7144138ab6bda921f74fe15e

See more details on using hashes here.

Supported by

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