Skip to content

Commit

Permalink
Merge pull request #98 from BIH-CEI/94-datafieldvalue_set-accept-type…
Browse files Browse the repository at this point in the history
…s-and-auto-create-valueset

made datafield accept a type instead of a valueset and auto create vs
  • Loading branch information
frehburg authored Sep 19, 2024
2 parents bf13d97 + 539d4c9 commit 68a834d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
10 changes: 6 additions & 4 deletions notebooks/erdri_cds_definition_in_code.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -838,18 +838,20 @@
" age_at_diagnosis_column= \"5.2. Age at diagnosis\",\n",
" diagnosis_of_the_rare_disease_column= \"6.1. Diagnosis of the rare disease\",\n",
" genetic_diagnosis_column= \"6.2. Genetic diagnosis\",\n",
" undiagnosed_case_column= None\n",
" undiagnosed_case_column= None,\n",
" \n",
" compliance='soft' # 'soft' or 'hard'\n",
")"
],
"metadata": {
"collapsed": false,
"ExecuteTime": {
"end_time": "2024-09-19T13:43:14.125217100Z",
"start_time": "2024-09-19T13:43:13.950917800Z"
"end_time": "2024-09-19T13:55:26.091646200Z",
"start_time": "2024-09-19T13:55:26.065437100Z"
}
},
"id": "2253ecd35c94e0d1",
"execution_count": 23
"execution_count": 29
},
{
"cell_type": "code",
Expand Down
13 changes: 11 additions & 2 deletions src/phenopacket_mapper/data_standards/data_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,14 @@ class DataField:
- The `id` field cannot be any of the Python keywords (e.g. `in`, `is`, `not`, `class`, etc.).
- The `id` field must be unique within a `DataModel`
If the `value_set` is a single type, it can be passed directly as the `value_set` parameter.
e.g.:
>>> DataField(name="Field 1", value_set=int)
DataField(name='Field 1', value_set=ValueSet(elements=[<class 'int'>], name='', description=''), id='field_1', description='', section='', required=True, specification='', ordinal='')
:ivar name: Name of the field
:ivar value_set: Value set of the field
:ivar value_set: Value set of the field, if the value set is only one type, can also pass that type directly
:ivar id: Id of the field, adhering to the naming rules stated above
:ivar description: Description of the field
:ivar section: Section of the field (Only applicable if the data model is divided into sections)
Expand All @@ -50,7 +56,7 @@ class DataField:
:ivar ordinal: Ordinal of the field (E.g. 1.1, 1.2, 2.1, etc.)
"""
name: str = field()
value_set: ValueSet = field()
value_set: Union[ValueSet, type] = field()
id: str = field(default=None)
description: str = field(default='')
section: str = field(default='')
Expand All @@ -63,6 +69,9 @@ def __post_init__(self):
from phenopacket_mapper.utils import str_to_valid_id
object.__setattr__(self, 'id', str_to_valid_id(self.name))

if isinstance(self.value_set, type):
object.__setattr__(self, 'value_set', ValueSet(elements=[self.value_set]))

def __str__(self):
ret = "DataField(\n"
ret += f"\t\tid: {self.id},\n"
Expand Down

0 comments on commit 68a834d

Please sign in to comment.