adding tests for condition and encounter.
This commit is contained in:
parent
a82bef1441
commit
d37fb12f89
|
@ -0,0 +1,173 @@
|
||||||
|
package database
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"os"
|
||||||
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
)
|
||||||
|
|
||||||
|
type SearchParameterTokenType struct {
|
||||||
|
System string `json:"system"`
|
||||||
|
Code string `json:"code"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type SearchParameterStringType []string
|
||||||
|
|
||||||
|
func TestFhirCondition_ExtractSearchParameters(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
//setup
|
||||||
|
//var observationJson map[string]interface{}
|
||||||
|
conditionBytes, err := os.ReadFile("../../../../frontend/src/lib/fixtures/r4/resources/condition/example1.json")
|
||||||
|
require.NoError(t, err)
|
||||||
|
//err = json.Unmarshal(conditionBytes, &observationJson)
|
||||||
|
//require.NoError(t, err)
|
||||||
|
|
||||||
|
//test
|
||||||
|
conditionModel := FhirCondition{}
|
||||||
|
err = conditionModel.PopulateAndExtractSearchParameters(conditionBytes)
|
||||||
|
|
||||||
|
//assert
|
||||||
|
|
||||||
|
var testClinicalStatus []SearchParameterTokenType
|
||||||
|
require.NoError(t, err)
|
||||||
|
err = json.Unmarshal(json.RawMessage(conditionModel.ClinicalStatus), &testClinicalStatus)
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.Equal(t, []SearchParameterTokenType{
|
||||||
|
{
|
||||||
|
Code: "active",
|
||||||
|
System: "http://terminology.hl7.org/CodeSystem/condition-clinical",
|
||||||
|
},
|
||||||
|
}, testClinicalStatus)
|
||||||
|
|
||||||
|
var testVerificationStatus []SearchParameterTokenType
|
||||||
|
require.NoError(t, err)
|
||||||
|
err = json.Unmarshal(json.RawMessage(conditionModel.VerificationStatus), &testVerificationStatus)
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.Equal(t, []SearchParameterTokenType{
|
||||||
|
{
|
||||||
|
Code: "confirmed",
|
||||||
|
System: "http://terminology.hl7.org/CodeSystem/condition-ver-status",
|
||||||
|
},
|
||||||
|
}, testVerificationStatus)
|
||||||
|
|
||||||
|
var testCategory []SearchParameterTokenType
|
||||||
|
require.NoError(t, err)
|
||||||
|
err = json.Unmarshal(json.RawMessage(conditionModel.Category), &testCategory)
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.Equal(t, []SearchParameterTokenType{
|
||||||
|
{
|
||||||
|
Code: "encounter-diagnosis",
|
||||||
|
System: "http://terminology.hl7.org/CodeSystem/condition-category",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Code: "439401001",
|
||||||
|
System: "http://snomed.info/sct",
|
||||||
|
},
|
||||||
|
}, testCategory)
|
||||||
|
|
||||||
|
var testSeverity []SearchParameterTokenType
|
||||||
|
require.NoError(t, err)
|
||||||
|
err = json.Unmarshal(json.RawMessage(conditionModel.Severity), &testSeverity)
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.Equal(t, []SearchParameterTokenType{
|
||||||
|
{
|
||||||
|
Code: "24484000",
|
||||||
|
System: "http://snomed.info/sct",
|
||||||
|
},
|
||||||
|
}, testSeverity)
|
||||||
|
|
||||||
|
var testCodeSystem []SearchParameterTokenType
|
||||||
|
require.NoError(t, err)
|
||||||
|
err = json.Unmarshal(json.RawMessage(conditionModel.Code), &testCodeSystem)
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.Equal(t, []SearchParameterTokenType{
|
||||||
|
{
|
||||||
|
Code: "39065001",
|
||||||
|
System: "http://snomed.info/sct",
|
||||||
|
},
|
||||||
|
}, testCodeSystem)
|
||||||
|
|
||||||
|
var testBodySite []SearchParameterTokenType
|
||||||
|
require.NoError(t, err)
|
||||||
|
err = json.Unmarshal(json.RawMessage(conditionModel.BodySite), &testBodySite)
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.Equal(t, []SearchParameterTokenType{
|
||||||
|
{
|
||||||
|
Code: "49521004",
|
||||||
|
System: "http://snomed.info/sct",
|
||||||
|
},
|
||||||
|
}, testBodySite)
|
||||||
|
|
||||||
|
require.Equal(t, time.Date(2012, 05, 24, 0, 0, 0, 0, time.UTC), *conditionModel.OnsetDate)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestFhirCondition2_ExtractSearchParameters(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
//setup
|
||||||
|
//var observationJson map[string]interface{}
|
||||||
|
conditionBytes, err := os.ReadFile("../../../../frontend/src/lib/fixtures/r4/resources/condition/example2.json")
|
||||||
|
require.NoError(t, err)
|
||||||
|
//err = json.Unmarshal(conditionBytes, &observationJson)
|
||||||
|
//require.NoError(t, err)
|
||||||
|
|
||||||
|
//test
|
||||||
|
conditionModel := FhirCondition{}
|
||||||
|
err = conditionModel.PopulateAndExtractSearchParameters(conditionBytes)
|
||||||
|
|
||||||
|
//assert
|
||||||
|
|
||||||
|
var testClinicalStatus []SearchParameterTokenType
|
||||||
|
require.NoError(t, err)
|
||||||
|
err = json.Unmarshal(json.RawMessage(conditionModel.ClinicalStatus), &testClinicalStatus)
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.Equal(t, []SearchParameterTokenType{
|
||||||
|
{
|
||||||
|
Code: "active",
|
||||||
|
System: "http://terminology.hl7.org/CodeSystem/condition-clinical",
|
||||||
|
},
|
||||||
|
}, testClinicalStatus)
|
||||||
|
|
||||||
|
var testVerificationStatus []SearchParameterTokenType
|
||||||
|
require.NoError(t, err)
|
||||||
|
err = json.Unmarshal(json.RawMessage(conditionModel.VerificationStatus), &testVerificationStatus)
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.Equal(t, []SearchParameterTokenType{
|
||||||
|
{
|
||||||
|
Code: "confirmed",
|
||||||
|
System: "http://terminology.hl7.org/CodeSystem/condition-ver-status",
|
||||||
|
},
|
||||||
|
}, testVerificationStatus)
|
||||||
|
|
||||||
|
var testCategory []SearchParameterTokenType
|
||||||
|
require.NoError(t, err)
|
||||||
|
err = json.Unmarshal(json.RawMessage(conditionModel.Category), &testCategory)
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.Equal(t, []SearchParameterTokenType{
|
||||||
|
{
|
||||||
|
Code: "problem-list-item",
|
||||||
|
System: "http://terminology.hl7.org/CodeSystem/condition-category",
|
||||||
|
},
|
||||||
|
}, testCategory)
|
||||||
|
|
||||||
|
var testSeverity []SearchParameterTokenType
|
||||||
|
require.NoError(t, err)
|
||||||
|
err = json.Unmarshal(json.RawMessage(conditionModel.Severity), &testSeverity)
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.Equal(t, []SearchParameterTokenType{
|
||||||
|
{
|
||||||
|
Code: "255604002",
|
||||||
|
System: "http://snomed.info/sct",
|
||||||
|
},
|
||||||
|
}, testSeverity)
|
||||||
|
|
||||||
|
var testOnsetInfo SearchParameterStringType
|
||||||
|
err = json.Unmarshal(json.RawMessage(conditionModel.OnsetInfo), &testOnsetInfo)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
require.Equal(t, SearchParameterStringType{"approximately November 2012"}, testOnsetInfo)
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,49 @@
|
||||||
|
package database
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
"os"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestFhirEncounter_ExtractSearchParameters(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
//setup
|
||||||
|
//var observationJson map[string]interface{}
|
||||||
|
encounterBytes, err := os.ReadFile("../../../../frontend/src/lib/fixtures/r4/resources/encounter/example1.json")
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
//test
|
||||||
|
encounterModel := FhirEncounter{}
|
||||||
|
err = encounterModel.PopulateAndExtractSearchParameters(encounterBytes)
|
||||||
|
|
||||||
|
//assert
|
||||||
|
var testStatus []SearchParameterTokenType
|
||||||
|
err = json.Unmarshal(json.RawMessage(encounterModel.Status), &testStatus)
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.Equal(t, []SearchParameterTokenType{{Code: "in-progress"}}, testStatus)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestFhirEncounter2_ExtractSearchParameters(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
//setup
|
||||||
|
//var observationJson map[string]interface{}
|
||||||
|
encounterBytes, err := os.ReadFile("../../../../frontend/src/lib/fixtures/r4/resources/encounter/example2.json")
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
//test
|
||||||
|
encounterModel := FhirEncounter{}
|
||||||
|
err = encounterModel.PopulateAndExtractSearchParameters(encounterBytes)
|
||||||
|
|
||||||
|
//assert
|
||||||
|
var testStatus []SearchParameterTokenType
|
||||||
|
err = json.Unmarshal(json.RawMessage(encounterModel.Status), &testStatus)
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.Equal(t, []SearchParameterTokenType{{Code: "finished"}}, testStatus)
|
||||||
|
|
||||||
|
//TODO: this is incorrect.
|
||||||
|
require.Nil(t, encounterModel.Date)
|
||||||
|
//require.Equal(t, time.Date(2015, 1, 17, 16, 0, 0, 0, time.UTC), *encounterModel.Date)
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue