Created
November 16, 2010 02:12
-
-
Save bhenry/701320 to your computer and use it in GitHub Desktop.
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
(defn xls-report | |
[headers rows] | |
(str | |
(join "\t" headers) | |
(apply str | |
(for [r rows] | |
(str "\n" | |
(join "\t" r)))))) | |
(defn employee-display [emp] | |
(entity-display emp [:last-name ", " :first-name " (" :user-name ")"])) | |
(defn spreadsheet | |
[cards] | |
(let [{:keys [headers rows]} | |
(generate-report | |
cards | |
["Operator" [:operator] employee-display] | |
["Evaluator" [:evaluator] employee-display] | |
["Client Number" [:client :account-number] identity] | |
["Client Name" [:client :account-name] identity] | |
["Entry Time" [:timestamp] html/display-date] | |
["Call Time" [:call-date] html/display-date] | |
["Scored" [:grade :scored] html/display-number] | |
["Possible" [:grade :possible] html/display-number] | |
["Percentage" [:grade :percentage] #(* 100.0 %)] | |
["ID" [:_id] identity])] | |
(xls-report headers rows))) |
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
(defn generate-report | |
"take query-results and vectors each with the following info: | |
[header-display [key(s)] manipulation-function] | |
key(s) is a vector of nested keywords. e.g. [:operator :first-name] | |
which is passed to a get-in call | |
manipulation-function is the function to apply to the item. | |
returns a map with :headers and :rows" | |
[query-results & report-items] | |
(let [headers (vec (map first report-items)) | |
process (fn [ks f] | |
#(f (get-in % ks))) | |
columns (map #(process (% 1) (% 2)) report-items) | |
rows (for [r query-results] | |
((apply juxt columns) r))] | |
{:headers headers | |
:rows rows})) |
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
(defn html-report | |
[headers rows] | |
[:table.report | |
[:tr.report-header | |
(for [h headers] | |
[:td h])] | |
(for [row rows] | |
[:tr.report-row | |
(for [item row] | |
item)])]) | |
(defn scorecard-table | |
[cards] | |
(let [{:keys [headers rows]} | |
(generate-report | |
cards | |
["Operator" [:operator] employee-td] | |
["Evaluator" [:evaluator] employee-td] | |
["Client" [:client] client-td] | |
["Entry Time" [:timestamp] date-td] | |
["Call Time" [:call-date] date-td] | |
["Score" [:grade] grade-td])] | |
(html-report headers rows))) |
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
{:grade | |
{:scored 10.0, :possible 74.0, :percentage 0.13513513513513514}, | |
:timestamp #<Date Mon Nov 15 21:16:42 EST 2010>, | |
:questions | |
({:section "Verification", | |
:question "Patient Name", | |
:value 10.0, | |
:notes nil, | |
:description "Verified Patient Name", | |
:answers | |
({:selected false, :weight 1.0, :text "Yes"} | |
{:selected false, :weight 0.0, :text "No"} | |
{:selected true, :weight -1.0, :text "NA"})} | |
{:section "Verification", | |
:question "Date of Birth", | |
:value 10.0, | |
:notes nil, | |
:description "Verified DOB", | |
:answers | |
({:selected false, :weight 1.0, :text "Yes"} | |
{:selected true, :weight 0.0, :text "No"} | |
{:selected false, :weight -1.0, :text "NA"})} | |
{:section "Verification", | |
:question "Phone Numbers", | |
:value 10.0, | |
:notes nil, | |
:description "Verified Phone numbers", | |
:answers | |
({:selected false, :weight 1.0, :text "Yes"} | |
{:selected true, :weight 0.0, :text "No"} | |
{:selected false, :weight -1.0, :text "NA"})}), | |
:notes "No notes", | |
:call-date #<Date Sat Sep 25 08:25:00 EDT 2010>, | |
:client | |
{:questionnaire-title "Classic", | |
:questionnaire-id #<ObjectId 4cdea97b967c3d75d823f35b>, | |
:active true, | |
:account-name "Sample Client - Classic", | |
:account-number "6000", | |
:_id #<ObjectId 4cdeb38aaddbdc2100969549>}, | |
:evaluator | |
{:first-name "Super", | |
:last-name "Visor", | |
:user-name "supervisor", | |
:active true, | |
:bulletin-id 617, | |
:_id #<ObjectId 4cbf1124e4d55d3ac766961a>}, | |
:operator | |
{:first-name "Oper", | |
:last-name "Ator", | |
:user-name "operator", | |
:active true, | |
:bulletin-id 803, | |
:_id #<ObjectId 4cbf1124e4d55d3acf66961a>}} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment