Exemple #1
0
def index(request):
    indexpage = get_template('index.html')

	# Declare global variables that may be modified here
    global Global_PATIENT_ID 
    global Global_ADHERE_VARS 

    smart = client.FHIRClient(state=request.session['client_state'])
    record_change_p = True
    patientID = smart.patient_id

    # Get the medication dispenses for this context
    dispenses = MedicationDispense.where({'patient': patientID}).perform(smart.server)

    pills = []

    if dispenses.entry:
        for dispense in dispenses.entry:
            d = dispense.resource
            name = d.medicationCodeableConcept.coding[0].display
            
            assert d.status == 'completed'
            quant = d.daysSupply.value
            when = d.whenHandedOver.isostring
            pills.append((None,name,quant,when))

    birthday, patient_name = get_birthday_name(smart)
    drug = 'all'

    # We only want to call the adherence_check once for a specific patient
    if Global_PATIENT_ID == patientID:
        meds_flags, gaps, refill_data, refill_day = Global_ADHERE_VARS
    else:
        tests = adherenceTests.AdherenceTests()
        meds_flags, gaps, refill_data, refill_day = tests.allTests(pills, drug, birthday)		
        Global_ADHERE_VARS = [meds_flags, gaps, refill_data, refill_day]  # save the data for future needs
        Global_PATIENT_ID = patientID
        
	# Medication information will be displayed by drug class. Here we
	# sort all the patient's medications into drug classes defined
	# in this application.
    drug_class_array = {}
    for n in range(len(meds_flags)):
        drug_class_array[meds_flags[n][5]] = 1
    sorted_drug_class_list = sorted(drug_class_array.keys())
                  
	# Send these variables to the page for rendering
    variables = Context({
        'head_title': u'Medication Adherence Monitor',
        'patientID': patientID,
        'meds_flags': meds_flags,			# Contains all the data needed for tables and plotting 
        'media_root': settings.MEDIA_ROOT,
        'patient_name': patient_name,
        'drug_class_array': sorted_drug_class_list,
    })
    output = indexpage.render(variables)
    response = HttpResponse(output)
    return response
Exemple #2
0
def index(request):
    indexpage = get_template('index.html')

	# Declare global variables that may be modified here
    global Global_PATIENT_ID 
    global Global_ADHERE_VARS 

    smart = client.FHIRClient(state=request.session['client_state'])
    record_change_p = True
    patientID = smart.patient_id

    # Get the medication dispenses for this context
    dispenses = MedicationDispense.where({'patient': patientID}).perform(smart.server)

    pills = []

    if dispenses.entry:
        for dispense in dispenses.entry:
            d = dispense.resource
            name = d.medicationCodeableConcept.coding[0].display
            
            assert d.status == 'completed'
            quant = d.daysSupply.value
            when = d.whenHandedOver.isostring
            pills.append((None,name,quant,when))

    birthday, patient_name = get_birthday_name(smart)
    drug = 'all'

    # We only want to call the adherence_check once for a specific patient
    if Global_PATIENT_ID == patientID:
        meds_flags, gaps, refill_data, refill_day = Global_ADHERE_VARS
    else:
        tests = adherenceTests.AdherenceTests()
        meds_flags, gaps, refill_data, refill_day = tests.allTests(pills, drug, birthday)		
        Global_ADHERE_VARS = [meds_flags, gaps, refill_data, refill_day]  # save the data for future needs
        Global_PATIENT_ID = patientID
        
	# Medication information will be displayed by drug class. Here we
	# sort all the patient's medications into drug classes defined
	# in this application.
    drug_class_array = {}
    for n in range(len(meds_flags)):
        drug_class_array[meds_flags[n][5]] = 1
    sorted_drug_class_list = sorted(drug_class_array.keys())
                  
	# Send these variables to the page for rendering
    variables = Context({
        'head_title': u'Medication Adherence Monitor',
        'patientID': patientID,
        'meds_flags': meds_flags,			# Contains all the data needed for tables and plotting 
        'media_root': settings.MEDIA_ROOT,
        'patient_name': patient_name,
        'drug_class_array': sorted_drug_class_list,
    })
    output = indexpage.render(variables)
    response = HttpResponse(output)
    return response
