Skip to main content

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

Metadata

Release files for edc-lab-results 1.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for edc-lab-results 1.0.2
File Size Uploaded Provenance Actions
edc_lab_results-1.0.2.tar.gz 41.4 kB Without provenance Details for edc_lab_results-1.0.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for edc-lab-results 1.0.2
File Interpreter ABI Platform Actions
edc_lab_results-1.0.2-py3-none-any.whl Python 3 none any Details for edc_lab_results-1.0.2-py3-none-any.whl

Total release size: 89.6 kB

Release files / edc_lab_results-1.0.2.tar.gz

Download URL edc_lab_results-1.0.2.tar.gz
Size 41.4 kB
Tags Source
SHA-256 checksum
How to use checksums
3e5ae8cce136e7cf7a8efa17eb8bf5f9470a07218e7bf8e2b10e201d0cbadfc1
BLAKE2b-256 checksum
How to use checksums
79d075278605d821a55a815d8e0ac3f87e9e8b34a6a8864296cb34a9770bace8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.11

Release files / edc_lab_results-1.0.2-py3-none-any.whl

Download URL edc_lab_results-1.0.2-py3-none-any.whl
Size 48.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1a0d099afd50ad1c1ac1791308eba23e7f10b2db68536cd2e6eb01540c413f94
BLAKE2b-256 checksum
How to use checksums
2b5352c80f6890eef52f4dd337e762950ce2cfcd991bfc7a2a01c413eec8214e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.11

Security for edc-lab-results 1.0.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.0.2 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page