Skip to content

SN Donor Calc Props #223

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ smaht-portal
Change Log
----------

0.98.0
======
`PR23: SN Donor Calc Props <https://github.com/smaht-dac/smaht-portal/pull/223>`_
* Add rev_link calc props for `Donor`: `death_circumstances`, `demographic`, `family_history`, `medical_history`, `tissue_collection`
* Add rev_link calc props for `MedicalHistory`: `diagnosis`, `exposure`, `medical_treatment`
* Adds tests for all calc_props for these two items


0.97.0
======
`PR238: SN Add valid_molecules required <https://github.com/smaht-dac/smaht-portal/pull/238>`_
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "encoded"
version = "0.97.0"
version = "0.98.0"
description = "SMaHT Data Analysis Portal"
authors = ["4DN-DCIC Team <[email protected]>"]
license = "MIT"
Expand Down
39 changes: 39 additions & 0 deletions src/encoded/tests/test_types_donor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import pytest
from webtest import TestApp

from .utils import get_search


@pytest.mark.workbook
def test_tissues_rev_link(es_testapp: TestApp, workbook: None) -> None:
"""Ensure tissues rev link works."""
tissues_search = get_search(es_testapp, "?type=Donor&tissues.uuid!=No+value")
assert tissues_search


@pytest.mark.workbook
def test_death_circumstances_rev_link(es_testapp: TestApp, workbook: None) -> None:
"""Ensure death circumstances rev link works."""
dc_search = get_search(es_testapp, "?type=Donor&death_circumstances.uuid!=No+value")
assert dc_search


@pytest.mark.workbook
def test_demographic_rev_link(es_testapp: TestApp, workbook: None) -> None:
"""Ensure demographic rev link works."""
dc_search = get_search(es_testapp, "?type=Donor&demographic.uuid!=No+value")
assert dc_search


@pytest.mark.workbook
def test_family_history_rev_link(es_testapp: TestApp, workbook: None) -> None:
"""Ensure family history rev link works."""
family_search = get_search(es_testapp, "?type=Donor&family_history.uuid!=No+value")
assert family_search


@pytest.mark.workbook
def test_medical_history_rev_link(es_testapp: TestApp, workbook: None) -> None:
"""Ensure family history rev link works."""
medical_search = get_search(es_testapp, "?type=Donor&medical_history.uuid!=No+value")
assert medical_search
25 changes: 25 additions & 0 deletions src/encoded/tests/test_types_medical_history.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import pytest
from webtest import TestApp

from .utils import get_search


@pytest.mark.workbook
def test_diagnosis_rev_link(es_testapp: TestApp, workbook: None) -> None:
"""Ensure diagnosis rev link works."""
diagnosis_search = get_search(es_testapp, "?type=MedicalHistory&diagnosis.uuid!=No+value")
assert diagnosis_search


@pytest.mark.workbook
def test_exposure_rev_link(es_testapp: TestApp, workbook: None) -> None:
"""Ensure exposure rev link works."""
exposure_search = get_search(es_testapp, "?type=MedicalHistory&exposure.uuid!=No+value")
assert exposure_search


@pytest.mark.workbook
def test_medical_treatment_rev_link(es_testapp: TestApp, workbook: None) -> None:
"""Ensure medical treatment rev link works."""
treatment_search = get_search(es_testapp, "?type=MedicalHistory&medical_treatment.uuid!=No+value")
assert treatment_search
78 changes: 78 additions & 0 deletions src/encoded/types/donor.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,74 @@ class Donor(SubmittedItem):
schema = load_schema("encoded:schemas/donor.json")
embedded_list = []
rev = {
"death_circumstances": ("DeathCircumstances", "donor"),
"demographic": ("Demographic", "donor"),
"family_history": ("FamilyHistory", "donor"),
"medical_history": ("MedicalHistory", "donor"),
"tissues": ("Tissue", "donor"),
"tissue_collection": ("TissueCollection", "donor")
}

@calculated_property(
schema={
"title": "Death Circumstances",
"description": "Circumstances of death of the donor",
"type": "string",
"linkTo": "DeathCircumstances"
},
)
def death_circumstances(self, request: Request) -> Union[str, None]:
result = self.rev_link_atids(request, "death_circumstances")
if result:
return result
return

@calculated_property(
schema={
"title": "Demographic",
"description": "Demographic information for the donor",
"type": "string",
"linkTo": "Demographic"
},
)
def demographic(self, request: Request) -> Union[str, None]:
result = self.rev_link_atids(request, "demographic")
if result:
return result
return

@calculated_property(
schema={
"title": "Family History",
"description": "Family history of the donor",
"type": "string",
"linkTo": "FamilyHistory"
},
)
def family_history(self, request: Request) -> Union[str, None]:
result = self.rev_link_atids(request, "family_history")
if result:
return result
return

@calculated_property(
schema={
"title": "Medical History",
"description": "Medical history of the donor",
"type": "string",
"linkTo": "MedicalHistory"
},
)
def medical_history(self, request: Request) -> Union[str, None]:
result = self.rev_link_atids(request, "medical_history")
if result:
return result
return

@calculated_property(
schema={
"title": "Tissues",
"description": "Tissues collected from the donor",
"type": "array",
"items": {
"type": "string",
Expand All @@ -36,3 +98,19 @@ def tissues(self, request: Request) -> Union[List[str], None]:
if result:
return result
return

@calculated_property(
schema={
"title": "Tissue Collection",
"description": "Tissue collection information for the donor",
"type": "string",
"linkTo": "TissueCollection"
},
)
def tissue_collection(self, request: Request) -> Union[str, None]:
result = self.rev_link_atids(request, "tissue_collection")
if result:
return result
return


62 changes: 61 additions & 1 deletion src/encoded/types/medical_history.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
from snovault import collection, load_schema
from typing import Union, List

from snovault import collection, load_schema, calculated_property
from pyramid.request import Request

from .submitted_item import SubmittedItem

Expand All @@ -15,3 +18,60 @@ class MedicalHistory(SubmittedItem):
item_type = "medical_history"
schema = load_schema("encoded:schemas/medical_history.json")
embedded_list = []

rev = {
"diagnosis": ("Diagnosis", "medical_history"),
"exposure": ("Exposure", "medical_history"),
"medical_treatment": ("MedicalTreatment", "medical_history"),
}

@calculated_property(
schema={
"title": "Diagnosis",
"description": "Diagnoses included in the medical history of the donor",
"type": "array",
"items": {
"type": "string",
"linkTo": "Diagnosis"
}
},
)
def diagnosis(self, request: Request) -> Union[List[str], None]:
result = self.rev_link_atids(request, "diagnosis")
if result:
return result
return

@calculated_property(
schema={
"title": "Exposure",
"description": "Exposures included in the medical history of the donor",
"type": "array",
"items": {
"type": "string",
"linkTo": "Exposure"
}
},
)
def exposure(self, request: Request) -> Union[List[str], None]:
result = self.rev_link_atids(request, "exposure")
if result:
return result
return

@calculated_property(
schema={
"title": "Medical Treatment",
"description": "Medical treatments included in the medical history of the donor",
"type": "array",
"items": {
"type": "string",
"linkTo": "MedicalTreatment"
}
},
)
def medical_treatment(self, request: Request) -> Union[List[str], None]:
result = self.rev_link_atids(request, "medical_treatment")
if result:
return result
return
Loading