Пример #1
0
    def load_closed_examinations(self, page_size, page_number, location,
                                 person):
        query_params = {
            "LocationId": location,
            "UserId": person,
            "CaseStatus": '',
            "OrderBy": "CaseCreated",
            "OpenCases": False,
            "PageSize": page_size,
            "PageNumber": page_number
        }

        response = examination_request_handler.load_examinations_index(
            query_params, self.auth_token)

        success = response.status_code == status.HTTP_200_OK

        if success:
            self.index_overview = IndexOverview(location, response.json(),
                                                page_size, page_number)
            for examination in response.json()['examinations']:
                examination['open'] = False
                self.examinations.append(ExaminationOverview(examination))
        else:
            log_api_error('case load', response.text)
Пример #2
0
    def post(self, request, examination_id):
        post_body = request.POST
        if CaseOutcome.SCRUTINY_CONFIRMATION_FORM_TYPE in post_body:
            result = CaseOutcome.complete_scrutiny(self.user.auth_token, examination_id)
        elif CaseOutcome.CORONER_REFERRAL_FORM_TYPE in post_body:
            result = CaseOutcome.confirm_coroner_referral(self.user.auth_token, examination_id)
        elif CaseOutcome.OUTSTANDING_ITEMS_FORM_TYPE in post_body:
            form = OutstandingItemsForm(post_body)
            result = CaseOutcome.update_outstanding_items(self.user.auth_token, examination_id, form.for_request())
        elif CaseOutcome.CLOSE_CASE_FORM_TYPE in post_body:
            result = CaseOutcome.close_case(self.user.auth_token, examination_id)
        else:
            result = GenericError(BadRequestResponse.new(), {'type': 'form', 'action': 'submitting'})

        if result and not result == status.HTTP_200_OK:
            log_api_error('case outcome update', result.get_message())
            self._log_case_outcome_unsuccessful(post_body, examination_id)
            return render_error(request, self.user, result)

        self._load_case_outcome(examination_id)
        context = self._set_context()

        self._log_case_outcome(post_body)

        return render(request, self.template, context, status=self.status_code)
Пример #3
0
    def post(self, request, user_id):
        post_body = request.POST
        status_code = status.HTTP_200_OK
        invalid = False
        form = PermissionBuilderForm(post_body)
        add_another = True if post_body.get('add_another') == "true" else False

        if form.is_valid():
            response = self.managed_user.add_permission(form, self.user.auth_token)

            if response.ok:
                if add_another:
                    form = PermissionBuilderForm()
                else:
                    return redirect('/users/%s/manage' % self.managed_user.user_id)
            else:
                invalid = True
                log_api_error('permission creation', response.text)
                status_code = response.status_code

        else:

            invalid = True
            status_code = status.HTTP_400_BAD_REQUEST

        context = self.__set_add_permission_context(form, invalid)

        return render(request, self.template, context, status=status_code)
Пример #4
0
    def post(self, request, location_id):
        post_body = request.POST
        print("post body:")
        print(post_body)
        form = LocationEditorForm(post_body)

        if form.is_valid():
            response = Location.update_location_me_office(
                form.to_dict(), location_id, self.user.auth_token)

            if response.ok:
                return redirect('/locations/%s/list' % location_id)
            else:
                invalid = True
                if response.status_code == 403:
                    form.is_me_office_error = "You dont have permission to change this location."
                log_api_error('location update', response.text)
                status_code = response.status_code
        else:
            invalid = True
            status_code = status.HTTP_400_BAD_REQUEST

        context = self.__set_editor_location_context(self.location,
                                                     invalid,
                                                     posted_form=form)
        return render(request, self.template, context, status=status_code)
Пример #5
0
    def load_by_id(cls, examination_id, auth_token):
        response = request_handler.load_patient_details_by_id(
            examination_id, auth_token)
        patient_details = None
        error = None
        case_status = None

        if response.ok:
            case_status = CaseStatus(response.json())
            modes_of_disposal_response = request_handler.load_modes_of_disposal(
                auth_token)
            if modes_of_disposal_response.ok:
                patient_details = PatientDetails(
                    response.json(), modes_of_disposal_response.json(),
                    examination_id)
            else:
                log_api_error('modes of disposal load', '')
                error = handle_error(modes_of_disposal_response, {
                    "action": "loading",
                    "type": "modes of disposal"
                })
        else:
            log_api_error('patient details load', response.text)
            error = handle_error(response, {
                "action": "loading",
                "type": "patient details"
            })
        return patient_details, case_status, error
Пример #6
0
    def load_permissions(self, auth_token):
        response = permissions_request_handler.load_permissions_for_user(
            self.user_id, auth_token)

        success = response.status_code == status.HTTP_200_OK

        if success:
            self.permissions = response.json()['permissions']
            for permission in self.permissions:
                permission_object = Permission(obj_dict=permission)
                self.permission_objects.append(permission_object)
        else:
            log_api_error('permissions load', response.text)
