Exemple #1
0
def show_dots_note(request, doc_id, template_name="pactcarehq/view_dots_submit.html"):
    context = RequestContext(request)
    xform = XFormInstance.get(doc_id)
    dots_note = {}
    raw = xform.to_json()['form']



    dots_note['chw'] = raw['Meta']['username']
    dots_note['encounter_date'] = raw['encounter_date']
    dots_note['schedued'] = raw['scheduled']
    dots_note['visit_type'] = raw['visit_type']
    dots_note['visit_kept'] = raw['visit_kept']
    dots_note['contact_type'] = raw['contact_type']
    
    if raw.has_key('observed_art'):
        dots_note['observed_art'] = raw['observed_art']
    else:
        dots_note['observed_art'] = 'No'

    if raw.has_key('observed_art_dose'):
        dots_note['observed_art_dose'] = raw['observed_art_dose']
    else:
        dots_note['observed_art_dose'] = 'No'
    if raw.has_key('observed_non_art_dose'):
        dots_note['observed_non_art_dose'] = raw['observed_non_art_dose']
    else:
        dots_note['observed_non_art_dose'] = 'No'

    if raw.has_key('observed_non_art'):
        dots_note['observed_non_art'] = raw['observed_non_art']
    else:
        dots_note['observed_non_art'] = 'No'
    try:
        raw['notes'] = raw['notes'].replace("'", """)
        raw['notes'] = raw['notes'].replace('"', """)
        raw['notes'] = raw['notes'].replace("\n", "<br>")
    except:
        raw['notes'] = ''



    context['dots_note'] = dots_note
    raw['pillbox_check']['check'] = ''
    raw['pillbox_check']['artnow'] = ''
    raw['pillbox_check']['nonartnow'] = ''
    raw['static'] = ''

    if raw.has_key('art_no_details'):
        raw['art_no_details'] = raw['art_no_details'].replace('"', "&quot;")
        raw['art_no_details'] = raw['art_no_details'].replace("'", '&apos;')
        raw['art_no_details'] = raw['art_no_details'].replace("\n", '<br>')

    if raw.has_key('non_art_no_details'):
        raw['non_art_no_details'] = raw['non_art_no_details'].replace('"', "&quot;")
        raw['non_art_no_details'] = raw['non_art_no_details'].replace("'", '&apos;')
        raw['non_art_no_details'] = raw['non_art_no_details'].replace("\n", '<br>')
    

    #for key, val in raw.items():
        #print "%s: %s" % (key, val)
    context['raw_note'] = simplejson.dumps(raw)
    case_id = xform['form']['case']['case_id']

    ###########################################################
    #for dev purposes this needs to be done for testing
    #but this is important still tog et the patient info for display
    #case_id = _hack_get_old_caseid(case_id)
    patient = PactPatient.view('patient/all', key=case_id, include_docs=True).first()
    if patient == None:
        patient_name = "Unknown"
    else:
        patient_name = patient.first_name + " " + patient.last_name
    context['patient_name'] = patient_name
    ##############################################################



    comment_docs = CSimpleComment.view('patient/all_comments', key=doc_id, include_docs=True).all()
    comment_arr = []
    for cdoc in comment_docs:
        if cdoc.deprecated:
            continue
        comment_arr.append([cdoc, cdoc.created])

    comment_arr = sorted(comment_arr, key=lambda x: x[1], reverse=True)
    context['comments'] = comment_arr

    if request.method == 'POST':
            form = ProgressNoteComment(data=request.POST)
            context['form'] = form
            if form.is_valid():
                edit_comment = form.cleaned_data["comment"]
                ccomment = CSimpleComment()
                ccomment.doc_fk_id = doc_id
                ccomment.comment = edit_comment
                ccomment.created_by = request.user.username
                ccomment.created = datetime.utcnow()
                ccomment.save()
                return HttpResponseRedirect(request.path)
    else:
        #it's a GET, get the default form
        if request.GET.has_key('comment'):
            context['form'] = ProgressNoteComment()
    return render_to_response(template_name, context_instance=context)
Exemple #2
0
def show_progress_note(request, doc_id, template_name="pactcarehq/view_progress_submit.html"):
    context = RequestContext(request)
    xform = XFormInstance.get(doc_id)
    progress_note = xform['form']['note']
    progress_note['memo'] = progress_note['memo'].replace('"', '&quot;')
    progress_note['memo'] = progress_note['memo'].replace("'", '&apos;')
    progress_note['memo'] = progress_note['memo'].replace("\n", '<br>')
    progress_note['memo'] = progress_note['memo'].replace("\t", '&nbsp;')

    progress_note['adherence']['freetext'] = progress_note['adherence']['freetext'].replace('"', '&quot;')
    progress_note['adherence']['freetext'] = progress_note['adherence']['freetext'].replace("\n", '<br>')
    progress_note['adherence']['freetext'] = progress_note['adherence']['freetext'].replace("\t", '&nbsp;')
    progress_note['adherence']['freetext'] = progress_note['adherence']['freetext'].replace("'", '&apos;')

    try:
        progress_note['times']['other_location'] = progress_note['times']['other_location'].replace("'", "&quot;")
    except:
        pass
    try:
        progress_note['adherence']['freetext'] = progress_note['adherence']['freetext'].replace("'", "&quot;")
    except:
        pass

    progress_note['chw'] = xform.form['Meta']['username']
    context['progress_note'] = simplejson.dumps(xform.to_json()['form']['note'])

    case_id = xform['form']['case']['case_id']



    ###########################################################
    #for dev purposes this needs to be done for testing
    #but this is important still tog et the patient info for display
    #case_id = _hack_get_old_caseid(case_id)
    patient = PactPatient.view('patient/all', key=case_id, include_docs=True).first()
    if patient == None:
        patient_name = "Unknown"
    else:
        patient_name = patient.first_name + " " + patient.last_name
    context['patient_name'] = patient_name
    ##############################################################



    comment_docs = CSimpleComment.view('patient/all_comments', key=doc_id, include_docs=True).all()
    comment_arr = []
    for cdoc in comment_docs:
        if cdoc.deprecated:
            continue
        comment_arr.append([cdoc, cdoc.created])

    comment_arr = sorted(comment_arr, key=lambda x: x[1], reverse=True)
    context['comments'] = comment_arr

    if request.method == 'POST':
            form = ProgressNoteComment(data=request.POST)
            context['form'] = form
            if form.is_valid():
                edit_comment = form.cleaned_data["comment"]
                ccomment = CSimpleComment()
                ccomment.doc_fk_id = doc_id
                ccomment.comment = edit_comment
                ccomment.created_by = request.user.username
                ccomment.created = datetime.utcnow()
                ccomment.save()
                return HttpResponseRedirect(reverse('show_progress_note', kwargs= {'doc_id': doc_id}))
    else:
        #it's a GET, get the default form
        if request.GET.has_key('comment'):
            context['form'] = ProgressNoteComment()
    return render_to_response(template_name, context_instance=context)