Created
September 17, 2013 00:39
-
-
Save nicktackes/6588662 to your computer and use it in GitHub Desktop.
clinical trials with multiple locations. Attempt to find the distance from your current geo location to the closest trial location
This file contains 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
curl -X DELETE localhost:9200/distance_facet_test | |
curl -X PUT localhost:9200/distance_facet_test -d ' | |
{ | |
"mappings":{"clinicaltrial":{"properties":{ | |
"title":{"type":"string"}, | |
"location":{ | |
"properties":{ | |
"facility":{ | |
"properties":{ | |
"name":{"type":"string", index:"not_analyzed"}, | |
"address":{ | |
"properties":{ | |
"city":{"type":"string", index:"not_analyzed"}, | |
"state":{"type":"string", index:"not_analyzed"}, | |
"zip":{"type":"string", index:"not_analyzed"}, | |
"country":{"type":"string", index:"not_analyzed"} | |
} | |
}, | |
"geo":{ | |
"type":"geo_point" | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
}' | |
curl -X POST "http://localhost:9200/distance_facet_test/clinicaltrial" -d ' | |
{ | |
"title":"A Single Arm, Open-label, Multicenter, Phase IV Trial to Assess Long Term Safety of Tobramycin Inhalation Powder (TIP) in Patients With Cystic Fibrosis", | |
"location":[ | |
{ | |
"facility":{ | |
"name":"Novartis Investigative Site", | |
"address":{ | |
"city":"Phoenix", | |
"state":"Arizona", | |
"zip":"85016", | |
"country":"United States" | |
}, | |
"geo":{ | |
"lat":"33.5021", | |
"lon":"-112.0305" | |
} | |
}, | |
"status":"Withdrawn" | |
}, | |
{ | |
"facility":{ | |
"name":"Novartis Investigative Site", | |
"address":{ | |
"city":"Little Rock", | |
"state":"Arkansas", | |
"zip":"72205", | |
"country":"United States" | |
}, | |
"geo":{ | |
"lat":"34.751", | |
"lon":"-92.3455" | |
} | |
}, | |
"status":"Active, not recruiting" | |
}, | |
{ | |
"facility":{ | |
"name":"Novartis Investigative Site", | |
"address":{ | |
"city":"Long Beach", | |
"state":"California", | |
"zip":"90801", | |
"country":"United States" | |
}, | |
"geo":{ | |
"lat":"33.8043", | |
"lon":"-118.201" | |
} | |
}, | |
"status":"Withdrawn" | |
}, | |
{ | |
"facility":{ | |
"name":"Novartis Investigative Site", | |
"address":{ | |
"city":"Orange", | |
"state":"California", | |
"zip":"92868-3874", | |
"country":"United States" | |
} | |
}, | |
"status":"Withdrawn" | |
}, | |
{ | |
"facility":{ | |
"name":"Novartis Investigative Site", | |
"address":{ | |
"city":"San Diego", | |
"state":"California", | |
"zip":"92123", | |
"country":"United States" | |
}, | |
"geo":{ | |
"lat":"32.7973", | |
"lon":"-117.1392" | |
} | |
}, | |
"status":"Withdrawn" | |
}, | |
{ | |
"facility":{ | |
"name":"Novartis Investigative Site", | |
"address":{ | |
"city":"Denver", | |
"state":"Colorado", | |
"zip":"80206", | |
"country":"United States" | |
}, | |
"geo":{ | |
"lat":"39.7331", | |
"lon":"-104.9524" | |
} | |
}, | |
"status":"Active, not recruiting" | |
}, | |
{ | |
"facility":{ | |
"name":"Novartis Investigative Site", | |
"address":{ | |
"city":"Valencia", | |
"state":"Comunidad Valenciana", | |
"zip":"46026", | |
"country":"Spain" | |
} | |
}, | |
"status":"Completed" | |
} | |
] | |
}' | |
curl -X POST "http://localhost:9200/distance_facet_test/clinicaltrial" -d ' | |
{ | |
"title":"Effectiveness of Vyvanse Compared to Concerta in Adolescents With Attention-deficit/Hyperactivity Disorder", | |
"location":[ | |
{ | |
"facility":{ | |
"name":"Nelson Handal", | |
"address":{ | |
"city":"Dothan", | |
"state":"Alabama", | |
"zip":"36303", | |
"country":"United States" | |
}, | |
"geo":{ | |
"lat":"31.2668", | |
"lon":"-85.3971" | |
} | |
}, | |
"status":"Recruiting" | |
}, | |
{ | |
"facility":{ | |
"name":"Wen Cal", | |
"address":{ | |
"city":"Tucson", | |
"state":"Arizona", | |
"zip":"85719", | |
"country":"United States" | |
}, | |
"geo":{ | |
"lat":"32.2474", | |
"lon":"-110.9491" | |
} | |
}, | |
"status":"Recruiting" | |
}, | |
{ | |
"facility":{ | |
"name":"Clinical Study Centers, LLC", | |
"address":{ | |
"city":"Little Rock", | |
"state":"Arkansas", | |
"zip":"72211", | |
"country":"United States" | |
}, | |
"geo":{ | |
"lat":"34.7413", | |
"lon":"-92.4222" | |
} | |
}, | |
"status":"Recruiting", | |
"investigator":{ | |
"last_name":"John Giblin, MD", | |
"role":"Principal Investigator" | |
} | |
}, | |
{ | |
"facility":{ | |
"name":"Bernardo Ng", | |
"address":{ | |
"city":"Imperial", | |
"state":"California", | |
"zip":"92251", | |
"country":"United States" | |
}, | |
"geo":{ | |
"lat":"32.847", | |
"lon":"-115.573" | |
} | |
}, | |
"status":"Recruiting" | |
}, | |
{ | |
"facility":{ | |
"name":"Synergy Clinical Research Center", | |
"address":{ | |
"city":"National City", | |
"state":"California", | |
"zip":"91950", | |
"country":"United States" | |
}, | |
"geo":{ | |
"lat":"32.6749", | |
"lon":"-117.0897" | |
} | |
}, | |
"status":"Recruiting", | |
"investigator":{ | |
"last_name":"Mohammed Bari", | |
"role":"Principal Investigator" | |
} | |
}, | |
{ | |
"facility":{ | |
"name":"Pacific Sleep Medicine, A Medical Corporation", | |
"address":{ | |
"city":"Oceanside", | |
"state":"California", | |
"zip":"92054", | |
"country":"United States" | |
}, | |
"geo":{ | |
"lat":"33.2072", | |
"lon":"-117.3573" | |
} | |
}, | |
"status":"Recruiting", | |
"investigator":{ | |
"last_name":"Susan Erman, MD", | |
"role":"Principal Investigator" | |
} | |
}, | |
{ | |
"facility":{ | |
"name":"Neuropsychiatric Research Center for Orange County", | |
"address":{ | |
"city":"Orange", | |
"state":"California", | |
"zip":"92868", | |
"country":"United States" | |
}, | |
"geo":{ | |
"lat":"33.7875", | |
"lon":"-117.8776" | |
} | |
}, | |
"status":"Recruiting", | |
"investigator":{ | |
"last_name":"Daniel F Chueh", | |
"role":"Principal Investigator" | |
} | |
}, | |
{ | |
"facility":{ | |
"name":"Peninsula Research Associates", | |
"address":{ | |
"city":"Rolling Hills Estates", | |
"state":"California", | |
"zip":"90274", | |
"country":"United States" | |
}, | |
"geo":{ | |
"lat":"33.7866", | |
"lon":"-118.2987" | |
} | |
}, | |
"status":"Recruiting", | |
"investigator":{ | |
"last_name":"Lawrence Sher", | |
"role":"Principal Investigator" | |
} | |
}, | |
{ | |
"facility":{ | |
"name":"PCSD - Feighner Research", | |
"address":{ | |
"city":"San Diego", | |
"state":"California", | |
"zip":"92108", | |
"country":"United States" | |
}, | |
"geo":{ | |
"lat":"32.7783", | |
"lon":"-117.1335" | |
} | |
}, | |
"status":"Recruiting", | |
"investigator":{ | |
"last_name":"Michael McManus", | |
"role":"Principal Investigator" | |
} | |
} | |
] | |
}' | |
curl -XPOST 'http://localhost:9200/distance_facet_test/_refresh' | |
curl -X POST "http://localhost:9200/distance_facet_test/clinicaltrial/_search" -d ' | |
{"filter":{ | |
"match_all" : { } | |
}, | |
"fields":"_source", | |
"script_fields":{ | |
"distance":{ | |
"params":{ | |
"lat":42.3788774, | |
"lon":-72.032366 | |
}, | |
"script": "c=doc['location.facility.geo'].empty ? null : doc['location.facility.geo']; nearest_distance=java.lang.Double.MAX_VALUE; if(c!=null){for(cur : c) {dist=cur.distance(lat, lon); if(dist < nearest_distance){ nearest_distance = dist}}}}; nearest_distance" | |
} | |
}, | |
"sort":{ | |
"_score":"desc" | |
}, "from":"0", "size":"10" | |
}' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment