Skip to content

Commit 2effa32

Browse files
committed
Refactor tests and update readme
1 parent 9c0589c commit 2effa32

3 files changed

Lines changed: 495 additions & 265 deletions

File tree

README.md

Lines changed: 49 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Finally, data DSL should be LLM-friendly and there should be an easy way to gene
2323
ChatGPT works pretty well with JSON and FHIRPath. So, you can just copy and paste the specification into ChatGPT and try to generate mappers.
2424

2525

26-
## Specification
26+
## Quick overview
2727

2828
The FHIRPath mapping language is a data DSL designed to convert data from QuestionnaireResponse (and not only) to any FHIR Resource.
2929

@@ -195,11 +195,30 @@ The final mapper will look like this:
195195
}
196196
```
197197

198-
### Accessing array result of expression
198+
## Specification
199+
200+
### Accessing the first result of the expression
199201

200202
From the example above, it's clearly seen that the expression inside `{{ }}` always evaluated as the first element or null.
201203

202-
There's a special syntax for accessing the whole array - `{[ expression ]}`.
204+
For example,
205+
206+
```json
207+
{
208+
"resourceType": "Patient",
209+
"name": [
210+
{
211+
"given": ["{[ QuestionnaireResponse.repeat(item).where(linkId='1').answer.value ]}"]
212+
}
213+
]
214+
}
215+
```
216+
217+
In this example, the result of the evaluation of the expression will be always the first element of the array.
218+
219+
### Accessing the array result of the expression
220+
221+
In order to use the array result, there's a special syntax - `{[ expression ]}`.
203222

204223
For example,
205224

@@ -214,19 +233,25 @@ For example,
214233
}
215234
```
216235

217-
In this example, the result of the evaluation of the expression will be always an array (empty or with results).
218-
236+
In this example, the result of the expression evaluation will always be an array if the expression returns not empty array.
219237

220-
### Null key removal
238+
### Empty arrays, objects and nulls removal
221239

222-
If an expression resolves to an empty set `{}`, the key will be removed from the object.
240+
If an expression resolves to an empty set `{}`, the value will be removed from the array and object.
241+
Moreover, empty arrays and objects also will be removed.
223242

224-
For example, if the gender field is missing in the QuestionnaireResponse from the example above:
243+
For example,
225244

226245
```json
227246
{
228247
"resourceType": "Patient",
229-
"gender": "{{ QuestionnaireResponse.repeat(item).where(linkId='4.1').answer.value.code }}"
248+
"name": [
249+
{
250+
"given": [
251+
"{{ QuestionnaireResponse.repeat(item).where(linkId='1').answer.value.string }}"
252+
]
253+
}
254+
]
230255
}
231256
```
232257

@@ -238,11 +263,20 @@ this template will be mapped into:
238263
}
239264
```
240265

241-
### Null key retention
266+
**Explanation:**
267+
268+
The expression `"{{ QuestionnaireResponse.repeat(item).where(linkId='1').answer.value.string }}"` resolves to null,
269+
which is then removed from the `given` array. Since `given` becomes null after removal, it gets removed from the object.
270+
The resulting empty object is then replaced with null, which is removed from the `name` array.
271+
Finally, the empty `name` array is replaced with null, causing the entire `name` key to be removed from the final result.
272+
273+
274+
### Nulls retention
242275

243276
**Note:** This feature is not mature enough and might change in the future.
244277

245278
To preserve the null value in the final result, use `{{+` and `+}}` instead of `{{` and `}}`:
279+
The null value will be also preserved in the array, it might be useful for primitive extensions.
246280

247281
```json
248282
{
@@ -262,28 +296,25 @@ The result will be:
262296

263297
**Note:** This feature is not mature enough and might change in the future.
264298

265-
### Automatic array flattening and null removal
299+
### Automatic array flattening
266300

267-
In FHIR resources, arrays of arrays and arrays of nulls are invalid constructions. To simplify writing mappers, there is automatic array flattening.
301+
In FHIR resources, arrays of arrays are invalid constructions. To simplify writing mappers, there is automatic array flattening.
268302

269303
For example:
270304

271305
```json
272306
{
273307
"list": [
274308
[
275-
1, 2, null, 3
309+
1, 2, 3
276310
],
277-
null,
278311
[
279-
4, 5, 6, null
312+
4, 5, 6
280313
]
281314
]
282315
}
283316
```
284317

285-
will be mapped into:
286-
287318
```json
288319
{
289320
"list": [
@@ -292,7 +323,7 @@ will be mapped into:
292323
}
293324
```
294325

295-
This is especially useful if there is conditional and iteration logic used.
326+
Note that since empty arrays, objects, and null values are automatically removed, any null elements created during expression evaluation in arrays will be automatically removed during flattening. This behavior is particularly beneficial when using conditional and iteration logic.
296327

297328
### String concatenation
298329

0 commit comments

Comments
 (0)