jsonformat

package
v0.6.3 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2020 License: Apache-2.0 Imports: 30 Imported by: 0

Documentation

Overview

Package jsonformat provides utility functions for FHIR proto conversion.

Index

Examples

Constants

View Source
const (
	STU3 = Version("STU3")
	R4   = Version("R4")
)

FHIR converter versions.

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 ParseDateTimeFromJSON

func ParseDateTimeFromJSON(rm json.RawMessage, l *time.Location, m proto.Message) error

ParseDateTimeFromJSON parses a FHIR date string into a DateTime proto, m.

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 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 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 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 NewMarshaller

func NewMarshaller(enableIndent bool, prefix, indent string, ver Version) (*Marshaller, error)

NewMarshaller returns a Marshaller.

func NewPrettyMarshaller

func NewPrettyMarshaller(ver 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) 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 Version) (*Unmarshaller, error)

NewUnmarshaller returns an Unmarshaller that performs resource validation.

func NewUnmarshallerWithoutValidation

func NewUnmarshallerWithoutValidation(tz string, ver 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 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", 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

type Version

type Version string

A Version is a version of the FHIR standard.

func (Version) String

func (v Version) String() string

String returns the Version as a string.

Directories

Path Synopsis
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