Skip to content

Commit 1f9a949

Browse files
authoredMar 23, 2022
Merge pull request #300 from bento-platform/develop
Version 2.8.0
2 parents bf350c4 + 57e51fd commit 1f9a949

21 files changed

+1795
-14
lines changed
 

‎.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,6 @@ htmlcov/
2727
# docs build
2828

2929
docs/_build
30+
31+
# project custom config file
32+
config.json

‎chord_metadata_service/chord/ingest.py

+11
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
from chord_metadata_service.mcode.mcode_ingest import ingest_mcodepacket
3636
from chord_metadata_service.phenopackets.schemas import PHENOPACKET_SCHEMA
3737
from chord_metadata_service.experiments.schemas import EXPERIMENT_SCHEMA
38+
from chord_metadata_service.restapi.utils import iso_duration_to_years
3839

3940
requests_unixsocket.monkeypatch()
4041

@@ -414,9 +415,19 @@ def ingest_phenopacket(phenopacket_data, table_id):
414415
subject_query = _query_and_check_nulls(subject, "date_of_birth", transform=isoparse)
415416
for k in ("alternate_ids", "age", "sex", "karyotypic_sex", "taxonomy"):
416417
subject_query.update(_query_and_check_nulls(subject, k))
418+
419+
# check if age is represented as a duration string (vs. age range values) and convert it to years
420+
age_numeric_value = None
421+
age_unit_value = None
422+
if "age" in subject:
423+
if "age" in subject["age"]:
424+
age_numeric_value, age_unit_value = iso_duration_to_years(subject["age"]["age"])
425+
417426
subject, _ = pm.Individual.objects.get_or_create(id=subject["id"],
418427
race=subject.get("race", ""),
419428
ethnicity=subject.get("ethnicity", ""),
429+
age_numeric=age_numeric_value,
430+
age_unit=age_unit_value if age_unit_value else "",
420431
extra_properties=subject.get("extra_properties", {}),
421432
**subject_query)
422433

‎chord_metadata_service/chord/tests/example_ingest.py

+10-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44

55
__all__ = ["EXAMPLE_INGEST_PHENOPACKET", "EXAMPLE_INGEST_OUTPUTS",
66
"EXAMPLE_INGEST_EXPERIMENT", "EXAMPLE_INGEST_OUTPUTS_EXPERIMENT",
7-
"EXAMPLE_INGEST_INVALID_PHENOPACKET"]
7+
"EXAMPLE_INGEST_INVALID_PHENOPACKET",
8+
"EXAMPLE_INGEST_MULTIPLE_PHENOPACKETS", "EXAMPLE_INGEST_MULTIPLE_OUTPUTS"]
89

910
with open(os.path.join(os.path.dirname(__file__), "example_phenopacket.json"), "r") as pf:
1011
EXAMPLE_INGEST_PHENOPACKET = json.load(pf)
@@ -24,3 +25,11 @@
2425

2526
with open(os.path.join(os.path.dirname(__file__), "example_invalid_phenopacket.json"), "r") as pf:
2627
EXAMPLE_INGEST_INVALID_PHENOPACKET = json.load(pf)
28+
29+
30+
with open(os.path.join(os.path.dirname(__file__), "example_multiple_phenopackets.json"), "r") as pf:
31+
EXAMPLE_INGEST_MULTIPLE_PHENOPACKETS = json.load(pf)
32+
33+
EXAMPLE_INGEST_MULTIPLE_OUTPUTS = {
34+
"json_document": os.path.join(os.path.dirname(__file__), "example_multiple_phenopackets.json"),
35+
}

0 commit comments

Comments
 (0)