2023-07-08 08:43:30 -06:00
|
|
|
package database
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"os"
|
|
|
|
"testing"
|
2023-11-13 11:37:48 -07:00
|
|
|
|
|
|
|
"github.com/stretchr/testify/require"
|
2023-07-08 08:43:30 -06:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestFhirObservation_ExtractSearchParameters(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
//setup
|
|
|
|
//var observationJson map[string]interface{}
|
|
|
|
observationBytes, err := os.ReadFile("../../../../frontend/src/lib/fixtures/r4/resources/observation/example1.json")
|
|
|
|
require.NoError(t, err)
|
|
|
|
//err = json.Unmarshal(observationBytes, &observationJson)
|
|
|
|
//require.NoError(t, err)
|
|
|
|
|
|
|
|
//test
|
|
|
|
observationModel := FhirObservation{}
|
|
|
|
err = observationModel.PopulateAndExtractSearchParameters(observationBytes)
|
|
|
|
|
|
|
|
//assert
|
|
|
|
type CodeSystemType struct {
|
|
|
|
System string `json:"system"`
|
|
|
|
Code string `json:"code"`
|
|
|
|
}
|
|
|
|
var testCodeSystem []CodeSystemType
|
|
|
|
require.NoError(t, err)
|
|
|
|
err = json.Unmarshal(json.RawMessage(observationModel.Code), &testCodeSystem)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, []CodeSystemType{
|
|
|
|
{
|
|
|
|
Code: "29463-7",
|
|
|
|
System: "http://loinc.org",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Code: "3141-9",
|
|
|
|
System: "http://loinc.org",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Code: "27113001",
|
|
|
|
System: "http://snomed.info/sct",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Code: "body-weight",
|
|
|
|
System: "http://acme.org/devices/clinical-codes",
|
|
|
|
},
|
|
|
|
}, testCodeSystem)
|
2023-11-13 11:37:48 -07:00
|
|
|
|
|
|
|
var testCategory []CodeSystemType
|
|
|
|
require.NoError(t, err)
|
|
|
|
err = json.Unmarshal(json.RawMessage(observationModel.Category), &testCategory)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, []CodeSystemType{
|
|
|
|
{
|
|
|
|
Code: "vital-signs",
|
|
|
|
System: "http://terminology.hl7.org/CodeSystem/observation-category",
|
|
|
|
},
|
|
|
|
}, testCategory)
|
|
|
|
|
|
|
|
var testStatus []interface{}
|
|
|
|
require.NoError(t, err)
|
|
|
|
err = json.Unmarshal(json.RawMessage(observationModel.Status), &testStatus)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, []interface{}{
|
|
|
|
map[string]interface{}{
|
|
|
|
"code": "final",
|
|
|
|
},
|
|
|
|
}, testStatus)
|
|
|
|
}
|