Skip to content

Commit e8fdc0f

Browse files
committed
make sure that we can access ContainedResources after parsing resource
When unmarshalling codes, if the valueset only contains lowercase codes, attempt to lowercase the input and make it case insensitive (Some EHRs screw this up -- epic).
1 parent 38d9e54 commit e8fdc0f

File tree

6 files changed

+44
-6
lines changed

6 files changed

+44
-6
lines changed

cmd/root.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import (
2323
// rootCmd represents the base command when called without any subcommands
2424
var rootCmd = &cobra.Command{
2525
Use: "gofhir-models-gen",
26-
Version: "0.0.11",
26+
Version: "0.0.12",
2727
}
2828

2929
// Execute adds all child commands to the root command and sets flags appropriately.

cmd/valueSet.go

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,22 @@ func generateValueSet(resources ResourceMap, valueSet fhir.ValueSet) (*jen.File,
6666
Id("UnmarshalJSON").
6767
Params(jen.Id("json").Op("[]").Byte()).
6868
Error().
69-
Block(
70-
jen.Id("s").Op(":=").Qual("strings", "Trim").Call(jen.String().Call(jen.Id("json")), jen.Lit(`"`)),
71-
jen.Switch(jen.Id("s")).BlockFunc(unmarshalRoot(*valueSet.Name, codeSystem.Concept)),
72-
jen.Return(jen.Nil()),
73-
)
69+
BlockFunc(func(group *jen.Group) {
70+
//check if all codes are lowercase
71+
requireLowercase := true
72+
for _, concept := range codeSystem.Concept {
73+
if !isLowerCase(concept.Code) {
74+
requireLowercase = false
75+
}
76+
}
77+
78+
group.Id("s").Op(":=").Qual("strings", "Trim").Call(jen.String().Call(jen.Id("json")), jen.Lit(`"`))
79+
if requireLowercase {
80+
group.Id("s").Op("=").Qual("strings", "ToLower").Call(jen.Id("s"))
81+
}
82+
group.Switch(jen.Id("s")).BlockFunc(unmarshalRoot(*valueSet.Name, codeSystem.Concept))
83+
group.Return(jen.Nil())
84+
})
7485

7586
// String function
7687
file.Func().
@@ -224,3 +235,7 @@ func definitions(valueSetName string, concepts []fhir.CodeSystemConcept) func(gr
224235
}
225236
}
226237
}
238+
239+
func isLowerCase(s string) bool {
240+
return s == strings.ToLower(s)
241+
}

fhir/bundle.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,11 @@ func (r Bundle) ResourceRef() (string, *string) {
103103
return "Bundle", r.Id
104104
}
105105

106+
// This function returns resource reference information
107+
func (r Bundle) ContainedResources() []json.RawMessage {
108+
return nil
109+
}
110+
106111
type OtherBundle Bundle
107112

108113
// MarshalJSON marshals the given Bundle as JSON into a byte slice

fhir/codeSystem.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ type CodeSystem struct {
2727
ImplicitRules *string `bson:"implicitRules,omitempty" json:"implicitRules,omitempty"`
2828
Language *string `bson:"language,omitempty" json:"language,omitempty"`
2929
Text *Narrative `bson:"text,omitempty" json:"text,omitempty"`
30+
Contained []json.RawMessage `bson:"contained,omitempty" json:"contained,omitempty"`
3031
Extension []Extension `bson:"extension,omitempty" json:"extension,omitempty"`
3132
ModifierExtension []Extension `bson:"modifierExtension,omitempty" json:"modifierExtension,omitempty"`
3233
Url *string `bson:"url,omitempty" json:"url,omitempty"`
@@ -125,6 +126,11 @@ func (r CodeSystem) ResourceRef() (string, *string) {
125126
return "CodeSystem", r.Id
126127
}
127128

129+
// This function returns resource reference information
130+
func (r CodeSystem) ContainedResources() []json.RawMessage {
131+
return r.Contained
132+
}
133+
128134
type OtherCodeSystem CodeSystem
129135

130136
// MarshalJSON marshals the given CodeSystem as JSON into a byte slice

fhir/structureDefinition.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ type StructureDefinition struct {
2727
ImplicitRules *string `bson:"implicitRules,omitempty" json:"implicitRules,omitempty"`
2828
Language *string `bson:"language,omitempty" json:"language,omitempty"`
2929
Text *Narrative `bson:"text,omitempty" json:"text,omitempty"`
30+
Contained []json.RawMessage `bson:"contained,omitempty" json:"contained,omitempty"`
3031
Extension []Extension `bson:"extension,omitempty" json:"extension,omitempty"`
3132
ModifierExtension []Extension `bson:"modifierExtension,omitempty" json:"modifierExtension,omitempty"`
3233
Url string `bson:"url" json:"url"`
@@ -99,6 +100,11 @@ func (r StructureDefinition) ResourceRef() (string, *string) {
99100
return "StructureDefinition", r.Id
100101
}
101102

103+
// This function returns resource reference information
104+
func (r StructureDefinition) ContainedResources() []json.RawMessage {
105+
return r.Contained
106+
}
107+
102108
type OtherStructureDefinition StructureDefinition
103109

104110
// MarshalJSON marshals the given StructureDefinition as JSON into a byte slice

fhir/valueSet.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ type ValueSet struct {
2727
ImplicitRules *string `bson:"implicitRules,omitempty" json:"implicitRules,omitempty"`
2828
Language *string `bson:"language,omitempty" json:"language,omitempty"`
2929
Text *Narrative `bson:"text,omitempty" json:"text,omitempty"`
30+
Contained []json.RawMessage `bson:"contained,omitempty" json:"contained,omitempty"`
3031
Extension []Extension `bson:"extension,omitempty" json:"extension,omitempty"`
3132
ModifierExtension []Extension `bson:"modifierExtension,omitempty" json:"modifierExtension,omitempty"`
3233
Url *string `bson:"url,omitempty" json:"url,omitempty"`
@@ -160,6 +161,11 @@ func (r ValueSet) ResourceRef() (string, *string) {
160161
return "ValueSet", r.Id
161162
}
162163

164+
// This function returns resource reference information
165+
func (r ValueSet) ContainedResources() []json.RawMessage {
166+
return r.Contained
167+
}
168+
163169
type OtherValueSet ValueSet
164170

165171
// MarshalJSON marshals the given ValueSet as JSON into a byte slice

0 commit comments

Comments
 (0)