diff --git a/src/phenopacket_mapper/mapping/mapper.py b/src/phenopacket_mapper/mapping/mapper.py index d37b6ebb..30667f82 100644 --- a/src/phenopacket_mapper/mapping/mapper.py +++ b/src/phenopacket_mapper/mapping/mapper.py @@ -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 @@ -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( diff --git a/src/phenopacket_mapper/mapping/phenopacket_element.py b/src/phenopacket_mapper/mapping/phenopacket_element.py index 58fa7928..f3bd5414 100644 --- a/src/phenopacket_mapper/mapping/phenopacket_element.py +++ b/src/phenopacket_mapper/mapping/phenopacket_element.py @@ -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: @@ -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 @@ -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)