Пример #7
0
    def __process_api_error(self, form, response):
        form_errors = form.register_form_errors(response.json())
        known_errors = form.register_known_api_errors(response.json())
        unknown_errors = form.register_unknown_api_errors(response.json())
        all_errors = known_errors + unknown_errors + form_errors

        if len(all_errors) > 0:
            for error in all_errors:
                log_api_error('case creation', error)
            status_code = response.status_code
        else:
            log_api_error('case creation', response.text)
            status_code = response.status_code
        return status_code
Пример #8
0
    def __process_api_error(self, medical_team_form, response):
        form_errors = medical_team_form.register_form_errors(response.json())
        known_errors = medical_team_form.register_known_api_errors(response.json())
        unknown_errors = medical_team_form.register_unknown_api_errors(response.json())
        all_errors = form_errors + known_errors + unknown_errors

        if len(all_errors) > 0:
            for all_errors in all_errors:
                log_api_error('medical team', all_errors)
            status_code = response.status_code
        else:
            log_api_error('medical team', response.text)
            status_code = response.status_code
        return status_code
Пример #9
0
    def load_by_id(cls, examination_id, auth_token):
        response = request_handler.load_case_outcome(auth_token,
                                                     examination_id)

        if response.status_code == status.HTTP_200_OK:
            return CaseOutcome(response.json(), examination_id), CaseStatus(
                response.json()), None
        else:
            log_api_error('case outcome load',
                          response.text if response.content != 'null' else '')
            return None, None, handle_error(response, {
                'type': 'case outcome',
                'action': 'loading'
            })
Пример #10
0
    def load_by_id(cls, examination_id, auth_token):
        response = request_handler.load_medical_team_by_id(
            examination_id, auth_token)
        medical_team = None
        error = None
        case_status = None

        if response.ok:
            medical_team = MedicalTeam(response.json(), examination_id)
            case_status = CaseStatus(response.json())
        else:
            log_api_error('medical team load', response.text)
            error = handle_error(response, {
                "action": "loading",
                "type": "medical team"
            })

        return medical_team, case_status, error
Пример #11
0
    def post(self, request):
        form = CreateUserForm(request.POST)

        if form.validate():
            response = User.create(form.response_to_dict(), self.user.auth_token)

            if response.ok:
                # 1. success
                return redirect('/users/%s/add_permission' % response.json()['userId'])
            else:
                # 2. api error
                log_api_error('user creation', response.text)
                form.register_response_errors(response)
                status_code = response.status_code
        else:
            # 3. front end error
            status_code = status.HTTP_400_BAD_REQUEST

        context = self.__set_create_user_context(form, True)
        return render(request, self.template, context, status=status_code)
Пример #12
0
    def post(self, request, user_id, permission_id):
        post_body = request.POST
        form = PermissionBuilderForm(post_body)

        if form.is_valid():
            response = self.managed_user.update_permission(form, permission_id, self.user.auth_token)

            if response.ok:
                return redirect('/users/%s/manage' % self.managed_user.user_id)
            else:
                invalid = True
                log_api_error('permission creation', response.text)
                status_code = response.status_code
        else:
            invalid = True
            status_code = status.HTTP_400_BAD_REQUEST

        permission = Permission.load_by_id(user_id, permission_id, self.user.auth_token)
        context = self.__set_edit_permission_context(permission, invalid, posted_form=form)

        return render(request, self.template, context, status=status_code)
Пример #13
0
    def load_examinations(self,
                          page_size,
                          page_number,
                          location,
                          person,
                          case_status,
                          sorting_order=None):
        query_params = {
            "LocationId":
            location,
            "UserId":
            person,
            "CaseStatus":
            case_status,
            "OrderBy":
            sorting_order
            or enums.results_sorting.SORTING_ORDERS_DEFAULT_FIRST[0][1],
            "OpenCases":
            enums.open_closed.OPEN,
            "PageSize":
            page_size,
            "PageNumber":
            page_number
        }

        response = examination_request_handler.load_examinations_index(
            query_params, self.auth_token)

        success = response.status_code == status.HTTP_200_OK

        if success:
            self.index_overview = IndexOverview(location, response.json(),
                                                page_size, page_number)
            for examination in response.json().get('examinations'):
                examination['open'] = True
                self.examinations.append(ExaminationOverview(examination))
        else:
            log_api_error('permissions load', response.text)
Пример #14
0
    def post(self, request, examination_id):
        post_body = request.POST
        form = VoidCaseForm(post_body)

        if not form.is_valid():
            status_code = status.HTTP_400_BAD_REQUEST
            monitor.log_void_case_unsuccessful(self.user, examination_id)
            context = self._get_context(examination_id, form)

            return render(request, self.template, context, status=status_code)

        else:
            result = Examination.void(examination_id, form.to_object(), self.user.auth_token)

            if result.status_code == status.HTTP_200_OK:
                monitor.log_void_case_success(self.user, examination_id)

                return redirect('void-case-success')

            else:
                log_api_error('void case', result.__dict__)
                monitor.log_void_case_unsuccessful(self.user, examination_id)

                return render_error(request, self.user, result)