Beispiel #1
0
 def test_patient_details_full_name_correctly_joins_first_and_last_names(
         self):
     patient_details_data = ExaminationMocks.get_patient_details_load_response_content(
     )
     patient_details = PatientDetails(patient_details_data)
     full_name = patient_details.full_name()
     self.assertEqual(
         full_name.split(' ')[0], patient_details_data.get('givenNames'))
     self.assertEqual(
         full_name.split(' ')[1], patient_details_data.get('surname'))
Beispiel #2
0
    def test_patient_details_get_nhs_number_returns_unknown_if_number_not_present(
            self):
        patient_details_data = ExaminationMocks.get_patient_details_load_response_content(
        )
        patient_details = PatientDetails(patient_details_data)
        self.assertIsNotNone(patient_details)
        patient_details.nhs_number = None

        display_nhs_number = patient_details.get_nhs_number()

        self.assertEquals(display_nhs_number, 'Unknown')
Beispiel #3
0
    def post(self, request, examination_id):
        self.medical_team, self.case_status, error = MedicalTeam.load_by_id(examination_id, self.user.auth_token)
        self.patient_details, self.case_status, error = PatientDetails.load_by_id(examination_id, self.user.auth_token)
        self.form = event_form_parser(request.POST)
        saved = False
        if self.form.is_valid():
            response = event_form_submitter(self.user.auth_token, examination_id, self.form)
            if response.ok:
                # scenario 1 - success
                log_successful_timeline_post(self.form, examination_id, self.user,
                                             self.patient_details.medical_examiner_office_responsible, response)
                saved = True
            else:
                # scenario 2 - api failure
                log_unsuccessful_timeline_post(self.form, examination_id, self.user,
                                               self.patient_details.medical_examiner_office_responsible, response)

            self.status_code = response.status_code
            self.form = None
        else:
            # scenario 3 - validation error
            self._log_unsuccessful_invalid_form(examination_id, self.form.is_final,
                                                self.patient_details.medical_examiner_office_responsible, self.form)
            self.status_code = status.HTTP_400_BAD_REQUEST

        self._load_breakdown(examination_id)

        context = self._set_context(examination_id, saved)

        return render(request, self.template, context, status=self.status_code)
Beispiel #4
0
 def test_patient_details_load_by_id_returns_an_error_object_if_load_fails(
         self, mock_patient_details):
     patient_details, case_status, error = PatientDetails.load_by_id(
         ExaminationMocks.EXAMINATION_ID, SessionMocks.ACCESS_TOKEN)
     self.assertIsNone(patient_details)
     self.assertIsNotNone(error)
     self.assertEquals(type(error), NotFoundError)
Beispiel #5
0
    def test_patient_details_update_does_not_update_the_patient_header_on_failure(
            self, mock_update):
        updated_header_content = ExaminationMocks.get_patient_details_update_response_content(
        ).get('header')
        self.assertNotEqual(
            ExaminationMocks.get_patient_details_load_response_content().get(
                'givenNames'), updated_header_content.get('givenNames'))

        patient_details, case_status, load_error = PatientDetails.load_by_id(
            ExaminationMocks.EXAMINATION_ID, SessionMocks.ACCESS_TOKEN)
        self.assertIsNone(load_error)
        self.assertIsNotNone(patient_details)

        starting_patient_header = patient_details.case_header
        self.assertEquals(
            starting_patient_header.given_names,
            ExaminationMocks.get_patient_details_load_response_content().get(
                'givenNames'))

        error = patient_details.update(
            ExaminationMocks.get_patient_details_load_response_content(),
            SessionMocks.ACCESS_TOKEN)
        self.assertIsNotNone(error)

        ending_patient_header = patient_details.case_header
        self.assertNotEquals(ending_patient_header.given_names,
                             updated_header_content.get('givenNames'))
        self.assertEquals(starting_patient_header.given_names,
                          ending_patient_header.given_names)
