Skip to main content

Simple blood result data collection format model classes for clinicedc/edc projects

Project description

pypi actions codecov downloads

edc-lab-results

Simple blood result data collection format for django models

In this design
  • a specimen requisition for a panel is completed first (SubjectRequisition)

  • result is received and entered into a result form

  • if a result is admnormal or gradable, an ActionItem is created.

Building the Model

Below we create a model class with BloodResultsModelMixin. On the class we specify the lab_panel and limit the FK the requisitions of this panel using limit_choices_to.

# models.py

from edc_lab.model_mixins import CrfWithRequisitionModelMixin, requisition_fk_options
from edc_lab_panels.panels import chemistry_panel

class BloodResultsFbc(
    CrfWithRequisitionModelMixin,
    BloodResultsModelMixin,
    BaseUuidModel,
):

    lab_panel = fbc_panel

    requisition = models.ForeignKey(
        limit_choices_to={"panel__name": fbc_panel.name}, **requisition_fk_options
    )

    class Meta(CrfWithActionModelMixin.Meta, BaseUuidModel.Meta):
        verbose_name = "Blood Result: FBC"
        verbose_name_plural = "Blood Results: FBC"

The above example has no fields for results, so let’s add some model mixins, one for each result item.

# models.py

class BloodResultsFbc(
    CrfWithRequisitionModelMixin,
    HaemoglobinModelMixin,
    HctModelMixin,
    RbcModelMixin,
    WbcModelMixin,
    PlateletsModelMixin,
    MchModelMixin,
    MchcModelMixin,
    McvModelMixin,
    BloodResultsModelMixin,
    CrfStatusModelMixin,
    BaseUuidModel,
):

    lab_panel = fbc_panel

    requisition = models.ForeignKey(
        limit_choices_to={"panel__name": fbc_panel.name}, **requisition_fk_options
    )

    class Meta(CrfWithActionModelMixin.Meta, BaseUuidModel.Meta):
        verbose_name = "Blood Result: FBC"
        verbose_name_plural = "Blood Results: FBC"

If an ActionItem is to be created because of an abnormal or reportable result item, add the ActionItem.

# models.py

class BloodResultsFbc(
    CrfWithActionModelMixin,
    CrfWithRequisitionModelMixin,
    HaemoglobinModelMixin,
    HctModelMixin,
    RbcModelMixin,
    WbcModelMixin,
    PlateletsModelMixin,
    MchModelMixin,
    MchcModelMixin,
    McvModelMixin,
    BloodResultsModelMixin,
    CrfStatusModelMixin,
    BaseUuidModel,
):
    action_name = BLOOD_RESULTS_FBC_ACTION

    lab_panel = fbc_panel

    requisition = models.ForeignKey(
        limit_choices_to={"panel__name": fbc_panel.name}, **requisition_fk_options
    )

    class Meta(CrfWithActionModelMixin.Meta, BaseUuidModel.Meta):
        verbose_name = "Blood Result: FBC"
        verbose_name_plural = "Blood Results: FBC"

Building the ModeForm class

The ModelForm class just needs the Model class and the panel. In this case BloodResultsFbc and fbc_panel.

# forms.py

class BloodResultsFbcFormValidator(BloodResultsFormValidatorMixin, CrfFormValidator):
    panel = fbc_panel


class BloodResultsFbcForm(ActionItemCrfFormMixin, CrfModelFormMixin, forms.ModelForm):
    form_validator_cls = BloodResultsFbcFormValidator

    class Meta(ActionItemCrfFormMixin.Meta):
        model = BloodResultsFbc
        fields = "__all__"

Building the ModelAdmin class

The ModelAdmin class needs the Model class, ModelForm class and the panel.

# admin.py

@admin.register(BloodResultsFbc, site=intecomm_subject_admin)
class BloodResultsFbcAdmin(BloodResultsModelAdminMixin, CrfModelAdmin):
    form = BloodResultsFbcForm
    fieldsets = BloodResultFieldset(
        BloodResultsFbc.lab_panel,
        model_cls=BloodResultsFbc,
        extra_fieldsets=[(-1, action_fieldset_tuple)],
    ).fieldsets

The SubjectRequistion ModelAdmin class

When using autocomplete for the subject requsition FK on the result form ModelAdmin class, the subject requsition model admin class needs to filter the search results passed to the autocomplete control.

If all result models are prefixed with “bloodresult”, you can filter on the path name like this:

# admin.py

@admin.register(SubjectRequisition, site=intecomm_subject_admin)
class SubjectRequisitionAdmin(RequisitionAdminMixin, CrfModelAdmin):
    form = SubjectRequisitionForm

    # ...

    def get_search_results(self, request, queryset, search_term):
        queryset, use_distinct = super().get_search_results(request, queryset, search_term)
        path = urlsplit(request.META.get("HTTP_REFERER")).path
        query = urlsplit(request.META.get("HTTP_REFERER")).query
        if "bloodresult" in str(path):
            attrs = parse_qs(str(query))
            try:
                subject_visit = attrs.get("subject_visit")[0]
            except (TypeError, IndexError):
                pass
            else:
                queryset = queryset.filter(subject_visit=subject_visit, is_drawn=YES)
        return queryset, use_distinct

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-lab-results-0.3.5.tar.gz (40.0 kB view details)

Uploaded Source

Built Distribution

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

edc_lab_results-0.3.5-py3-none-any.whl (45.7 kB view details)

Uploaded Python 3

File details

Details for the file edc-lab-results-0.3.5.tar.gz.

File metadata

  • Download URL: edc-lab-results-0.3.5.tar.gz
  • Upload date:
  • Size: 40.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.4

File hashes

Hashes for edc-lab-results-0.3.5.tar.gz
Algorithm Hash digest
SHA256 3a306e5bd9e4ed2d9ee0494f1e5366a405a46d612c7b128ac1f3c7ce61ce10ba
MD5 6d41943f953aa0a838fbc750ae87d8df
BLAKE2b-256 79e988bbbfdd051d570dcfdfb305906a2e83d5e31e545c7a42c79e13bc2f9ec1

See more details on using hashes here.

File details

Details for the file edc_lab_results-0.3.5-py3-none-any.whl.

File metadata

File hashes

Hashes for edc_lab_results-0.3.5-py3-none-any.whl
Algorithm Hash digest
SHA256 d2050b91ce187c89c8eef1cf35b20cb932ca6e22968e576cc86c11c5a9d2ad62
MD5 aa6f4f426128f74bc645472d7e2fbab2
BLAKE2b-256 88d3f6a3da525ac840bacfeb4316801bd2a9fed385e16a15d449d43dcbc954ab

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