-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add initial FHIR endpoint for CodeSystem by OID (#56)
- Loading branch information
Showing
7 changed files
with
880 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package r5 | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/google/fhir/go/proto/google/fhir/proto/r5/core/codes_go_proto" | ||
datatypespb "github.com/google/fhir/go/proto/google/fhir/proto/r5/core/datatypes_go_proto" | ||
r5pb "github.com/google/fhir/go/proto/google/fhir/proto/r5/core/resources/code_system_go_proto" | ||
"github.com/skylight-hq/phinvads-go/internal/database/models/xo" | ||
) | ||
|
||
func SerializeCodeSystemToFhir(cs *xo.CodeSystem) (*r5pb.CodeSystem, error) { | ||
fhirCS := &r5pb.CodeSystem{ | ||
Id: newId(cs.Oid), | ||
Status: &r5pb.CodeSystem_StatusCode{Value: codes_go_proto.PublicationStatusCode_DRAFT}, | ||
Version: newString(cs.Version), | ||
Name: newString(cs.Name), | ||
Description: newNullableMarkdown(cs.Definitiontext), | ||
Experimental: newBoolean(cs.Legacyflag), | ||
Url: newNullableUri(cs.Sourceurl), | ||
Date: newDateTime(cs.Statusdate), | ||
Publisher: newNullableString(cs.Distributionsourceversionname), | ||
Title: newNullableString(cs.Assigningauthorityversionname), | ||
Content: &r5pb.CodeSystem_ContentCode{Value: 4}, | ||
// TODO: Count | ||
// TODO: Concept | ||
} | ||
|
||
fhirCS.Identifier = []*datatypespb.Identifier{ | ||
{ | ||
System: newUri("urn:ietf:rfc:3986"), // Assuming this system for oid mapping | ||
Value: newString(fmt.Sprintf("urn:oid:%s", cs.Oid)), | ||
}, | ||
} | ||
|
||
fhirCS.Meta = &datatypespb.Meta{ | ||
Profile: []*datatypespb.Canonical{ | ||
{Value: "http://hl7.org/fhir/StructureDefinition/shareablecodesystem"}, | ||
}, | ||
} | ||
|
||
fhirCS.Text = &datatypespb.Narrative{ | ||
Status: &datatypespb.Narrative_StatusCode{Value: codes_go_proto.NarrativeStatusCode_GENERATED}, | ||
Div: newXhtml("<div>Your narrative text here</div>"), | ||
} | ||
|
||
fhirCS.Contact = []*datatypespb.ContactDetail{ | ||
{ | ||
Name: newString("PHIN Vocabulary Services"), | ||
Telecom: []*datatypespb.ContactPoint{ | ||
{ | ||
System: &datatypespb.ContactPoint_SystemCode{Value: 5}, | ||
Value: newString("https://www.cdc.gov/phin/php/phinvads/index.html"), | ||
}, | ||
{ | ||
System: &datatypespb.ContactPoint_SystemCode{Value: 3}, | ||
Value: newString("[email protected]"), | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
return fhirCS, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package r5 | ||
|
||
import ( | ||
"database/sql" | ||
"time" | ||
|
||
datatypespb "github.com/google/fhir/go/proto/google/fhir/proto/r5/core/datatypes_go_proto" | ||
) | ||
|
||
func newString(value string) *datatypespb.String { | ||
if value == "" { | ||
return nil | ||
} | ||
return &datatypespb.String{Value: value} | ||
} | ||
|
||
func newBoolean(value bool) *datatypespb.Boolean { | ||
return &datatypespb.Boolean{Value: value} | ||
} | ||
|
||
func newDateTime(t time.Time) *datatypespb.DateTime { | ||
if t.IsZero() { | ||
return nil | ||
} | ||
return &datatypespb.DateTime{ | ||
ValueUs: t.UnixMicro(), | ||
Precision: datatypespb.DateTime_MICROSECOND, | ||
} | ||
} | ||
|
||
func newNullableString(ns sql.NullString) *datatypespb.String { | ||
if ns.Valid { | ||
return newString(ns.String) | ||
} | ||
return nil | ||
} | ||
|
||
func newId(value string) *datatypespb.Id { | ||
return &datatypespb.Id{Value: value} | ||
} | ||
|
||
func newMarkdown(value string) *datatypespb.Markdown { | ||
return &datatypespb.Markdown{Value: value} | ||
} | ||
|
||
func newNullableMarkdown(ns sql.NullString) *datatypespb.Markdown { | ||
if ns.Valid { | ||
return newMarkdown(ns.String) | ||
} | ||
return nil | ||
} | ||
|
||
func newUri(value string) *datatypespb.Uri { | ||
return &datatypespb.Uri{Value: value} | ||
} | ||
|
||
func newNullableUri(ns sql.NullString) *datatypespb.Uri { | ||
if ns.Valid { | ||
return newUri(ns.String) | ||
} | ||
return nil | ||
} | ||
|
||
func newXhtml(value string) *datatypespb.Xhtml { | ||
return &datatypespb.Xhtml{Value: value} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters