diff --git a/fixtures/condition_with_contained_patient.json b/fixtures/condition_with_contained_patient.json index 51aebe7a..311410a0 100644 --- a/fixtures/condition_with_contained_patient.json +++ b/fixtures/condition_with_contained_patient.json @@ -15,6 +15,9 @@ }], "gender": "male", "birthDate": "1950-09-02", + "managingOrganization": { + "reference": "Organization/1" + }, "extension":[ { "url":"http://hl7.org/fhir/StructureDefinition/us-core-race", diff --git a/models/domainresource.go b/models/domainresource.go index b3a62609..902deed1 100644 --- a/models/domainresource.go +++ b/models/domainresource.go @@ -26,10 +26,34 @@ package models +import ( + "gopkg.in/mgo.v2/bson" +) + +type ContainedResources []interface{} + type DomainResource struct { Resource `bson:",inline"` - Text *Narrative `bson:"text,omitempty" json:"text,omitempty"` - Contained []interface{} `bson:"contained,omitempty" json:"contained,omitempty"` - Extension []Extension `bson:"extension,omitempty" json:"extension,omitempty"` - ModifierExtension []Extension `bson:"modifierExtension,omitempty" json:"modifierExtension,omitempty"` + Text *Narrative `bson:"text,omitempty" json:"text,omitempty"` + Contained ContainedResources `bson:"contained,omitempty" json:"contained,omitempty"` + Extension []Extension `bson:"extension,omitempty" json:"extension,omitempty"` + ModifierExtension []Extension `bson:"modifierExtension,omitempty" json:"modifierExtension,omitempty"` +} + +// Convert contained resources from map[string]interfac{} to specific types. +// Custom marshalling methods on those types will then hide internal fields +// like @context and referenceid. +func (x *ContainedResources) SetBSON(raw bson.Raw) (err error) { + + // alias type to avoid infinite loop when calling Unmarshal + type containedResources ContainedResources + x2 := (*containedResources)(x) + if err = raw.Unmarshal(x2); err == nil { + if x != nil { + for i := range *x { + (*x)[i] = BSONMapToResource((*x)[i].(bson.M), true) + } + } + } + return } diff --git a/server/resource_controller.go b/server/resource_controller.go index be0edb80..1a236913 100644 --- a/server/resource_controller.go +++ b/server/resource_controller.go @@ -291,9 +291,6 @@ func (u CustomJSONRenderer) Render(w http.ResponseWriter) (err error) { data = bytes.Replace(data, []byte("\\u003e"), []byte(">"), -1) data = bytes.Replace(data, []byte("\\u0026"), []byte("&"), -1) - // Convert "_id" to "id" - data = bytes.Replace(data, []byte("\"_id\":"), []byte("\"id\":"), -1) - writeContentType(w, fhirJSONContentType) _, err = w.Write(data) return