Beispiel #1
0
func TestParseAllCCDs(t *testing.T) {
	walkAllCCDs(func(path string, info os.FileInfo, err error) error {
		shouldfail := strings.HasPrefix(info.Name(), "fail_")

		doc := xmlx.New()
		err = doc.LoadFile(path, charset.NewReaderLabel)
		if shouldfail && err != nil {
			return nil
		}

		c := ccd.NewDefaultCCD()
		err = parseAndRecover(t, c, path, doc)
		if shouldfail && err == nil {
			t.Errorf("%s: Expected failure, instead received success.", path)
			atomic.AddInt64(&unsuccessfulCCDs, 1)
		} else if !shouldfail && err != nil {
			t.Errorf("%s: Failed: %v", path, err)
			atomic.AddInt64(&unsuccessfulCCDs, 1)
		} else {
			atomic.AddInt64(&successfulCCDs, 1)
		}

		return nil
	})
	//successful here means that it only failed if the name started with fail_
	t.Logf("parsed %d CCDS. %d successful, %d unsuccessful\n", (successfulCCDs + unsuccessfulCCDs), successfulCCDs, unsuccessfulCCDs)
}
Beispiel #2
0
func TestParse_Address(t *testing.T) {
	c := ccd.NewDefaultCCD()
	err := parseAndRecover(t, c, "testdata/specific/address.xml", nil)
	if err != nil {
		t.Fatal(err)
	}

	addr := ccd.Address{
		Line1:   "Line1",
		Line2:   "Line2",
		City:    "City",
		County:  "County",
		State:   "ST",
		Zip:     "12345",
		Country: "Country",
		Use:     "HP",
	}

	if !reflect.DeepEqual(addr, c.Patient.Addresses[0]) {
		t.Fatalf("Expected:\n%#v, got:\n%#v", addr, c.Patient.Addresses[0])
	}

	if !c.Patient.Name.IsZero() {
		t.Fatalf("Patient.Name was suppose to be empty, but it's not")
	}
}
Beispiel #3
0
func TestParse_Medications(t *testing.T) {
	c := ccd.NewDefaultCCD()
	err := parseAndRecover(t, c, "testdata/specific/medications.xml", nil)
	if err != nil {
		t.Fatal(err)
	}

	meds := []ccd.Medication{
		ccd.Medication{
			Name:           "Albuterol 0.09 MG/ACTUAT inhalant solution",
			Administration: "",
			Dose: ccd.MedicationDose{
				LowValue:  "0.09",
				LowUnit:   "mg/actuat",
				HighValue: "",
				HighUnit:  "",
			},
			Status:     "Active",
			StatusCode: "completed",
			StartDate:  time.Time{},
			StopDate:   time.Date(2012, 8, 6, 0, 0, 0, 0, time.UTC),
			Period:     time.Duration(43200000000000),
			Code: ccd.Code{
				CodeSystemName: "",
				Type:           "",
				CodeSystem:     "2.16.840.1.113883.6.88",
				Code:           "573621",
				DisplayName:    "Albuterol 0.09 MG/ACTUAT inhalant solution",
				Translations: []ccd.Code{ccd.Code{
					CodeSystemName: "RxNorm",
					Type:           "",
					CodeSystem:     "2.16.840.1.113883.6.88",
					Code:           "573621",
					DisplayName:    "Proventil 0.09 MG/ACTUAT inhalant solution",
					OriginalText:   "",
				}},
			},
			Reason: &ccd.MedicationReason{
				Value: ccd.Code{
					CodeSystemName: "",
					Type:           "CD",
					CodeSystem:     "2.16.840.1.113883.6.96",
					Code:           "233604007",
					DisplayName:    "Pneumonia",
				},
				Date: time.Time{},
			},
		},
	}

	if len(meds) != len(c.Medications) {
		t.Fatalf("Expected %d medications. Got %d", len(meds), len(c.Medications))
	}

	for i, _ := range meds {
		if !reflect.DeepEqual(meds[i], c.Medications[i]) {
			t.Fatalf("Differences in medication %d: %v", i, pretty.Compare(meds[i], c.Medications[i]))
		}
	}
}
Beispiel #4
0
func TestNulls(t *testing.T) {
	c := ccd.NewDefaultCCD()
	err := parseAndRecover(t, c, "testdata/specific/nulls.xml", nil)
	if err != nil {
		t.Fatal(err)
	}

	if c.Allergies != nil {
		t.Fatal("expected allergies to be nil")
	}
	if c.Encounters != nil {
		t.Fatal("expected encounters to be nil")
	}
	if c.Immunizations != nil {
		t.Fatal("expected immunizations to be nil")
	}
	if c.Medications != nil {
		t.Fatal("expected medications to be nil")
	}
	if c.Problems != nil {
		t.Fatal("expected problems to be nil")
	}
	if c.Results != nil {
		t.Fatal("expected results to be nil")
	}
}
Beispiel #5
0
func TestMedDate(t *testing.T) {
	cc := ccd.NewDefaultCCD()
	// first three meds missing date in xml data
	err := cc.ParseFile("testdata/ccd.xml")
	if err != nil {
		t.Fatal(err)
	}

	for _, med := range cc.Medications[:3] {
		if !med.StartDate.IsZero() {
			t.Fatal("Expected medication StartDate to be zero.")
		}
	}

	cc.AddParsers(Parser())

	// reparse with our new parser added
	err = cc.ParseFile("testdata/ccd.xml")
	if err != nil {
		t.Fatal(err)
	}

	for _, med := range cc.Medications[:3] {
		if med.StartDate.IsZero() {
			t.Fatal("Expected medication StartDate to be non-zero.")
		}
	}
}
Beispiel #6
0
func TestInvalidCCD(t *testing.T) {
	c := ccd.NewDefaultCCD()
	err := parseAndRecover(t, c, "testdata/specific/invalid_ccd.xml", nil)
	if err == nil {
		t.Fatal("Expected parsing of CCD to fail and throw and error.")
	}

	err = parseAndRecover(t, c, "testdata/specific/valid_ccd.xml", nil)
	if err != nil {
		t.Fatal(err)
	}
}
Beispiel #7
0
func TestNewStuff(t *testing.T) {
	t.Skip("just for my own needs")

	c := ccd.NewDefaultCCD()
	err := parseAndRecover(t, c, "testdata/public/sample_ccdas/Allscripts Samples/Professional EHR/Encounter Based C-CDA CCD - 08-06-2012 [Jones, Isabella - 170314E2].xml", nil)
	if err != nil {
		t.Fatal(err)
	}

	_ = spew.Dump

	spew.Dump(c.Results)
}
Beispiel #8
0
func TestNewStuff(t *testing.T) {
	t.Skip("just for my own needs")

	c := ccd.NewDefaultCCD()
	c.AddParsers(medtable.Parser())
	err := parseAndRecover(t, c, "testdata/private/2013-08-26T04_03_24 - 0b7fddbdc631aecc6c96090043f690204f7d0d9d.xml", nil)
	//err := parseAndRecover(t, c, "testdata/public/ToC_CCDA_CCD_CompGuideSample_FullXML_v01a.xml", nil)
	//err := parseAndRecover(t, c, "testdata/public/SampleCCDDocument.xml", nil)
	if err != nil {
		t.Fatal(err)
	}

	_ = spew.Dump

	//spew.Dump(c.Patient)
}
Beispiel #9
0
func TestParseAllCCDs(t *testing.T) {
	walkAllCCDs(func(path string, info os.FileInfo, err error) error {
		shouldfail := strings.HasPrefix(info.Name(), "fail_")

		doc := xmlx.New()
		err = doc.LoadFile(path, nil)
		if shouldfail && err != nil {
			return nil
		}

		c := ccd.NewDefaultCCD()
		err = parseAndRecover(t, c, path, doc)
		if shouldfail && err == nil {
			t.Fatalf("%s: Expected failure, instead received success.", path)
		} else if !shouldfail && err != nil {
			t.Fatalf("%s: Failed: %v", path, err)
		}

		return nil
	})
}
Beispiel #10
0
func TestParse_Name(t *testing.T) {
	c := ccd.NewDefaultCCD()
	err := parseAndRecover(t, c, "testdata/specific/name.xml", nil)
	if err != nil {
		t.Fatal(err)
	}

	name := ccd.Name{
		First:    "First",
		Middle:   "Middle",
		Last:     "Last",
		Suffix:   "Suffix",
		Prefix:   "Prefix",
		Type:     "PN",
		NickName: "NickName",
	}

	if !reflect.DeepEqual(name, c.Patient.Name) {
		t.Fatalf("Expected:\n%#v, got:\n%#v", name, c.Patient.Name)
	}
}
Beispiel #11
0
//TestParse_Problems parses a specific ccd with many different types of problems and compares it to a pre-made output.
func TestParse_Problems(t *testing.T) {
	c := ccd.NewDefaultCCD()
	err := parseAndRecover(t, c, "testdata/specific/problems.xml", nil)
	if err != nil {
		t.Fatal(err)
	}

	problems := []ccd.Problem{
		ccd.Problem{
			Name:        "Pneumonia",
			Time:        ccd.Time{Low: parseTime("2012-08-06"), Value: parseTime("2012-08-06")},
			Status:      "Active",
			ProblemType: "Complaint",
			Code: ccd.Code{
				CodeSystemName: "",
				Type:           "CD",
				CodeSystem:     "2.16.840.1.113883.6.96",
				Code:           "233604007",
				DisplayName:    "Pneumonia",
			},
		},
		ccd.Problem{
			Name:        "CEREBRAL ARTERY OCCLUSION, UNSPECIFIED, WITH CEREBRAL INFARCTION",
			Time:        ccd.Time{Low: parseTime("2009-07-09"), Value: parseTime("2009-07-09")},
			Status:      "Active",
			ProblemType: "Problem",
			Code: ccd.Code{
				CodeSystemName: "ICD-9-CM",
				Type:           "",
				CodeSystem:     "2.16.840.1.113883.6.104",
				Code:           "434.91",
				DisplayName:    "CEREBRAL ARTERY OCCLUSION, UNSPECIFIED, WITH CEREBRAL INFARCTION",
				Translations: []ccd.Code{
					ccd.Code{
						CodeSystemName: "ICD-9-CM",
						Type:           "",
						CodeSystem:     "2.16.840.1.113883.6.104",
						Code:           "434.91",
						DisplayName:    "CEREBRAL ARTERY OCCLUSION, UNSPECIFIED, WITH CEREBRAL INFARCTION",
						OriginalText:   "",
					}},
			},
		},
		ccd.Problem{
			Name:        "Body mass index 30+ - obesity",
			Time:        ccd.Time{Low: parseTime("2011-01-18"), Value: parseTime("2011-01-18")},
			Status:      "Active",
			ProblemType: "",
			Code: ccd.Code{
				CodeSystemName: "",
				Type:           "CD",
				CodeSystem:     "",
				Code:           "",
				DisplayName:    "Body mass index 30+ - obesity",
				Translations: []ccd.Code{
					{
						CodeSystemName: "SNOMED CT",
						Type:           "",
						CodeSystem:     "2.16.840.1.113883.6.96",
						Code:           "162864005",
						DisplayName:    "",
						OriginalText:   "",
					},
				},
			},
		},
		ccd.Problem{
			Name:        "GERD (gastroesophageal reflux disease)",
			Time:        ccd.Time{},
			Status:      "Active",
			ProblemType: "Problem",
			Code: ccd.Code{
				CodeSystemName: "ICD-9 CM",
				Type:           "",
				CodeSystem:     "2.16.840.1.113883.6.103",
				Code:           "530.81",
				DisplayName:    "GERD (gastroesophageal reflux disease)",
				Translations: []ccd.Code{ccd.Code{
					CodeSystemName: "ICD-9 CM",
					Type:           "",
					CodeSystem:     "2.16.840.1.113883.6.103",
					Code:           "530.81",
					DisplayName:    "GERD (gastroesophageal reflux disease)",
					OriginalText:   "",
				},
				},
			},
		},
		ccd.Problem{
			Name:        "JOINT PAIN PELVIS",
			Time:        ccd.Time{},
			Status:      "Active",
			ProblemType: "ASSERTION",
			Code: ccd.Code{
				Type:           "CD",
				CodeSystem:     "2.16.840.1.113883.6.103",
				CodeSystemName: "",
				Code:           "719.45",
				DisplayName:    "JOINT PAIN PELVIS",
			},
		}}

	if len(problems) != len(c.Problems) {
		t.Fatalf("Wrong number of problems in specific problems test. Expected: %d got: %d", len(problems), len(c.Problems))
	}
	for i, _ := range problems {
		if !reflect.DeepEqual(problems[i], c.Problems[i]) {
			t.Fatalf("Problem #%d differed: %v", pretty.Compare(problems[i], c.Problems[i]))
		}
	}
}