diff --git a/generator/cmd/generate_elements.go b/generator/cmd/generate_elements.go index 43e4d2c..27430d5 100644 --- a/generator/cmd/generate_elements.go +++ b/generator/cmd/generate_elements.go @@ -4,7 +4,7 @@ import ( "fmt" "github.com/dave/jennifer/jen" - "github.com/ivido/go-fhir/generator/fhir" + "github.com/formelio/go-fhir/generator/fhir" ) func generateElements(alreadyGeneratedTypes, typesToGenerate map[string]bool) error { diff --git a/generator/cmd/generate_fields.go b/generator/cmd/generate_fields.go index 5883de0..c519ef8 100644 --- a/generator/cmd/generate_fields.go +++ b/generator/cmd/generate_fields.go @@ -7,7 +7,7 @@ import ( "unicode" "github.com/dave/jennifer/jen" - "github.com/ivido/go-fhir/generator/fhir" + "github.com/formelio/go-fhir/generator/fhir" ) type FieldType int diff --git a/generator/cmd/generate_resources.go b/generator/cmd/generate_resources.go index 4792233..51813b8 100644 --- a/generator/cmd/generate_resources.go +++ b/generator/cmd/generate_resources.go @@ -5,7 +5,7 @@ import ( "os" "github.com/dave/jennifer/jen" - "github.com/ivido/go-fhir/generator/fhir" + "github.com/formelio/go-fhir/generator/fhir" ) func generateResources() { diff --git a/generator/cmd/generate_util.go b/generator/cmd/generate_util.go index 577d4b4..61f4733 100644 --- a/generator/cmd/generate_util.go +++ b/generator/cmd/generate_util.go @@ -4,14 +4,15 @@ import ( "fmt" "github.com/dave/jennifer/jen" - "github.com/ivido/go-fhir/generator/fhir" + "github.com/formelio/go-fhir/generator/fhir" ) /* // is documented here " -type struct { - ..fields -} + + type struct { + ..fields + } */ func generateStruct(file *jen.File, definition fhir.StructureDefinition, elementDefinitions []fhir.ElementDefinition, requiredElements map[string]bool) ([]string, error) { var err error @@ -25,34 +26,35 @@ func generateStruct(file *jen.File, definition fhir.StructureDefinition, element /* // MarshalJSON marshals the given as JSON into a byte slice -func (r ) MarshalJSON() ([]byte, error) { - IF(HAS_CONTAINED): - ------------------ - // If the field has contained resources, we need to marshal them individually and store them in RawContained - if len(r.Contained) > 0 { - r.RawContained = make([]json.RawMessage, len(r.Contained)) - var err error - for i, contained := range r.Contained { - r.RawContained[i], err = json.Marshal(contained) - if err != nil { - return nil, err + + func (r ) MarshalJSON() ([]byte, error) { + IF(HAS_CONTAINED): + ------------------ + // If the field has contained resources, we need to marshal them individually and store them in RawContained + if len(r.Contained) > 0 { + r.RawContained = make([]json.RawMessage, len(r.Contained)) + var err error + for i, contained := range r.Contained { + r.RawContained[i], err = json.Marshal(contained) + if err != nil { + return nil, err + } } } - } - ------------------ + ------------------ - buffer := bytes.NewBuffer([]byte{}) - jsonEncoder := json.NewEncoder(buffer) - jsonEncoder.SetEscapeHTML(false) - err := jsonEncoder.Encode(struct { - ResourceType string `json:"resourceType"` - Other - }{ - Other: Other(r), - ResourceType: "", - }) - return buffer.Bytes(), err -} + buffer := bytes.NewBuffer([]byte{}) + jsonEncoder := json.NewEncoder(buffer) + jsonEncoder.SetEscapeHTML(false) + err := jsonEncoder.Encode(struct { + ResourceType string `json:"resourceType"` + Other + }{ + Other: Other(r), + ResourceType: "", + }) + return buffer.Bytes(), err + } */ func generateResourceMarshal(file *jen.File, resourceType string, hasContained bool) { file.Commentf("MarshalJSON marshals the given %s as JSON into a byte slice", resourceType) @@ -84,23 +86,23 @@ func generateResourceMarshal(file *jen.File, resourceType string, hasContained b } /* -func (r *) UnmarshalJSON(data []byte) error { - if err := json.Unmarshal(data, (*Other)(r)); err != nil { - return err - } - if len(r.RawContained) > 0 { - var err error - r.Contained = make([]IResource, len(r.RawContained)) - for i, rawContained := range r.RawContained { - r.Contained[i], err = UnmarshalResource(rawContained) - if err != nil { - return err + func (r *) UnmarshalJSON(data []byte) error { + if err := json.Unmarshal(data, (*Other)(r)); err != nil { + return err + } + if len(r.RawContained) > 0 { + var err error + r.Contained = make([]IResource, len(r.RawContained)) + for i, rawContained := range r.RawContained { + r.Contained[i], err = UnmarshalResource(rawContained) + if err != nil { + return err + } } } + r.RawContained = nil + return nil } - r.RawContained = nil - return nil -} */ func generateResourceUnmarshal(file *jen.File, resourceType string, hasContained bool) { file.Commentf("UnmarshalJSON unmarshals the given byte slice into %s", resourceType) @@ -124,7 +126,9 @@ func generateResourceUnmarshal(file *jen.File, resourceType string, hasContained }) } -/* generates the json tags for the field +/* + generates the json tags for the field + `bson:",omitempty" json:",omitempty"` */ func generateTags(statement *jen.Statement, jsonTag string) { @@ -143,9 +147,10 @@ func generateOperators(statement *jen.Statement, list, required bool) { /* // Returns the resourceType of the resource, makes this resource an instance of IResource -func (r ) GetResourceType() ResourceType { - return ResourceType) GetResourceType() ResourceType { + return ResourceType) MarshalJSON() ([]byte, error) { - if . != nil { - r, err := json.Marshal(.) - if err != nil { - return nil, err + func (r *) MarshalJSON() ([]byte, error) { + if . != nil { + r, err := json.Marshal(.) + if err != nil { + return nil, err + } + .Raw = r } - .Raw = r + return json.Marshal((*Other)()) } - return json.Marshal((*Other)()) -} */ func generateElementMarshal(file *jen.File, resourceFields []string, typeIdentifier string) { file.Func().Params(jen.Id("r").Op("*").Id(typeIdentifier)).Id("MarshalJSON").Params().Params(jen.Op("[]").Byte(), jen.Error()).BlockFunc(func(marshal *jen.Group) { diff --git a/generator/cmd/generate_valueSets.go b/generator/cmd/generate_valueSets.go index 97bf11f..64c69b0 100644 --- a/generator/cmd/generate_valueSets.go +++ b/generator/cmd/generate_valueSets.go @@ -7,7 +7,7 @@ import ( "strings" "github.com/dave/jennifer/jen" - "github.com/ivido/go-fhir/generator/fhir" + "github.com/formelio/go-fhir/generator/fhir" ) func generateValueSets() { diff --git a/generator/cmd/read_sources.go b/generator/cmd/read_sources.go index ab208e4..b5674fb 100644 --- a/generator/cmd/read_sources.go +++ b/generator/cmd/read_sources.go @@ -7,7 +7,7 @@ import ( "path/filepath" "strings" - "github.com/ivido/go-fhir/generator/fhir" + "github.com/formelio/go-fhir/generator/fhir" ) func readSourcesToContext(dir string) { diff --git a/generator/main.go b/generator/main.go index db05e78..ee3a63e 100644 --- a/generator/main.go +++ b/generator/main.go @@ -1,6 +1,6 @@ package main -import "github.com/ivido/go-fhir/generator/cmd" +import "github.com/formelio/go-fhir/generator/cmd" func main() { cmd.Execute()