Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot unmarshal Observations that contain QuantityComparators #17

Open
reiman2222 opened this issue Mar 18, 2024 · 0 comments
Open

Cannot unmarshal Observations that contain QuantityComparators #17

reiman2222 opened this issue Mar 18, 2024 · 0 comments

Comments

@reiman2222
Copy link

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)
	}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant