Skip to content

Commit

Permalink
CDR: add identifier use conversion helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
loafoe committed Jun 15, 2022
1 parent aad02bb commit ef0398f
Show file tree
Hide file tree
Showing 6 changed files with 120 additions and 53 deletions.
45 changes: 45 additions & 0 deletions cdr/helper/fhir/r4/identifier/identifier.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package identifier

import (
"strings"

r4gp "github.com/google/fhir/go/proto/google/fhir/proto/r4/core/codes_go_proto"
r4dt "github.com/google/fhir/go/proto/google/fhir/proto/r4/core/datatypes_go_proto"
)

func UseToString(val *r4dt.Identifier_UseCode) string {
enum := val.Value.Enum()
if enum != nil {
return enum.String()
}
return ""
}

func StringToUse(use string) *r4dt.Identifier_UseCode {
switch strings.ToLower(use) {
case "temp":
return &r4dt.Identifier_UseCode{
Value: r4gp.IdentifierUseCode_TEMP,
}
case "usual":
return &r4dt.Identifier_UseCode{
Value: r4gp.IdentifierUseCode_USUAL,
}
case "official":
return &r4dt.Identifier_UseCode{
Value: r4gp.IdentifierUseCode_OFFICIAL,
}
case "old":
return &r4dt.Identifier_UseCode{
Value: r4gp.IdentifierUseCode_OLD,
}
case "secondary":
return &r4dt.Identifier_UseCode{
Value: r4gp.IdentifierUseCode_SECONDARY,
}
default:
return &r4dt.Identifier_UseCode{
Value: r4gp.IdentifierUseCode_INVALID_UNINITIALIZED,
}
}
}
17 changes: 17 additions & 0 deletions cdr/helper/fhir/r4/identifier/identifier_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package identifier_test

import (
"testing"

r4gp "github.com/google/fhir/go/proto/google/fhir/proto/r4/core/codes_go_proto"
r4dt "github.com/google/fhir/go/proto/google/fhir/proto/r4/core/datatypes_go_proto"
"github.com/philips-software/go-hsdp-api/cdr/helper/fhir/r4/identifier"
"github.com/stretchr/testify/assert"
)

func TestIdentifierToString(t *testing.T) {
val := identifier.UseToString(&r4dt.Identifier_UseCode{
Value: r4gp.IdentifierUseCode_TEMP,
})
assert.Equal(t, "TEMP", val)
}
31 changes: 2 additions & 29 deletions cdr/helper/fhir/r4/practitioner/practitioner.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package practitioner

import (
"fmt"

r4gp "github.com/google/fhir/go/proto/google/fhir/proto/r4/core/codes_go_proto"
r4dt "github.com/google/fhir/go/proto/google/fhir/proto/r4/core/datatypes_go_proto"
r4pprac "github.com/google/fhir/go/proto/google/fhir/proto/r4/core/resources/practitioner_go_proto"
identifierhelper "github.com/philips-software/go-hsdp-api/cdr/helper/fhir/r4/identifier"
)

type WithFunc func(resource *r4pprac.Practitioner) error
Expand All @@ -18,32 +16,7 @@ func WithIdentifier(system, value, use string) WithFunc {
val := &r4dt.Identifier{
System: &r4dt.Uri{Value: system},
Value: &r4dt.String{Value: value},
}
switch use {
case "":
break
case "temp":
val.Use = &r4dt.Identifier_UseCode{
Value: r4gp.IdentifierUseCode_TEMP,
}
case "usual":
val.Use = &r4dt.Identifier_UseCode{
Value: r4gp.IdentifierUseCode_USUAL,
}
case "official":
val.Use = &r4dt.Identifier_UseCode{
Value: r4gp.IdentifierUseCode_OFFICIAL,
}
case "old":
val.Use = &r4dt.Identifier_UseCode{
Value: r4gp.IdentifierUseCode_OLD,
}
case "secondary":
val.Use = &r4dt.Identifier_UseCode{
Value: r4gp.IdentifierUseCode_SECONDARY,
}
default:
return fmt.Errorf("unknown use '%s'", use)
Use: identifierhelper.StringToUse(use),
}
resource.Identifier = append(resource.Identifier, val)
return nil
Expand Down
38 changes: 38 additions & 0 deletions cdr/helper/fhir/stu3/identifier/identifier.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package identifier

import (
stu3dt "github.com/google/fhir/go/proto/google/fhir/proto/stu3/datatypes_go_proto"
)

func UseToString(val *stu3dt.IdentifierUseCode) string {
enum := val.Value.Enum()
if enum != nil {
return enum.String()
}
return ""
}

func StringToUse(use string) *stu3dt.IdentifierUseCode {
switch use {
case "temp":
return &stu3dt.IdentifierUseCode{
Value: stu3dt.IdentifierUseCode_TEMP,
}
case "usual":
return &stu3dt.IdentifierUseCode{
Value: stu3dt.IdentifierUseCode_USUAL,
}
case "official":
return &stu3dt.IdentifierUseCode{
Value: stu3dt.IdentifierUseCode_OFFICIAL,
}
case "secondary":
return &stu3dt.IdentifierUseCode{
Value: stu3dt.IdentifierUseCode_SECONDARY,
}
default:
return &stu3dt.IdentifierUseCode{
Value: stu3dt.IdentifierUseCode_INVALID_UNINITIALIZED,
}
}
}
16 changes: 16 additions & 0 deletions cdr/helper/fhir/stu3/identifier/identifier_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package identifier_test

import (
"testing"

stu3dt "github.com/google/fhir/go/proto/google/fhir/proto/stu3/datatypes_go_proto"
"github.com/philips-software/go-hsdp-api/cdr/helper/fhir/stu3/identifier"
"github.com/stretchr/testify/assert"
)

func TestIdentifierToString(t *testing.T) {
val := identifier.UseToString(&stu3dt.IdentifierUseCode{
Value: stu3dt.IdentifierUseCode_TEMP,
})
assert.Equal(t, "TEMP", val)
}
26 changes: 2 additions & 24 deletions cdr/helper/fhir/stu3/practitioner/practitioner.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package practitioner

import (
"fmt"

stu3dt "github.com/google/fhir/go/proto/google/fhir/proto/stu3/datatypes_go_proto"
stu3pb "github.com/google/fhir/go/proto/google/fhir/proto/stu3/resources_go_proto"
identifierhelper "github.com/philips-software/go-hsdp-api/cdr/helper/fhir/stu3/identifier"
)

type WithFunc func(resource *stu3pb.Practitioner) error
Expand All @@ -17,28 +16,7 @@ func WithIdentifier(system, value, use string) WithFunc {
val := &stu3dt.Identifier{
System: &stu3dt.Uri{Value: system},
Value: &stu3dt.String{Value: value},
}
switch use {
case "":
break
case "temp":
val.Use = &stu3dt.IdentifierUseCode{
Value: stu3dt.IdentifierUseCode_TEMP,
}
case "usual":
val.Use = &stu3dt.IdentifierUseCode{
Value: stu3dt.IdentifierUseCode_USUAL,
}
case "official":
val.Use = &stu3dt.IdentifierUseCode{
Value: stu3dt.IdentifierUseCode_OFFICIAL,
}
case "secondary":
val.Use = &stu3dt.IdentifierUseCode{
Value: stu3dt.IdentifierUseCode_SECONDARY,
}
default:
return fmt.Errorf("unknown use '%s'", use)
Use: identifierhelper.StringToUse(use),
}
resource.Identifier = append(resource.Identifier, val)
return nil
Expand Down

0 comments on commit ef0398f

Please sign in to comment.