Documentation
¶
Overview ¶
Package jsonpbhelper provides version agnostic utility functions for FHIR proto conversion.
Index ¶
- Constants
- Variables
- func AddInternalExtension(pb, ext proto.Message) error
- func CamelToSnake(camelCase string) string
- func ExtensionFieldName(url string) string
- func ExtensionHasURL(pb proto.Message, url string) bool
- func ExtensionURL(pb protoreflect.Message) (string, error)
- func ExtensionValue(pb protoreflect.Message) (protoreflect.Message, error)
- func ExtractTimezone(t time.Time) string
- func ExtractTimezoneFromLoc(tz *time.Location) string
- func FieldMap(desc protoreflect.MessageDescriptor) map[string]protoreflect.FieldDescriptor
- func GetExtensionFieldDesc(d protoreflect.MessageDescriptor) (protoreflect.FieldDescriptor, error)
- func GetField(d protoreflect.MessageDescriptor, f string) protoreflect.FieldDescriptor
- func GetInternalExtension(pb, ext proto.Message) (proto.Message, error)
- func GetLocation(tz string) (*time.Location, error)
- func GetOneofField(messageType protoreflect.MessageDescriptor, ...) (protoreflect.FieldDescriptor, error)
- func GetTimeFromUsec(us int64, tz string) (time.Time, error)
- func GetTimestampUsec(t time.Time) int64
- func HasInternalExtension(pb, ext proto.Message) bool
- func InternalExtensionURL(desc protoreflect.MessageDescriptor) (string, error)
- func IsChoice(d protoreflect.MessageDescriptor) bool
- func IsPrimitiveType(d protoreflect.MessageDescriptor) bool
- func IsResourceType(d protoreflect.MessageDescriptor) bool
- func IsSubmilli(s string) bool
- func IsSubmilliTime(s string) bool
- func IsSubsecond(s string) bool
- func IsSubsecondTime(s string) bool
- func ReferenceFieldForType(resType string) (protoreflect.Name, bool)
- func RemoveInternalExtension(pb, ext proto.Message) error
- func ResourceIDField(ref protoreflect.Message) (protoreflect.FieldDescriptor, error)
- func ResourceTypeForReference(resField protoreflect.Name) (string, bool)
- func SerializeTime(us int64, precision Precision) (string, error)
- func SnakeToCamel(snakeCase string) string
- func SnakeToLowerCamel(s string) string
- func UnmarshalCode(jsonPath string, in protoreflect.Message, rm json.RawMessage) (proto.Message, error)
- func ValidateReferenceType(msgField protoreflect.FieldDescriptor, ref protoreflect.Message) error
- func ValidateRequiredFields(pb protoreflect.Message) error
- func ValidateString(s string) error
- type IsJSON
- type JSONArray
- type JSONObject
- type JSONRawValue
- type JSONString
- type Precision
- type Time
- type UnmarshalError
Constants ¶
const ( // SecondToMicro records the conversion between second and microsecond. SecondToMicro = int64(time.Second) / int64(time.Microsecond) // MicroToNano records the conversion between microsecond and nanosecond. MicroToNano = int64(time.Microsecond) // UTC represents the UTC timezone string. UTC = "Z" // DefaultAnalyticsRecurExpansionDepth indicates the default max depth for recursive expansion // in marshalling to analytics schema. DefaultAnalyticsRecurExpansionDepth = 2 // LayoutYear for year layout. LayoutYear = "2006" // LayoutMonth for month layout. LayoutMonth = "2006-01" // LayoutDay for day layout. LayoutDay = "2006-01-02" // LayoutSeconds for second layout. LayoutSeconds = "2006-01-02T15:04:05-07:00" // LayoutMillis for millisecond layout. LayoutMillis = "2006-01-02T15:04:05.000-07:00" // LayoutMicros for microsecond layout. LayoutMicros = "2006-01-02T15:04:05.000000-07:00" // LayoutSecondsUTC for second layout plus UTC. LayoutSecondsUTC = "2006-01-02T15:04:05Z" // LayoutMillisUTC for millisecond layout plus UTC. LayoutMillisUTC = "2006-01-02T15:04:05.000Z" // LayoutMicrosUTC for microsecond layout plus UTC. LayoutMicrosUTC = "2006-01-02T15:04:05.000000Z" // LayoutTimeSecond for time layout. LayoutTimeSecond = "15:04:05" // LayoutTimeMilliSecond for millisecond time layout. LayoutTimeMilliSecond = "15:04:05.000" // LayoutTimeMicroSecond for microsecond time layout. LayoutTimeMicroSecond = "15:04:05.000000" // MidnightTimeStr for midnight time string. MidnightTimeStr = "00:00:00" // RefOneofName for oneof reference name. RefOneofName = "reference" // RefFieldSuffix for reference field suffix. RefFieldSuffix = "_id" // RefFragment for reference fragment. RefFragment = "fragment" // RefFragmentPrefix for reference fragment prefix. RefFragmentPrefix = "#" // RefHistory for reference history. RefHistory = "_history" // RefRawURI for reference raw URI. RefRawURI = "uri" // RefAnyResource is the reference ID type name that fits any FHIR resources. RefAnyResource = "Resource" )
const ( // ContainedField is the JSON field name of inline resources. ContainedField = "contained" // ResourceTypeField constant. ResourceTypeField = "resourceType" // OneofName field constant. OneofName = "oneof_resource" // Extension field constant. Extension = "extension" )
Variables ¶
var ( // DateCompiledRegex for date regex. DateCompiledRegex *regexp.Regexp // DateTimeCompiledRegex for datetime regex. DateTimeCompiledRegex *regexp.Regexp // TimeCompiledRegex for time regex. TimeCompiledRegex *regexp.Regexp // InstantCompiledRegex for instant regex. InstantCompiledRegex *regexp.Regexp // IDCompiledRegex for ID regex. IDCompiledRegex *regexp.Regexp // OIDCompiledRegex for OID regex. OIDCompiledRegex *regexp.Regexp // PositiveIntCompiledRegex for positive integer regex. PositiveIntCompiledRegex *regexp.Regexp // UnsignedIntCompiledRegex for unsigned integer regex. UnsignedIntCompiledRegex *regexp.Regexp // CodeCompiledRegex for decimal regex. CodeCompiledRegex *regexp.Regexp // UUIDCompiledRegex for UUID regex. UUIDCompiledRegex *regexp.Regexp // JSP for JSP regex. JSP jsoniter.API // RegexValues stores the proto message full names and the regex validation // for its value fields. This map is supposed to be populated during // initialization (i.e.: func init()), once initialization is done, it should // not be modified anymore. RegexValues map[protoreflect.FullName]*regexp.Regexp )
Functions ¶
func AddInternalExtension ¶
AddInternalExtension adds a Google-internal extension ext if it is not existing in proto pb.
func CamelToSnake ¶
CamelToSnake converts a CamelCase string into snake_case by putting one '_' character before each uppercase char and lowercasing all characters.
func ExtensionFieldName ¶
ExtensionFieldName takes the extension url and returns the field name for the extension. The new field name will be the substring after the last occurrence of "/" in the url. Any invalid BigQuery field name characters will be replaced with an underscore, and an underscore prefix will be added if the field name does not start with a letter or underscore.
func ExtensionHasURL ¶
ExtensionHasURL checks if an extension proto has the given URL.
func ExtensionURL ¶
func ExtensionURL(pb protoreflect.Message) (string, error)
ExtensionURL returns the extension URL value.
func ExtensionValue ¶
func ExtensionValue(pb protoreflect.Message) (protoreflect.Message, error)
ExtensionValue returns the extension value proto.
func ExtractTimezone ¶
ExtractTimezone returns the timezone from time.
func ExtractTimezoneFromLoc ¶
ExtractTimezoneFromLoc returns the timezone from locale.
func FieldMap ¶
func FieldMap(desc protoreflect.MessageDescriptor) map[string]protoreflect.FieldDescriptor
FieldMap returns a lookup table for a message's fields from the FHIR JSON field names. Choice fields map to the choice message type.
func GetExtensionFieldDesc ¶
func GetExtensionFieldDesc(d protoreflect.MessageDescriptor) (protoreflect.FieldDescriptor, error)
GetExtensionFieldDesc returns the extension field descriptor.
func GetField ¶
func GetField(d protoreflect.MessageDescriptor, f string) protoreflect.FieldDescriptor
GetField returns the field descriptor.
func GetInternalExtension ¶
GetInternalExtension returns the first extension in pb whose URL matches that of extension ext from proto pb, and nil if there is no match. Only the extension type is used, and its values, if populated, in the input extension is ignored.
func GetLocation ¶
GetLocation parses tz as an IANA location or a UTC offset.
func GetOneofField ¶
func GetOneofField(messageType protoreflect.MessageDescriptor, oneofName, fieldName protoreflect.Name) (protoreflect.FieldDescriptor, error)
GetOneofField returns the oneof field, ensuring the given field is part of the given oneof.
func GetTimeFromUsec ¶
GetTimeFromUsec generates a time.Time object from the given usec and timezone.
func GetTimestampUsec ¶
GetTimestampUsec converts t to a unix timestamp.
func HasInternalExtension ¶
HasInternalExtension returns true iff the proto message pb contains a Google-internal FHIR extension ext. Only the extension type is used, and its values, if populated, in the input extension is ignored.
func InternalExtensionURL ¶
func InternalExtensionURL(desc protoreflect.MessageDescriptor) (string, error)
InternalExtensionURL returns the internal extension URL.
func IsChoice ¶
func IsChoice(d protoreflect.MessageDescriptor) bool
IsChoice returns true iff the message type d is a FHIR choice type.
func IsPrimitiveType ¶
func IsPrimitiveType(d protoreflect.MessageDescriptor) bool
IsPrimitiveType returns true iff the message type d is a primitive FHIR data type.
func IsResourceType ¶
func IsResourceType(d protoreflect.MessageDescriptor) bool
IsResourceType returns true iff the message type d is a FHIR resource type.
func IsSubmilli ¶
IsSubmilli checks if the date input is sub-millisecond.
func IsSubmilliTime ¶
IsSubmilliTime checks if the time input is sub-millisecond.
func IsSubsecondTime ¶
IsSubsecondTime checks if the time input is sub-second.
func ReferenceFieldForType ¶
func ReferenceFieldForType(resType string) (protoreflect.Name, bool)
ReferenceFieldForType returns the reference field that should be populated for the supplied resource type.
func RemoveInternalExtension ¶
RemoveInternalExtension removes extension ext from proto pb if it exists. Only the extension type is used, and its values, if populated, in the input extension is ignored.
func ResourceIDField ¶
func ResourceIDField(ref protoreflect.Message) (protoreflect.FieldDescriptor, error)
ResourceIDField returns the resource-typed field that is populated in this reference, or nil if this is another type of reference.
func ResourceTypeForReference ¶
func ResourceTypeForReference(resField protoreflect.Name) (string, bool)
ResourceTypeForReference returns the resource type that is associated with this reference field.
func SerializeTime ¶
SerializeTime serializes the values from a Time proto message to a JSON string.
func SnakeToCamel ¶
SnakeToCamel converts a snake_case string into a CamelCase string.
func SnakeToLowerCamel ¶
SnakeToLowerCamel converts the snake case to lower camel case.
func UnmarshalCode ¶
func UnmarshalCode(jsonPath string, in protoreflect.Message, rm json.RawMessage) (proto.Message, error)
UnmarshalCode interprets `rm` as a value of the enum that is the same type as `in`. `in` will not be modified.
func ValidateReferenceType ¶
func ValidateReferenceType(msgField protoreflect.FieldDescriptor, ref protoreflect.Message) error
ValidateReferenceType returns an error is `ref` is a strongly typed reference that is not compatible with the types allowed by `msgField`. References should be normalized before being passed to this function.
func ValidateRequiredFields ¶
func ValidateRequiredFields(pb protoreflect.Message) error
ValidateRequiredFields returns an error if any field isn't populated in pb that should be, according to the ValidationRequirement annotation.
func ValidateString ¶
ValidateString returns an error is the string does not conform to FHIR requirements for size and control characters.
Types ¶
type IsJSON ¶
type IsJSON interface {
// IsJSON method.
IsJSON()
}
IsJSON defines JSON related interface.
type JSONObject ¶
JSONObject defines JSON map.
type JSONRawValue ¶
type JSONRawValue []byte
JSONRawValue defines JSON bytes.
func (JSONRawValue) MarshalJSON ¶
func (v JSONRawValue) MarshalJSON() ([]byte, error)
MarshalJSON marshals JSON to bytes.
type Precision ¶
type Precision int32
Precision is used to indicate the precision of the ValueUs field of a Time.
const ( // PrecisionUnspecified indicates that the precision of the ValueUs field in a // Time is unknown. PrecisionUnspecified Precision = 0 // PrecisionSecond indicates that the precision of the ValueUs field in a Time // is to the second. PrecisionSecond Precision = 1 // PrecisionMillisecond indicates that the precision of the ValueUs field in a // Time is to the millisecond. PrecisionMillisecond Precision = 2 // PrecisionMicrosecond indicates that the precision of the ValueUs field in a // Time is to the microsecond. PrecisionMicrosecond Precision = 3 )
type Time ¶
Time contains the result of a parsed FHIR time. The fields correspond to the version-specific fields of a DateTime proto.
type UnmarshalError ¶
type UnmarshalError struct { // Path is the location where the error occurred. Path string // Details is a high level message about what the error was. This value should // not come from other libraries to ensure no PHI is reported. Details string // Diagnostics contains additional debugging information that will be appended to the end of // `Details`. This may include PHI and should not be reported where PHI is prohibited. For // example, a response is fine, but logs are not. Diagnostics string }
UnmarshalError is a public error message for an error that occurred during unmarshaling. This type allows us to return detailed error information without exposing user data.
func (*UnmarshalError) Error ¶
func (e *UnmarshalError) Error() string