83 lines
3.2 KiB
Common Lisp
83 lines
3.2 KiB
Common Lisp
(load "~/quicklisp/setup.lisp")
|
|
(ql:quickload :hunchentoot)
|
|
(ql:quickload :drakma)
|
|
(ql:quickload :com.inuoe.jzon)
|
|
|
|
(uiop:define-package tfc-server
|
|
(:use :cl :hunchentoot :com.inuoe.jzon))
|
|
|
|
(in-package :tfc-server)
|
|
|
|
(defun handle-post-request (request)
|
|
(let ((form-data (hunchentoot:req request)))
|
|
(with-response-buffer (stream :content-type "text/plain")
|
|
(format stream "Received form data: ~A" form-data))))
|
|
|
|
(push (create-prefix-dispatcher "/data" 'handle-post-request) hunchentoot:*dispatch-table*)
|
|
|
|
(hunchentoot:define-easy-handler (say-yo :uri "/yo") (name)
|
|
(setf (hunchentoot:content-type*) "text/plain")
|
|
(format nil "Hey~@[ ~A~]!" name))
|
|
|
|
(hunchentoot:define-easy-handler (respond :uri "/health-form") ()
|
|
(setf (hunchentoot:content-type*) "multipart/form-data")
|
|
(let ((request-type (hunchentoot:request-method hunchentoot:*request*)))
|
|
(cond ((eq request-type :get) nil)
|
|
((eq request-type :post)
|
|
(let* ((data (hunchentoot:raw-post-data :force-text t))
|
|
(json-obj (com.inuoe.jzon:parse data))
|
|
)
|
|
;; (print (format nil "Json: ~A" (com.inuoe.jzon:stringify json-obj)))
|
|
(uiop:println "Received Health Form")
|
|
(render-json json-obj)
|
|
(setq last json-obj)
|
|
(process-form json-obj)
|
|
data)))))
|
|
|
|
(defvar last)
|
|
(defvar *token* "boFFRM68vvXbO-DO7S9YDg86lHX027-hd07mn0dh")
|
|
|
|
(defun print-hash-entry (key value)
|
|
(format t "~S: ~S~%" key value))
|
|
|
|
(defun process-form (form)
|
|
"Processes the form and sends it on"
|
|
(let ((firstname (gethash "firstname" form))
|
|
(lastname (gethash "lastname" form))
|
|
(parentfirstname (gethash "parentfirstname" form))
|
|
(parentlastname (gethash "parentlastname" form))
|
|
(street (gethash "street" form))
|
|
(city (gethash "city" form))
|
|
(state (gethash "state" form))
|
|
(zip (gethash "zip" form))
|
|
(cellphone (gethash "cellphone" form))
|
|
(homephone (gethash "homephone" form))
|
|
(add-emergency-contact (gethash "add-emergency-contact" form))
|
|
(add-emergency-contact-phone (gethash "add-emergency-contact-phone" form))
|
|
(doctorname (gethash "doctorname" form))
|
|
(doctorcity (gethash "doctorcity" form))
|
|
(doctorphone (gethash "doctorphone" form))
|
|
(medical-coverage (gethash "medical-coverage" form))
|
|
(insurance-name (gethash "insurance-name" form))
|
|
(policy-number (gethash "policy-number" form))
|
|
(image (gethash "image" form))
|
|
(agreement (gethash "agreement" form))
|
|
(allergies (gethash "allergies" form))
|
|
(allergies-other (gethash "allergies-other" form))
|
|
(specific-allergies (gethash "specific-allergies" form))
|
|
(allergic-treatment (gethash "allergic-treatment" form))
|
|
(conditions (gethash "conditions" form))
|
|
(tetanus-shot (gethash "tetanus-shot" form))
|
|
(swimming-ability (gethash "swimming-ability" form))
|
|
(medication-schedule (gethash "medication-schedule" form))
|
|
(other-notes (gethash "other-notes" form))
|
|
(age (gethash "age" form)))
|
|
(uiop:println "---")
|
|
(maphash 'print-hash-entry form)
|
|
(uiop:println "---")))
|
|
|
|
|
|
(defun render-json (object)
|
|
(uiop:println (format nil "Json: ~A" (com.inuoe.jzon:stringify object))))
|
|
|