Beispiel #6
0
 def test_patient_details_load_by_id_returns_a_case_status_object_if_successful(
         self):
     patient_details, case_status, error = PatientDetails.load_by_id(
         ExaminationMocks.EXAMINATION_ID, SessionMocks.ACCESS_TOKEN)
     self.assertIsNone(error)
     self.assertIsNotNone(case_status)
     self.assertEquals(type(case_status), CaseStatus)
Beispiel #7
0
 def test_initialising_with_the_none_date_results_in_no_dod(self):
     loaded_data = ExaminationMocks.get_patient_details_load_response_content(
     )
     loaded_data['dateOfDeath'] = NONE_DATE
     patient_details = PatientDetails(loaded_data)
     self.assertIsNone(patient_details.date_of_death)
     self.assertIsNone(patient_details.day_of_death)
     self.assertIsNone(patient_details.month_of_death)
     self.assertIsNone(patient_details.year_of_death)
Beispiel #8
0
 def test_patient_details_update_returns_error_if_update_fails(
         self, mock_update):
     patient_details, case_status, load_error = PatientDetails.load_by_id(
         ExaminationMocks.EXAMINATION_ID, SessionMocks.ACCESS_TOKEN)
     self.assertIsNone(load_error)
     self.assertIsNotNone(patient_details)
     error = patient_details.update(
         ExaminationMocks.get_patient_details_load_response_content(),
         SessionMocks.ACCESS_TOKEN)
     self.assertIsNotNone(error)
Beispiel #9
0
 def test_initialising_with_a_bereaved_sets_the_representatives(self):
     loaded_data = ExaminationMocks.get_patient_details_load_response_content(
     )
     bereaved = PeopleMocks.get_bereaved_representative_response_dict()
     loaded_data['representatives'].append(bereaved)
     patient_details = PatientDetails(
         loaded_data, DatatypeMocks.get_modes_of_disposal_list())
     self.assertEqual(len(patient_details.representatives), 1)
     self.assertEqual(patient_details.representatives[0].full_name,
                      bereaved['fullName'])
Beispiel #10
0
 def test_initialising_with_a_mode_of_disposal_and_the_enums_sets_the_mode_of_disposal(
         self):
     loaded_data = ExaminationMocks.get_patient_details_load_response_content(
     )
     mode_of_disposal = list(
         DatatypeMocks.get_modes_of_disposal_list().keys())[0]
     loaded_data['modeOfDisposal'] = mode_of_disposal
     patient_details = PatientDetails(
         loaded_data, DatatypeMocks.get_modes_of_disposal_list())
     self.assertEqual(patient_details.mode_of_disposal, mode_of_disposal)
Beispiel #11
0
    def get(self, request, examination_id):
        self._load_breakdown(examination_id)
        if self.error:
            return render_error(request, self.user, self.error)

        self.medical_team, self.case_status, error = MedicalTeam.load_by_id(examination_id, self.user.auth_token)
        self.patient_details, self.case_status, error = PatientDetails.load_by_id(examination_id, self.user.auth_token)
        self.amend_type = request.GET.get('amendType')

        context = self._set_context(examination_id, False)

        return render(request, self.template, context, status=self.status_code)
Beispiel #12
0
    def dispatch(self, request, *args, **kwargs):
        if self.examination_section == enums.examination_sections.PATIENT_DETAILS:
            self.examination, self.case_status, self.error = PatientDetails.load_by_id(kwargs.get('examination_id'),
                                                                                       self.user.auth_token)
        elif self.examination_section == enums.examination_sections.MEDICAL_TEAM:
            self.examination, self.case_status, self.error = MedicalTeam.load_by_id(kwargs.get('examination_id'),
                                                                                    self.user.auth_token)
        elif self.examination_section == enums.examination_sections.CASE_BREAKDOWN:
            print('not implemented yet')
        elif self.examination_section == enums.examination_sections.CASE_OUTCOMES:
            print('not implemented yet')
        else:
            log_internal_error('EditExaminationSectionBaseView section load', 'Unknown examination section requested')

        if self.error is not None:
            return render_error(request, self.user, self.error)

        return super().dispatch(request, *args, **kwargs)