|
35 | 35 | from chord_metadata_service.mcode.mcode_ingest import ingest_mcodepacket
|
36 | 36 | from chord_metadata_service.phenopackets.schemas import PHENOPACKET_SCHEMA
|
37 | 37 | from chord_metadata_service.experiments.schemas import EXPERIMENT_SCHEMA
|
| 38 | +from chord_metadata_service.restapi.utils import iso_duration_to_years |
38 | 39 |
|
39 | 40 | requests_unixsocket.monkeypatch()
|
40 | 41 |
|
@@ -414,9 +415,19 @@ def ingest_phenopacket(phenopacket_data, table_id):
|
414 | 415 | subject_query = _query_and_check_nulls(subject, "date_of_birth", transform=isoparse)
|
415 | 416 | for k in ("alternate_ids", "age", "sex", "karyotypic_sex", "taxonomy"):
|
416 | 417 | 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 | + |
417 | 426 | subject, _ = pm.Individual.objects.get_or_create(id=subject["id"],
|
418 | 427 | race=subject.get("race", ""),
|
419 | 428 | ethnicity=subject.get("ethnicity", ""),
|
| 429 | + age_numeric=age_numeric_value, |
| 430 | + age_unit=age_unit_value if age_unit_value else "", |
420 | 431 | extra_properties=subject.get("extra_properties", {}),
|
421 | 432 | **subject_query)
|
422 | 433 |
|
|
0 commit comments