Skip to content

Commit

Permalink
Only load referenced predicates
Browse files Browse the repository at this point in the history
  • Loading branch information
justin13601 committed Aug 12, 2024
1 parent 1bcd50b commit 7d79a73
Showing 1 changed file with 17 additions and 15 deletions.
32 changes: 17 additions & 15 deletions src/aces/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -1166,9 +1166,25 @@ def load(cls, config_path: str | Path, predicates_path: str | Path = None) -> Ta
if loaded_dict:
raise ValueError(f"Unrecognized keys in configuration file: '{', '.join(loaded_dict.keys())}'")

logger.info("Parsing windows...")
if windows is None:
windows = {}
logger.warning(

Check warning on line 1172 in src/aces/config.py

View check run for this annotation

Codecov / codecov/patch

src/aces/config.py#L1171-L1172

Added lines #L1171 - L1172 were not covered by tests
"No windows specified in configuration file. Extracting only matching trigger events."
)
else:
windows = {n: WindowConfig(**w) for n, w in windows.items()}

logger.info("Parsing trigger event...")
trigger = EventConfig(trigger)

referenced_predicates = {pred for w in windows.values() for pred in w.referenced_predicates}
referenced_predicates.add(trigger.predicate)

logger.info("Parsing predicates...")
predicates_to_parse = {k: v for k, v in predicates.items() if k in referenced_predicates}
predicate_objs = {}
for n, p in predicates.items():
for n, p in predicates_to_parse.items():
if "expr" in p:
predicate_objs[n] = DerivedPredicateConfig(**p)
else:
Expand All @@ -1183,20 +1199,6 @@ def load(cls, config_path: str | Path, predicates_path: str | Path = None) -> Ta
}
predicate_objs.update(patient_demographics)

logger.info("Parsing trigger event...")
trigger = EventConfig(trigger)

logger.info("Parsing windows...")
if windows is None:
windows = {}
logger.warning(
"No windows specified in configuration file. Extracting only matching trigger events."
)
else:
windows = {n: WindowConfig(**w) for n, w in windows.items()}

print(predicate_objs)

return cls(predicates=predicate_objs, trigger=trigger, windows=windows)

def save(self, config_path: str | Path, do_overwrite: bool = False):
Expand Down

0 comments on commit 7d79a73

Please sign in to comment.