예제 #1
0
파일: views.py 프로젝트: csillagharcos/Path
def CountStatistics(cases, notView=True):
    """ Query """
    indicator_one_numerator = subindicator_one_30 = subindicator_two_2 = subindicator_one = 0
    countable_case = uncountable_case = ()
    for case in cases:
        if calculate_age(case.date_of_birth, case.date_of_admission) <= 15 and (case.icd == "I21" or case.icd == "I22"):
            uncountable_case += (case,)
        else:
            countable_case += (case,)

    if len(countable_case) < 60 and notView:
        return False

    """ Working """
    for case in countable_case:
        if case.patient_discharge_status == 2 and (case.date_of_discharge - case.date_of_admission).days <= 30:
            indicator_one_numerator += 1
        if (
            case.patient_discharge_status == 2
            and (case.date_of_discharge - case.date_of_admission).days <= 30
            and not case.patient_admission_status
        ):
            subindicator_one += 1
        if not case.patient_admission_status and (
            case.patient_discharge_status == 0 or case.patient_discharge_status == 2
        ):
            subindicator_one_30 += 1
        if case.patient_discharge_status == 2 and (case.date_of_discharge - case.date_of_admission).days <= 2:
            subindicator_two_2 += 1

    """ Counting """
    try:
        indicator_one = float(indicator_one_numerator) / len(countable_case) * 100
    except ZeroDivisionError:
        indicator_one = 0
    try:
        subindicator_one = float(subindicator_one) / float(subindicator_one_30) * 100
    except ZeroDivisionError:
        subindicator_one = 0
    try:
        subindicator_two = float(subindicator_two_2) / len(countable_case) * 100
    except ZeroDivisionError:
        subindicator_two = 0
    """ Displaying """
    context = {
        "overall": len(cases),
        "removed": len(uncountable_case),
        "counted": len(countable_case),
        "indicator_one": indicator_one,
        "subindicator_one": subindicator_one,
        "subindicator_two": subindicator_two,
    }
    return context
예제 #2
0
파일: views.py 프로젝트: derekzhang79/Path
def Statistics(request):
    ''' Query '''
    countable_case=uncountable_case=()
    cases = c20.objects.all()
    a=""
    for case in cases:
        error=False
        if not case.diagnosis_code == "I21" and not case.diagnosis_code == "I22":
            uncountable_case += (case,)
            error = True
        if calculate_age(case.date_of_birth) < 15 and not error:
            uncountable_case += (case,)
            error = True
        if (case.type_of_discharge == 0 or case.type_of_discharge == 2 or case.type_of_discharge == 3 or case.patient_allergic_aspirin == 1 or case.aspirin_intolerance == 1 or case.aspirin_refusal == 1) and not error:
            uncountable_case += (case,)
            error = True
        if not error:
            countable_case += (case,)

    cindicator_one = cindicator_two = cindicator_three = 0
    indicator_one = indicator_two = indicator_three = 0
    ''' Working '''
    for case in countable_case:
        if case.aspirin_at_discharge == 1:
            cindicator_one += 1
        if case.non_aspirin_platelet == 1:
            cindicator_two += 1
        if case.aspirin_at_discharge == 1 or case.non_aspirin_platelet == 1:
            cindicator_three += 1
    for case in uncountable_case:
        a += str(case.case_id)+", "

    ''' Counting '''
    try: indicator_one = float(cindicator_one) / len(countable_case) * 100
    except: indicator_one = 0
    try: indicator_two = float(cindicator_two) / len(countable_case) * 100
    except: indicator_one = 0
    try: indicator_three = float(cindicator_three) / len(countable_case) * 100
    except: indicator_one = 0

    ''' Displaying '''
    context = {
        "overall": len(cases),
        "removed": len(uncountable_case),
        "counted": len(countable_case),
        "indicator_one": indicator_one,
        "indicator_two": indicator_two,
        "indicator_three": indicator_three,
        "a": a,
    }
    return render_to_response('c20_statistics.html', context, context_instance=RequestContext(request))
예제 #3
0
파일: views.py 프로젝트: csillagharcos/Path
def CountStatistics(cases, notView = True):
    ''' Query '''
    countable_case=uncountable_case=()
    for case in cases:
        error=False
        if not case.diagnosis_code == "I21" and not case.diagnosis_code == "I22":
            uncountable_case += (case,)
            error = True
        if calculate_age(case.date_of_birth) < 15 and not error:
            uncountable_case += (case,)
            error = True
        if (case.type_of_discharge == 0 or case.type_of_discharge == 2 or case.type_of_discharge == 3 or case.patient_allergic_aspirin == 1 or case.aspirin_intolerance == 1 or case.aspirin_refusal == 1) and not error:
            uncountable_case += (case,)
            error = True
        if not error:
            countable_case += (case,)

    if len(countable_case) < 30 and notView:
        return False

    cindicator_one = cindicator_two = cindicator_three = 0
    indicator_one = indicator_two = indicator_three = 0
    ''' Working '''
    for case in countable_case:
        if case.aspirin_at_discharge == 1:
            cindicator_one += 1
        if case.non_aspirin_platelet == 1:
            cindicator_two += 1
        if case.aspirin_at_discharge == 1 or case.non_aspirin_platelet == 1:
            cindicator_three += 1

    ''' Counting '''
    try: indicator_one = float(cindicator_one) / len(countable_case) * 100
    except: indicator_one = 0
    try: indicator_two = float(cindicator_two) / len(countable_case) * 100
    except: indicator_one = 0
    try: indicator_three = float(cindicator_three) / len(countable_case) * 100
    except: indicator_one = 0

    ''' Displaying '''
    context = {
        "overall": len(cases),
        "removed": len(uncountable_case),
        "counted": len(countable_case),
        "indicator_one": indicator_one,
        "indicator_two": indicator_two,
        "indicator_three": indicator_three,
        }
    return context
예제 #4
0
파일: views.py 프로젝트: derekzhang79/Path
def Statistics(request):
    ''' Query '''
    indicator_one_numerator = subindicator_one_30 = subindicator_two_2 = subindicator_one = 0
    countable_case=uncountable_case=()
    cases = c32.objects.all()
    for case in cases:
        if calculate_age(case.date_of_birth, case.date_of_admission) < 18:
            uncountable_case += (case,)
        else:
            countable_case += (case,)

    ''' Working '''
    for case in countable_case:
        if case.patient_discharge_status == 2 and (case.date_of_discharge - case.date_of_admission).days <= 30:
            indicator_one_numerator += 1
        if case.patient_discharge_status == 2 and (case.date_of_discharge - case.date_of_admission).days <= 30 and not case.patient_admission_status:
            subindicator_one += 1
        if not case.patient_admission_status and (case.patient_discharge_status == 0 or case.patient_discharge_status == 2):
            subindicator_one_30 += 1
        if case.patient_discharge_status == 2 and (case.date_of_discharge - case.date_of_admission).days <= 2:
            subindicator_two_2 += 1

    ''' Counting '''
    try: indicator_one = float( indicator_one_numerator ) / len(countable_case) * 100
    except ZeroDivisionError: indicator_one = 0
    try: subindicator_one = float( subindicator_one ) / float(subindicator_one_30)  * 100
    except ZeroDivisionError: subindicator_one = 0
    try: subindicator_two = float( subindicator_two_2 ) / len(countable_case) * 100
    except ZeroDivisionError: subindicator_two = 0

    ''' Displaying '''
    context = {
        "overall": len(cases),
        "removed": len(uncountable_case),
        "counted": len(countable_case),
        "indicator_one": indicator_one,
        "subindicator_one": subindicator_one,
        "subindicator_two": subindicator_two,
    }
    return render_to_response('c32_statistics.html', context, context_instance=RequestContext(request))
