jsonformat

package
v0.7.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 10, 2022 License: Apache-2.0 Imports: 29 Imported by: 23

Documentation

Overview

Package jsonformat provides utility functions for FHIR proto conversion.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func DenormalizeReference

func DenormalizeReference(pb proto.Message) error

DenormalizeReference recovers the absolute reference URI from a normalized representation.

func NormalizeReference

func NormalizeReference(pb proto.Message) error

NormalizeReference normalizes a relative or internal reference into its specialized field.

func SerializeInstant

func SerializeInstant(instant proto.Message) (string, error)

SerializeInstant takes an Instant proto message and serializes it to a datetime string.

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) MarshalToJSONObject

func (m *Marshaller) MarshalToJSONObject(pb proto.Message) (jsonpbhelper.JSONObject, error)

MarshalToJSONObject returns the resource message as a JSON object, instead of marshalling the JSON data to a []byte. This can be useful if you need to modify the marshalled JSON data without needing to re-decode it.

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) UnmarshalFromReaderWithErrorReporter

func (u *Unmarshaller) UnmarshalFromReaderWithErrorReporter(in io.Reader, er errorreporter.ErrorReporter) (proto.Message, error)

UnmarshalFromReaderWithErrorReporter read FHIR data as JSON from an io.Reader and unmarshals it 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) 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)

UnmarshalWithErrorReporter unmarshals a FHIR resource from JSON []byte data 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.

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL