Skip to content
This repository was archived by the owner on Apr 29, 2024. It is now read-only.

Commit 051cb81

Browse files
committed
manually adding bson import/export to administrative gender
1 parent b380eb1 commit 051cb81

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

fhir-models/fhir/administrativeGender.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ package fhir
1717
import (
1818
"encoding/json"
1919
"fmt"
20+
bson "go.mongodb.org/mongo-driver/bson"
21+
bsonrw "go.mongodb.org/mongo-driver/bson/bsonrw"
22+
bsontype "go.mongodb.org/mongo-driver/bson/bsontype"
2023
"strings"
2124
)
2225

@@ -33,6 +36,39 @@ const (
3336
AdministrativeGenderUnknown
3437
)
3538

39+
func (code *NameUse) MarshalBSONValue() (bsontype.Type, []byte, error) {
40+
return bson.MarshalValue(code.Code())
41+
}
42+
func (code *NameUse) UnmarshalBSONValue(t bsontype.Type, bytes []byte) error {
43+
if t != bsontype.String {
44+
err := fmt.Errorf("UnmarshalBSONValue error: cannot unmarshal non string value")
45+
return err
46+
}
47+
reader := bsonrw.NewBSONValueReader(t, bytes)
48+
decoder, err := bson.NewDecoder(reader)
49+
if err != nil {
50+
return err
51+
}
52+
var s string
53+
err = decoder.Decode(&s)
54+
if err != nil {
55+
return err
56+
}
57+
switch s {
58+
case "male":
59+
*code = AdministrativeGenderMale
60+
case "female":
61+
*code = AdministrativeGenderFemale
62+
case "other":
63+
*code = AdministrativeGenderOther
64+
case "unknown":
65+
*code = AdministrativeGenderUnknown
66+
default:
67+
return fmt.Errorf("unknown AdministrativeGender code `%s`", s)
68+
}
69+
return nil
70+
}
71+
3672
func (code *AdministrativeGender)MarshalJSON() ([]byte, error) {
3773
return json.Marshal(code.Code())
3874
}

0 commit comments

Comments
 (0)