Exemple #1
0
"""
This signal is for _after_ a form is added to a patient and all the 
previous signals have been called.  This should only be used for 
dynmic data that nothing else should depend on (e.g. custom report 
fields).
"""
patient_updated = Signal(providing_args=["patient_id"])

def add_clinic_ids(sender, form, **kwargs):
    """
    Adds a top level clinic_ids prefix to a form.  This allows
    the form to sync with multiple clinics.
    """
    if not hasattr(form, "clinic_ids"):
        form.clinic_ids = []
    if hasattr(form, "meta") and "clinic_id" in form.meta and form.meta["clinic_id"] not in form.clinic_ids: 
        form.clinic_ids.append(form.meta["clinic_id"])
        form.save()
xform_saved.connect(add_clinic_ids)

def fix_old_chw_ref_id(sender, form, **kwargs):
    chw_ref_id = form.chw_referral_id if hasattr(form, 'chw_referral_id') else None
    if chw_ref_id and len(chw_ref_id) == 7:
        form.chw_referral_id = '%s0%s' % (chw_ref_id[:4], chw_ref_id[4:])
        form.save()

xform_saved.connect(fix_old_chw_ref_id)

# wire this up too
xform_saved.connect(add_sha1)
Exemple #2
0
            def calculate_zscore(l_value,m_value,s_value,x_value):
                #for L != 0, Z = (((X/M)^L)-1)/(L*S)
                eval_power = pow((float(x_value) / m_value),l_value)
                return ((eval_power - 1) / (l_value * s_value))
            
            def compare_sd(zscore_value):
                if zscore_value >= 0: 
                    return "0"
                elif 0 > zscore_value and zscore_value >= -2: 
                    return "-2"
                elif -2 > zscore_value and zscore_value >= -3: 
                    return "-3"
                elif -3 > zscore_value:
                    return "below -3"
            
            zscore_num = calculate_zscore(zscore.l_value, zscore.m_value, zscore.s_value, form["vitals"]["weight"])
            sd_num = compare_sd(zscore_num)
            
            if form.xpath("nutrition/weight_for_age") == sd_num:
                form.zscore_calc_good = "true"
            else:
                form.zscore_calc_good = "false"
        
        else:
            form.zscore_calc_good = "unable_to_calc"
        
        form.save()
    

xform_saved.connect(insert_zscores)
Exemple #3
0
                #aka, acetyl_salicylic_acid-tablet-600-3-3
                drug = each_drug["common_drug"].split('-')[0]
                formulation_prescribed = each_drug["common_drug"].split('-')[1]
            else:    
                #find drug from drill down options on xform
                drug = each_drug["uncommon"]["drug_prescribed"]
                formulation_prescribed = each_drug["uncommon"]["drug_formulation"]
                
            try:
                dbdrug = Drug.objects.get(slug=drug)
            except Drug.DoesNotExist:
                continue # no drug, do nothing
            
            #check the formulation prescribed is possible
            formulations_checked = []
            types_checked = []
            for formulation in dbdrug.formulations.all():
                if formulation_prescribed == formulation.name: 
                    formulations_checked = [formulation_prescribed]
                    break
                else:
                    formulations_checked = ["other"]
            for type in dbdrug.types.all(): types_checked.append(type.name)
            
            drug = CDrugRecord(name=dbdrug.slug, types=types_checked, formulations=formulations_checked)
            form.drugs_prescribed.append(drug.to_json())
            
        form.save()  

xform_saved.connect(add_drug_information)