Coder Social home page Coder Social logo

golang-fhir-models's Introduction

Golang FHIR Models

This repository contains a FHIR® R4 models for Go. The models consist of Go structs for each resource and data type. The structs are suitable for JSON encoding/decoding.

Features

  • resources implement the Marshaler interface
  • unmarshal functions are provided for every resource
  • enums are provided for every ValueSet used in a required binding, has a computer friendly name and refers only to one CodeSystem
  • enums implement Code(), Display() and Definition() methods

Usage

In your project, import github.com/samply/golang-fhir-models/fhir-models/fhir and you are done.

TODOs

Develop

This repository contains two Go modules, the generated models itself and the generator. Both modules use go generate to generate the FHIR models. For go generate to work, you have to install the generator first. To do that, run go install in the fhir-models-gen directory. After that, you can regenerate the FHIR Models under fhir-models and the subset of FHIR models under fhir-models-gen.

License

Copyright 2019 - 2022 The Samply Community

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

golang-fhir-models's People

Contributors

alexanderkiel avatar hugojbello avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

golang-fhir-models's Issues

MarshalJSON escapes HTML characters

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.

Extension does not model value[x]

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

Pointer on resources' properties?

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.

Missing "event Coding" in messageheader

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

Cannot unmarshal Observations that contain QuantityComparators

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)
	}
}

Fix Partially Wrong Codes in ValueSets

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.