Groovy web console

subscribe to the feed Subscribe
to this
site
sample rule (via #groovywebconsole)
tweet this snippet Tweet
this
script

sample rule

Published 5 months ago by Abhinandan with tags davaa
Actions  ➤ Edit in console Back to console Show/hide line numbers View recent scripts
//sample 1//Map patientData = [diagnosis: "BTI", acquired: "Hospital", PCNallergy : "None"]

//sample 2
Map patientData = [diagnosis: "BTI", acquired: "Community", severe : false, PCNallergy : "None"]

//sample 3
//Map patientData = [diagnosis: "BTI", acquired: "Community", severe : false, PCNallergy : "Severe"]

//sample 4
//Map patientData = [diagnosis: "BTI", severe : false, acquired: "Hospital", PCNallergy : "None"]

Set route = []
String preferredAntibiotic

println("------------------ START: Rule analysis ------------------")
Date startDate = new Date()
println(startDate)

if (patientData.diagnosis >= "BTI") {
    route << "L1"
}

if (patientData.acquired == "Community") {
    route << "L2"
} else if (patientData.acquired == "Hospital"){
    route << "L3"
}

if (patientData.severe == false) {
    route << "L4"
}

if (patientData.PCNallergy == "Severe") {
    route << "L5"
} else if (patientData.PCNallergy == "None"){
    route << "L6"
}

println("route:" + route)

if (route.equals(["L1", "L2", "L4", "L5"] as Set)) {
    preferredAntibiotic = "ciprofloxacin"
} else if (route.equals(["L1", "L2", "L4", "L6"] as Set)) {
    preferredAntibiotic = "ceftriaxone"
} else if (route.equals(["L1", "L3", "L6"] as Set)) {
    preferredAntibiotic = "Piperacilin"
} else {
    preferredAntibiotic = "Not available"
}

println("preferred Antibiotic is:" + preferredAntibiotic)
def timeDuration = ((new Date().time) - startDate.time )

println("END: Rule analysis \nElapsed time in Milliseconds:"+timeDuration)