Example #1
0
func (s *ServerSuite) TestRecordMatchRequestMissingRecordSet(c *C) {
	// Insert a record match system interface to the DB
	r := ptm_models.InsertResourceFromFile(database, "RecordMatchSystemInterface", "../fixtures/record-match-sys-if-01.json")
	recMatchSysIface := r.(*ptm_models.RecordMatchSystemInterface)
	c.Assert(*recMatchSysIface, NotNil)

	// Insert a record set to the DB
	r = ptm_models.InsertResourceFromFile(database, "RecordSet", "../fixtures/record-set-01.json")
	masterRecSet := r.(*ptm_models.RecordSet)
	c.Assert(*masterRecSet, NotNil)

	// Insert a 2nd record set to the DB
	r = ptm_models.InsertResourceFromFile(database, "RecordSet", "../fixtures/record-set-02.json")
	queryRecSet := r.(*ptm_models.RecordSet)
	c.Assert(*queryRecSet, NotNil)

	recMatchRun := &ptm_models.RecordMatchRun{}
	recMatchRun.RecordMatchSystemInterfaceID = recMatchSysIface.ID
	recMatchRun.MatchingMode = "query"
	// ensure the master record set ID doesn't match the one loaded above
	recMatchRun.MasterRecordSetID = "569408c1a291020e5b3636f1"
	recMatchRun.QueryRecordSetID = queryRecSet.ID

	// construct a record match request
	req, err := newRecordMatchRequest("http://replace.me/with/selurl/global", recMatchRun, database)
	c.Assert(err, NotNil)
	c.Assert(req, IsNil)

	// Modify the record match run so the master record set exists and query doesn't
	recMatchRun.MasterRecordSetID = masterRecSet.ID
	recMatchRun.QueryRecordSetID = "569408c1a291020e5b3636f1"
	req, err = newRecordMatchRequest("http://replace.me/with/selurl/global", recMatchRun, database)
	c.Assert(err, NotNil)
	c.Assert(req, IsNil)
}
Example #2
0
func (s *ServerSuite) TestNewRecordMatchQueryRequest(c *C) {
	// Insert a record match system interface to the DB
	r := ptm_models.InsertResourceFromFile(database, "RecordMatchSystemInterface", "../fixtures/record-match-sys-if-01.json")
	recMatchSysIface := r.(*ptm_models.RecordMatchSystemInterface)
	c.Assert(*recMatchSysIface, NotNil)

	// Insert a record set to the DB
	r = ptm_models.InsertResourceFromFile(database, "RecordSet", "../fixtures/record-set-01.json")
	masterRecSet := r.(*ptm_models.RecordSet)
	c.Assert(*masterRecSet, NotNil)

	// Insert a 2nd record set to the DB
	r = ptm_models.InsertResourceFromFile(database, "RecordSet", "../fixtures/record-set-02.json")
	queryRecSet := r.(*ptm_models.RecordSet)
	c.Assert(*queryRecSet, NotNil)

	recMatchRun := &ptm_models.RecordMatchRun{}
	recMatchRun.RecordMatchSystemInterfaceID = recMatchSysIface.ID
	recMatchRun.MatchingMode = "query"
	recMatchRun.MasterRecordSetID = masterRecSet.ID
	recMatchRun.QueryRecordSetID = queryRecSet.ID

	// Build a record match run
	// construct a record match request
	req, err := newRecordMatchRequest("http://replace.me/with/selurl/global", recMatchRun, database)
	c.Assert(err, IsNil)
	buf, _ := req.Message.MarshalJSON()
	logger.Log.WithFields(
		logrus.Fields{"method": "TestNewRecordMatchQueryRequest",
			"request": string(buf)}).Info("")
	c.Assert(req, NotNil)
	c.Assert(req.Message.Type, Equals, "message")
	c.Assert(len(req.Message.Entry), Equals, 3) //MsgHdr + two Param`
}
Example #3
0
func (s *ServerSuite) TestNewRecordMatchDedupRequest(c *C) {
	// Insert a record match system interface to the DB
	r := ptm_models.InsertResourceFromFile(database, "RecordMatchSystemInterface", "../fixtures/record-match-sys-if-01.json")
	recMatchSysIface := r.(*ptm_models.RecordMatchSystemInterface)
	c.Assert(*recMatchSysIface, NotNil)

	// Insert a record set to the DB
	r = ptm_models.InsertResourceFromFile(database, "RecordSet", "../fixtures/record-set-01.json")
	masterRecSet := r.(*ptm_models.RecordSet)
	c.Assert(*masterRecSet, NotNil)

	// Insert a corresponding record match run to the DB
	recMatchRun := &ptm_models.RecordMatchRun{}
	ptm_models.LoadResourceFromFile("../fixtures/record-match-run-post-01.json", recMatchRun)
	recMatchRun.MasterRecordSetID = masterRecSet.ID
	recMatchRun.RecordMatchSystemInterfaceID = recMatchSysIface.ID

	// Build a record match run
	// construct a record match request
	req, err := newRecordMatchRequest("http://localhost/fhir", recMatchRun, database)
	c.Assert(err, IsNil)
	buf, _ := req.Message.MarshalJSON()
	logger.Log.WithFields(
		logrus.Fields{"method": "TestNewRecordMatchDedupRequest",
			"request": string(buf)}).Info("")
	c.Assert(req, NotNil)
	c.Assert(req.Message.Type, Equals, "message")
	c.Assert(len(req.Message.Entry), Equals, 2) //MsgHdr + Param`
}
Example #4
0
func (s *ServerSuite) TestSearch(c *C) {
	ptm_models.InsertResourceFromFile(Database(), "RecordMatchRun", "../fixtures/record-match-run-01.json")
	ptm_models.InsertResourceFromFile(Database(), "RecordMatchRun", "../fixtures/record-match-run-02.json")
	code, body := request("GET", "/RecordMatchRun?recordMatchContextId=56a21d9aa291020ca7dd225f", nil, "", s.Server.Engine)
	c.Assert(code, Equals, http.StatusOK)
	decoder := json.NewDecoder(bytes.NewBufferString(body))
	var runs []ptm_models.RecordMatchRun
	err := decoder.Decode(&runs)
	util.CheckErr(err)
	c.Assert(len(runs), Equals, 1)

}
Example #5
0
func (s *ServerSuite) TestGetRecordMatchContexts(c *C) {
	recs := [4]*ptm_models.RecordMatchContext{}

	// Add record match contexts
	for i := 0; i < len(recs); i++ {
		r := ptm_models.InsertResourceFromFile(Database(), "RecordMatchContext", "../fixtures/record-match-context-01.json")
		recs[i] = r.(*ptm_models.RecordMatchContext)
	}

	e := s.Server.Engine

	// retrieve collection of record match contexts
	code, body := request("GET", "/RecordMatchContext", nil, "", e)
	c.Assert(code, Equals, http.StatusOK)
	logger.Log.Debug("response body: " + body)

	// check that ID of each created resource is in response
	for i, rec := range recs {
		logger.Log.Debug("Chk in Body i: " + strconv.Itoa(i) + " resource id: " + rec.ID.Hex())
		// confirm response body contains resource ID
		pat := regexp.MustCompile(rec.ID.Hex())
		c.Assert(pat.MatchString(body), Equals, true)
	}

	// Try to Get each resource created above
	for _, rec := range recs {
		path := "/RecordMatchContext/" + rec.ID.Hex()
		code, body = request("GET", path, nil, "", e)
		c.Assert(code, Equals, http.StatusOK)
		// confirm response body contains resource ID
		pat := regexp.MustCompile(rec.ID.Hex())
		c.Assert(pat.MatchString(body), Equals, true)
	}

	// Delete the resources created above
	for _, rec := range recs {
		path := "/RecordMatchContext/" + rec.ID.Hex()
		logger.Log.Debug("About to call DELETE: " + path)
		code, body = request("DELETE", path, nil, "", e)
		c.Assert(code, Equals, http.StatusNoContent)
	}

	code, body = request("GET", "/RecordMatchContext", nil, "", e)
	c.Assert(code, Equals, http.StatusOK)

	for i, rec := range recs {
		logger.Log.Debug("Delete, i: " + strconv.Itoa(i) + " resource id: " + rec.ID.Hex())
		// confirm response body no longer contains resource ID
		pat := regexp.MustCompile(rec.ID.Hex())
		c.Assert(pat.MatchString(body), Equals, false)
	}
}
Example #6
0
// TestNewMessageHeader tests that a MessageHeader for a record-match
// request is constructed from information in a RecordMatchRun object.
func (s *ServerSuite) TestNewMessageHeader(c *C) {
	// Insert a record match system interface to the DB
	r := ptm_models.InsertResourceFromFile(database, "RecordMatchSystemInterface", "../fixtures/record-match-sys-if-01.json")
	recMatchSysIface := r.(*ptm_models.RecordMatchSystemInterface)
	c.Assert(*recMatchSysIface, NotNil)

	recMatchRun := &ptm_models.RecordMatchRun{}
	ptm_models.LoadResourceFromFile("../fixtures/record-match-run-post-01.json", recMatchRun)
	recMatchRun.RecordMatchSystemInterfaceID = recMatchSysIface.ID

	// Build a record match run
	// construct a record match request
	src := "http://replace.me/with/selurl/global"
	msgHdr, _ := newMessageHeader(src, recMatchRun, database)
	c.Assert(msgHdr, NotNil)
	c.Assert(msgHdr.Source.Endpoint, Equals, src)
	c.Assert(msgHdr.Event.Code, Equals, "record-match")
}
Example #7
0
func (s *ServerSuite) TestGetRecordMatchRunLinks(c *C) {
	resource := ptm_models.InsertResourceFromFile(database, "RecordMatchRun", "../fixtures/record-match-run-responses.json")
	rmr := resource.(*ptm_models.RecordMatchRun)
	provider := func() *mgo.Database { return database }
	handler := GetRecordMatchRunLinksHandler(provider)
	url := fmt.Sprintf("/RecordMatchRunLinks/%s?limit=2", rmr.ID.Hex())
	r, err := http.NewRequest("GET", url, nil)
	util.CheckErr(err)
	e := gin.New()
	rw := httptest.NewRecorder()
	e.GET("/RecordMatchRunLinks/:id", handler)
	e.ServeHTTP(rw, r)
	c.Assert(rw.Code, Equals, http.StatusOK)
	var links []ptm_models.Link
	decoder := json.NewDecoder(rw.Body)
	err = decoder.Decode(&links)
	util.CheckErr(err)
	c.Assert(len(links), Equals, 2)
	lastLink := links[1]
	c.Assert(lastLink.Score, Equals, 0.82)
	c.Assert(lastLink.Source, Equals, "http://localhost:3001/Patient/5616b69a1cd462440e0006ae")
	c.Assert(lastLink.Target, Equals, "http://localhost:3001/Patient/57335da265ddb433bd30f0ee")
	c.Assert(lastLink.Match, Equals, "probable")
}