Skip to content

Commit

Permalink
Merge pull request #204 from samply/fix/fcknzs
Browse files Browse the repository at this point in the history
workaround for messed up AST
  • Loading branch information
enola-dkfz authored Feb 6, 2025
2 parents 4ffbf04 + 4f431ea commit 365b323
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
12 changes: 11 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
# Samply.Focus v0.10.0 2024-12-11
# Samply.Focus v0.11.0 2025-02-??

## Major changes
* Querying EUCAIM API v1
* CQL generation supports empty AST of an arbitary debth

## Minor changes
??


# Samply.Focus v0.10.0 2025-02-03

## Major changes
* Laplace-rs version 0.5.0 (includes a statrs breaking change)
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "focus"
version = "0.10.0"
version = "0.11.0"
edition = "2021"
license = "Apache-2.0"

Expand Down
9 changes: 8 additions & 1 deletion src/cql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ fn generate_cql(ast: ast::Ast) -> Result<String, FocusError> {

cql = cql.replace("{{lists}}", lists.as_str());

if retrieval_criteria.is_empty() {
if retrieval_criteria.is_empty() || retrieval_criteria.chars().all(|c| [' ', '(', ')'].contains(&c)) { //to deal with an empty criteria tree of an arbitrary depth
cql = cql.replace("{{retrieval_criteria}}", "true"); //()?
} else {
let formatted_retrieval_criteria = format!("({})", retrieval_criteria);
Expand Down Expand Up @@ -394,6 +394,8 @@ mod test {

const CURRENT: &str = r#"{"ast":{"operand":"OR","children":[{"operand":"AND","children":[{"operand":"OR","children":[{"key":"gender","type":"EQUALS","system":"","value":"male"}]},{"operand":"OR","children":[{"key":"diagnosis","type":"EQUALS","system":"http://fhir.de/CodeSystem/dimdi/icd-10-gm","value":"C61"}]},{"operand":"OR","children":[{"key":"donor_age","type":"BETWEEN","system":"","value":{"min":10,"max":90}}]}]},{"operand":"AND","children":[{"operand":"OR","children":[{"key":"sampling_date","type":"BETWEEN","system":"","value":{"min":"1900-01-01","max":"2024-10-25"}}]},{"operand":"OR","children":[{"key":"storage_temperature","type":"EQUALS","system":"","value":"temperature2to10"}]}]}]},"id":"53b4414e-75e4-401b-b794-20a2936e1be5"}"#;

const VAFAN: &str = r#"{"ast":{"nodeType":"branch","operand":"OR","children":[{"nodeType":"branch","operand":"AND","children":[]}]},"id":"0b29f6d1-4e6a-4679-9212-3327e498b304__search__0b29f6d1-4e6a-4679-9212-3327e498b304"}"#;

#[test]
fn test_common() {
// maybe nothing here
Expand Down Expand Up @@ -444,6 +446,11 @@ mod test {
include_str!("../resources/test/result_empty.cql").to_string()
);

pretty_assertions::assert_eq!(
generate_cql(serde_json::from_str(VAFAN).unwrap()).unwrap(),
include_str!("../resources/test/result_empty.cql").to_string()
);

pretty_assertions::assert_eq!(
generate_cql(serde_json::from_str(CURRENT).unwrap()).unwrap(),
include_str!("../resources/test/result_current.cql").to_string()
Expand Down

0 comments on commit 365b323

Please sign in to comment.