1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
use helios_sof::{ContentType, SofBundle, SofViewDefinition, run_view_definition};
#[test]
fn debug_column_ordering() {
// Create test data matching the column ordering test
let patient_json = serde_json::json!({
"resourceType": "Patient",
"id": "pt1",
"name": [
{"family": "TestFamily"}
]
});
// Create bundle
let bundle_json = serde_json::json!({
"resourceType": "Bundle",
"id": "test-bundle",
"type": "collection",
"entry": [{"resource": patient_json}]
});
let bundle: helios_fhir::r4::Bundle = serde_json::from_value(bundle_json).unwrap();
let bundle = SofBundle::R4(bundle);
// Create ViewDefinition exactly like the failing test
let view_definition_json = serde_json::json!({
"resourceType": "ViewDefinition",
"resource": "Patient",
"status": "active",
"select": [
{
"column": [
{
"path": "'A'",
"name": "a",
"type": "string"
},
{
"path": "'B'",
"name": "b",
"type": "string"
}
],
"select": [
{
"forEach": "name",
"column": [
{
"path": "'C'",
"name": "c",
"type": "string"
},
{
"path": "'D'",
"name": "d",
"type": "string"
}
]
}
],
"unionAll": [
{
"column": [
{
"path": "'E1'",
"name": "e",
"type": "string"
},
{
"path": "'F1'",
"name": "f",
"type": "string"
}
]
},
{
"column": [
{
"path": "'E2'",
"name": "e",
"type": "string"
},
{
"path": "'F2'",
"name": "f",
"type": "string"
}
]
}
]
},
{
"column": [
{
"path": "'G'",
"name": "g",
"type": "string"
},
{
"path": "'H'",
"name": "h",
"type": "string"
}
]
}
]
});
let view_definition: helios_fhir::r4::ViewDefinition =
serde_json::from_value(view_definition_json).unwrap();
let view_definition = SofViewDefinition::R4(view_definition);
println!("=== Testing column ordering ===");
let result = run_view_definition(view_definition, bundle, ContentType::Json).unwrap();
let result_str = String::from_utf8(result).unwrap();
println!("Result: {}", result_str);
let result_rows: Vec<serde_json::Value> = serde_json::from_str(&result_str).unwrap();
println!("\nActual result:");
for (i, row) in result_rows.iter().enumerate() {
println!("Row {}: {:?}", i + 1, row);
}
println!("\nExpected result (first row):");
println!(
"{{\"a\": \"A\", \"b\": \"B\", \"c\": \"C\", \"d\": \"D\", \"e\": \"E1\", \"f\": \"F1\", \"g\": \"G\", \"h\": \"H\"}}"
);
println!(
"{{\"a\": \"A\", \"b\": \"B\", \"c\": \"C\", \"d\": \"D\", \"e\": \"E2\", \"f\": \"F2\", \"g\": \"G\", \"h\": \"H\"}}"
);
}