def editAdmitDischarge(request, emritem): user = viewhelper.get_user(request) if user is None: viewhelper.unauth(request) if not userauth.userCan_EMRItem(user, emritem, 'edit'): viewhelper.unauth(request) #TODO: allow hospital admin to edit all admission fields form = None if request.method == "POST": form = AdmitDishchargeForm(request.POST) if form.is_valid(): m = form.save(commit=True, update=emritem) return viewhelper.toEmr(request, emritem.patient.pk) else: form = AdmitDishchargeForm() form.defaults(emritem) form.lockField('hospital', emritem.emradmitstatus.hospital) form.lockField('patient', emritem.patient) return render( request, 'emr/emritem_edit.html', viewhelper.getBaseContext(request, user, form=form, patient=emritem.patient))
def view_log(request): user = get_user(request) if (user is None): return viewhelper.unauth(request, "You much be logged in to view this page") if not viewhelper.isHosadmin(user): return viewhelper.unauth( request, "You much be a hospital admin to view the page") form = None logs = Syslog.objects.all().order_by("date_created") if request.method == "POST": form = DateSearchForm(request.POST) if form.is_valid(): logs = logs.filter( date_created__gte=form.cleaned_data['start']).filter( date_created__lte=form.cleaned_data['end']) build = Syslog.objects.none() for w in form.cleaned_data['keywords'].split(' '): build |= logs.filter(message__icontains=w) logs = build else: form = DateSearchForm() return render( request, 'syslogging/System_Log.html', viewhelper.getBaseContext(request, user, form=form, logs=logs, title="System Logs"))
def exportEMR(request, pk): user = viewhelper.get_user(request) if user is None: return viewhelper.unauth(request) patient = get_object_or_404(Patient, pk=pk) if not userauth.userCan_EMR(user, patient, 'view'): # TODO: add syslogging to unauth, Syslog.unauth_acess(request) return viewhelper.unauth(request) emr = patient.emritem_set.all().order_by('-date_created') ctx = {'patient': patient, 'user': user, 'EMRItems': emr} if hasattr(patient, 'emrprofile'): ctx['EMRProfile'] = patient.emrprofile return render(request, 'emr/export_emr.html', ctx)
def viewEmrItem(request, pk): user = viewhelper.get_user(request) if user is None: return viewhelper.unauth(request) item = get_object_or_404(EMRItem, pk=pk) if not userauth.userCan_EMR(user, item.patient, 'view'): # TODO: add syslogging to unauth, Syslog.unauth_acess(request) return viewhelper.unauth(request) return render( request, 'emr/view_emr_item.html', viewhelper.getBaseContext(request, user, item=item, title="Medical Record Detail", permissions=getPermissionsContext( user, item.patient)))
def editEmrItem(request, pk): user = viewhelper.get_user(request) if user is None: return viewhelper.unauth(request) emritem = get_object_or_404(EMRItem, pk=pk) if not userauth.userCan_EMRItem(user, emritem, 'edit'): return viewhelper.unauth(request) if hasattr(emritem, 'emradmitstatus'): return editAdmitDischarge(request, emritem) form = None if request.method == "GET": form = getFormFromReqType(emrItemType(emritem), emritem.patient, user) form.defaults(emritem) else: form = getFormFromReqType(emrItemType(emritem), emritem.patient, user, post=request.POST, files=request.FILES) if form.is_valid(): if isPrescription(emritem): m = form.save(update=emritem, commit=False) m.emrprescription.provider = user m.emrprescription.save() m.save() else: form.save(update=emritem, commit=True) return HttpResponseRedirect( reverse('emr:vemri', args=(emritem.pk, ))) return render( request, 'emr/emritem_edit.html', viewhelper.getBaseContext(request, user, form=form, patient=emritem.patient))
def editEmrProfile(request, pk): user = viewhelper.get_user(request) if user is None: viewhelper.unauth(request) patient = get_object_or_404(Patient, pk=pk) if not userauth.userCan_EMR(user, patient, 'vitals'): return viewhelper.unauth(request) form = None if request.method == "GET": form = ProfileCreateForm() if hasattr(patient, 'emrprofile'): form.defaults(patient.emrprofile) elif request.method == "POST": form = ProfileCreateForm(request.POST) if form.is_valid(): m = None if hasattr(patient, 'emrprofile'): m = form.save(commit=False, model=patient.emrprofile) else: m = form.save(commit=False) m.patient = patient # TODO: notification m.save() return HttpResponseRedirect(reverse('emr:vemr', args=(pk, ))) return render( request, 'emr/emritem_edit.html', viewhelper.getBaseContext( request, user, form=form, title="Edit {0}'s Basic Health Information".format( patient.user.get_full_name()), patient=patient))
def viewEMR(request, pk): user = viewhelper.get_user(request) if user is None: return viewhelper.unauth(request) patient = get_object_or_404(Patient, pk=pk) if not userauth.userCan_EMR(user, patient, 'view'): # TODO: add syslogging to unauth, Syslog.unauth_acess(request) return viewhelper.unauth(request) emr = patient.emritem_set.all().order_by('-date_created') form = None ff = getFilterForm(user) if request.method == "POST": form = FilterSortForm(request.POST, instance=ff) if form.is_valid(): form.save(commit=True) else: form = FilterSortForm(instance=ff) if not (ff is None): if ff.filters != "": build = emr.none() if 'prescription' in ff.filters: build |= emr.exclude(emrprescription=None) if 'vitals' in ff.filters: build |= emr.exclude(emrvitals=None) if 'test' in ff.filters: build |= emr.exclude(emrtest=None) if 'pending' in ff.filters: build |= emr.filter(emrtest__released=False) if 'admit' in ff.filters: build |= emr.filter(emradmitstatus__admit=True) if 'discharge' in ff.filters: build |= emr.filter(emradmitstatus__admit=False) emr = build if ff.keywords != "": build = emr.none() words = ff.keywords.split(' ') for word in words: build |= emr.filter(content__contains=word) build |= emr.filter(emrvitals__bloodPressure__contains=word) if viewhelper.try_parse(word): num = int(word) build |= emr.filter(priority=num) build |= emr.filter(emrprescription__dosage=num) build |= emr.filter(emrprescription__amountPerDay=num) build |= emr.filter(emrvitals__height=num) build |= emr.filter(emrvitals__weight=num) emr = build if ff.sort != "": if 'date' in ff.sort: emr = emr.order_by('-date_created') elif 'priority' in ff.sort: emr = emr.order_by('-priority') elif 'alph' in ff.sort: emr = emr.order_by('content') elif 'vitals' in ff.sort: emr = list(emr.exclude(emrvitals=None)) + list( emr.filter(emrvitals=None)) ctx = { 'EMRItems': emr, 'form': form, 'patient': patient, 'permissions': getPermissionsContext(user, patient), 'admit': viewhelper.isAdmitted(patient) } if ctx['admit']: ctx['hospital'] = patient.admittedHospital() if hasattr(patient, 'emrprofile'): ctx['EMRProfile'] = patient.emrprofile Syslog.viewEMR(patient, user) return render( request, 'emr/filter_emr.html', viewhelper.getBaseContext( request, user, title="{0}'s Electronic Medical Record".format( patient.user.get_full_name()), **ctx))