Documentation ¶
Overview ¶
Package jsonformat provides utility functions for FHIR proto conversion.
Index ¶
- func DenormalizeReference(pb proto.Message) error
- func NormalizeReference(pb proto.Message) error
- func SerializeInstant(instant proto.Message) (string, error)
- type ContainedResourceOrError
- type ExtensionError
- type Marshaller
- func NewAnalyticsMarshaller(maxDepth int, ver fhirversion.Version) (*Marshaller, error)
- func NewAnalyticsMarshallerWithInferredSchema(maxDepth int, ver fhirversion.Version) (*Marshaller, error)
- func NewAnalyticsV2MarshallerWithInferredSchema(maxDepth int, ver fhirversion.Version) (*Marshaller, error)
- func NewMarshaller(enableIndent bool, prefix, indent string, ver fhirversion.Version) (*Marshaller, error)
- func NewPrettyMarshaller(ver fhirversion.Version) (*Marshaller, error)
- func (m *Marshaller) Marshal(pb proto.Message) ([]byte, error)
- func (m *Marshaller) MarshalElement(pb proto.Message) ([]byte, error)
- func (m *Marshaller) MarshalResource(r proto.Message) ([]byte, error)
- func (m *Marshaller) MarshalResourceToString(r proto.Message) (string, error)
- func (m *Marshaller) MarshalToString(pb proto.Message) (string, error)
- type Unmarshaller
- func (u *Unmarshaller) Unmarshal(in []byte) (proto.Message, error)
- func (u *Unmarshaller) UnmarshalDSTU2(in []byte) (*rpb.ContainedResource, error)
- func (u *Unmarshaller) UnmarshalR3(in []byte) (*rpb.ContainedResource, error)
- func (u *Unmarshaller) UnmarshalR4(in []byte) (*rpb.ContainedResource, error)
- func (u *Unmarshaller) UnmarshalR4Streaming(in io.Reader) <-chan *ContainedResourceOrError
- func (u *Unmarshaller) UnmarshalWithErrorReporter(in []byte, er errorreporter.ErrorReporter) (proto.Message, error)
- func (u *Unmarshaller) UnmarshalWithOutcome(in []byte) (proto.Message, *errorreporter.MultiVersionOperationOutcome, error)
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DenormalizeReference ¶
DenormalizeReference recovers the absolute reference URI from a normalized representation.
func NormalizeReference ¶
NormalizeReference normalizes a relative or internal reference into its specialized field.
Types ¶
type ContainedResourceOrError ¶
type ContainedResourceOrError struct { ContainedResource *rpb.ContainedResource Error error }
ContainedResourceOrError holds a ContainedResource or an error as a single entity. If Error is set, that indicates there was an error unmarshaling this contained resource (and the error is propogated through from the underlying UnmarshalR4 call).
type ExtensionError ¶
type ExtensionError struct {
// contains filtered or unexported fields
}
ExtensionError is an error that occurs when the extension is invalid for the marshaller, such as when an extension has empty URL value. TODO: Use ErrorReporter for more robust special case handling.
func (*ExtensionError) Error ¶
func (e *ExtensionError) Error() string
type Marshaller ¶
type Marshaller struct {
// contains filtered or unexported fields
}
Marshaller is an object for serializing FHIR protocol buffer messages into a JSON object.
func NewAnalyticsMarshaller ¶
func NewAnalyticsMarshaller(maxDepth int, ver fhirversion.Version) (*Marshaller, error)
NewAnalyticsMarshaller returns an Analytics Marshaller with limited support for extensions. A default maxDepth of 2 will be used if the input is 0.
func NewAnalyticsMarshallerWithInferredSchema ¶
func NewAnalyticsMarshallerWithInferredSchema(maxDepth int, ver fhirversion.Version) (*Marshaller, error)
NewAnalyticsMarshallerWithInferredSchema returns an Analytics Marshaller with support for extensions as first class fields. A default maxDepth of 2 will be used if the input is 0.
func NewAnalyticsV2MarshallerWithInferredSchema ¶
func NewAnalyticsV2MarshallerWithInferredSchema(maxDepth int, ver fhirversion.Version) (*Marshaller, error)
NewAnalyticsV2MarshallerWithInferredSchema returns an Analytics Marshaller with support for extensions as first class fields. A default maxDepth of 2 will be used if the input is 0.
func NewMarshaller ¶
func NewMarshaller(enableIndent bool, prefix, indent string, ver fhirversion.Version) (*Marshaller, error)
NewMarshaller returns a Marshaller.
func NewPrettyMarshaller ¶
func NewPrettyMarshaller(ver fhirversion.Version) (*Marshaller, error)
NewPrettyMarshaller returns a pretty Marshaller.
func (*Marshaller) Marshal ¶
func (m *Marshaller) Marshal(pb proto.Message) ([]byte, error)
Marshal returns serialized JSON object of a ContainedResource protobuf message.
func (*Marshaller) MarshalElement ¶
func (m *Marshaller) MarshalElement(pb proto.Message) ([]byte, error)
MarshalElement marshals any FHIR complex value to JSON.
func (*Marshaller) MarshalResource ¶
func (m *Marshaller) MarshalResource(r proto.Message) ([]byte, error)
MarshalResource functions identically to Marshal, but accepts a fhir.Resource interface instead of a ContainedResource. This allows for reduced nesting in declaring messages, and does not require knowledge of the specific Resource type.
func (*Marshaller) MarshalResourceToString ¶
func (m *Marshaller) MarshalResourceToString(r proto.Message) (string, error)
MarshalResourceToString functions identically to MarshalToString, but accepts a fhir.Resource interface instead of a ContainedResource. See MarshalResource() for rationale.
func (*Marshaller) MarshalToString ¶
func (m *Marshaller) MarshalToString(pb proto.Message) (string, error)
MarshalToString returns serialized JSON object of a ContainedResource protobuf message as string.
type Unmarshaller ¶
type Unmarshaller struct { TimeZone *time.Location // MaxNestingDepth is the maximum number of levels a field can have. The unmarshaller will // return an error when a resource has a field exceeding this limit. If the value is negative // or 0, then the maximum nesting depth is unbounded. MaxNestingDepth int // contains filtered or unexported fields }
Unmarshaller is an object for converting a JSON object to protocol buffer.
func NewUnmarshaller ¶
func NewUnmarshaller(tz string, ver fhirversion.Version) (*Unmarshaller, error)
NewUnmarshaller returns an Unmarshaller that performs resource validation.
func NewUnmarshallerWithoutValidation ¶
func NewUnmarshallerWithoutValidation(tz string, ver fhirversion.Version) (*Unmarshaller, error)
NewUnmarshallerWithoutValidation returns an Unmarshaller that doesn't perform resource validation.
func (*Unmarshaller) Unmarshal ¶
func (u *Unmarshaller) Unmarshal(in []byte) (proto.Message, error)
Unmarshal a FHIR resource from JSON into a ContainedResource proto. The FHIR version of the proto is determined by the version the Unmarshaller was created with.
func (*Unmarshaller) UnmarshalDSTU2 ¶
func (u *Unmarshaller) UnmarshalDSTU2(in []byte) (*rpb.ContainedResource, error)
UnmarshalDSTU2 returns the corresponding protobuf message given a serialized FHIR JSON object
func (*Unmarshaller) UnmarshalR3 ¶
func (u *Unmarshaller) UnmarshalR3(in []byte) (*rpb.ContainedResource, error)
UnmarshalR3 returns the corresponding protobuf message given a serialized FHIR JSON object
func (*Unmarshaller) UnmarshalR4 ¶
func (u *Unmarshaller) UnmarshalR4(in []byte) (*rpb.ContainedResource, error)
UnmarshalR4 returns the corresponding protobuf message given a serialized FHIR JSON object
func (*Unmarshaller) UnmarshalR4Streaming ¶
func (u *Unmarshaller) UnmarshalR4Streaming(in io.Reader) <-chan *ContainedResourceOrError
UnmarshalR4Streaming reads FHIR NDJSON from the provided io.Reader and writes parsed ContainedResources (or an error) to the returned channel. When the input io.Reader is exhausted and there are no more messages to be parsed, the output channel will be closed.
Example ¶
json := `{"resourceType":"Patient", "id": "exampleID1"} {"resourceType":"Patient", "id": "exampleID2"}` u, err := NewUnmarshaller("America/Los_Angeles", fhirversion.R4) if err != nil { fmt.Println("error") } jsonReader := bytes.NewReader([]byte(json)) resourceChan := u.UnmarshalR4Streaming(jsonReader) for r := range resourceChan { if r.Error != nil { fmt.Printf("err: %v", r.Error) } else { fmt.Printf("%s\n", r.ContainedResource.GetPatient().Id.GetValue()) } }
Output: exampleID1 exampleID2
func (*Unmarshaller) UnmarshalWithErrorReporter ¶
func (u *Unmarshaller) UnmarshalWithErrorReporter(in []byte, er errorreporter.ErrorReporter) (proto.Message, error)
TODO: report parseContainedResource error with error reporter UnmarshalWithErrorReporter unmarshalls a FHIR resource from JSON into a ContainedResource proto. During the process, the validation errors are reported according to user defined error reporter. The FHIR version of the proto is determined by the version the Unmarshaller was created with.
func (*Unmarshaller) UnmarshalWithOutcome ¶
func (u *Unmarshaller) UnmarshalWithOutcome(in []byte) (proto.Message, *errorreporter.MultiVersionOperationOutcome, error)
UnmarshalWithOutcome unmarshalls a FHIR resource from JSON into a ContainedResource proto. During the process, the validation errors are reported according to the predefined OperationErrorReporter. The FHIR version of the proto is determined by the version the Unmarshaller was created with.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package errorreporter makes all validation errors visible to callers so they can report or handle them as appropriate for the surrounding system.
|
Package errorreporter makes all validation errors visible to callers so they can report or handle them as appropriate for the surrounding system. |
Package fhirvalidate performs additional validations on FHIR protos according to rules in the FHIR spec.
|
Package fhirvalidate performs additional validations on FHIR protos according to rules in the FHIR spec. |
internal
|
|
accessor
Package accessor contains the getter/setter functions to access reflected FHIR proto messages.
|
Package accessor contains the getter/setter functions to access reflected FHIR proto messages. |
jsonpbhelper
Package jsonpbhelper provides version agnostic utility functions for FHIR proto conversion.
|
Package jsonpbhelper provides version agnostic utility functions for FHIR proto conversion. |
protopath
Package protopath defines methods for getting and setting nested proto fields using selectors.
|
Package protopath defines methods for getting and setting nested proto fields using selectors. |