Skip to content

Instantly share code, notes, and snippets.

View tternquist's full-sized avatar

Tom Ternquist tternquist

View GitHub Profile
@tternquist
tternquist / faers_slim.jsonl
Created April 21, 2026 15:24
Lilly FAERS + labels slim
This file has been truncated, but you can view the full file.
{"safetyreportid": "10003319", "receiveDate": "20140312", "serious": 1, "seriousnessdeath": 0, "seriousnesshospitalization": 1, "seriousnesslifethreatening": 0, "occurcountry": "US", "reportType": "1", "patientSex": "2", "patientAge": "46", "patientAgeUnit": "801", "drugs": [{"medicinalproduct": "BENLYSTA", "drugcharacterization": "1", "drugindication": "SYSTEMIC LUPUS ERYTHEMATOSUS", "manufacturer": "GlaxoSmithKline LLC", "genericName": "BELIMUMAB", "brandName": "BENLYSTA", "pharmClass_epc": "B Lymphocyte Stimulator-specific Inhibitor [EPC]", "route": "SUBCUTANEOUS"}, {"medicinalproduct": "PLAQUENIL", "drugcharacterization": "2", "drugindication": null, "manufacturer": "Advanz Pharma (US) Corp.", "genericName": "HYDROXYCHLOROQUINE SULFATE", "brandName": "PLAQUENIL", "pharmClass_epc": null, "route": "ORAL"}, {"medicinalproduct": "FOLTX", "drugcharacterization": "2", "drugindication": null, "manufacturer": null, "genericName": null, "brandName": null, "pharmClass_epc": null, "route": null}, {"medicinalproduct"
@tternquist
tternquist / trials_slim.jsonl
Created April 21, 2026 15:21
Eli Lilly clinical trials, slim, 600 records
This file has been truncated, but you can view the full file.
{"nctId": "NCT00883051", "briefTitle": "Dose-ranging Study of Oral COL-144 in Acute Migraine Treatment", "officialTitle": "A Double Blind Randomized Placebo-Controlled Parallel Group Dose-Ranging Study of Oral COL-144 in the Acute Treatment of Migraine", "overallStatus": "COMPLETED", "startDate": "2009-07", "completionDate": "2010-02", "leadSponsor": "Eli Lilly and Company", "collaborators": ["CoLucid Pharmaceuticals"], "studyType": "INTERVENTIONAL", "phases": ["PHASE2"], "primaryPurpose": "TREATMENT", "enrollment": 512, "briefSummary": "The purpose of this study is to evaluate the efficacy and safety of a range of oral doses of COL-144 in treating migraine headache, in order to select a dose or doses for further evaluation.", "conditions": ["Migraine Disorders"], "keywords": ["COL-144", "acute treatment", "migraine"], "interventions": [{"type": "DRUG", "name": "Lasmiditan", "otherNames": ["LY573144"]}, {"type": "DRUG", "name": "Placebo", "otherNames": []}], "meshConditions": ["Migraine Disorders"], "meshInte
sem:sparql("PREFIX fn: <http://www.w3.org/2005/xpath-functions#>
SELECT ?doc {?s <isDefinedBy> ?o
BIND(fn:doc(?o) as ?doc)}") ! map:get(.,"doc")
@tternquist
tternquist / batch-processing-with-spawn-function.xqy
Last active May 31, 2017 17:03
Batch processing in marklogic with spawn function
xquery version "1.0-ml";
let $input := for $i in (1 to 100) return $i
let $batch-size := 2
let $input-size := fn:count($input)
let $num-batches := xs:int(math:ceil($input-size div $batch-size ))
let $result :=
for $batch-start in (1 to $num-batches)
let $processing-seq := $input[($batch-size * ($batch-start - 1) + 1) to ($batch-size * ($batch-start ))]
return
xdmp:spawn-function(function() {
@tternquist
tternquist / root-element-query.xqy
Last active December 22, 2016 23:09
Query on root element in MarkLogic
declare namespace qry = "http://marklogic.com/cts/query";
let $root-element := "*:myRootElem"
return
cts:term-query(xdmp:plan(/xdmp:unpath($root-element))//qry:final-plan//qry:term-query/qry:key)
@tternquist
tternquist / gzip-encoding.xqy
Created December 22, 2016 23:01
Gzip encoding for MarkLogic REST extension
let $result := element result {"Hi"}
return
if(fn:contains(xdmp:get-request-header("Accept-encoding"),"gzip"))
then
(
document {
xdmp:gzip(
text { $result } )
},
xdmp:add-response-header("Content-encoding", "gzip")
@tternquist
tternquist / dynamic-xpath-expression.xqy
Created December 22, 2016 22:55
Perform a dynamic xpath expression in MarkLogic
let $xml := <hi><test><inner>test</inner></test></hi>
return $xml/xdmp:unpath("/test/inner")
let $test := element outer {
attribute at {1},
element a { "a" },
element b { "b" },
element c { "c" }
}
return
element outer {
$test/(node()|@*)[. except $test/c]
@tternquist
tternquist / ml-permissions-role-name.xqy
Created December 22, 2016 22:41
Get role name and permissions for MarkLogic document
import module namespace sec="http://marklogic.com/xdmp/security" at
"/MarkLogic/security.xqy";
declare function local:document-get-permissions($uri) {
xdmp:document-get-permissions($uri) !
xdmp:invoke-function(function() {
element role {.,
sec:get-role-names(xs:unsignedLong(.//sec:role-id ))
}
},<options xmlns="xdmp:eval"><database>{xdmp:database("Security")}</database></options>)
};
@tternquist
tternquist / sum-maps.xqy
Created November 23, 2016 12:48
Sum maps in XQuery (1.0-ml)
xquery version "1.0-ml";
declare namespace html = "http://www.w3.org/1999/xhtml";
let $existing := map:entry("foo",9)
let $maps := (
map:entry("foo",1),
map:entry("foo",2),
map:entry("foo",3),
map:entry("foo",4),
map:entry("foo",5),
map:entry("foo",1)