Skip to content

Commit 26a025f

Browse files
committed
CQL workaround for nothing OR nothing OR nothing...
1 parent 289fd45 commit 26a025f

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/cql.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ fn generate_cql(ast: ast::Ast, project: Project) -> Result<String, FocusError> {
7272
|| retrieval_criteria
7373
.chars()
7474
.all(|c| [' ', '(', ')'].contains(&c))
75+
|| retrieval_criteria.replace("or"," ")
76+
.chars()
77+
.all(|c| [' ', '(', ')'].contains(&c))
7578
{
7679
//to deal with an empty criteria tree of an arbitrary depth
7780
cql = cql.replace("{{retrieval_criteria}}", "true"); //()?
@@ -431,6 +434,9 @@ mod test {
431434

432435
const EMPTY: &str =
433436
r#"{"ast":{"children":[],"operand":"OR"}, "id":"a6f1ccf3-ebf1-424f-9d69-4e5d135f2340"}"#;
437+
438+
const EMPTY_OR: &str =
439+
r#"{"ast":{"operand":"OR","children":[{"operand":"AND","children":[]},{"operand":"AND","children":[]}]},"id":"f1f59c3b-fbe6-4941-a718-c6656c96b70e"}"#;
434440

435441
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"}"#;
436442

@@ -505,6 +511,11 @@ mod test {
505511
include_str!("../resources/test/result_empty.cql").to_string()
506512
);
507513

514+
pretty_assertions::assert_eq!(
515+
generate_cql(serde_json::from_str(EMPTY).unwrap(), Project::Bbmri).unwrap(),
516+
include_str!("../resources/test/result_empty.cql").to_string()
517+
);
518+
508519
pretty_assertions::assert_eq!(
509520
generate_cql(serde_json::from_str(VAFAN).unwrap(), Project::Bbmri).unwrap(),
510521
include_str!("../resources/test/result_empty.cql").to_string()

0 commit comments

Comments
 (0)