Skip to main content

Pivoted reference model for clinicedc/edc modules

Project description

pypi actions coverage

edc-reference

Pivoted reference table for EDC modules

edc_reference creates a pivoted table of CRF and Requisition records with a small subset of values that can be efficiently referenced. The module is used by edc_metadata_rules to quickly determine if a CRF or Requisition model instance exists avoiding the need to query each individual model class.

See also edc_metadata_rules

Usage and Configuration

Declare a model with the ReferenceModelMixin.

from edc_reference.model_mixins import ReferenceModelMixin

class CrfOne(ReferenceModelMixin, BaseUuidModel):

    subject_visit = models.ForeignKey(SubjectVisit, on_delete=PROTECT)

    report_datetime = models.DateTimeField(default=get_utcnow)

    f1 = models.CharField(max_length=50)

    f2 = models.CharField(max_length=50)

    f3 = models.CharField(max_length=50)

    f4 = models.DatetimeField(null=True)

Register the model and the relevant fields with the site global, site_reference_configs:

from edc_reference.site_reference import ReferenceModelConfig

reference = ReferenceModelConfig(
    model='edc_reference.crfone',
    fields=['f1', 'f4'])
site_reference_configs.register(reference)

Create a model instance:

crf_one = CrfOne.objects.create(
    subject_visit=subject_visit,
    f1='happiness'
    f4=get_utcnow())

The Reference model will be updated:

from edc_reference.models import Reference

reference = Reference.objects.get(
    identifier=self.subject_identifier,
    timepoint=self.subject_visit.visit_code,
    report_datetime=crf_one.report_datetime,
    field_name='f1')

>>> reference.__dict__
{ ...
 'datatype': 'CharField',
 'field_name': 'f1',
 'identifier': '1',
 'model': 'edc_reference.crfone',
 'report_datetime': datetime.datetime(2017, 7, 7, 13, 30, 6, 545140, tzinfo=<UTC>),
 'timepoint': 'code',
 'value_date': None,
 'value_datetime': None,
 'value_int': None,
 'value_str': 'happiness',
 ...}

Get the value from the reference instance:

>>> reference.value
'happiness'

Model managers methods are also available, for example:

reference = Reference.objects.crf_get_for_visit(
    model='edc_reference.crfone',
    visit=self.subject_visit,
    field_name='f1')

>>> reference.value
'happiness'

Accessing pivoted data with LongitudinalRefset

TODO

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-reference-0.3.24.tar.gz (53.8 kB view details)

Uploaded Source

Built Distribution

edc_reference-0.3.24-py3-none-any.whl (68.1 kB view details)

Uploaded Python 3

File details

Details for the file edc-reference-0.3.24.tar.gz.

File metadata

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

File hashes

Hashes for edc-reference-0.3.24.tar.gz
Algorithm Hash digest
SHA256 349d5ac607f1b6d053a262f7522a0673a6822b437074ff8dcfdf20bdeb54c0b3
MD5 b8cf9bd8543b7f1f73f3a8e497d3c5d1
BLAKE2b-256 c0ea5ee2cdf9b71b3189487de4b634d84532e646cf33e7cb59846eb8e326f382

See more details on using hashes here.

File details

Details for the file edc_reference-0.3.24-py3-none-any.whl.

File metadata

File hashes

Hashes for edc_reference-0.3.24-py3-none-any.whl
Algorithm Hash digest
SHA256 4e754be068c51c9804c95505d3518a068c495a210be96e28087e6134116ea01d
MD5 ec9f4ddca1b0ceebb9e6e3e5af86d867
BLAKE2b-256 cbed44056cdf607e71c329489fcab795e1393e7ff5187ce5106c23df95d40a5d

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