Skip to content
This repository has been archived by the owner on Oct 3, 2022. It is now read-only.

Commit

Permalink
Fixes #8
Browse files Browse the repository at this point in the history
Signed-off-by: Wout Slakhorst <wout.slakhorst@nedap.com>
  • Loading branch information
woutslakhorst committed Dec 17, 2019
1 parent 5322dfe commit 37cf632
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 6 deletions.
2 changes: 1 addition & 1 deletion api/api_test.go
Expand Up @@ -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",
Expand Down
4 changes: 4 additions & 0 deletions examples/observation_consent.json
Expand Up @@ -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"
}
]
}
Expand Down
24 changes: 19 additions & 5 deletions pkg/validation.go
Expand Up @@ -25,6 +25,7 @@ import (
"github.com/sirupsen/logrus"
"github.com/xeipuuv/gojsonschema"
"gopkg.in/thedevsaddam/gojsonq.v2"
"strings"
"sync"
"time"
)
Expand Down Expand Up @@ -61,20 +62,33 @@ 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
for _, classList := range listOfClasses {
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
Expand Down
14 changes: 14 additions & 0 deletions pkg/validation_test.go
Expand Up @@ -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"
Expand Down

0 comments on commit 37cf632

Please sign in to comment.