def basicnote_detail(request, pk, model): note = get_object_or_404(model, pk=pk) active_role = get_active_role(request) can_sign = False can_update = False attestable = (model == models.AttestableBasicNote) title = "" if attestable: can_sign = note.group_can_sign(active_role) can_update = group_has_perm(active_role, 'workup.change_attestablebasicnote') title = "Attestable Basic Note" else: can_update = group_has_perm(active_role, 'workup.change_basicnote') title = "Basic Note" return render( request, 'workup/basicnote_detail.html', { 'note': note, 'can_sign': can_sign, 'can_update': can_update, 'attestable': attestable, 'title': title })
def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) self.pt = get_object_or_404(Patient, pk=self.kwargs['pt_id']) context['pt'] = self.pt context['labs'] = Lab.objects.filter(patient=self.kwargs['pt_id']) active_role = get_active_role(self.request) for perm in ['add_lab']: context[perm] = group_has_perm(active_role, 'labs.%s' % perm) return context
def get_context_data(self, **kwargs): context = super(DrugListView, self).get_context_data(**kwargs) context['patients'] = Patient.objects.filter( needs_workup=True).order_by('last_name').select_related('gender') active_role = get_active_role(self.request) context['can_export_csv'] = group_has_perm(active_role, 'inventory.export_csv') return context
def get_context_data(self, **kwargs): context = super(LabDetailView,self).get_context_data(**kwargs) self.lab = get_object_or_404(Lab, pk=self.kwargs['pk']) context['lab'] = self.lab context['pt'] = self.lab.patient measurement_list = get_measurements_from_lab(self.lab.id) context['measurement_list'] = measurement_list active_role = get_active_role(self.request) for perm in ['change_lab']: context[perm] = group_has_perm(active_role, 'labs.%s' % perm) return context
def workup_detail(request, pk): workup = get_object_or_404(models.Workup, pk=pk) active_role = get_active_role(request) can_sign = models.Workup.group_can_sign(active_role) can_export_pdf = group_has_perm(active_role, 'workup.export_pdf_Workup') return render(request, 'workup/workup_detail.html', { 'workup': workup, 'can_sign': can_sign, 'can_export_pdf': can_export_pdf })
def view_all_as_table(request,pt_id,month_range=6): """ Lab table view with recent labs A table with rows as measurement values and columns as labs Displays recent labs """ if request.method == 'GET' and 'select' in request.GET: month_range = int(request.GET['select']) # Get qs for the patient pt = get_object_or_404(Patient, id=pt_id) lab_types = list(LabType.objects.all()) to_tz = timezone.get_default_timezone() time_threshold = datetime.now(to_tz) - timedelta(days=month_range*31) lab_qs = Lab.objects.filter(patient=pt_id, lab_time__gt=time_threshold) lab_days = sorted([lab.get_day() for lab in lab_qs], reverse=True) unique_lab_days=reduce(lambda l, x: l if x in l else l+[x], lab_days, []) listed_lab_days = unique_lab_days[:] n_days = len(listed_lab_days) # Initiate empty table # width = # of labs # height = # of measurement types table_header = ['','Reference'] col_header_len = len(table_header) table_header += [ str(x) for x in listed_lab_days ] table_content = [] sorted_measure_types = [] dup_lab_bool = False for t_lab_type in lab_types: m_types = get_measurementtypes_from_labtype(t_lab_type.id) table_content.append([table_header[:]]) table_content[-1][0][0] = ('Lab Category: '+str(t_lab_type)) sorted_measure_types.append([]) for mt in m_types: table_content[-1].append(([mt, mt.get_ref()] + ['']*n_days)) sorted_measure_types[-1].append(mt) # Fill in entries for t_lab in lab_qs.reverse(): if (not (t_lab.get_day() in listed_lab_days)): continue measurements = get_measurements_from_lab(t_lab.id) col_index = listed_lab_days.index(t_lab.get_day()) + col_header_len for m in measurements: section_index = lab_types.index(t_lab.lab_type) m_type = m.measurement_type row_index = (sorted_measure_types[section_index]).index(m_type) current_value = table_content[section_index][row_index+1][col_index] if current_value=='': table_content[section_index][row_index+1][col_index] = m else: table_content[section_index][row_index+1][col_index] = m table_content[section_index][0][col_index] += '*' dup_lab_bool = True qs = {'patient':pt, 'table_content': table_content, 'add_lab': group_has_perm(get_active_role(request), 'labs.add_lab'), 'no_lab_bool':len(lab_qs)==0, 'dup_lab_bool': dup_lab_bool} return render(request, 'labs/lab_all_table.html', qs)
def group_can_activate(cls, group): """takes a group and checks if it has activate permission to this object.""" return group_has_perm(group, 'core.activate_Patient')