#reader(lib "htdp-beginner-reader.ss" "lang")((modname blood-test-2list) (read-case-sensitive #t) (teachpacks ()) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ())))
(define-struct range (label low high units))
(define-struct result (label code))
(define READINGS
(list 1.9
136
48
887
33
6.9
0.9))
(define RANGES
(list (make-range "ALB" 2.2 3.9 "g/dl")
(make-range "ALKP" 23 212 "U/L")
(make-range "ALT" 10 100 "U/L")
(make-range "AMYL" 500 1500 "U/L")
(make-range "BUN" 7 27 "mg/dl")
(make-range "Ca" 7.9 12.0 "mg/dl")
(make-range "CREA" 0.5 1.8 "mg/dl")))
(define RESULTS
(list (make-result "ALB" "L")
(make-result "ALKP" "N")
(make-result "ALT" "N")
(make-result "AMYL" "N")
(make-result "BUN" "H")
(make-result "Ca" "L")
(make-result "CREA" "N")))
(check-expect (readings->results READINGS RANGES) RESULTS)
(define (readings->results a-lord a-lorg)
(cond
[(empty? a-lorg) empty]
[(cons? a-lorg)
(cons (make-result (range-label (first a-lorg)) (compute-code (first a-lorg) (first a-lord)))
(readings->results (rest a-lord) (rest a-lorg)))]))
(check-expect (compute-code (make-range "ALT" 10 100 "U/L") 67) "N")
(check-expect (compute-code (make-range "ALT" 10 100 "U/L") 6) "L")
(check-expect (compute-code (make-range "ALT" 10 100 "U/L") 167) "H")
(check-expect (compute-code (make-range "ALT" 10 100 "U/L") 100) "N")
(define (compute-code a-range a-reading)
(cond [(< a-reading (range-low a-range)) "L"]
[(> a-reading (range-high a-range)) "H"]
[else "N"]))
(require 2htdp/image)
(define BAR (add-line (add-line (empty-scene 200 10) 50 0 50 10 "black")
150 0 150 10 "black"))
(define (result-bars->image a-loi)
(cond [(empty? a-loi) (empty-scene 0 0)]
[(cons? a-loi) (above (first a-loi)
(result-bars->image (rest a-loi)))]))
(define (readings->image a-lorg a-lord)
(result-bars->image (readings->result-bars a-lorg a-lord)))
(define (readings->result-bars a-lorg a-lord)
(cond
[(empty? a-lorg) empty]
[(cons? a-lorg)
(cons (above/align "left"
(text (range-label (first a-lorg)) 10 "black")
(indicator-bar (first a-lorg) (first a-lord)))
(readings->result-bars (rest a-lorg) (rest a-lord)))]))
(define (indicator-bar a-range a-reading)
(place-image (rectangle 5 10 "solid"
(cond [(string=? "N" (compute-code a-range a-reading)) "blue"]
[(string=? "L" (compute-code a-range a-reading)) "red"]
[(string=? "H" (compute-code a-range a-reading)) "red"]))
(+ 50 (* (- a-reading (range-low a-range))
(/ 100 (- (range-high a-range) (range-low a-range)))))
5
BAR))
(require (planet nah22/racketui))
(define/web range/web
(structure make-range ["Label" string] ["Low" number] ["High" number] ["Units" string]))
(define/web reading/web
number)
(define/web result/web
(structure make-result
["Label" string]
["Result Code" (oneof ["Low Result" (constant "L")]
["Normal Result" (constant "N")]
["High Result" (constant "H")])]))
(web-launch
"Blood Test Result Analyzer"
(function "Analyzes blood test results"
(readings->results ["List of readings" (listof ["Reading" reading/web])]
["List of ranges" (listof ["Range" range/web])]
-> ["List of results" (listof ["Result" result/web])])))