diff --git a/flatehr/build.py b/flatehr/build.py index bbae540..b8a43ae 100644 --- a/flatehr/build.py +++ b/flatehr/build.py @@ -24,7 +24,7 @@ def __init__( self, paths: Dict, ehr_id: Dict, - set_missing_required_to_default: bool = True, + set_missing_required_to_default: bool = False, ): self._ehr_id = EhrId(set(ehr_id.get("maps_to", [])), ehr_id["value"]) self._set_missing_required_to_default = set_missing_required_to_default @@ -182,39 +182,39 @@ def build_composition( consumed_paths = [] ehr_id_kvs = {} - for source_key, source_value in source_kvs: - - if source_key in conf.ehr_id.maps_to: - ehr_id_kvs[source_key] = source_value - - _paths = conf.inverse_mappings[source_key] - for path in _paths: - if "*" in path._id: - continue - - if not path.suffixes: - composition.add(path._id) - else: - try: - value_dicts = pending_value_dicts.pop((source_key, path._id)) - except KeyError: - value_dicts = [ - ValueDict(composition.template, path, path.value_map) - ] - - for k in path.maps_to: - if k != source_key: - pending_value_dicts[(k, path._id)] += value_dicts - - if path._id.startswith("ctx/"): - ctx[path._id] = value_dicts[0] - else: - composition[path._id] = value_dicts[0] - - for vd in value_dicts: - if source_value: - vd.add_source_key_value(source_key, source_value) - consumed_paths.append(path) + for source_key, source_values in source_kvs: + for source_value in source_values: + if source_key in conf.ehr_id.maps_to: + ehr_id_kvs[source_key] = source_value + + _paths = conf.inverse_mappings[source_key] + for path in _paths: + if "*" in path._id: + continue + + if not path.suffixes: + composition.add(path._id) + else: + try: + value_dicts = pending_value_dicts.pop((source_key, path._id)) + except KeyError: + value_dicts = [ + ValueDict(composition.template, path, path.value_map) + ] + + for k in path.maps_to: + if k != source_key: + pending_value_dicts[(k, path._id)] += value_dicts + + if path._id.startswith("ctx/"): + ctx[path._id] = value_dicts[0] + else: + composition[path._id] = value_dicts[0] + + for vd in value_dicts: + if source_value: + vd.add_source_key_value(source_key, source_value) + consumed_paths.append(path) for path in set([p for p in conf.paths if not p._id.startswith("ctx")]) - set( consumed_paths @@ -245,7 +245,7 @@ def _get_conf(conf_file: str) -> Config: paths=conf_kwargs["paths"], ehr_id=conf_kwargs["ehr_id"], set_missing_required_to_default=conf_kwargs.get( - "set_missing_required_to_default", True + "set_missing_required_to_default", False ), ) diff --git a/flatehr/cli/generate.py b/flatehr/cli/generate.py index cbd654c..a9fa00f 100644 --- a/flatehr/cli/generate.py +++ b/flatehr/cli/generate.py @@ -132,7 +132,7 @@ def conf_from_file(conf_file: str) -> Config: paths=conf_kwargs["paths"], ehr_id=conf_kwargs["ehr_id"], set_missing_required_to_default=conf_kwargs.get( - "set_missing_required_to_default", True + "set_missing_required_to_default", False ), ) diff --git a/flatehr/core.py b/flatehr/core.py index 6363c9d..4d0ecf9 100644 --- a/flatehr/core.py +++ b/flatehr/core.py @@ -286,5 +286,6 @@ def flat( value_dicts.update(ctx or {}) for _id, suffixes in value_dicts.items(): for suffix, value in suffixes.items(): - dct[_id + suffix] = value + if value: + dct[_id + suffix] = value return dct