
Medical Physics is about application of physics to medicine — radiation/x-rays, E&M, lasers, radionuclides, ultrasound etc.
Two biggest areas of activity:
Numbers:
Staff
Main areas of focus
~20 radiation treatment & imaging units
To ensure accurate & safe treatment delivery, lots of QC activity
CNSC requires data to be stored for 7-10 years.
Need a reliable, easy to use way to record & store this data
When confronted with a problem, people often say:
‘I know...I'll use Excel!’Now they have two problems.
QATrack+ is a web app built with Django
Start investigating deploying Django...
"If you [run Django on] Windows you're going to have a bad time, trust me."
"Forced to run Django on Windows? That's about when I'd pack my shit and leave."
"The people I know who deploy Django on Windows [...] proxy IIS to CherryPy.
That's probably the sanest way."
- Jacob Kaplan Moss
Users can define Python snippets for doing calculations
ftp = (temperature + 273.15)/295.15*(1.3332*760)/pressure
dose = ftp*p_ion*kq_sw*electrometer_reading
from scipy import stats readings = [r1, r2, r3, r4, r5, r6, r7, r8, r9] mus = [2, 3, 5, 11, 20, 50, 100, 200, 400] ys = [m for r,m in zip(readings,mus) if r] xs = [r for r in readings if r] slope, intercept, r_value, p_value, std_err = stats.linregress(xs,ys) dose_intercept = intercept
Pseudo code for the view (Actual view is ~130 lines)
class CalculatedTest(JSONResponseMixin, View): def post(self, *args, **kwargs): #retrieve test calculation procedures from db calculated_tests = self.calculated_tests(self.request.POST.get("test_list") # set up a dict with current values of all tests (from POST data) calculation_context = self.calculation_context() #figure out the order the results need to be calculated on calculation_order = self.resolve_dependency_order(calculated_tests) results = {} for test in calculation_order: procedure = calculated_tests[test].procedure code = compile(procedure, "", "exec") exec code in calculation_context results[test] = calculation_context[test] return self.render_json_response(results)
Don't do this in public facing website!!!
def get_patient_ids(): """return all available patient ID's on remote XiO server""" find_dvh = "find {0} -name {1}".format(settings.XIO_PATH, "rtog_dvh.dat") with fabric.api.settings(host_string="host", user="user", password="password"): results = fabric.api.run(find_dvh, stdout=StringIO.StringIO()) return [clean_patient_id(x) for x in results.split()] def get_patient_plans(patient_id): """return all available treatment plans for input patient""" dvh_path = "/{0}/{1}/rtog_dvh.dat".format(settings.XIO_DVH_ROOT, patient_id) with fabric.api.settings(host_string="host", user="user", password="password"): data = StringIO.StringIO() fabric.api.get(dvh_pat, local_path=data) dvh_dat = data.getvalue() return dvh_to_plan(dvh_dat)
<div>
<p>
First name: <input data-bind='value: firstName' />
Last name: <input data-bind='value: lastName' />
<strong>Hello, <span data-bind='text: fullName'> </span>!</strong>
</p>
</div>
<script type="text/javascript">
var ViewModel = function(first, last) {
this.firstName = ko.observable(first);
this.lastName = ko.observable(last);
this.fullName = ko.computed(function() {
return this.firstName() + " " + this.lastName();
}, this);
};
ko.applyBindings(new ViewModel("Planet", "Earth"));
</script>
First name: Last name: Hello, !
We're using Python in a number of other tools as well:
Python is gaining traction in our department and Medical Physics in general. Great news!