func (m *MongoSearchSuite) SetUpSuite(c *C) { m.EST = time.FixedZone("EST", -5*60*60) m.Local, _ = time.LoadLocation("Local") //turnOnDebugLog() // Set up the database m.DBServer = &dbtest.DBServer{} m.DBServer.SetPath(c.MkDir()) m.Session = m.DBServer.Session() db := m.Session.DB("fhir-test") m.MongoSearcher = &MongoSearcher{db} // Read in the data in FHIR format data, err := ioutil.ReadFile("../fixtures/search_test_data.json") util.CheckErr(err) maps := make([]interface{}, 19) err = json.Unmarshal(data, &maps) util.CheckErr(err) for _, resourceMap := range maps { r := models.MapToResource(resourceMap, true) collection := models.PluralizeLowerResourceName(reflect.TypeOf(r).Elem().Name()) util.CheckErr(db.C(collection).Insert(r)) } }
func (m *MongoSearchSuite) TestEncounterTypeQueryWithCountAndOffset(c *C) { // First do with an offset of 1 q := Query{"Encounter", "type=http://www.ama-assn.org/go/cpt|99201&_offset=1&_count=1"} mq := m.MongoSearcher.CreateQuery(q) num, err := mq.Count() util.CheckErr(err) c.Assert(num, Equals, 1) offset1 := &models.Encounter{} err = mq.One(offset1) util.CheckErr(err) // Now do an offset of 2 q = Query{"Encounter", "type=http://www.ama-assn.org/go/cpt|99201&_offset=2&_count=1"} mq = m.MongoSearcher.CreateQuery(q) num, err = mq.Count() util.CheckErr(err) c.Assert(num, Equals, 1) offset2 := &models.Encounter{} err = mq.One(offset2) util.CheckErr(err) // Now make sure they are not the same c.Assert(offset1.Id, Not(Equals), offset2.Id) }
func (s *ServiceSuite) TestUnconfirmedResourcesDontGenerateEvents(c *C) { data, err := ioutil.ReadFile("fixtures/brad_bradworth_event_source_bundle.json") util.CheckErr(err) bundle := new(models.Bundle) json.Unmarshal(data, bundle) // Switch a few resources to be unconfirmed bundle.Entry[2].Resource.(*models.Condition).VerificationStatus = "refuted" bundle.Entry[4].Resource.(*models.MedicationStatement).Status = "entered-in-error" es, err := BundleToEventStream(bundle) util.CheckErr(err) c.Assert(es.Patient, NotNil) c.Assert(es.Patient.Id, Equals, "507f1f77bcf86cd799439001") c.Assert(es.Events, HasLen, 3) loc := time.FixedZone("-0500", -5*60*60) // Event 0 (Condition: Atrial Fibrillation) c.Assert(es.Events[0].Date.Equal(time.Date(2012, time.September, 20, 8, 0, 0, 0, loc)), Equals, true) c.Assert(es.Events[0].Type, Equals, "Condition") c.Assert(es.Events[0].End, Equals, false) c.Assert(es.Events[0].Value, DeepEquals, bundle.Entry[1].Resource) // Event 1 (Condition: Cerebral infarction due to cerebral artery occlusion) c.Assert(es.Events[1].Date.Equal(time.Date(2014, time.January, 17, 20, 35, 0, 0, loc)), Equals, true) c.Assert(es.Events[1].Type, Equals, "Condition") c.Assert(es.Events[1].End, Equals, false) c.Assert(es.Events[1].Value, DeepEquals, bundle.Entry[3].Resource) // Event 2 (Condition END: Cerebral infarction due to cerebral artery occlusion) c.Assert(es.Events[2].Date.Equal(time.Date(2014, time.January, 17, 20, 40, 0, 0, loc)), Equals, true) c.Assert(es.Events[2].Type, Equals, "Condition") c.Assert(es.Events[2].End, Equals, true) c.Assert(es.Events[2].Value, DeepEquals, bundle.Entry[3].Resource) }
func performSearch(c *C, url string) *models.Bundle { res, err := http.Get(url) util.CheckErr(err) decoder := json.NewDecoder(res.Body) bundle := &models.Bundle{} err = decoder.Decode(bundle) util.CheckErr(err) return bundle }
func (s *ServerSuite) TestGetPatient(c *C) { res, err := http.Get(s.Server.URL + "/Patient/" + s.FixtureId) util.CheckErr(err) decoder := json.NewDecoder(res.Body) patient := &models.Patient{} err = decoder.Decode(patient) util.CheckErr(err) c.Assert(patient.Name[0].Family[0], Equals, "Donald") }
func LoadBundleFromFixture(fileName string) *Bundle { data, err := os.Open(fileName) defer data.Close() util.CheckErr(err) decoder := json.NewDecoder(data) bundle := &Bundle{} err = decoder.Decode(bundle) util.CheckErr(err) return bundle }
func loadPatientFromFixture(fileName string) *models.Patient { data, err := os.Open(fileName) defer data.Close() util.CheckErr(err) decoder := json.NewDecoder(data) patient := &models.Patient{} err = decoder.Decode(patient) util.CheckErr(err) return patient }
func LoadMapFromFixture(fileName string) interface{} { data, err := os.Open(fileName) defer data.Close() util.CheckErr(err) decoder := json.NewDecoder(data) i := make(map[string]interface{}) err = decoder.Decode(&i) util.CheckErr(err) return i }
func (r *RecordMatchRunSuite) SetUpSuite(c *C) { data, err := os.Open("../fixtures/record-match-run-responses.json") util.CheckErr(err) defer data.Close() decoder := json.NewDecoder(data) rmr := &RecordMatchRun{} err = decoder.Decode(rmr) util.CheckErr(err) r.Run = rmr }
func do_dact(filename string) { reader, err := dbxml.Open(filename) util.CheckErr(err) fmt.Println(">>>", filename) docs, err := reader.All() util.CheckErr(err) for docs.Next() { do_data(filename, docs.Name(), []byte(docs.Content())) } showmemstats() reader.Close() }
func (m *MongoSearchSuite) TestConditionReferenceQueryByPatientGender(c *C) { q := Query{"Condition", "patient.gender=male"} mq := m.MongoSearcher.CreateQuery(q) num, err := mq.Count() util.CheckErr(err) c.Assert(num, Equals, 5) q = Query{"Condition", "patient.gender=female"} mq = m.MongoSearcher.CreateQuery(q) num, err = mq.Count() util.CheckErr(err) c.Assert(num, Equals, 1) }
func (m *MongoSearchSuite) TestPatientNameStringQuery(c *C) { q := Query{"Patient", "name=Peters"} mq := m.MongoSearcher.CreateQuery(q) num, err := mq.Count() util.CheckErr(err) c.Assert(num, Equals, 2) q = Query{"Patient", "name=John"} mq = m.MongoSearcher.CreateQuery(q) num, err = mq.Count() util.CheckErr(err) c.Assert(num, Equals, 1) }
func (m *MongoSearchSuite) TestImmunizationDoseSequenceWrongNumberQuery(c *C) { q := Query{"Immunization", "dose-sequence=0"} mq := m.MongoSearcher.CreateQuery(q) num, err := mq.Count() util.CheckErr(err) c.Assert(num, Equals, 0) q = Query{"Immunization", "dose-sequence=2"} mq = m.MongoSearcher.CreateQuery(q) num, err = mq.Count() util.CheckErr(err) c.Assert(num, Equals, 0) }
func main() { data, err := ioutil.ReadFile("xpath.xml") util.CheckErr(err) doc, err := xml.Parse(data, nil, nil, 0, xml.DefaultEncodingBytes) util.CheckErr(err) defer doc.Free() n, err := doc.Root().Search(`/probe/header/@vendor`) fmt.Println("Vendor:") fmt.Println(n) util.CheckErr(err) }
func (i *IndividualResultSuite) TestFindResultsForMeasurePopulation(c *C) { pq := PopulationQuery{MeasureID: "efgh", EffectiveDate: 1234, Population: InitialPatientPopulation} pr, err := FindResultsForMeasurePopulation(i.Database, pq) util.CheckErr(err) c.Assert(pr.Total, Equals, 2) pt := pr.Patients[0] c.Assert(pt.Last, Equals, "A") pq.Population = Denominator pr, err = FindResultsForMeasurePopulation(i.Database, pq) util.CheckErr(err) c.Assert(pr.Total, Equals, 1) pt = pr.Patients[0] c.Assert(pt.Last, Equals, "A") }
func (q *QualityReportSuite) TestFindOrCreateQualityReport(c *C) { qr := &QualityReport{MeasureID: "abcd", EffectiveDate: 1234, NPI: "efg"} id := bson.NewObjectId() qr.ID = id q.Database.C("query_cache").Insert(qr) qrToFind := &QualityReport{MeasureID: "abcd", EffectiveDate: 1234} err := FindOrCreateQualityReport(q.Database, qrToFind) util.CheckErr(err) c.Assert(qrToFind.NPI, Equals, "efg") qrDoesntExist := &QualityReport{MeasureID: "foobar", EffectiveDate: 1234} err = FindOrCreateQualityReport(q.Database, qrDoesntExist) util.CheckErr(err) count, _ := q.Database.C("query_cache").Count() c.Assert(count, Equals, 2) }
func (q *QualityReportSuite) TestFindQualityAndPopulateQualityReport(c *C) { qr := &QualityReport{MeasureID: "abcd", EffectiveDate: 1234, NPI: "efg"} id := bson.NewObjectId() qr.ID = id q.Database.C("query_cache").Insert(qr) qrToFind := &QualityReport{MeasureID: "abcd", EffectiveDate: 1234} exists, err := FindQualityAndPopulateQualityReport(q.Database, qrToFind) util.CheckErr(err) c.Assert(exists, Equals, true) c.Assert(qrToFind.NPI, Equals, "efg") qrDoesntExist := &QualityReport{MeasureID: "foobar", EffectiveDate: 1234} exists, err = FindQualityAndPopulateQualityReport(q.Database, qrDoesntExist) util.CheckErr(err) c.Assert(exists, Equals, false) }
func (s *ServerSuite) TestUpdatePatient(c *C) { data, err := os.Open("../fixtures/patient-example-c.json") util.CheckErr(err) defer data.Close() client := &http.Client{} req, err := http.NewRequest("PUT", s.Server.URL+"/Patient/"+s.FixtureId, data) util.CheckErr(err) _, err = client.Do(req) patientCollection := Database.C("patients") patient := models.Patient{} err = patientCollection.Find(bson.M{"_id": s.FixtureId}).One(&patient) util.CheckErr(err) c.Assert(patient.Name[0].Family[0], Equals, "Darkwing") }
func (m *MongoSearchSuite) TestNonMatchingDeviceStringQuery(c *C) { q := Query{"Device", "manufacturer=Zinc"} mq := m.MongoSearcher.CreateQuery(q) num, err := mq.Count() util.CheckErr(err) c.Assert(num, Equals, 0) }
func main() { doUtf8 := true doRaw := true if util.IsTerminal(os.Stdin) { syntax() return } for _, arg := range os.Args[1:] { switch arg { case "-r": doUtf8 = false case "-u": doRaw = false default: syntax() return } } if !doUtf8 && !doRaw { syntax() return } data, err := ioutil.ReadAll(os.Stdin) util.CheckErr(err) str := string(data) if doRaw { fmt.Println("[[[RAW]]]") n := 0 for i, p := range textcat.GetPatterns(str, false) { if i == textcat.MaxPatterns { break } n += 1 fmt.Printf("%s\t%d\n", p.S, p.I) } if n < textcat.MaxPatterns { fmt.Fprintf(os.Stderr, "Warning: there are less than %d raw patterns\n", textcat.MaxPatterns) } } if doUtf8 { fmt.Println("[[[UTF8]]]") n := 0 for i, p := range textcat.GetPatterns(str, true) { if i == textcat.MaxPatterns { break } n += 1 fmt.Printf("%s\t%d\n", p.S, p.I) } if n < textcat.MaxPatterns { fmt.Fprintf(os.Stderr, "Warning: there are less than %d utf8 patterns\n", textcat.MaxPatterns) } } }
func (m *MongoSearchSuite) TestSubscriptionURLQuery(c *C) { q := Query{"Subscription", "url=https://biliwatch.com/customers/mount-auburn-miu/on-result"} mq := m.MongoSearcher.CreateQuery(q) num, err := mq.Count() util.CheckErr(err) c.Assert(num, Equals, 1) }
func (m *MongoSearchSuite) TestValueQuantityQueryByValueAndWrongUnit(c *C) { q := Query{"Observation", "value-quantity=185||pounds"} mq := m.MongoSearcher.CreateQuery(q) num, err := mq.Count() util.CheckErr(err) c.Assert(num, Equals, 0) }
func (m *MongoSearchSuite) TestNonMatchingPatientAddressStringQuery(c *C) { q := Query{"Patient", "address=CA"} mq := m.MongoSearcher.CreateQuery(q) num, err := mq.Count() util.CheckErr(err) c.Assert(num, Equals, 0) }
func (m *MongoSearchSuite) TestNonMatchingPatientNameStringQuery(c *C) { q := Query{"Patient", "name=Peterson"} mq := m.MongoSearcher.CreateQuery(q) num, err := mq.Count() util.CheckErr(err) c.Assert(num, Equals, 0) }
func (s *UploadSuite) TestUnorderedDependencies(c *C) { // Setup the mock server resourceCount := 0 ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { output := "Created" decoder := json.NewDecoder(r.Body) switch { case strings.Contains(r.RequestURI, "Patient"): if isValid(decoder, &models.Patient{}) { w.Header().Add("Location", "http://localhost/Patient/1/_history/1") } case strings.Contains(r.RequestURI, "Condition"): if isValid(decoder, &models.Condition{}) { w.Header().Add("Location", "http://localhost/Condition/1") // Purposefully no _history to test this use case } } fmt.Fprintln(w, output) resourceCount++ })) defer ts.Close() patient := &models.Patient{Id: "a1"} condition := &models.Condition{Id: "b2"} condition.Patient = &models.Reference{Reference: "cid:a1"} // Upload the resources in the wrong order refMap, err := UploadResources([]interface{}{condition, patient}, ts.URL) util.CheckErr(err) // Assert that it processed all resources and correctly mapped refs c.Assert(len(refMap), Equals, 2) c.Assert(refMap["a1"], Equals, "Patient/1") c.Assert(refMap["b2"], Equals, "Condition/1") }
func (m *MongoSearchSuite) TestConditionIdQuery(c *C) { q := Query{"Condition", "_id=8664777288161060797"} mq := m.MongoSearcher.CreateQuery(q) num, err := mq.Count() util.CheckErr(err) c.Assert(num, Equals, 1) cond := &models.Condition{} err = mq.One(cond) util.CheckErr(err) cond2 := &models.Condition{} err = m.Session.DB("fhir-test").C("conditions").FindId("8664777288161060797").One(cond2) c.Assert(cond, DeepEquals, cond2) }
func InsertResourceFromFile(db *mgo.Database, resourceType string, filePath string) interface{} { collection := db.C(GetCollectionName(resourceType)) resource := NewStructForResourceName(resourceType) LoadResourceFromFile(filePath, resource) // Set a unique identifier to this resource rptr := reflect.ValueOf(resource) r := rptr.Elem() logger.Log.WithFields(logrus.Fields{"kind": r.Kind()}).Debug("InsertResourceFromFile") if r.Kind() == reflect.Struct { logger.Log.WithFields(logrus.Fields{"method": "InsertResourceFromFile"}).Debug("Recognize struct") f := r.FieldByName("ID") if f.IsValid() { logger.Log.WithFields(logrus.Fields{"method": "InsertResourceFromFile"}).Debug("Id field is valid") if f.CanSet() { objID := bson.NewObjectId() logger.Log.WithFields( logrus.Fields{"method": "InsertResourceFromFile", "obj id": objID}).Debug("ID field can be set") f.Set(reflect.ValueOf(objID)) } } } //logger.Log.WithFields(logrus.Fields{"resource": resource}).Info("InsertResourceFromFile") err := collection.Insert(resource) util.CheckErr(err) return resource }
func (m *MongoSearchSuite) TestConditionMultipleCodesWrongICD10Query(c *C) { q := Query{"Condition", "code=http://hl7.org/fhir/sid/icd-9|428.0,http://snomed.info/sct|981000124106,http://hl7.org/fhir/sid/icd-10|I21.0"} mq := m.MongoSearcher.CreateQuery(q) num, err := mq.Count() util.CheckErr(err) c.Assert(num, Equals, 2) }
func (m *MongoSearchSuite) TestValueQuantityQueryByValueAndSystemAndWrongCode(c *C) { q := Query{"Observation", "value-quantity=185|http://unitsofmeasure.org|lbs"} mq := m.MongoSearcher.CreateQuery(q) num, err := mq.Count() util.CheckErr(err) c.Assert(num, Equals, 0) }
func (m *MongoSearchSuite) TestDeviceStringQuery(c *C) { q := Query{"Device", "manufacturer=Acme"} mq := m.MongoSearcher.CreateQuery(q) num, err := mq.Count() util.CheckErr(err) c.Assert(num, Equals, 1) dev := &models.Device{} err = mq.One(dev) util.CheckErr(err) dev2 := &models.Device{} err = m.Session.DB("fhir-test").C("devices").FindId("7045606679745526995").One(dev2) c.Assert(dev, DeepEquals, dev2) }