예제 #1
0
파일: views.py 프로젝트: dlanphear9/apps
def authorize(request):
    client = FHIRClient(state=request.session['client_state'],
                        secret=_ENDPOINT['secret'])
    client.update_access_token(request.GET.get('code'))
    request.session['client_state'] = client.state
    #return redirect(reverse('index'))
    return redirect('index.html')
예제 #2
0
파일: app.py 프로젝트: dlanphear9/apps
def index():
    client = FHIRClient(state=session['client_state'],
                        secret=settings['secret'])
    patient = client.Patient()
    prescriptions = client.MedicationPrescription()

    out = """<!DOCTYPE html>
        <html>
          <head><title>Sample REST App</title></head>
          <body>
    """

    h = ' '.join((patient['name'][0]['given'][0],
                  patient['name'][0]['family'][0], patient['birthDate']))
    out += "<h1>Medications for <span id='name'>%s</span></h1>\n" % h
    out += "<ul id='med_list'>\n"

    # medication may only be present as a reference in the prescription -> in a complete implementation
    # would need to implement a more flexible/adaptive mechanism for retrieval

    for prescription in prescriptions:
        meds = prescription['contained']
        for med in meds:
            out += "<li>%s</li>" % med['name']

    out += """
        </ul>
       </body>
      </html>"""

    return out
예제 #3
0
파일: app.py 프로젝트: dlanphear9/apps
def authorize():
    client = FHIRClient(state=session['client_state'], secret=settings['secret'])
    client.update_access_token(request.args.get('code', ''))
    session['client_state'] = client.state
    return redirect(url_for('index'))
예제 #4
0
파일: views.py 프로젝트: dlanphear9/apps
def authorize(request):
    client = FHIRClient(state=request.session['client_state'], secret=_ENDPOINT['secret'])
    client.update_access_token(request.GET.get('code'))
    request.session['client_state'] = client.state
    #return redirect(reverse('index'))
    return redirect('index.html')
예제 #5
0
파일: views.py 프로젝트: dlanphear9/apps
def index(request):
    indexpage = get_template('index.html')

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

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

    # Get the medication dispenses for this context
    dispenses = client.MedicationDispense()

    pills = []

    for dispense in dispenses:
        assert dispense['contained'][0]['resourceType'] == 'Medication'
        name = dispense['contained'][0]['name']
        assert dispense['dispense'][0]['status'] == 'completed'
        quant = list(
            ext['valueQuantity']['value']
            for ext in dispense['dispense'][0]['extension'] if ext['url'] ==
            'http://fhir-registry.smartplatforms.org/Profile/dispense#days-supply'
        )[0]
        when = dispense['dispense'][0]['whenHandedOver']
        pills.append((None, name, quant, when))

    birthday, patient_name = get_birthday_name(client)
    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
예제 #6
0
파일: views.py 프로젝트: dlanphear9/apps
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
    client = FHIRClient(state=request.session['client_state'],
                        secret=_ENDPOINT['secret'])

    # Get the medication dispenses for this context
    dispenses = client.MedicationDispense()

    pills = []

    for dispense in dispenses:
        assert dispense['contained'][0]['resourceType'] == 'Medication'
        name = dispense['contained'][0]['name']
        assert dispense['dispense'][0]['status'] == 'completed'
        quant = dispense['dispense'][0]['quantity']['value']
        when = dispense['dispense'][0]['whenHandedOver']
        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)
예제 #7
0
파일: app.py 프로젝트: dlanphear9/apps
def authorize():
    client = FHIRClient(state=session['client_state'],
                        secret=settings['secret'])
    client.update_access_token(request.args.get('code', ''))
    session['client_state'] = client.state
    return redirect(url_for('index'))