Exemple #1
0
def single_patient(request, patient_id):
    patient = loader.get_patient(patient_id)
    xforms = CXFormInstance.view("patient/xforms", key=patient.get_id, include_docs=True)
    encounter_types = get_encounters(patient)
    options = TouchscreenOptions.default()
    # TODO: are we upset about how this breaks MVC?
    options.nextbutton.show  = False
    options.backbutton = ButtonOptions(text="BACK", 
                                       link=reverse("patient_select"))
    
    encounters = sorted(patient.encounters, key=lambda encounter: encounter.visit_date, reverse=True)
    # TODO: figure out a way to do this more centrally
    # Inject cases into encounters so we can show them linked in the view
    for encounter in patient.encounters:
        if encounter.get_xform():
            encounter.dynamic_data["classification"] = get_classification(encounter.get_xform().namespace)
            encounter.dynamic_data["cases"] = []
            for case in patient.cases:
                if case.encounter_id == encounter.get_id:
                    encounter.dynamic_data["cases"].append(case)
        
    
    return render_to_response(request, "patient/single_patient_touchscreen.html", 
                              {"patient": patient,
                               "encounters": encounters,
                               "xforms": xforms,
                               "encounter_types": encounter_types,
                               "options": options })
Exemple #2
0
def single_encounter(request, patient_id, encounter_id):
    patient = loader.get_patient(patient_id)
    encounters = [enc for enc in patient.encounters if enc.get_id == encounter_id]
    if not encounters:
        raise Exception("No matching encounter for id %s in patient %s" % (encounter_id, patient_id))
    encounter = encounters[0]
    return render_to_response(request, "encounter/single_encounter.html", 
                              {"patient": patient,
                               "encounter": encounter,
                               "options": TouchscreenOptions.default()})
Exemple #3
0
def lookup_by_id(request):
    """
    Get a patient by ID, returning the json representation of the patient
    """
    pat_id = request.GET.get('id')
    if pat_id != None:
        patients = CPatient.view(VIEW_PATIENT_BY_BHOMA_ID, key=pat_id, reduce=False, include_docs=True).all()
        return _patient_list_response(patients)
    else:
        pat_uuid = request.GET.get('uuid')
        patient = loader.get_patient(pat_uuid)
        return HttpResponse(json.dumps(patient.to_json()), mimetype='text/json')
Exemple #4
0
def render_content (request, template):
    if template == 'single-patient':
        pat_uuid = request.POST.get('uuid')
        if pat_uuid:
            patient = loader.get_patient(pat_uuid)
            return render_to_response(request, 'patient/single_patient_block.html', {'patient': patient})
        else: 
            return HttpResponse("No patient.")
    elif template == 'single-patient-edit':
        patient = json.loads(request.raw_post_data)
        patient['dob'] = string_to_datetime(patient['dob']).date() if patient['dob'] else None
        ADDR_MAX_LEN = 25
        patient['full_address'] = ', '.join(filter(lambda x: x, [truncate(patient['address'], ADDR_MAX_LEN), patient['village']]))

        return render_to_response(request, 'patient/patient_edit_overview.html', {'patient': patient})
    else:
        return HttpResponse(("Unknown template type: %s. What are you trying " 
                             "to do and how did you get here?") % template)
Exemple #5
0
def edit_patient(request, patient_id):
    if request.method == "POST":
        data = json.loads(request.POST.get('result'))
        patinfo = data.get('patient')

        if patinfo:
            #this is all quite similar to creating a new patient; the code should probably be
            #consolidated

            patient = loader.get_patient(patinfo['_id'])
            patient.first_name = patinfo['fname']
            patient.last_name = patinfo['lname']
            patient.birthdate = string_to_datetime(patinfo['dob']).date() if patinfo['dob'] else None
            patient.birthdate_estimated = patinfo['dob_est']
            patient.gender = patinfo['sex']

            if patinfo.get('phone'):
                patient.phones = [CPhone(is_default=True, number=patinfo['phone'])]
            else:
                patient.phones = []
            
            patient.address = CAddress(village=patinfo.get('village'),
                                       address=patinfo.get('address'),
                                       clinic_id=settings.BHOMA_CLINIC_ID,
                                       zone=patinfo['chw_zone'],
                                       zone_empty_reason=patinfo['chw_zone_na'])

            #update mother info only if was edited during patient edit, or if no linkage has yet been created
            if patinfo.get('mother_edited') or (patinfo.get('motherable') and (len(patient.relationships) == 0 or patient.relationships[0].patient_uuid == None)):
                mother = relationship_from_instance(patinfo)
                patient.relationships = [mother] if mother else []

            patient.save()

        return HttpResponseRedirect(reverse("single_patient", args=(data.get('_id'),)))

    return render_to_response(request, "bhoma_touchscreen.html", 
                              {'form': {'name': 'patient edit', 
                                        'wfobj': 'wfEditPatient',
                                        'wfargs': json.dumps(patient_id)}, 
                               'mode': 'workflow',
                               'dynamic_scripts': ["%spatient/javascripts/patient_reg.js" \
                                                   % settings.STATIC_URL,] })
Exemple #6
0
def test(request):
    dynamic = string_to_boolean(request.GET["dynamic"]) if "dynamic" in request.GET else True
    template = request.GET["template"] if "template" in request.GET \
                                       else "touchscreen/example-inner.html"
    header = request.GET["header"] if "header" in request.GET \
                                   else "Hello World!"
    pat_id = request.GET["id"] if "id" in request.GET \
                               else "000000000001" 
    try:
        patient = loader.get_patient(pat_id)
    except Exception:
        patient = None
    if dynamic:
        return render_to_response(request, "touchscreen/wrapper-dynamic.html", 
                                  {"header": header,
                                   "template": template,
                                   "patient": patient,
                                   "options": TouchscreenOptions.default()})
    else:
        return render_to_response(request, template, 
                              {"patient": patient,
                               "options": TouchscreenOptions.default()})