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 (s *UploadSuite) TestPostToFHIRServer(c *C) { // Setup the mock server resourceCount, patientCount, encounterCount, conditionCount, immunizationCount, observationCount, procedureCount, diagnosticReportCount, medicationStatementCount := 0, 0, 0, 0, 0, 0, 0, 0, 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", fmt.Sprintf("http://localhost/Patient/%d/_history/1", resourceCount)) patientCount++ } case strings.Contains(r.RequestURI, "Encounter"): if isValid(decoder, &models.Encounter{}) { w.Header().Add("Location", fmt.Sprintf("http://localhost/Encounter/%d/_history/1", resourceCount)) encounterCount++ } case strings.Contains(r.RequestURI, "Condition"): if isValid(decoder, &models.Condition{}) { w.Header().Add("Location", fmt.Sprintf("http://localhost/Condition/%d/_history/1", resourceCount)) conditionCount++ } case strings.Contains(r.RequestURI, "Immunization"): if isValid(decoder, &models.Immunization{}) { w.Header().Add("Location", fmt.Sprintf("http://localhost/Immunization/%d/_history/1", resourceCount)) immunizationCount++ } case strings.Contains(r.RequestURI, "Observation"): if isValid(decoder, &models.Observation{}) { w.Header().Add("Location", fmt.Sprintf("http://localhost/Observation/%d/_history/1", resourceCount)) observationCount++ } case strings.Contains(r.RequestURI, "Procedure"): if isValid(decoder, &models.Procedure{}) { w.Header().Add("Location", fmt.Sprintf("http://localhost/Procedure/%d/_history/1", resourceCount)) procedureCount++ } case strings.Contains(r.RequestURI, "DiagnosticReport"): if isValid(decoder, &models.DiagnosticReport{}) { w.Header().Add("Location", fmt.Sprintf("http://localhost/DiagnosticReport/%d/_history/1", resourceCount)) diagnosticReportCount++ } case strings.Contains(r.RequestURI, "MedicationStatement"): if isValid(decoder, &models.MedicationStatement{}) { w.Header().Add("Location", fmt.Sprintf("http://localhost/MedicationStatement/%d/_history/1", resourceCount)) medicationStatementCount++ } } fmt.Fprintln(w, output) resourceCount++ })) defer ts.Close() // Read in the data in FHIR format data, err := ioutil.ReadFile("../fixtures/john_peters.json") util.CheckErr(err) maps := make([]interface{}, 19) err = json.Unmarshal(data, &maps) util.CheckErr(err) fhirmodels := make([]interface{}, 0, len(maps)) for _, resourceMap := range maps { r := models.MapToResource(resourceMap, true) fhirmodels = append(fhirmodels, r) } // Upload the resources and check the counts refMap, err := UploadResources(fhirmodels, ts.URL) c.Assert(patientCount, Equals, 1) c.Assert(encounterCount, Equals, 4) c.Assert(conditionCount, Equals, 5) c.Assert(immunizationCount, Equals, 1) c.Assert(observationCount, Equals, 4) c.Assert(procedureCount, Equals, 2) c.Assert(diagnosticReportCount, Equals, 1) c.Assert(medicationStatementCount, Equals, 1) c.Assert(resourceCount, Equals, 19) c.Assert(len(refMap), Equals, 19) c.Assert(fhirmodels[0].(*models.Patient).Id, Equals, "0") }