def filter_queryset(self, queryset): search_key = self.request.query_params.get('search') if not search_key: return super(DoctorHomeColumnViewSet, self).filter_queryset(queryset) # search by cached doctor first/last name hospital = self.request.user.hospital doctors = get_doctors_cache(hospital).get('doctors', {}) id_list = [row.id for row in queryset if search_key in doctors.get(row.author.remote_id).get('full_name')] queryset = queryset.filter(id__in=id_list).union(super(DoctorHomeColumnViewSet, self).filter_queryset(queryset)) return queryset
def perform_create(self, serializer): serializer.save(author=self.request.user) group_id = serializer.instance.column_group_id columns = DoctorHomeColumn.objects.filter(group_id=group_id, is_deleted=False).select_related('author') context = { "doctor_data_from_cache": get_doctors_cache(self.request.user.hospital).get('doctors', {}), "request": self.request, "column_group_map": {group_id: [x.author.remote_id for x in columns]} } columns_serializer = DoctorHomeColumnSerializer(instance=columns, many=True, context=context) data = {'cell': serializer.data, 'new_columns': columns_serializer.data} send_ws_clinic_message(11, data, self.request.user.hospital.id, self.request.user.remote_id)
def get_serializer_context(self): context = super(DoctorHomeColumnViewSet, self).get_serializer_context() if self.request: context.update({ "doctor_data_from_cache": get_doctors_cache(self.request.user.hospital).get('doctors', {}) }) doctor_ordering = DoctorHomeColumnOrder.objects.filter( doctor=self.request.user).values('column_id', 'order') context.update({ "doctor_column_orders": {c.get('column_id'): c.get('order') for c in doctor_ordering} }) column_group_values = self._get_doctor_column_queryset().values('author__remote_id', 'group_id') column_group_map = {} def make_map(record): group_id = record.get('group_id') if not column_group_map.get(group_id): column_group_map[group_id] = [] column_group_map[group_id].append(record.get('author__remote_id')) [make_map(record) for record in column_group_values] context.update({ "column_group_map": column_group_map }) if self.request.query_params.get('nested'): my_patients = Patient.objects.filter( doctorpatient__in=self.request.user.my_patients_list_participants.all(), doctorpatient__show=True ).distinct() not_hidden_group_id_list = DoctorHomeColumn.objects.filter( Q(author__hospital=self.request.user.hospital) & Q(is_deleted=False)).exclude( id__in=self.request.user.hidden_doctor_home_column_list.all()).distinct( 'group_id').values_list('group_id', flat=True) clinic_column_cells = DoctorHomeCell.objects.filter( patient__hospital=self.request.user.hospital, column_group_id__in=not_hidden_group_id_list, patient__in=my_patients ) context.update({ "clinic_column_cells_queryset": clinic_column_cells }) return context
def full_name(self): # Pay attention. This property can be slowly return get_doctors_cache(self.hospital).get('doctors', {}).get(self.remote_id)
def get_display_data(user): hospital_cache = get_doctors_cache(user.hospital) if not hospital_cache.get('doctors').get(user.remote_id): update_cached_doctor_data(doctor_remote_id=user.remote_id, hospital=user.hospital) hospital_cache = get_doctors_cache(user.hospital) return hospital_cache.get('doctors', {"full_name": "", "full_photo": ""}).get(user.remote_id)