samply / golang-fhir-models Goto Github PK
View Code? Open in Web Editor NEWFHIR Models for Go
License: Apache License 2.0
FHIR Models for Go
License: Apache License 2.0
In the docs for Extensibility it reads
The value[x] element has an actual name of "value" and then the TitleCased name of one of these defined types, and its contents are those as defined for that type:
valueBase64Binary: base64Binary
valueBoolean: boolean
valueCanonical: canonical
...
The Extension type does not provide for the values, which is the useful part of the extension
What happened:
Marshalling an IssueType
leads to partially wrong codes within the result. This makes it impossible to unmarshall an IssueType if it has previously been marshalled using this package.
What you expected to happen:
Being able to marshall an IssueType
and unmarshall it right back.
Example for reproduction:
issueType := fm.IssueTypeTooLong
issueTypeRawJSON, _ := json.Marshal(issueType)
var parsedIssueType fm.IssueType
err := json.Unmarshal(issueTypeRawJSON, &parsedIssueType)
if err != nil {
fmt.Println(err)
}
This will fail with the following error message: unknown IssueType code Content Too Long
Additional Info:
The problem has to be in IssueType
's Code
function. It seems to be mimicking the Display
function at several places instead of ensuring it is doing the opposite of what the switch statement in the Unmarshalling
function does.
Environment:
golang-fhir-models version: 0.2.0
Hello,
Thanks for this nice package.
I was wondering why is there pointer on each generated resources' properties?
My objective here is to read fhir data from a bigquery. But the type mapping is not possible because of properties generated with pointer
I know this is not the purpose of this package to let us map fhir data from bigquery.
For example :
func (r Request) EncounteredPatients(practitionerId string) ([]fhir.Patient, error) {
it, err := r.Raw(fmt.Sprintf(`SELECT *
FROM <gcp_project_id>.<bigquery_datasets>.Patient patient
INNER JOIN (
SELECT DISTINCT subject.patientId
FROM bios-innov.metamedical.Encounter as encounter, UNNEST(encounter.participant) as participant
WHERE participant.individual.practitionerId = '%v') encounters
ON patient.id = encounters.PatientId`, practitionerId))
if err != nil {
return []fhir.Patient{}, fmt.Errorf("EncounteredPatients failed for %v: %w", practitionerId, err)
}
patients := make([]fhir.Patient, 0, 0)
for {
var patient fhir.Patient
err := it.Next(&patient)
if err == iterator.Done {
break
}
if err != nil {
return patients, fmt.Errorf("Failed to read result : %w", err) // TODO: Handle error.
}
// fmt.Println(row)
patients = append(patients, patient)
}
return patients, nil
}
Will lead to an error bigquery: schema field active of type BOOLEAN is not assignable to struct field Active of type *bool
But doing this
func (r Request) EncounteredPatients(practitionerId string) ([]fhir.Patient, error) {
it, err := r.Raw(fmt.Sprintf(`SELECT *
FROM <gcp_project_id>.<bigquery_datasets>.Patient patient
INNER JOIN (
SELECT DISTINCT subject.patientId
FROM bios-innov.metamedical.Encounter as encounter, UNNEST(encounter.participant) as participant
WHERE participant.individual.practitionerId = '%v') encounters
ON patient.id = encounters.PatientId`, practitionerId))
if err != nil {
return []fhir.Patient{}, fmt.Errorf("EncounteredPatients failed for %v: %w", practitionerId, err)
}
patients := make([]fhir.Patient, 0, 0)
for {
var patient fhir.Patient
var row map[string]bigquery.Value
err := it.Next(&row)
if err == iterator.Done {
break
}
if err != nil {
return patients, fmt.Errorf("Failed to read result : %w", err) // TODO: Handle error.
}
jsonRaw, errJson := json.Marshal(row)
if errJson != nil {
return patients, fmt.Errorf("Failed to marshal result : %w", errJson)
}
errReDecode := json.Unmarshal(jsonRaw, &patient)
if errReDecode != nil {
return patients, fmt.Errorf("Failed to Unmarshal result : %w", errReDecode)
}
// fmt.Println(row)
patients = append(patients, patient)
}
return patients, nil
}
Will succeed.
Thanks for the code
While using this library found that it is missing eventCoding in the message Header as per the standards in the hl7 URL. Felt like it would be nice to address and once it is updated it will be useful for parsing out that information in my code as well.
http://hl7.org/fhir/R4/messageheader.html.
{
"resourceType" : "MessageHeader",
// from Resource: id, meta, implicitRules, and language
// from DomainResource: text, contained, extension, and modifierExtension
// event[x]: Code for the event this message represents or link to event definition. One of these 2:
"eventCoding" : { Coding },
..................
//ignoring remaining fields
}
Any suggestions will be helpful
https://github.com/samply/golang-fhir-models/blob/master/fhir-models-gen/cmd/valueSet.go#L60 and https://github.com/samply/golang-fhir-models/blob/master/fhir-models-gen/cmd/genResources.go#L277 encode HTML characters deemed problematic (&
, <
, and >
), because that is the default behaviour of json.Marshal
. This behaviour can be turned off by using a custom encoder, see https://pkg.go.dev/encoding/json#Encoder.SetEscapeHTML.
There are certain fields in the FHIR models which contain those "problematic" characters, but they must not be escaped. For example, http://hl7.org/fhir/R4B/valueset-quantity-comparator.html and the div
field of http://hl7.org/fhir/R4B/narrative.html.
I have a fix for this at michaelsauter@b45358a.
So far I've been working based on https://github.com/lifebox-healthcare/golang-fhir-models, as it contains PR #7, which I need for my work as well. @alexanderkiel I am wondering if the samply
repo is still maintained? If not, can we somehow designate what the "main" fork is going forward so that all changes go in there? I detected a bunch of other issues and have fixes for them locally as well (wrong value
decimal type, spelling of ID fields, gen script issues and FHIR v4.3.0 compatibility).
FYI @frankoid https://github.com/lifebox-healthcare/golang-fhir-models does not have issues enabled, otherwise I could open issues there as well (if the samply
repo is not maintained). If your fork isn't maintained either, I'm going to open a new fork, enable issues there and push my fixes.
When marshaling then unmarshaling Observations we are encountering the following error
"unknown QuantityComparator code `\u003c`"
It appears that this is to do with how the UnmarshalJSON
function is implemented for the QuantityComparator
Its seems that simply stringing the quantity comparator doesnt properly convert \u003c
into <
and instead the code would need to use json.Unmarshall?
https://github.com/samply/golang-fhir-models/blob/master/fhir-models/fhir/quantityComparator.go#L40
Example:
package observationtest
import (
"encoding/json"
"github.com/samply/golang-fhir-models/fhir-models/fhir"
"testing"
)
func Test_observation_marshalling(t *testing.T) {
id := "123"
snomed := "snomed"
code := "456"
lessThan := fhir.QuantityComparatorLessThan
o := fhir.Observation{
Id: &id,
Status: fhir.ObservationStatusPreliminary,
Code: fhir.CodeableConcept{
Coding: []fhir.Coding{
{
System: &snomed,
Code: &code,
},
},
},
ValueQuantity: &fhir.Quantity{
Comparator: &lessThan,
},
}
b, err := json.Marshal(o)
if err != nil {
panic(err)
}
var observationUnmarshalled fhir.Observation
err = json.Unmarshal(b, &observationUnmarshalled)
if err != nil {
panic(err)
}
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.