def create(self, validated_data): file_id = self.validated_data.get('file') file = get_file_by_file_id(file_id) survey_id = self.validated_data.get('survey_type') try: user = self.context.get('request')._user except AttributeError: user = None survey = None if survey_id: survey = get_survey_by_id(survey_id=int(survey_id)) if not survey: raise ValidationError("Survey does not exist.") if not check_user_permissions(user, survey.id): raise ValidationError("No permission.") validated_data.update({ 'survey_type': survey, 'name': survey.pk, 'file': file, 'user': user }) return super().create(validated_data)
def list(self, request, *args, **kwargs): qs_key = str(self.request.user.uuid) + '_emergency_contacts' if 'page' not in request.query_params: file = get_file_by_file_id(file_id=request.query_params.get('file')) if not file: return Response(status=status.HTTP_404_NOT_FOUND) queryset = get_active_emergency_contacts().filter(patient=file.patient) cache.set(qs_key, queryset, 86400) return super().list(request, *args, **kwargs)
def _journal_comment(self, message, instance, user, action, **kwargs): if message: for lang in settings.MODELTRANSLATION_LANGUAGES: with translation.override(lang): self.journal_name_map[lang] = self._name_generator(instance) create_journal_message( self.journal_name_map['en'], self.journal_name_map['fr'], self.journal_name_map['nl'], message, get_file_by_file_id(instance.file.file_id) if instance else None, user, self._comment_slug, action, **kwargs )
def user_activity_track(username, email, activity, file_id, patient_id, data): file = get_file_by_file_id(file_id) patient = get_patient(patient_id) if file: patient = file.patient elif patient: patient = patient Activity.objects.create(user=username, email=email, activity=activity, patient=patient, patient_id=getattr(patient, 'patient_id', None), file_id=file, data=data)
def _get_context(self, response): file = get_file_by_file_id(self.request.data['file']) if not file: return {} patient = file.patient patient.insurance_policy = dict(HEALTH_INSURANCE).get(patient.insurance_policy) ctx = { 'created': get_current_time_zone_datetime(), 'type': dict(REPORT_TYPE)[self.request.data['type']], 'comment_lines': self.request.data.get('comment', '').split('\n'), 'logo': f'data:image/jpeg;base64,{base64.b64encode(response.content).decode("utf-8")}', 'username': self.request.user, 'patient': patient, 'file_created': file.created, 'unit': file.unit.name, 'bed': file.bed, } ctx.update(ReportContextHelper.get_specification_context(file)[self.request.data['type']]) self.template_path = f'reports/{self.request.data["type"]}_report.html' return ctx
def validate_file(file): return get_file_by_file_id(file)
def create(self, validated_data): file = get_file_by_file_id(validated_data.pop('file')) if file: validated_data['patient'] = get_file_by_file_id(file).patient validated_data['creator'] = self._kwargs['context']['request'].user return super().create(validated_data)
def retrieve(self, request, **kwargs): file = kwargs['file_id'] file = get_file_by_file_id(file) if not file: return Response(status=status.HTTP_404_NOT_FOUND) return Response({'is_released': bool(file.is_released)}, status=status.HTTP_200_OK)