From 37cf632dc56953d42d1c15869c49e5fe3e7ccc02 Mon Sep 17 00:00:00 2001 From: Wout Slakhorst Date: Tue, 17 Dec 2019 15:29:02 +0100 Subject: [PATCH 1/3] Fixes #8 Signed-off-by: Wout Slakhorst --- api/api_test.go | 2 +- examples/observation_consent.json | 4 ++++ pkg/validation.go | 24 +++++++++++++++++++----- pkg/validation_test.go | 14 ++++++++++++++ 4 files changed, 38 insertions(+), 6 deletions(-) diff --git a/api/api_test.go b/api/api_test.go index 4e4d332..d05ada9 100644 --- a/api/api_test.go +++ b/api/api_test.go @@ -96,7 +96,7 @@ func validationResult() ValidationResponse { Consent: &SimplifiedConsent{ Actors: []Identifier{"urn:oid:2.16.840.1.113883.2.4.6.1:00000007"}, Custodian: Identifier("urn:oid:2.16.840.1.113883.2.4.6.1:00000000"), - Resources: []string{"Observation"}, + Resources: []string{"http://hl7.org/fhir/resource-types#Observation","urn:oid:1.3.6.1.4.1.54851.1:MEDICAL"}, Subject: Identifier("urn:oid:2.16.840.1.113883.2.4.6.3:999999990"), }, Outcome: "valid", diff --git a/examples/observation_consent.json b/examples/observation_consent.json index 322aeca..fee1925 100644 --- a/examples/observation_consent.json +++ b/examples/observation_consent.json @@ -108,6 +108,10 @@ { "system": "http://hl7.org/fhir/resource-types", "code": "Observation" + }, + { + "system": "urn:oid:1.3.6.1.4.1.54851.1", + "code": "MEDICAL" } ] } diff --git a/pkg/validation.go b/pkg/validation.go index 5f3f4a5..10f5a88 100644 --- a/pkg/validation.go +++ b/pkg/validation.go @@ -25,6 +25,7 @@ import ( "github.com/sirupsen/logrus" "github.com/xeipuuv/gojsonschema" "gopkg.in/thedevsaddam/gojsonq.v2" + "strings" "sync" "time" ) @@ -61,9 +62,10 @@ func ValidatorInstance() *Validator { return instance } -// ResourcesFrom extracts the consent resources from some fhir json -func ResourcesFrom(jsonq *gojsonq.JSONQ) []string { - var resources []string +// DataClassesFrom extracts the consent provision classes from some fhir json, replaces ResourcesFrom +// It combines the system and code field to a single string using the correct divider (: or #) based on the type of system +func DataClassesFrom(jsonq *gojsonq.JSONQ) []string { + var dataClasses []string listOfClasses := jsonq.Copy().From("provision.provision").Pluck("class").([]interface{}) // lists of lists @@ -71,10 +73,22 @@ func ResourcesFrom(jsonq *gojsonq.JSONQ) []string { cls := classList.([]interface{}) for _, cl := range cls { clMap := cl.(map[string]interface{}) - resources = append(resources, fmt.Sprintf("%s", clMap["code"])) + system := clMap["system"].(string) + divider := "#" + + if strings.Index(system, "urn:oid") != -1 { + divider = ":" + } + + dataClasses = append(dataClasses, fmt.Sprintf("%s%s%s", clMap["system"], divider, clMap["code"])) } } - return resources + return dataClasses +} + +// ResourcesFrom extracts the consent resources from some fhir json, deprecated, replaced by DataClassesFrom +func ResourcesFrom(jsonq *gojsonq.JSONQ) []string { + return DataClassesFrom(jsonq) } // ActorsFrom extracts the consent actors from some fhir json diff --git a/pkg/validation_test.go b/pkg/validation_test.go index 4828cfd..2d2b277 100644 --- a/pkg/validation_test.go +++ b/pkg/validation_test.go @@ -88,6 +88,20 @@ func validationBackend() Validator { return client } +func TestResourcesFrom(t *testing.T) { + bytes, _ := ioutil.ReadFile("../examples/observation_consent.json") + jsonq := gojsonq.New().JSONString(string(bytes)) + dataClasses := ResourcesFrom(jsonq) + + t.Run("with namespace", func(t *testing.T) { + assert.Equal(t, "http://hl7.org/fhir/resource-types#Observation", dataClasses[0]) + }) + + t.Run("with urn", func(t *testing.T) { + assert.Equal(t, "urn:oid:1.3.6.1.4.1.54851.1:MEDICAL", dataClasses[1]) + }) +} + func TestPeriodFrom(t *testing.T) { //"start": "2016-06-23T17:02:33+10:00", //"end": "2016-06-23T17:32:33+10:00" From db234edba83f54ce8b66113e9eb0455c6afcb495 Mon Sep 17 00:00:00 2001 From: Wout Slakhorst Date: Mon, 6 Jan 2020 13:16:17 +0100 Subject: [PATCH 2/3] changed oids in test files to use constant Signed-off-by: Wout Slakhorst --- api/api_test.go | 11 +++++++---- go.mod | 2 +- go.sum | 2 ++ pkg/validation_test.go | 11 +++++++---- 4 files changed, 17 insertions(+), 9 deletions(-) diff --git a/api/api_test.go b/api/api_test.go index d05ada9..7548ca7 100644 --- a/api/api_test.go +++ b/api/api_test.go @@ -21,12 +21,15 @@ package api import ( "bytes" - "github.com/golang/mock/gomock" - "github.com/nuts-foundation/nuts-fhir-validation/pkg" - "github.com/nuts-foundation/nuts-go-core/mock" + "fmt" "io/ioutil" "net/http" "testing" + + "github.com/golang/mock/gomock" + "github.com/nuts-foundation/nuts-fhir-validation/pkg" + core "github.com/nuts-foundation/nuts-go-core" + "github.com/nuts-foundation/nuts-go-core/mock" ) func TestDefaultValidationBackend_Validate(t *testing.T) { @@ -96,7 +99,7 @@ func validationResult() ValidationResponse { Consent: &SimplifiedConsent{ Actors: []Identifier{"urn:oid:2.16.840.1.113883.2.4.6.1:00000007"}, Custodian: Identifier("urn:oid:2.16.840.1.113883.2.4.6.1:00000000"), - Resources: []string{"http://hl7.org/fhir/resource-types#Observation","urn:oid:1.3.6.1.4.1.54851.1:MEDICAL"}, + Resources: []string{"http://hl7.org/fhir/resource-types#Observation", fmt.Sprintf("%s:MEDICAL", core.NutsConsentClassesOID)}, Subject: Identifier("urn:oid:2.16.840.1.113883.2.4.6.3:999999990"), }, Outcome: "valid", diff --git a/go.mod b/go.mod index c3b96e3..76e9e63 100644 --- a/go.mod +++ b/go.mod @@ -11,7 +11,7 @@ require ( github.com/magiconair/properties v1.8.1 // indirect github.com/mattn/go-colorable v0.1.4 // indirect github.com/mattn/go-isatty v0.0.10 // indirect - github.com/nuts-foundation/nuts-go-core v0.0.0-20191028170600-66675906a53a + github.com/nuts-foundation/nuts-go-core v0.0.0-20191218133145-27ebcf628fab github.com/pelletier/go-toml v1.5.0 // indirect github.com/sirupsen/logrus v1.4.2 github.com/spf13/cobra v0.0.5 diff --git a/go.sum b/go.sum index f416a7e..1bbc5a0 100644 --- a/go.sum +++ b/go.sum @@ -97,6 +97,8 @@ github.com/nuts-foundation/nuts-go-core v0.0.0-20191014142450-dd0fd3a25ffb h1:Sd github.com/nuts-foundation/nuts-go-core v0.0.0-20191014142450-dd0fd3a25ffb/go.mod h1:tPPkfE9y+T+jTc8klZ0B8FXtc23p9NIpg5BjI+FIiEs= github.com/nuts-foundation/nuts-go-core v0.0.0-20191028170600-66675906a53a h1:0r1YHKAMSiP6yFy322lNclOU53LVfdkuRFsdQBJ/NU0= github.com/nuts-foundation/nuts-go-core v0.0.0-20191028170600-66675906a53a/go.mod h1:+IeGzu5J8qlF4Jcol+mY+MRcLDIfJ8OQnQV4wDp887o= +github.com/nuts-foundation/nuts-go-core v0.0.0-20191218133145-27ebcf628fab h1:Dxjdaw+HToUVmh2H1/pg+BFNzNWm72bqVlA3LqcCiGs= +github.com/nuts-foundation/nuts-go-core v0.0.0-20191218133145-27ebcf628fab/go.mod h1:+IeGzu5J8qlF4Jcol+mY+MRcLDIfJ8OQnQV4wDp887o= github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U= github.com/pelletier/go-toml v1.2.0 h1:T5zMGML61Wp+FlcbWjRDT7yAxhJNAiPPLOFECq181zc= github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic= diff --git a/pkg/validation_test.go b/pkg/validation_test.go index 2d2b277..fee46a2 100644 --- a/pkg/validation_test.go +++ b/pkg/validation_test.go @@ -20,11 +20,14 @@ package pkg import ( - "github.com/stretchr/testify/assert" - "gopkg.in/thedevsaddam/gojsonq.v2" + "fmt" "io/ioutil" "testing" "time" + + core "github.com/nuts-foundation/nuts-go-core" + "github.com/stretchr/testify/assert" + "gopkg.in/thedevsaddam/gojsonq.v2" ) func TestDefaultValidationBackend_ValidateAgainstSchema(t *testing.T) { @@ -98,7 +101,7 @@ func TestResourcesFrom(t *testing.T) { }) t.Run("with urn", func(t *testing.T) { - assert.Equal(t, "urn:oid:1.3.6.1.4.1.54851.1:MEDICAL", dataClasses[1]) + assert.Equal(t, fmt.Sprintf("%s:MEDICAL", core.NutsConsentClassesOID), dataClasses[1]) }) } @@ -121,4 +124,4 @@ func TestVersionFrom(t *testing.T) { jsonq := gojsonq.New().JSONString(string(bytes)) assert.Equal(t, "1", VersionFrom(jsonq)) -} \ No newline at end of file +} From ab68c25c1b21a463dfdeeac7b015cb115ce76a76 Mon Sep 17 00:00:00 2001 From: Wout Slakhorst Date: Mon, 6 Jan 2020 13:27:42 +0100 Subject: [PATCH 3/3] forgot urn part Signed-off-by: Wout Slakhorst --- api/api_test.go | 2 +- pkg/validation_test.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/api/api_test.go b/api/api_test.go index 7548ca7..45c5a02 100644 --- a/api/api_test.go +++ b/api/api_test.go @@ -99,7 +99,7 @@ func validationResult() ValidationResponse { Consent: &SimplifiedConsent{ Actors: []Identifier{"urn:oid:2.16.840.1.113883.2.4.6.1:00000007"}, Custodian: Identifier("urn:oid:2.16.840.1.113883.2.4.6.1:00000000"), - Resources: []string{"http://hl7.org/fhir/resource-types#Observation", fmt.Sprintf("%s:MEDICAL", core.NutsConsentClassesOID)}, + Resources: []string{"http://hl7.org/fhir/resource-types#Observation", fmt.Sprintf("urn:oid:%s:MEDICAL", core.NutsConsentClassesOID)}, Subject: Identifier("urn:oid:2.16.840.1.113883.2.4.6.3:999999990"), }, Outcome: "valid", diff --git a/pkg/validation_test.go b/pkg/validation_test.go index fee46a2..b15ff4e 100644 --- a/pkg/validation_test.go +++ b/pkg/validation_test.go @@ -101,7 +101,7 @@ func TestResourcesFrom(t *testing.T) { }) t.Run("with urn", func(t *testing.T) { - assert.Equal(t, fmt.Sprintf("%s:MEDICAL", core.NutsConsentClassesOID), dataClasses[1]) + assert.Equal(t, fmt.Sprintf("urn:oid:%s:MEDICAL", core.NutsConsentClassesOID), dataClasses[1]) }) }