Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions cmd/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,12 +202,19 @@ func mainWrapper(ctx context.Context, cfg cliConfig) error {
config.Parameters = params
}
if cfg.Parameters != "" {
if config.Parameters == nil {
config.Parameters = make(map[result.DefKey]string)
}
for _, param := range strings.Split(cfg.Parameters, ",") {
parts := strings.Split(param, "=")
if len(parts) != 2 {
return fmt.Errorf("--parameters was passed an invalid input string: %s", param)
}
config.Parameters[result.DefKey{Name: parts[0]}] = parts[1]
key := result.DefKey{Name: parts[0]}
if nameParts := strings.Split(parts[0], "."); len(nameParts) == 2 {
key = result.DefKey{Library: result.LibKey{Name: nameParts[0]}, Name: nameParts[1]}
}
config.Parameters[key] = parts[1]
}
}
elm, err := cql.Parse(ctx, cqlLibs, config)
Expand Down Expand Up @@ -256,7 +263,7 @@ func runCQLWithBundleDir(ctx context.Context, elm *cql.ELM, fhirBundleDir string
return err
}
if len(bundleFilePaths) == 0 {
fmt.Printf("no files found in FHIR bundle directory %s, exiting", fhirBundleDir)
fmt.Printf("no files found in FHIR bundle directory %s, exiting\n", fhirBundleDir)
return nil
}

Expand Down
20 changes: 16 additions & 4 deletions cmd/cli/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ func TestCLI(t *testing.T) {
fhirBundle string
fhirTerminology string
fhirParameters string
parameters string
returnPrivateDefs bool
executionTimestampOverride string
wantTestResult string
Expand All @@ -55,7 +56,7 @@ func TestCLI(t *testing.T) {
fhirBundle: `{"resourceType": "Bundle", "id": "example", "entry": []}`,
fhirTerminology: `{"resourceType": "ValueSet", "id": "https://test/emptyVS", "url": "https://test/emptyVS"}`,
fhirParameters: `{"resourceType": "Parameters", "id": "example", "parameter": []}`,
wantTestResult: `{"@type": "System.Boolean", "value": true}`,
wantTestResult: `"TESTRESULT": {"@type": "System.Boolean", "value": true}`,
},
{
name: "ReturnPrivateDefs is set and returned",
Expand All @@ -64,7 +65,7 @@ func TestCLI(t *testing.T) {
define private TESTRESULT: true`,
fhirBundle: `{"resourceType": "Bundle", "id": "example", "entry": []}`,
returnPrivateDefs: true,
wantTestResult: `{"@type": "System.Boolean", "value": true}`,
wantTestResult: `"TESTRESULT": {"@type": "System.Boolean", "value": true}`,
},
{
name: "Can override execution timestamp",
Expand All @@ -73,7 +74,17 @@ func TestCLI(t *testing.T) {
define TESTRESULT: Now()`,
fhirBundle: `{"resourceType": "Bundle", "id": "example", "entry": []}`,
executionTimestampOverride: "@2018-02-02T15:02:03.000-04:00",
wantTestResult: `{"@type": "System.DateTime","value": "@2018-02-02T15:02:03.000-04:00"}`,
wantTestResult: `"TESTRESULT": {"@type": "System.DateTime","value": "@2018-02-02T15:02:03.000-04:00"}`,
},
{
name: "Parameters passed without FHIR parameters file",
cql: `
library TESTLIB
parameter ParamString String default 'default'
define TESTRESULT: ParamString`,
fhirBundle: `{"resourceType": "Bundle", "id": "example", "entry": []}`,
parameters: "TESTLIB.ParamString='override'",
wantTestResult: `"ParamString": {"@type": "System.String", "value": "override"}, "TESTRESULT": {"@type": "System.String", "value": "override"}`,
},
}
for _, tc := range tests {
Expand Down Expand Up @@ -103,6 +114,7 @@ func TestCLI(t *testing.T) {
JSONOutputDir: testDirCfg.JSONOutputDir,
ReturnPrivateDefs: tc.returnPrivateDefs,
ExecutionTimestampOverride: tc.executionTimestampOverride,
Parameters: tc.parameters,
}
if tc.fhirTerminology != "" {
cfg.FHIRTerminologyDir = testDirCfg.FHIRTerminologyDir
Expand Down Expand Up @@ -137,7 +149,7 @@ func TestCLI(t *testing.T) {
"evalResults": [
{
"expressionDefinitions": {
"TESTRESULT": %s
%s
},
"libName": "TESTLIB",
"libVersion": ""
Expand Down
Loading