Documentation ¶
Index ¶
- Variables
- func GenerateIfNoneExist(cr *bcrpb.ContainedResource, system string, emptyIsErr bool) (string, error)
- func ID(cr *bcrpb.ContainedResource) string
- func TypeOf(cr *bcrpb.ContainedResource) resource.Type
- func URI(cr *bcrpb.ContainedResource) *dtpb.Uri
- func URIString(cr *bcrpb.ContainedResource) string
- func Unwrap(cr *bcrpb.ContainedResource) fhir.Resource
- func VersionID(cr *bcrpb.ContainedResource) string
- func VersionedURI(cr *bcrpb.ContainedResource) *dtpb.Uri
- func VersionedURIString(cr *bcrpb.ContainedResource) (string, bool)
- func Wrap(res fhir.Resource) *bcrpb.ContainedResource
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var (
ErrGenerateIfNoneExist error = errors.New("GenerateIfNoneExist()")
)
Functions ¶
func GenerateIfNoneExist ¶
func GenerateIfNoneExist(cr *bcrpb.ContainedResource, system string, emptyIsErr bool) (string, error)
GenerateIfNoneExist generates an If-None-Exist header value using a single Identifier from the contained resource. The provided system is used to filter identifiers to only an identifier with a matching system.
If no matching Identifier is found, return error if emptyIsErr is true, or return empty string and no error if emptyIsErr is false.
The GCP FHIR store only supports atomic conditional operations on a single identifier, so this function returns an error if there are multiple identifiers matching the query.
This is used for FHIR conditional create or other conditional methods. Untrusted data in Identifiers is escaped both for FHIR and for URL safety.
Example ¶
package main import ( "fmt" "github.com/fhir-fli/fhirpath-go/fhir" "github.com/fhir-fli/fhirpath-go/pkg/containedresource" dtpb "github.com/google/fhir/go/proto/google/fhir/proto/r4/core/datatypes_go_proto" "github.com/google/fhir/go/proto/google/fhir/proto/r4/core/resources/patient_go_proto" ) func main() { patient := &patient_go_proto.Patient{ Id: fhir.ID("12345"), Identifier: []*dtpb.Identifier{ &dtpb.Identifier{ System: &dtpb.Uri{Value: "http://fake.com"}, Value: &dtpb.String{Value: "9efbf82d-7a58-4d14-bec1-63f8fda148a8"}, }, }, } cr := containedresource.Wrap(patient) value, err := containedresource.GenerateIfNoneExist(cr, "http://fake.com", true) if err != nil { panic(err) } headers := map[string]string{} if value != "" { headers["If-None-Exist"] = value } fmt.Printf("If-None-Exist: %v", headers["If-None-Exist"]) }
Output: If-None-Exist: identifier=http%3A%2F%2Ffake.com%7C9efbf82d-7a58-4d14-bec1-63f8fda148a8
func ID ¶
func ID(cr *bcrpb.ContainedResource) string
ID is a helper for getting the ID of a contained resource.
If the contained resource is nil, or the contained resource does not contain any resource, this will return an empty string.
Example ¶
package main import ( "fmt" "github.com/fhir-fli/fhirpath-go/fhir" "github.com/fhir-fli/fhirpath-go/pkg/containedresource" "github.com/google/fhir/go/proto/google/fhir/proto/r4/core/resources/patient_go_proto" ) func main() { patient := &patient_go_proto.Patient{ Id: fhir.ID("12345"), } cr := containedresource.Wrap(patient) id := containedresource.ID(cr) fmt.Printf("Contained Resource ID = %v", id) }
Output: Contained Resource ID = 12345
func TypeOf ¶
func TypeOf(cr *bcrpb.ContainedResource) resource.Type
TypeOf is a helper for getting the type-name of a contained resource.
If the contained resource is nil, or the contained resource does not contain any resource, this function will panic.
Example ¶
package main import ( "fmt" "github.com/fhir-fli/fhirpath-go/fhir" "github.com/fhir-fli/fhirpath-go/pkg/containedresource" "github.com/google/fhir/go/proto/google/fhir/proto/r4/core/resources/patient_go_proto" ) func main() { patient := &patient_go_proto.Patient{ Id: fhir.ID("12345"), } cr := containedresource.Wrap(patient) crType := containedresource.TypeOf(cr) fmt.Printf("Contained Resource type = %v", crType) }
Output: Contained Resource type = Patient
func URI ¶
func URI(cr *bcrpb.ContainedResource) *dtpb.Uri
URI is a helper for getting the URI of a contained-resource as a FHIR URI object. The URI is returned in the format Type/ID, e.g. Patient/123.
func URIString ¶
func URIString(cr *bcrpb.ContainedResource) string
URIString is a helper for getting the URI of a contained-resource in string form. The URI is returned in the format Type/ID, e.g. Patient/123.
func Unwrap ¶
func Unwrap(cr *bcrpb.ContainedResource) fhir.Resource
Unwrap will extract the underlying value contained in this resource, if there is one, and return it. This enables downstream callers to switch off of the resource type, or to perform type-conversions.
This function is effectively the inverse of `ContainedResource`, such that the following assertion will always hold: `proto.Equal(fhirutil.Unwrap(fhirutil.ContainedResource(resource)), resource)`
Example ¶
package main import ( "fmt" "github.com/fhir-fli/fhirpath-go/fhir" "github.com/fhir-fli/fhirpath-go/pkg/containedresource" "github.com/google/fhir/go/proto/google/fhir/proto/r4/core/resources/patient_go_proto" "google.golang.org/protobuf/proto" ) func main() { patient := &patient_go_proto.Patient{ Id: fhir.ID("12345"), } cr := containedresource.Wrap(patient) unwrapped := containedresource.Unwrap(cr).(*patient_go_proto.Patient) if proto.Equal(patient, unwrapped) { fmt.Printf("Resources match!") } }
Output: Resources match!
func VersionID ¶
func VersionID(cr *bcrpb.ContainedResource) string
VersionID gets the version-ID of the specified contained-resource as a string. If `nil` is provided, this returns an empty string.
func VersionedURI ¶
func VersionedURI(cr *bcrpb.ContainedResource) *dtpb.Uri
VersionedURI is a helper for getting the URI of a contained-resource as a FHIR URI object. The URI is returned in the format Type/ID/_history/VERSION.
func VersionedURIString ¶
func VersionedURIString(cr *bcrpb.ContainedResource) (string, bool)
VersionedURIString is a helper for getting the URI of a contained-resource in string form. The URI is returned in the format Type/ID/_history/VERSION.
func Wrap ¶
func Wrap(res fhir.Resource) *bcrpb.ContainedResource
Wrap creates a ContainedResource proto based on an existing FHIR proto. Usage:
patient := &Patient{...} cr := Wrap(patient)
Example ¶
package main import ( "fmt" "github.com/fhir-fli/fhirpath-go/fhir" "github.com/fhir-fli/fhirpath-go/pkg/containedresource" "github.com/google/fhir/go/proto/google/fhir/proto/r4/core/resources/patient_go_proto" ) func main() { patient := &patient_go_proto.Patient{ Id: fhir.ID("12345"), } cr := containedresource.Wrap(patient) fmt.Printf("Patient ID = %v", cr.GetPatient().GetId().GetValue()) }
Output: Patient ID = 12345
Types ¶
This section is empty.