Skip to main content

Structure map test

This is a utility to help you write tests for your structure maps using sample Questionnare Responses as test data. It provides multiple test assetions that you can use to test the map file.

Command

fhir-tools test [path].json

Config

To test a structure map you need to create a config a json config file that has the following properties

PropertyDescription
typeThe type of transformation you are currently doing str_test for tests
mapInformation about the actual FML file you want to test. All you need is the path and an optional name
testsAn array of the questionnare reponses you want to tests with this structure map

Structure map config

ElementDescription
pathThe location to the file
name?The Src name

The actual test array needs the following structure

PropertyDescription
responseThe path to the questinare response
verifyAn array of the actual tests and required values

The test section of the file needs the following

PropertyDescription
typeThe type of assertion test you are trying to run
pathThe JSONPath to run to get the actual data
value?The value to compare with
valueRange?A range of values to compare with

Value Range

PropertyDescription
startStarting point of the range date or number
endEnding point of the range date or number

Example file

{
"type": "str_test",
"map": {
"path": "./exposed_infant_hiv_test_and_results.map",
"name": "tracing"
},
"tests": [
{
"response": "./response/positive.json",
"verify": [
{
"type": "eq",
"path": "$.resourceType",
"value": "Bundle"
},
{
"type": "lte",
"path": "$.entry[?(@.resource.resourceType == \"Task\")].resource.code.coding[0].code",
"value": "225368008"
},
{
"type": "eq",
"path": "$.resourceType",
"value": "jeff"
}
]
}
]
}

Available Test Assetions

The following operators are available:

OperatorDescription
eqEqual
eqiEqual (case-insensitive)
neNot equal
ltLess than
lteLess than or equal to
gtGreater than
gteGreater than or equal to
inIncluded in an array
notInNot included in an array
containsContains
notContainsDoes not contain
containsiContains (case-insensitive)
notContainsiDoes not contain (case-insensitive)
nullIs null
notNullIs not null
betweenIs between
startsWithStarts with
startsWithiStarts with (case-insensitive)
endsWithEnds with
endsWithiEnds with (case-insensitive)
orJoins the filters in an "or" expression
andJoins the filters in an "and" expression
notJoins the filters in an "not" expression