Skip to content

Commit

Permalink
fixed some bugs in the setup of the mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
frehburg committed Sep 24, 2024
1 parent efde206 commit b41738b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
9 changes: 6 additions & 3 deletions src/phenopacket_mapper/mapping/mapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from phenopackets import Phenopacket

from phenopacket_mapper.data_standards.data_model import DataModel, DataSet, DataField
from phenopacket_mapper.data_standards.data_model import DataModel, DataSet, DataField, DataFieldValue
from phenopacket_mapper.mapping import PhenopacketElement


Expand Down Expand Up @@ -61,9 +61,12 @@ def map(self, data: DataSet) -> List[Phenopacket]:
kwargs = {}
for key, e in self.elements.items():
if isinstance(e, DataField):
kwargs[key] = e
data_field = e
value: DataFieldValue = getattr(instance, data_field.id).value
kwargs[key] = value
elif isinstance(e, PhenopacketElement):
kwargs[key] = e.map(instance)
phenopacket_element = e
kwargs[key] = phenopacket_element.map(instance)

try:
phenopackets_list.append(
Expand Down
13 changes: 9 additions & 4 deletions src/phenopacket_mapper/mapping/phenopacket_element.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from typing import Union, Dict

from phenopacket_mapper.data_standards import DataModelInstance, DataField
from phenopacket_mapper.data_standards import DataModelInstance, DataField, DataFieldValue


class PhenopacketElement:
Expand All @@ -15,7 +15,7 @@ def __init__(self, phenopacket_element, **kwargs):
"""
self.phenopacket_element = phenopacket_element
self.elements: Dict[str, Union[PhenopacketElement, DataField]] = {}
for k, v in kwargs:
for k, v in kwargs.items():
setattr(self, k, v)
self.elements[k] = v

Expand All @@ -34,11 +34,16 @@ def map(self, instance: DataModelInstance):
:param instance: the ´DataModelInstance´ from which to map to a Phenopacket schema element
:return: the resulting Phenopacket schema element
"""
print(self.elements)
kwargs = {}
for key, e in self.elements.items():
print(f"{key=} {e=}")
if isinstance(e, DataField):
kwargs[key] = e
data_field = e
value: DataFieldValue = getattr(instance, data_field.id).value
kwargs[key] = value
elif isinstance(e, PhenopacketElement):
kwargs[key] = e.map(instance)
phenopacket_element = e
kwargs[key] = phenopacket_element.map(instance)

return self.phenopacket_element(**kwargs)

0 comments on commit b41738b

Please sign in to comment.