Exemple #3
0
def risk(request):
    """ This function creates data and serves detailed  
    information about adherence for specific medications."""
	
	# Declare global variables that may be modified here
    global Global_PATIENT_ID 
    global Global_ADHERE_VARS 
	
    # Get the name of the drug if a specific one was requested.
    # The default is 'all' drugs.
    drug = request.GET.get('drug', 'all')
       
    # Current context information
    smart = client.FHIRClient(state=request.session['client_state'])

    # Get the medication dispenses for this context
    dispenses = MedicationDispense.where({'patient': smart.patient_id}).perform(smart.server)

    pills = []
        
    if dispenses.entry:
        for dispense in dispenses.entry:
            d = dispense.resource
            name = d.medicationCodeableConcept.coding[0].display
            
            assert d.status == 'completed'
            quant = d.daysSupply.value
            when = d.whenHandedOver.isostring
            pills.append((None,name,quant,when))
    
    # The the fulfillment gap and MPR prediction data    
    meds_flags, gaps, refill_data, refill_day = Global_ADHERE_VARS

    names = []
    if drug == 'all':   # get all the drugs for this patient
        for pill in pills: 
            name = pill[1]
            names.append(name)
            d = pill[3]
    else: # only use the specified drug name
        meds_flags_new = []
        names.append(drug)      
        for item in meds_flags:
            if drug == item[0]:
                meds_flags_new.append(item)
        meds_flags = meds_flags_new 
                
    ad_data = []
    med_names = []

    for n in names:
        d = {}
        d["title"] = str(n)
        med_names.append(n)
        d["subtitle"] = 'adherence'
        d["measures"] = [1.0]
        ad_data.append(d)
           
    drug_class_array = {}
    for n in range(len(meds_flags)):
        drug_class_array[meds_flags[n][5]] = 1
    sorted_drug_class_array = sorted(drug_class_array.keys())
                            
    # Determine width and height of chart by the number of drugs to be shown
    width = 400
    height = 100
    if len(names) == 1:
        width = 500
        height = 200
    
    variables = RequestContext(request, {
                'head_title': u'Predicted 1-year medication possession ratio (MPR)',
                'med_names': med_names,
                'meds_flags': meds_flags,
                'refill_day': simplejson.dumps(refill_day),
                'refill': simplejson.dumps(refill_data),
                'gaps': simplejson.dumps(gaps),
                'width': width,
                'height': height,
                'drug_class_array': sorted_drug_class_array,
                })     
    response = render_to_response("risk.html", context_instance=variables )
    return HttpResponse(response)
Exemple #4
0
def risk(request):
    """ This function creates data and serves detailed  
    information about adherence for specific medications."""
	
	# Declare global variables that may be modified here
    global Global_PATIENT_ID 
    global Global_ADHERE_VARS 
	
    # Get the name of the drug if a specific one was requested.
    # The default is 'all' drugs.
    drug = request.GET.get('drug', 'all')
       
    # Current context information
    smart = client.FHIRClient(state=request.session['client_state'])

    # Get the medication dispenses for this context
    dispenses = MedicationDispense.where({'patient': smart.patient_id}).perform(smart.server)

    pills = []
        
    if dispenses.entry:
        for dispense in dispenses.entry:
            d = dispense.resource
            name = d.medicationCodeableConcept.coding[0].display
            
            assert d.status == 'completed'
            quant = d.daysSupply.value
            when = d.whenHandedOver.isostring
            pills.append((None,name,quant,when))
    
    # The the fulfillment gap and MPR prediction data    
    meds_flags, gaps, refill_data, refill_day = Global_ADHERE_VARS

    names = []
    if drug == 'all':   # get all the drugs for this patient
        for pill in pills: 
            name = pill[1]
            names.append(name)
            d = pill[3]
    else: # only use the specified drug name
        meds_flags_new = []
        names.append(drug)      
        for item in meds_flags:
            if drug == item[0]:
                meds_flags_new.append(item)
        meds_flags = meds_flags_new 
                
    ad_data = []
    med_names = []

    for n in names:
        d = {}
        d["title"] = str(n)
        med_names.append(n)
        d["subtitle"] = 'adherence'
        d["measures"] = [1.0]
        ad_data.append(d)
           
    drug_class_array = {}
    for n in range(len(meds_flags)):
        drug_class_array[meds_flags[n][5]] = 1
    sorted_drug_class_array = sorted(drug_class_array.keys())
                            
    # Determine width and height of chart by the number of drugs to be shown
    width = 400
    height = 100
    if len(names) == 1:
        width = 500
        height = 200
    
    variables = RequestContext(request, {
                'head_title': u'Predicted 1-year medication possession ratio (MPR)',
                'med_names': med_names,
                'meds_flags': meds_flags,
                'refill_day': simplejson.dumps(refill_day),
                'refill': simplejson.dumps(refill_data),
                'gaps': simplejson.dumps(gaps),
                'width': width,
                'height': height,
                'drug_class_array': sorted_drug_class_array,
                })     
    response = render_to_response("risk.html", context_instance=variables )
    return HttpResponse(response)