예제 #5
0
파일: views.py 프로젝트: csillagharcos/Path
def CountStatistics(cases, notView=True):
    ''' Query '''
    countable_case=uncountable_case=()
    for case in cases:
        if calculate_age(case.date_of_birth, case.date_of_admission) <= 18 or case.patient_admission_status == 1 or case.type_of_admission == 1 or case.type_of_admission == 2 or case.patient_discharge_status == 1 or case.patient_discharge_status == 3:
            uncountable_case += (case,)
        else:
            if (case.diagnosis_group == 0 and (case.icd == "I61" or case.icd == "I62" or case.icd == "I63" or case.icd == "I64")) or (case.diagnosis_group == 1 and (case.icd == "J13" or case.icd == "J14" or case.icd == "J15" or case.icd == "J18" or case.icd == "A48.1")) or (case.diagnosis_group == 2 and (case.icd == "S72.0" or case.icd == "S72.1" or case.icd == "S72.2")) or (case.diagnosis_group == 3 and (case.drg == "177A" or case.drg == "177B" or case.drg == "177C" or case.drg == "177D" or case.drg == "190A" or case.drg == "192A" or case.drg == "192B")) or (case.diagnosis_group == 4 and (case.drg == "398A" or case.drg == "398B")) or (case.diagnosis_group == 5 and (case.icd == "K40" or case.drg == "281B" or case.drg == "282A" or case.drg == "282B")) or (case.diagnosis_group == 6 and case.drg == "097A") or (case.diagnosis_group == 7 and (case.drg == "344" or case.drg == "345" or case.drg == "369Z")) or (case.diagnosis_group == 8 and case.drg == "2030"):
                countable_case += (case,)
            else:
                uncountable_case += (case,)

    if len(countable_case) < 60 and notView:
        return False

    ''' Working '''
    s_days = hap_days = hf_days = cabg_days = ka_days = ih_days = taa_days = c_days = v_days = ()
    sd_days = hapd_days = hfd_days = cabgd_days = kad_days = ihd_days = taad_days = cd_days = vd_days = ()
    sde_days = hapde_days = hfde_days = cabgde_days = kade_days = ihde_days = taade_days = cde_days = vde_days = ()
    s_dates = hap_dates = hf_dates = cabg_dates = ka_dates = ih_dates = taa_dates = c_dates = v_dates = ()
    for case in countable_case:
        if not case.diagnosis_group: #Stroke
            s_days += ((case.date_of_discharge - case.date_of_admission).days+1,)
            s_dates += (case.date_of_admission,)
            if case.was_surgical_procedure == 1:
                sd_days += ((case.date_of_surgical_procedure - case.date_of_admission).days+1,)
                sde_days += ((case.date_of_discharge - case.date_of_surgical_procedure).days+1,)
        elif case.diagnosis_group == 1: #Hospital acquired pneumonia
            hap_days += ((case.date_of_discharge - case.date_of_admission).days+1,)
            hap_dates += (case.date_of_admission,)
            if case.was_surgical_procedure == 1:
                hapd_days += ((case.date_of_surgical_procedure - case.date_of_admission).days+1,)
                hapde_days += ((case.date_of_discharge - case.date_of_surgical_procedure).days+1,)
        elif case.diagnosis_group == 2: #Hip fracture
            hf_days += ((case.date_of_discharge - case.date_of_admission).days+1,)
            hf_dates += (case.date_of_admission,)
            if case.was_surgical_procedure == 1:
                hfd_days += ((case.date_of_surgical_procedure - case.date_of_admission).days+1,)
                hfde_days += ((case.date_of_discharge - case.date_of_surgical_procedure).days+1,)
        elif case.diagnosis_group == 3: #CABG
            cabg_days += ((case.date_of_discharge - case.date_of_admission).days+1,)
            cabg_dates += (case.date_of_admission,)
            if case.was_surgical_procedure == 1:
                cabgd_days += ((case.date_of_surgical_procedure - case.date_of_admission).days+1,)
                cabgde_days += ((case.date_of_discharge - case.date_of_surgical_procedure).days+1,)
        elif case.diagnosis_group == 4: #Knee arthroscopy
            ka_days += ((case.date_of_discharge - case.date_of_admission).days+1,)
            ka_dates += (case.date_of_admission,)
            if case.was_surgical_procedure == 1:
                kad_days += ((case.date_of_surgical_procedure - case.date_of_admission).days+1,)
                kade_days += ((case.date_of_discharge - case.date_of_surgical_procedure).days+1,)
        elif case.diagnosis_group == 5: #Inguinal hernia
            ih_days += ((case.date_of_discharge - case.date_of_admission).days+1,)
            ih_dates += (case.date_of_admission,)
            if case.was_surgical_procedure == 1:
                ihd_days += ((case.date_of_surgical_procedure - case.date_of_admission).days+1,)
                ihde_days += ((case.date_of_discharge - case.date_of_surgical_procedure).days+1,)
        elif case.diagnosis_group == 6: #Tonsillectomy and/or adenoidectomy
            taa_days += ((case.date_of_discharge - case.date_of_admission).days+1,)
            taa_dates += (case.date_of_admission,)
            if case.was_surgical_procedure == 1:
                taad_days += ((case.date_of_surgical_procedure - case.date_of_admission).days+1,)
                taade_days += ((case.date_of_discharge - case.date_of_surgical_procedure).days+1,)
        elif case.diagnosis_group == 7: #Cholecystectomy
            c_days += ((case.date_of_discharge - case.date_of_admission).days+1,)
            c_dates += (case.date_of_admission,)
            if case.was_surgical_procedure == 1:
                cd_days += ((case.date_of_surgical_procedure - case.date_of_admission).days+1,)
                cde_days += ((case.date_of_discharge - case.date_of_surgical_procedure).days+1,)
        elif case.diagnosis_group == 8: #Varicose veins - stripping and ligation
            v_days += ((case.date_of_discharge - case.date_of_admission).days+1,)
            v_dates += (case.date_of_admission,)
            if case.was_surgical_procedure == 1:
                vd_days += ((case.date_of_surgical_procedure - case.date_of_admission).days+1,)
                vde_days += ((case.date_of_discharge - case.date_of_surgical_procedure).days+1,)

    ''' Stroke '''
    try: s_first_date = sorted(s_dates)[0]
    except: s_first_date = 0
    try: s_last_date = sorted(s_dates, reverse=True)[0]
    except: s_last_date = 0
    try: s_avg = float(sum(s_days)) / len(s_days)
    except: s_avg = 0
    try: s_med = median(s_days)
    except: s_med = 0
    try: sd_avg = float(sum(sd_days)) / len(sd_days)
    except: sd_avg = 0
    try: sd_med = median(sd_days)
    except: sd_med = 0
    try: sde_avg = float(sum(sde_days)) / len(sde_days)
    except: sde_avg = 0
    try: sde_med = median(sde_days)
    except: sde_med = 0

    ''' Hospital acquired pneumonia '''
    try: hap_first_date = sorted(hap_dates)[0]
    except: hap_first_date = 0
    try: hap_last_date = sorted(hap_dates, reverse=True)[0]
    except: hap_last_date = 0
    try: hap_avg = float(sum(hap_days)) / len(hap_days)
    except: hap_avg = 0
    try: hap_med = median(hap_days)
    except: hap_med = 0
    try: hapd_avg = float(sum(hapd_days)) / len(hapd_days)
    except: hapd_avg = 0
    try: hapd_med = median(hapd_days)
    except: hapd_med = 0
    try: hapde_avg = float(sum(hapde_days)) / len(hapde_days)
    except: hapde_avg = 0
    try: hapde_med = median(hapde_days)
    except: hapde_med = 0

    ''' Hip fracture '''
    try: hf_first_date = sorted(hf_dates)[0]
    except: hf_first_date = 0
    try: hf_last_date = sorted(hf_dates, reverse=True)[0]
    except: hf_last_date = 0
    try: hf_avg = float(sum(hf_days)) / len(hf_days)
    except: hf_avg = 0
    try: hf_med = median(hf_days)
    except: hf_med = 0
    try: hfd_avg = float(sum(hfd_days)) / len(hfd_days)
    except: hfd_avg = 0
    try: hfd_med = median(hfd_days)
    except: hfd_med = 0
    try: hfde_avg = float(sum(hfde_days)) / len(hfde_days)
    except: hfde_avg = 0
    try: hfde_med = median(hfde_days)
    except: hfde_med = 0

    ''' CABG '''
    try: cabg_first_date = sorted(cabg_dates)[0]
    except: cabg_first_date = 0
    try: cabg_last_date = sorted(cabg_dates, reverse=True)[0]
    except: cabg_last_date = 0
    try: cabg_avg = float(sum(cabg_days)) / len(cabg_days)
    except: cabg_avg = 0
    try: cabg_med = median(cabg_days)
    except: cabg_med = 0
    try: cabgd_avg = float(sum(cabgd_days)) / len(cabgd_days)
    except: cabgd_avg = 0
    try: cabgd_med = median(cabgd_days)
    except: cabgd_med = 0
    try: cabgde_avg = float(sum(cabgde_days)) / len(cabgde_days)
    except: cabgde_avg = 0
    try: cabgde_med = median(cabgde_days)
    except: cabgde_med = 0

    ''' Knee arthroscopy '''
    try: ka_first_date = sorted(ka_dates)[0]
    except: ka_first_date = 0
    try: ka_last_date = sorted(ka_dates, reverse=True)[0]
    except: ka_last_date = 0
    try: ka_avg = float(sum(ka_days)) / len(ka_days)
    except: ka_avg = 0
    try: ka_med = median(ka_days)
    except: ka_med = 0
    try: kad_avg = float(sum(kad_days)) / len(kad_days)
    except: kad_avg = 0
    try: kad_med = median(kad_days)
    except: kad_med = 0
    try: kade_avg = float(sum(kade_days)) / len(kade_days)
    except: kade_avg = 0
    try: kade_med = median(kade_days)
    except: kade_med = 0

    ''' Inguinal hernia '''
    try: ih_first_date = sorted(ih_dates)[0]
    except: ih_first_date = 0
    try: ih_last_date = sorted(ih_dates, reverse=True)[0]
    except: ih_last_date = 0
    try: ih_avg = float(sum(ih_days)) / len(ih_days)
    except: ih_avg = 0
    try: ih_med = median(ih_days)
    except: ih_med = 0
    try: ihd_avg = float(sum(ihd_days)) / len(ihd_days)
    except: ihd_avg = 0
    try: ihd_med = median(ihd_days)
    except: ihd_med = 0
    try: ihde_avg = float(sum(ihde_days)) / len(ihde_days)
    except: ihde_avg = 0
    try: ihde_med = median(ihde_days)
    except: ihde_med = 0

    ''' Tonsillectomy and/or adenoidectomy '''
    try: taa_first_date = sorted(taa_dates)[0]
    except: taa_first_date = 0
    try: taa_last_date = sorted(taa_dates, reverse=True)[0]
    except: taa_last_date = 0
    try: taa_avg = float(sum(taa_days)) / len(taa_days)
    except: taa_avg = 0
    try: taa_med = median(taa_days)
    except: taa_med = 0
    try: taad_avg = float(sum(taad_days)) / len(taad_days)
    except: taad_avg = 0
    try: taad_med = median(taad_days)
    except: taad_med = 0
    try: taade_avg = float(sum(taade_days)) / len(taade_days)
    except: taade_avg = 0
    try: taade_med = median(taade_days)
    except: taade_med = 0

    ''' Cholecystectomy '''
    try: c_first_date = sorted(c_dates)[0]
    except: c_first_date = 0
    try: c_last_date = sorted(c_dates, reverse=True)[0]
    except: c_last_date = 0
    try: c_avg = float(sum(c_days)) / len(c_days)
    except: c_avg = 0
    try: c_med = median(c_days)
    except: c_med = 0
    try: cd_avg = float(sum(cd_days)) / len(cd_days)
    except: cd_avg = 0
    try: cd_med = median(cd_days)
    except: cd_med = 0
    try: cde_avg = float(sum(cde_days)) / len(cde_days)
    except: cde_avg = 0
    try: cde_med = median(cde_days)
    except: cde_med = 0

    ''' Varicose veins - stripping and ligation '''
    try: v_first_date = sorted(v_dates)[0]
    except: v_first_date = 0
    try: v_last_date = sorted(v_dates, reverse=True)[0]
    except: v_last_date = 0
    try: v_avg = float(sum(v_days)) / len(v_days)
    except: v_avg = 0
    try: v_med = median(v_days)
    except: v_med = 0
    try: vd_avg = float(sum(vd_days)) / len(vd_days)
    except: vd_avg = 0
    try: vd_med = median(vd_days)
    except: vd_med = 0
    try: vde_avg = float(sum(vde_days)) / len(vde_days)
    except: vde_avg = 0
    try: vde_med = median(vde_days)
    except: vde_med = 0


    ''' Counting '''
    diagnosis = [
        [_('Stroke'), s_first_date, s_last_date, s_avg, s_med, sd_avg, sd_med, sde_avg, sde_med, len(s_days)],
        [_('Hospital acquired pneumonia'), hap_first_date, hap_last_date, hap_avg, hap_med, hapd_avg, hapd_med, hapde_avg, hapde_med, len(hap_days)],
        [_('Hip fracture'), hf_first_date, hf_last_date, hf_avg, hf_med, hfd_avg, hfd_med, hfde_avg, hfde_med, len(hf_days)],
        [_('CABG'), cabg_first_date, cabg_last_date, cabg_avg, cabg_med, cabgd_avg, cabgd_med, cabgde_avg, cabgde_med, len(cabg_days)],
        [_('Knee arthroscopy'), ka_first_date, ka_last_date, ka_avg, ka_med, kad_avg, kad_med, kade_avg, kade_med, len(ka_days)],
        [_('Inguinal hernia'), ih_first_date, ih_last_date, ih_avg, ih_med, ihd_avg, ihd_med, ihde_avg, ihde_med, len(ih_days)],
        [_('Tonsillectomy and/or adenoidectomy'), taa_first_date, taa_last_date, taa_avg, taa_med, taad_avg, taad_med, taade_avg, taade_med, len(taa_days)],
        [_('Cholecystectomy'), c_first_date, c_last_date, c_avg, c_med, cd_avg, cd_med, cde_avg, cde_med, len(c_days)],
        [_('Varicose veins - stripping and ligation'), v_first_date, v_last_date, v_avg, v_med, vd_avg, vd_med, vde_avg, vde_med, len(v_days)],
    ]
    ''' Displaying '''
    context = {
        "overall": len(cases),
        "removed": len(uncountable_case),
        "counted": len(countable_case),
        "diagnosis": diagnosis
    }
    return context
