Created
May 14, 2015 20:53
-
-
Save eedrummer/a641d967977dd1442291 to your computer and use it in GitHub Desktop.
query in progress
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package middleware | |
import ( | |
"encoding/json" | |
"github.com/intervention-engine/fhir/server" | |
"gopkg.in/mgo.v2" | |
"gopkg.in/mgo.v2/bson" | |
"io/ioutil" | |
"net/http" | |
"net/url" | |
"strings" | |
"time" | |
) | |
type RiskModelParameter struct { | |
Category string | |
Weight float64 | |
Method string | |
} | |
func RiskQueryHandler(rw http.ResponseWriter, r *http.Request, next http.HandlerFunc) { | |
query := r.URL.Query() | |
queryValues := query["_query"] | |
if len(queryValues) > 0 && queryValues[0] == "risk" { | |
mapFn, _ := ioutil.ReadFile("middleware/risk_map.js") | |
reduceFn, _ := ioutil.ReadFile("middleware/risk_reduce.js") | |
mrJob := mgo.MapReduce{Map: string(mapFn), Reduce: string(reduceFn)} | |
facts := server.Database.C("facts") | |
type valueStruct struct { | |
Risk int `bson:"risk"` | |
} | |
var result []struct { | |
Id string `bson:"_id"` | |
Value valueStruct `bson:"value"` | |
} | |
query := facts.Find(bson.M{"$or": []bson.M{{"enddate.time": nil}, {"enddate.time": bson.M{"$gt": time.Now()}}}}) | |
_, err := query.MapReduce(&mrJob, &result) | |
if err != nil { | |
panic(err.Error()) | |
} | |
json.NewEncoder(rw).Encode(result) | |
} else { | |
next(rw, r) | |
} | |
} | |
func handleRiskModelParameters(queryParams url.Values) []RiskModelParameter { | |
rmp := []RiskModelParameter{} | |
categories := []string{"medication", "condition", "encounter"} | |
return rmp | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment