示例#1
0
def calc_cri_advanced(request):
    """Calculates complex CRI dosages based on multiple inputs.

    GET parameters:
        weight: weight in kgs
        rate: current cri rate
        volume: current iv volume in mL
        infusion: target infusion rate

    Context:
        rx: calculated dosages rounded to 3 decimal places

    """

    meds = CRI.objects.filter(calc_type='adv')
    form = CRIAdvancedForm()
    rx = dict()

    for med in meds:
        rx[med] = dict()

    if request.method == 'GET' and request.is_ajax():
        form = CRIAdvancedForm(data=request.GET)

        if form.is_valid():
            weight = float(request.GET['weight'])
            rate = float(request.GET['rate'])
            volume = float(request.GET['volume'])
            infusion = float(request.GET['infusion'])

            for med in meds:
                rx[med] = {'maint': round((weight * 30 * 2.2)/24, 3),
                           'maint_plus': round((weight * 30 + 70)/24, 3),
                           'add': round(((weight * infusion * med.factor) / (rate/60)) * volume, 3)}

    return render(request, 'calc/cri_advanced.html', {'navbar': 'calc',
                                                      'form': form,
                                                      'rx': rx})
示例#2
0
 def test_form_rejects_empty_string(self):
     form = CRIAdvancedForm(data={'weight': '',
                                  'rate': '',
                                  'vol': '',
                                  'replacement': ''})
     self.assertFalse(form.is_valid())
示例#3
0
 def test_form_rejects_non_numeric_input(self):
     form = CRIAdvancedForm(data={'weight': 'wait',
                                  'rate': 'eight',
                                  'vol': 'volume',
                                  'replacement': 'enplacement'})
     self.assertFalse(form.is_valid())