예제 #6
0
파일: views.py 프로젝트: csillagharcos/Path
def CountStatistics(cases, notView=True):
    countable_case=uncountable_case=()
    for case in cases:
        if case.other_diagnoses.count() > 0:
            uncountable_case += (case,)
        else:
            countable_case += (case,)

    if len(countable_case) < 30 and notView:
        return False

    ''' Working '''
    numerator = map(float,[0,0,0,0,0,0,0,0])
    agedenominator = [0,0,0]
    previousdenominator = [0,0]
    for case in countable_case:
        age = calculate_age(case.date_of_birth, case.date_of_delivery.date())
        if age < 20:
            agedenominator[0] += 1
        elif 20 <= age <= 35:
            agedenominator[1] += 1
        elif age > 35:
            agedenominator[2] += 1
        if not case.number_of_prev_deliveries:
            previousdenominator[0] += 1
        elif case.number_of_prev_deliveries >= 1:
            previousdenominator[1] += 1
        if case.drg_code == "671A" or case.drg_code == "671B":
            numerator[0] += 1                                               #indicator 1
            if not case.the_c_section:
                numerator[1] += 1                                           #subindicator 1
            else:
                numerator[2] += 1                                           #subindicator 2
            ''' Subindicator 3 '''
            if age < 20:
                numerator[3] += 1                                           #subindicator 3.1
            elif 20 <= age <= 35:
                numerator[4] += 1                                           #subindicator 3.2
            elif age > 35:
                numerator[5] += 1                                           #subindicator 3.3
            ''' Subindicator 4 '''
            if not case.number_of_prev_deliveries:
                numerator[6] += 1                                           #subindicator 4.1
            elif case.number_of_prev_deliveries >= 1:
                numerator[7] += 1                                           #subindicator 4.2

    ''' Counting '''
    try: indicator_one       = numerator[0] / len(countable_case)     * 100
    except: indicator_one    = 0
    try: subindicator_one    = numerator[1] / len(countable_case)     * 100
    except: subindicator_one = 0
    try: subindicator_two    = numerator[2] / len(countable_case)     * 100
    except: subindicator_two = 0
    try:
        subindicator_three_one  = numerator[3] / agedenominator[0]   * 100
    except ZeroDivisionError:
        subindicator_three_one  = 0

    try:
        subindicator_three_two  = numerator[4] / agedenominator[1]   * 100
    except ZeroDivisionError:
        subindicator_three_two  = 0

    try:
        subindicator_three_three= numerator[5] / agedenominator[2]   * 100
    except ZeroDivisionError:
        subindicator_three_three= 0

    try:
        subindicator_four_one   = numerator[6] / previousdenominator[0] * 100
    except ZeroDivisionError:
        subindicator_four_one   = 0

    try:
        subindicator_four_two   = numerator[7] / previousdenominator[1] * 100
    except ZeroDivisionError:
        subindicator_four_two   = 0

    ''' Displaying '''
    context = {
        "overall": len(cases),
        "removed": len(uncountable_case),
        "counted": len(countable_case),
        "indicator_one": indicator_one,
        "subindicator_one": subindicator_one,
        "subindicator_two": subindicator_two,
        "subindicator_three_one": subindicator_three_one,
        "subindicator_three_two": subindicator_three_two,
        "subindicator_three_three": subindicator_three_three,
        "subindicator_four_one": subindicator_four_one,
        "subindicator_four_two": subindicator_four_two,
        }
    return context
