def search_results(request): query = request.GET.get('q', '') if not query: return HttpResponseRedirect(reverse("patient_search")) patients = CPatient.view(VIEW_PATIENT_SEARCH, key=query.lower(), include_docs=True) minus_duplicates = SortedDict() for patient in patients: if not patient.get_id in minus_duplicates: minus_duplicates[patient.get_id] = patient return render_to_response(request, "patient/search_results.html", {"patients": minus_duplicates.values(), "query": query} )
def patient_excel(request): # we have to make sure to update any patients without export tags # before redirecting to the export view. for pat in CPatient.view("patient/missing_export_tag", include_docs=True): try: pat.save() except ResourceConflict: # workaround potential conflicts by trying twice pat = CPatient.get(pat.get_id) pat.save() return HttpResponseRedirect("%s?export_tag=CPatient&filename=Patients" % reverse("export_data_async"))
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')
def fuzzy_match(request): # TODO this currently always returns nothing fname = request.POST.get('fname') lname = request.POST.get('lname') gender = request.POST.get('sex') dob = request.POST.get('dob') def prep(val): return val.strip().lower() if val and isinstance(val, basestring) else val startkey = map(prep, [gender, lname, fname, dob]) endkey = map(prep, [gender, lname, fname, dob, {}]) pats = CPatient.view(VIEW_PATIENT_FUZZY_SEARCH, startkey=startkey, endkey=endkey, reduce=False, include_docs=True).all() return _patient_list_response(pats)
def delete_all_patients(): for pat in CPatient.view(const.VIEW_PATIENT_BY_BHOMA_ID, reduce=False, include_docs=True).all(): pat.delete()