예제 #7
0
파일: views.py 프로젝트: csillagharcos/Path
def CountStatistics(cases, notView=True):
    ''' Query '''
    accepted_diagnose_codes = ("371A", "371B", "371C", "371H", "371K", "372A", "372C", "372M", "372N", "372X", "372Y")
    countable_case=uncountable_case=()
    medicines=()
    for medicine in Medicine.objects.all():
        medicines += (medicine.name,)
    for case in cases:
        if case.principal_diagnoses_code in accepted_diagnose_codes and case.procedure_planned and calculate_age(case.date_of_birth) >= 18 and not case.preoperative_infection and not case.generic_name_of_drug in medicines:
            countable_case += (case,)
        else:
            uncountable_case += (case,)

    if len(countable_case) < 30 and notView:
        return False

    ''' Working '''
    indicator_one = indicator_twoa = indicator_twob = indicator_three = indicator_four = indicator_five = indicator_six = indicator_seven = indicator_eight = indicator_nine = indicator_ten = 0
    for case in countable_case:
        indicator_tracker = 0
        try: first_med_dose = Medicine.objects.get(name = case.name_of_first_dose).dose
        except: first_med_dose = 0
        try: second_med_dose = Medicine.objects.get(name = case.name_of_second_dose).dose
        except: second_med_dose = 0
        try: first_med_doseUnder = Medicine.objects.get(name = case.name_of_first_dose).doseUnder
        except: first_med_doseUnder = 0
        try: second_med_doseUnder = Medicine.objects.get(name = case.name_of_second_dose).doseUnder
        except: second_med_doseUnder = 0
        #indicator one
        acceptable = False
        if case.name_of_first_dose in medicines or case.name_of_second_dose in medicines:
            if case.name_of_first_dose == "Cefazolin" or case.name_of_first_dose == "Cefuroxim" or case.name_of_first_dose == "Vancomycin":
                indicator_one += 1
                indicator_tracker += 1
                acceptable = True
            elif case.name_of_second_dose == "Cefazolin" or case.name_of_second_dose == "Cefuroxim" or case.name_of_second_dose == "Cefuroxim":
                indicator_one += 1
                indicator_tracker += 1
                acceptable = True

        #indicator two A
        if case.weight_of_patient >= 60:
            if first_med_dose == case.first_dose and second_med_dose == case.second_dose and acceptable:
                indicator_twoa += 1
                indicator_tracker += 1
        elif case.weight_of_patient < 60:
            if (first_med_dose == case.first_dose and second_med_dose == case.second_dose) or (first_med_doseUnder == case.first_dose and second_med_doseUnder == case.second_dose) and acceptable:
                indicator_twoa += 1
                indicator_tracker += 1

        #indicator two B
        if case.weight_of_patient >= 60:
            if (first_med_dose == case.first_dose or second_med_dose == case.second_dose) and acceptable:
                indicator_twob += 1
        else:
            if (first_med_doseUnder == case.first_dose or second_med_doseUnder == case.second_dose) and acceptable:
                indicator_twob += 1

        #indicator three
        if case.route_of_admin == 1:
            indicator_three += 1
            indicator_tracker += 1

        #indicator four
        try:
            if (case.surgical_incision - case.date_of_first_dose).seconds <= 3600:
                indicator_four += 1
                indicator_tracker += 1
        except:
            pass

        #indicator five
        try:
            if (case.date_of_wound_close - case.date_of_last_dose).seconds <= 86400:
                indicator_five += 1
            #indicator seven
            else:
                indicator_seven += 1
        except:
            indicator_seven += 1

        #indicator six
        if indicator_tracker < 4:
            indicator_six += 1
        else:
            indicator_ten += 1

        #indicator eight
        if not case.antibiotic_given:
            indicator_eight += 1

        #indicator nine
        if case.first_dose is None: fd = 0
        else: fd = case.first_dose
        if case.second_dose is None: sd = 0
        else: sd = case.second_dose
        if case.date_of_first_dose == case.date_of_last_dose and case.total_dose_in_24h == fd + sd:
            indicator_nine += 1

    ''' Counting '''
    try: one = float(indicator_one) / len(countable_case) * 100
    except: one = 0
    try: twoa = float(indicator_twoa) / len(countable_case) * 100
    except: twoa = 0
    try: twob = float(indicator_twob) / len(countable_case) * 100
    except: twob = 0
    try: three = float(indicator_three) / len(countable_case) * 100
    except: three = 0
    try: four = float(indicator_four) / len(countable_case) * 100
    except: four = 0
    try: five = float(indicator_five) / len(countable_case) * 100
    except: five = 0
    try: six = float(indicator_six) / len(countable_case) * 100
    except: six = 0
    try: seven = float(indicator_seven) / len(countable_case) * 100
    except: seven = 0
    try: eight = float(indicator_eight) / len(countable_case) * 100
    except: eight = 0
    try: nine = float(indicator_nine) / len(countable_case) * 100
    except: nine = 0
    try: ten = float(indicator_ten) / len(countable_case) * 100
    except: ten = 0

    ''' Displaying '''
    context = {
        "overall": len(cases),
        "removed": len(uncountable_case),
        "counted": len(countable_case),
        "one": one,
        "twoa": twoa,
        "twob": twob,
        "three": three,
        "four": four,
        "five": five,
        "six": six,
        "seven": seven,
        "eight": eight,
        "nine": nine,
        "ten": ten,
        }
    return context
예제 #8
0
파일: views.py 프로젝트: derekzhang79/Path
def Statistics(request):
    ''' Query '''
    countable_case=uncountable_case=()
    cases = c8.objects.all()
    for case in cases:
        if calculate_age(case.date_of_birth, case.date_of_admission) <= 18 or case.patient_admission_status == 1 or case.type_of_admission == 1 or case.type_of_admission == 2 or case.patient_discharge_status == 1 or case.patient_discharge_status == 3:
            uncountable_case += (case,)
        else:
            countable_case += (case,)

    ''' Working '''
    s_days = hap_days = hf_days = cabg_days = ka_days = ih_days = taa_days = c_days = v_days = ()
    sd_days = hapd_days = hfd_days = cabgd_days = kad_days = ihd_days = taad_days = cd_days = vd_days = ()
    sde_days = hapde_days = hfde_days = cabgde_days = kade_days = ihde_days = taade_days = cde_days = vde_days = ()
    s_dates = hap_dates = hf_dates = cabg_dates = ka_dates = ih_dates = taa_dates = c_dates = v_dates = ()
    for case in countable_case:
        if not case.diagnosis_group:         #Stroke
            s_days += ((case.date_of_discharge - case.date_of_admission).days+1,)
            s_dates += (case.date_of_admission,)
            if case.was_surgical_procedure == 1:
                sd_days += ((case.date_of_surgical_procedure - case.date_of_admission).days+1,)
                sde_days += ((case.date_of_discharge - case.date_of_surgical_procedure).days+1,)
        elif case.diagnosis_group == 1: #Hospital acquired pneumonia
            hap_days += ((case.date_of_discharge - case.date_of_admission).days+1,)
            hap_dates += (case.date_of_admission,)
            if case.was_surgical_procedure == 1:
                hapd_days += ((case.date_of_surgical_procedure - case.date_of_admission).days+1,)
                hapde_days += ((case.date_of_discharge - case.date_of_surgical_procedure).days+1,)
        elif case.diagnosis_group == 2: #Hip fracture
            hf_days += ((case.date_of_discharge - case.date_of_admission).days+1,)
            hf_dates += (case.date_of_admission,)
            if case.was_surgical_procedure == 1:
                hfd_days += ((case.date_of_surgical_procedure - case.date_of_admission).days+1,)
                hfde_days += ((case.date_of_discharge - case.date_of_surgical_procedure).days+1,)
        elif case.diagnosis_group == 3: #CABG
            cabg_days += ((case.date_of_discharge - case.date_of_admission).days+1,)
            cabg_dates += (case.date_of_admission,)
            if case.was_surgical_procedure == 1:
                cabgd_days += ((case.date_of_surgical_procedure - case.date_of_admission).days+1,)
                cabgde_days += ((case.date_of_discharge - case.date_of_surgical_procedure).days+1,)
        elif case.diagnosis_group == 4: #Knee arthroscopy
            ka_days += ((case.date_of_discharge - case.date_of_admission).days+1,)
            ka_dates += (case.date_of_admission,)
            if case.was_surgical_procedure == 1:
                kad_days += ((case.date_of_surgical_procedure - case.date_of_admission).days+1,)
                kade_days += ((case.date_of_discharge - case.date_of_surgical_procedure).days+1,)
        elif case.diagnosis_group == 5: #Inguinal hernia
            ih_days += ((case.date_of_discharge - case.date_of_admission).days+1,)
            ih_dates += (case.date_of_admission,)
            if case.was_surgical_procedure == 1:
                ihd_days += ((case.date_of_surgical_procedure - case.date_of_admission).days+1,)
                ihde_days += ((case.date_of_discharge - case.date_of_surgical_procedure).days+1,)
        elif case.diagnosis_group == 6: #Tonsillectomy and/or adenoidectomy
            taa_days += ((case.date_of_discharge - case.date_of_admission).days+1,)
            taa_dates += (case.date_of_admission,)
            if case.was_surgical_procedure == 1:
                taad_days += ((case.date_of_surgical_procedure - case.date_of_admission).days+1,)
                taade_days += ((case.date_of_discharge - case.date_of_surgical_procedure).days+1,)
        elif case.diagnosis_group == 7: #Cholecystectomy
            c_days += ((case.date_of_discharge - case.date_of_admission).days+1,)
            c_dates += (case.date_of_admission,)
            if case.was_surgical_procedure == 1:
                cd_days += ((case.date_of_surgical_procedure - case.date_of_admission).days+1,)
                cde_days += ((case.date_of_discharge - case.date_of_surgical_procedure).days+1,)
        elif case.diagnosis_group == 8: #Varicose veins - stripping and ligation
            v_days += ((case.date_of_discharge - case.date_of_admission).days+1,)
            v_dates += (case.date_of_admission,)
            if case.was_surgical_procedure == 1:
                vd_days += ((case.date_of_surgical_procedure - case.date_of_admission).days+1,)
                vde_days += ((case.date_of_discharge - case.date_of_surgical_procedure).days+1,)

    ''' Stroke '''
    try: s_first_date = sorted(s_dates)[0]
    except: s_first_date = 0
    try: s_last_date = sorted(s_dates, reverse=True)[0]
    except: s_last_date = 0
    try: s_avg = float(sum(s_days)) / len(s_days)
    except: s_avg = 0
    try: s_med = median(s_days)
    except: s_med = 0
    try: sd_avg = float(sum(sd_days)) / len(sd_days)
    except: sd_avg = 0
    try: sd_med = median(sd_days)
    except: sd_med = 0
    try: sde_avg = float(sum(sde_days)) / len(sde_days)
    except: sde_avg = 0
    try: sde_med = median(sde_days)
    except: sde_med = 0

    ''' Hospital acquired pneumonia '''
    try: hap_first_date = sorted(hap_dates)[0]
    except: hap_first_date = 0
    try: hap_last_date = sorted(hap_dates, reverse=True)[0]
    except: hap_last_date = 0
    try: hap_avg = float(sum(hap_days)) / len(hap_days)
    except: hap_avg = 0
    try: hap_med = median(hap_days)
    except: hap_med = 0
    try: hapd_avg = float(sum(hapd_days)) / len(hapd_days)
    except: hapd_avg = 0
    try: hapd_med = median(hapd_days)
    except: hapd_med = 0
    try: hapde_avg = float(sum(hapde_days)) / len(hapde_days)
    except: hapde_avg = 0
    try: hapde_med = median(hapde_days)
    except: hapde_med = 0

    ''' Hip fracture '''
    try: hf_first_date = sorted(hf_dates)[0]
    except: hf_first_date = 0
    try: hf_last_date = sorted(hf_dates, reverse=True)[0]
    except: hf_last_date = 0
    try: hf_avg = float(sum(hf_days)) / len(hf_days)
    except: hf_avg = 0
    try: hf_med = median(hf_days)
    except: hf_med = 0
    try: hfd_avg = float(sum(hfd_days)) / len(hfd_days)
    except: hfd_avg = 0
    try: hfd_med = median(hfd_days)
    except: hfd_med = 0
    try: hfde_avg = float(sum(hfde_days)) / len(hfde_days)
    except: hfde_avg = 0
    try: hfde_med = median(hfde_days)
    except: hfde_med = 0
    
    ''' CABG '''
    try: cabg_first_date = sorted(cabg_dates)[0]
    except: cabg_first_date = 0
    try: cabg_last_date = sorted(cabg_dates, reverse=True)[0]
    except: cabg_last_date = 0
    try: cabg_avg = float(sum(cabg_days)) / len(cabg_days)
    except: cabg_avg = 0
    try: cabg_med = median(cabg_days)
    except: cabg_med = 0
    try: cabgd_avg = float(sum(cabgd_days)) / len(cabgd_days)
    except: cabgd_avg = 0
    try: cabgd_med = median(cabgd_days)
    except: cabgd_med = 0
    try: cabgde_avg = float(sum(cabgde_days)) / len(cabgde_days)
    except: cabgde_avg = 0
    try: cabgde_med = median(cabgde_days)
    except: cabgde_med = 0
    
    ''' Knee arthroscopy '''
    try: ka_first_date = sorted(ka_dates)[0]
    except: ka_first_date = 0
    try: ka_last_date = sorted(ka_dates, reverse=True)[0]
    except: ka_last_date = 0
    try: ka_avg = float(sum(ka_days)) / len(ka_days)
    except: ka_avg = 0
    try: ka_med = median(ka_days)
    except: ka_med = 0
    try: kad_avg = float(sum(kad_days)) / len(kad_days)
    except: kad_avg = 0
    try: kad_med = median(kad_days)
    except: kad_med = 0
    try: kade_avg = float(sum(kade_days)) / len(kade_days)
    except: kade_avg = 0
    try: kade_med = median(kade_days)
    except: kade_med = 0

    ''' Inguinal hernia '''
    try: ih_first_date = sorted(ih_dates)[0]
    except: ih_first_date = 0
    try: ih_last_date = sorted(ih_dates, reverse=True)[0]
    except: ih_last_date = 0
    try: ih_avg = float(sum(ih_days)) / len(ih_days)
    except: ih_avg = 0
    try: ih_med = median(ih_days)
    except: ih_med = 0
    try: ihd_avg = float(sum(ihd_days)) / len(ihd_days)
    except: ihd_avg = 0
    try: ihd_med = median(ihd_days)
    except: ihd_med = 0
    try: ihde_avg = float(sum(ihde_days)) / len(ihde_days)
    except: ihde_avg = 0
    try: ihde_med = median(ihde_days)
    except: ihde_med = 0
    
    ''' Tonsillectomy and/or adenoidectomy '''
    try: taa_first_date = sorted(taa_dates)[0]
    except: taa_first_date = 0
    try: taa_last_date = sorted(taa_dates, reverse=True)[0]
    except: taa_last_date = 0
    try: taa_avg = float(sum(taa_days)) / len(taa_days)
    except: taa_avg = 0
    try: taa_med = median(taa_days)
    except: taa_med = 0
    try: taad_avg = float(sum(taad_days)) / len(taad_days)
    except: taad_avg = 0
    try: taad_med = median(taad_days)
    except: taad_med = 0
    try: taade_avg = float(sum(taade_days)) / len(taade_days)
    except: taade_avg = 0
    try: taade_med = median(taade_days)
    except: taade_med = 0

    ''' Cholecystectomy '''
    try: c_first_date = sorted(c_dates)[0]
    except: c_first_date = 0
    try: c_last_date = sorted(c_dates, reverse=True)[0]
    except: c_last_date = 0
    try: c_avg = float(sum(c_days)) / len(c_days)
    except: c_avg = 0
    try: c_med = median(c_days)
    except: c_med = 0
    try: cd_avg = float(sum(cd_days)) / len(cd_days)
    except: cd_avg = 0
    try: cd_med = median(cd_days)
    except: cd_med = 0
    try: cde_avg = float(sum(cde_days)) / len(cde_days)
    except: cde_avg = 0
    try: cde_med = median(cde_days)
    except: cde_med = 0

    ''' Varicose veins - stripping and ligation '''
    try: v_first_date = sorted(v_dates)[0]
    except: v_first_date = 0
    try: v_last_date = sorted(v_dates, reverse=True)[0]
    except: v_last_date = 0
    try: v_avg = float(sum(v_days)) / len(v_days)
    except: v_avg = 0
    try: v_med = median(v_days)
    except: v_med = 0
    try: vd_avg = float(sum(vd_days)) / len(vd_days)
    except: vd_avg = 0
    try: vd_med = median(vd_days)
    except: vd_med = 0
    try: vde_avg = float(sum(vde_days)) / len(vde_days)
    except: vde_avg = 0
    try: vde_med = median(vde_days)
    except: vde_med = 0


    ''' Counting '''
    diagnosis = (
        (_('Stroke'), s_first_date, s_last_date, s_avg, s_med, sd_avg, sd_med, sde_avg, sde_med, len(s_days) ),
        (_('Hospital acquired pneumonia'), hap_first_date, hap_last_date, hap_avg, hap_med, hapd_avg, hapd_med, hapde_avg, hapde_med, len(hap_days)),
        (_('Hip fracture'), hf_first_date, hf_last_date, hf_avg, hf_med, hfd_avg, hfd_med, hfde_avg, hfde_med, len(hf_days)),
        (_('CABG'), cabg_first_date, cabg_last_date, cabg_avg, cabg_med, cabgd_avg, cabgd_med, cabgde_avg, cabgde_med, len(cabg_days)),
        (_('Knee arthroscopy'), ka_first_date, ka_last_date, ka_avg, ka_med, kad_avg, kad_med, kade_avg, kade_med, len(ka_days)),
        (_('Inguinal hernia'), ih_first_date, ih_last_date, ih_avg, ih_med, ihd_avg, ihd_med, ihde_avg, ihde_med, len(ih_days)),
        (_('Tonsillectomy and/or adenoidectomy'), taa_first_date, taa_last_date, taa_avg, taa_med, taad_avg, taad_med, taade_avg, taade_med, len(taa_days)),
        (_('Cholecystectomy'), c_first_date, c_last_date, c_avg, c_med, cd_avg, cd_med, cde_avg, cde_med, len(c_days)),
        (_('Varicose veins - stripping and ligation'), v_first_date, v_last_date, v_avg, v_med, vd_avg, vd_med, vde_avg, vde_med, len(v_days)),
        )
    quantity = (2,0,0,0,0,0,0,0,0)
    ''' Displaying '''
    context = {
        "overall": len(cases),
        "removed": len(uncountable_case),
        "counted": len(countable_case),
        "diagnosis": diagnosis
    }
    return render_to_response('c8_statistics.html', context, context_instance=RequestContext(request))
예제 #9
0
파일: views.py 프로젝트: csillagharcos/Path
def CountStatistics(cases, notView=True, language_code="hu"):
    """ Query """
    countable_case = uncountable_case = ()
    medicines = ()
    acceptable_diagnoses = diagCode.objects.filter(language=language_code)
    for medicine in Medicine.objects.all():
        medicines += (medicine.name,)
    for case in cases:
        exists = False
        for diag in acceptable_diagnoses:
            if case.principal_diagnoses_code in diag.code:
                exists = True
            if case.principal_procedure_code in diag.code:
                exists = True
        if (
            exists
            and case.procedure_planned
            and calculate_age(case.date_of_birth) >= 18
            and not case.preoperative_infection
            and not case.generic_name_of_drug in medicines
        ):
            countable_case += (case,)
        else:
            uncountable_case += (case,)

    if len(countable_case) < 30 and notView:
        return False

    """ Working """
    indicator_one = (
        indicator_twoa
    ) = (
        indicator_twob
    ) = (
        indicator_three
    ) = (
        indicator_four
    ) = indicator_five = indicator_six = indicator_seven = indicator_eight = indicator_nine = indicator_ten = 0
    for case in countable_case:
        indicator_tracker = 0
        try:
            first_med_dose = Medicine.objects.get(name=case.name_of_first_dose).dose
        except:
            first_med_dose = 0
        try:
            second_med_dose = Medicine.objects.get(name=case.name_of_second_dose).dose
        except:
            second_med_dose = 0
        try:
            first_med_doseUnder = Medicine.objects.get(name=case.name_of_first_dose).doseUnder
        except:
            first_med_doseUnder = 0
        try:
            second_med_doseUnder = Medicine.objects.get(name=case.name_of_second_dose).doseUnder
        except:
            second_med_doseUnder = 0
        # indicator one
        acceptable = False
        if case.name_of_first_dose in medicines or case.name_of_second_dose in medicines:
            if (
                case.name_of_first_dose == "Cefazolin"
                or case.name_of_first_dose == "Cefuroxim"
                or case.name_of_first_dose == "Cefotaxim"
                or case.name_of_first_dose == "Ceftriaxon"
            ) and (case.name_of_second_dose == "Metronidazol" or case.name_of_second_dose == "Clindamycin"):
                indicator_one += 1
                indicator_tracker += 1
                acceptable = True
            elif (
                case.name_of_second_dose == "Cefazolin"
                or case.name_of_second_dose == "Cefuroxim"
                or case.name_of_second_dose == "Cefotaxim"
                or case.name_of_second_dose == "Ceftriaxon"
            ) and (case.name_of_first_dose == "Metronidazol" or case.name_of_first_dose == "Clindamycin"):
                indicator_one += 1
                indicator_tracker += 1
                acceptable = True
            elif (
                case.name_of_first_dose == "Cefazolin"
                or case.name_of_first_dose == "Cefotaxim"
                or case.name_of_first_dose == "Cefuroxim"
                or case.name_of_first_dose == "Ceftriaxon"
                or case.name_of_first_dose == "Clindamycin"
                or case.name_of_first_dose == "Amoxy/clav"
            ):
                indicator_one += 1
                indicator_tracker += 1
                acceptable = True
            elif (
                case.name_of_second_dose == "Cefazolin"
                or case.name_of_second_dose == "Cefotaxim"
                or case.name_of_second_dose == "Cefuroxim"
                or case.name_of_second_dose == "Ceftriaxon"
                or case.name_of_second_dose == "Clindamycin"
                or case.name_of_second_dose == "Amoxy/clav"
            ):
                indicator_one += 1
                indicator_tracker += 1
                acceptable = True

        # indicator two A
        if case.weight_of_patient >= 60:
            if (first_med_dose == case.first_dose or second_med_dose == case.second_dose) and acceptable:
                indicator_twoa += 1
                indicator_tracker += 1
        elif case.weight_of_patient < 60:
            if (
                (first_med_dose == case.first_dose or second_med_dose == case.second_dose)
                or (first_med_doseUnder == case.first_dose or second_med_doseUnder == case.second_dose)
                and acceptable
            ):
                indicator_twoa += 1
                indicator_tracker += 1

        # indicator two B
        if case.weight_of_patient >= 60:
            if (
                first_med_dose == case.first_dose
                and (second_med_dose == case.second_dose or case.second_dose is None)
                and acceptable
            ):
                indicator_twob += 1
        else:
            if (first_med_doseUnder == case.first_dose and second_med_doseUnder == case.second_dose) and acceptable:
                indicator_twob += 1

        # indicator three
        if case.route_of_admin == 1:
            indicator_three += 1
            indicator_tracker += 1

        # indicator four
        try:
            if (case.surgical_incision - case.date_of_first_dose).seconds <= 3600:
                indicator_four += 1
                indicator_tracker += 1
        except:
            pass

        # indicator five
        try:
            if (case.date_of_wound_close - case.date_of_last_dose).seconds <= 86400:
                indicator_five += 1
            # indicator seven
            else:
                indicator_seven += 1
        except:
            indicator_seven += 1

        # indicator six
        if indicator_tracker < 4:
            indicator_six += 1
        else:
            indicator_ten += 1

        # indicator eight
        if not case.antibiotic_given:
            indicator_eight += 1

        # indicator nine
        if case.first_dose is None:
            fd = 0
        else:
            fd = case.first_dose
        if case.second_dose is None:
            sd = 0
        else:
            sd = case.second_dose
        if case.date_of_first_dose == case.date_of_last_dose and case.total_dose_in_24h == fd + sd:
            indicator_nine += 1

    """ Counting """
    try:
        one = float(indicator_one) / len(countable_case) * 100
    except:
        one = 0
    try:
        twoa = float(indicator_twoa) / len(countable_case) * 100
    except:
        twoa = 0
    try:
        twob = float(indicator_twob) / len(countable_case) * 100
    except:
        twob = 0
    try:
        three = float(indicator_three) / len(countable_case) * 100
    except:
        three = 0
    try:
        four = float(indicator_four) / len(countable_case) * 100
    except:
        four = 0
    try:
        five = float(indicator_five) / len(countable_case) * 100
    except:
        five = 0
    try:
        six = float(indicator_six) / len(countable_case) * 100
    except:
        six = 0
    try:
        seven = float(indicator_seven) / len(countable_case) * 100
    except:
        seven = 0
    try:
        eight = float(indicator_eight) / len(countable_case) * 100
    except:
        eight = 0
    try:
        nine = float(indicator_nine) / len(countable_case) * 100
    except:
        nine = 0
    try:
        ten = float(indicator_ten) / len(countable_case) * 100
    except:
        ten = 0

    """ Displaying """
    context = {
        "overall": len(cases),
        "removed": len(uncountable_case),
        "counted": len(countable_case),
        "one": one,
        "twoa": twoa,
        "twob": twob,
        "three": three,
        "four": four,
        "five": five,
        "six": six,
        "seven": seven,
        "eight": eight,
        "nine": nine,
        "ten": ten,
    }
    return context
예제 #10
0
파일: views.py 프로젝트: derekzhang79/Path
def Statistics(request):
    ''' Query '''
    accepted_diagnose_codes = ("C18", "C19", "C20", "C20.0", "C20.1", "C20.2", "C20.8")
    countable_case=uncountable_case=()
    cases = c21.objects.all()
    medicines=()
    for medicine in Medicine.objects.all():
        medicines += (medicine.name,)
    for case in cases:
        if case.principal_diagnoses_code in accepted_diagnose_codes and case.procedure_planned and calculate_age(case.date_of_birth) >= 18 and not case.preoperative_infection and not case.generic_name_of_drug in medicines:
            countable_case += (case,)
        else:
            uncountable_case += (case,)

    ''' Working '''
    indicator_one = indicator_twoa = indicator_twob = indicator_three = indicator_four = indicator_five = indicator_six = indicator_seven = indicator_eight = indicator_nine = indicator_ten = 0
    for case in countable_case:
        indicator_tracker = 0
        try: first_med_dose = Medicine.objects.get(name = case.name_of_first_dose).dose
        except: first_med_dose = 0
        try: second_med_dose = Medicine.objects.get(name = case.name_of_second_dose).dose
        except: second_med_dose = 0
        try: first_med_doseUnder = Medicine.objects.get(name = case.name_of_first_dose).doseUnder
        except: first_med_doseUnder = 0
        try: second_med_doseUnder = Medicine.objects.get(name = case.name_of_second_dose).doseUnder
        except: second_med_doseUnder = 0
        #indicator one
        acceptable = False
        if case.name_of_first_dose in medicines and case.name_of_second_dose in medicines:
            if (case.name_of_first_dose == "Cefazolin" or case.name_of_first_dose== "Cefotaxim" or case.name_of_first_dose== "Cefuroxim" or case.name_of_first_dose== "Ceftriaxon") and (case.name_of_second_dose== "Metronidazol" or case.name_of_second_dose== "Clindamycin"):
                indicator_one += 1
                indicator_tracker += 1
                acceptable = True
            elif (case.name_of_second_dose== "Cefazolin" or case.name_of_second_dose== "Cefotaxim" or case.name_of_second_dose== "Cefuroxim" or case.name_of_second_dose== "Ceftriaxon") and (case.name_of_first_dose== "Metronidazol" or case.name_of_first_dose== "Clindamycin"):
                indicator_one += 1
                indicator_tracker += 1
                acceptable = True
            elif case.name_of_first_dose== "Ertapenem" or case.name_of_second_dose == "Ertapenem":
                indicator_one += 1
                indicator_tracker += 1
                acceptable = True

        #indicator two A
        if case.weight_of_patient >= 60:
            if first_med_dose == case.first_dose and second_med_dose == case.second_dose and acceptable:
                indicator_twoa += 1
                indicator_tracker += 1
        elif case.weight_of_patient < 60:
            if (first_med_dose == case.first_dose and second_med_dose == case.second_dose) or (first_med_doseUnder == case.first_dose and second_med_doseUnder == case.second_dose) and acceptable:
                indicator_twoa += 1
                indicator_tracker += 1

        #indicator two B
        if case.weight_of_patient >= 60:
            if first_med_dose == case.first_dose and second_med_dose == case.second_dose and acceptable:
                indicator_twob += 1
        else:
            if first_med_doseUnder == case.first_dose and second_med_doseUnder == case.second_dose and acceptable:
                indicator_twob += 1

        #indicator three
        if case.route_of_admin == 1:
            indicator_three += 1
            indicator_tracker += 1

        #indicator four
        try:
            if (case.surgical_incision - case.date_of_first_dose).seconds <= 3600:
                indicator_four += 1
                indicator_tracker += 1
        except:
            pass

        #indicator five
        try:
            if (case.date_of_wound_close - case.date_of_last_dose).seconds <= 86400:
                indicator_five += 1
                indicator_tracker += 1
            #indicator seven
            else:
                indicator_seven += 1
        except:
            indicator_seven += 1

        #indicator six
        if indicator_tracker < 5:
            indicator_six += 1
        else:
            indicator_ten += 1

        #indicator eight
        if not case.antibiotic_given:
            indicator_eight += 1

        #indicator nine
        if case.first_dose is None: fd = 0
        else: fd = case.first_dose
        if case.second_dose is None: sd = 0
        else: sd = case.second_dose
        if case.date_of_first_dose == case.date_of_last_dose and case.total_dose_in_24h == fd + sd:
            indicator_nine += 1

    ''' Counting '''
    try: one = float(indicator_one) / len(countable_case) * 100
    except: one = 0
    try: twoa = float(indicator_twoa) / len(countable_case) * 100
    except: twoa = 0
    try: twob = float(indicator_twob) / len(countable_case) * 100
    except: twob = 0
    try: three = float(indicator_three) / len(countable_case) * 100
    except: three = 0
    try: four = float(indicator_four) / len(countable_case) * 100
    except: four = 0
    try: five = float(indicator_five) / len(countable_case) * 100
    except: five = 0
    try: six = float(indicator_six) / len(countable_case) * 100
    except: six = 0
    try: seven = float(indicator_seven) / len(countable_case) * 100
    except: seven = 0
    try: eight = float(indicator_eight) / len(countable_case) * 100
    except: eight = 0
    try: nine = float(indicator_nine) / len(countable_case) * 100
    except: nine = 0
    try: ten = float(indicator_ten) / len(countable_case) * 100
    except: ten = 0

    ''' Displaying '''
    context = {
        "overall": len(cases),
        "removed": len(uncountable_case),
        "counted": len(countable_case),
        "one": one,
        "twoa": twoa,
        "twob": twob,
        "three": three,
        "four": four,
        "five": five,
        "six": six,
        "seven": seven,
        "eight": eight,
        "nine": nine,
        "ten": ten,
    }
    return render_to_response('c21_statistics.html', context, context_instance=RequestContext(request))