Ejemplo n.º 1
0
    def test_from_client_json_raises_BadRequest_for_excessively_long_value_string(
            self):
        self.insert_codes()
        q_id = self.create_questionnaire('questionnaire1.json')
        p_id = self.create_participant()
        self.send_consent(p_id)

        # First check that the normal case actually writes out correctly
        string = 'a' * QuestionnaireResponseAnswer.VALUE_STRING_MAXLEN
        string_answers = [["nameOfChild", string]]
        resource = make_questionnaire_response_json(
            p_id, q_id, string_answers=string_answers)
        qr = self.questionnaire_response_dao.from_client_json(
            resource, participant_id=int(p_id[1:]))
        with self.questionnaire_response_answer_dao.session() as session:
            self.questionnaire_response_dao.insert(qr)
            all_strings_query = session.query(
                QuestionnaireResponseAnswer.valueString).all()
            all_strings = [obj.valueString for obj in all_strings_query]
            self.assertTrue(string in all_strings)

        # Now check that the incorrect case throws
        string = 'a' * (QuestionnaireResponseAnswer.VALUE_STRING_MAXLEN + 1)
        string_answers = [["nameOfChild", string]]
        resource = make_questionnaire_response_json(
            p_id, q_id, string_answers=string_answers)
        with self.assertRaises(BadRequest):
            qr = self.questionnaire_response_dao.from_client_json(
                resource, participant_id=int(p_id[1:]))
Ejemplo n.º 2
0
  def submit_questionnaire_response(self, participant_id, questionnaire_id, race_code, gender_code,
                                    first_name, middle_name, last_name, zip_code,
                                    state_code, street_address, city, sex_code,
                                    sexual_orientation_code, phone_number, recontact_method_code,
                                    language_code, education_code, income_code, date_of_birth,
                                    cabor_signature_uri):
    code_answers = []
    _add_code_answer(code_answers, "race", race_code)
    _add_code_answer(code_answers, "genderIdentity", gender_code)
    _add_code_answer(code_answers, "state", state_code)
    _add_code_answer(code_answers, "sex", sex_code)
    _add_code_answer(code_answers, "sexualOrientation", sexual_orientation_code)
    _add_code_answer(code_answers, "recontactMethod", recontact_method_code)
    _add_code_answer(code_answers, "language", language_code)
    _add_code_answer(code_answers, "education", education_code)
    _add_code_answer(code_answers, "income", income_code)

    qr = make_questionnaire_response_json(participant_id,
                                          questionnaire_id,
                                          code_answers = code_answers,
                                          string_answers = [("firstName", first_name),
                                                            ("middleName", middle_name),
                                                            ("lastName", last_name),
                                                            ("streetAddress", street_address),
                                                            ("city", city),
                                                            ("phoneNumber", phone_number),
                                                            ("zipCode", zip_code)],
                                          date_answers = [("dateOfBirth", date_of_birth)],
                                          uri_answers = [("CABoRSignature", cabor_signature_uri)])
    with FakeClock(TIME_1):
      self.send_post('Participant/%s/QuestionnaireResponse' % participant_id, qr)
Ejemplo n.º 3
0
 def _submit_consent_questionnaire_response(self, participant_id, questionnaire_id,
                                            ehr_consent_answer, time=TIME_1):
   code_answers = []
   _add_code_answer(code_answers, "ehrConsent", ehr_consent_answer)
   qr = make_questionnaire_response_json(participant_id, questionnaire_id,
                                         code_answers=code_answers)
   with FakeClock(time):
     self.send_post('Participant/%s/QuestionnaireResponse' % participant_id, qr)
Ejemplo n.º 4
0
 def _submit_race_questionnaire_response(self, participant_id,
                                         race_answers):
     code_answers = []
     for answer in race_answers:
         _add_code_answer(code_answers, "race", answer)
     qr = make_questionnaire_response_json(participant_id,
                                           self._questionnaire_id,
                                           code_answers=code_answers)
     self.send_post('Participant/%s/QuestionnaireResponse' % participant_id,
                    qr)
Ejemplo n.º 5
0
 def submit_questionnaire_response(self, participant_id, questionnaire_id,
                                   race_code, gender_code, state,
                                   date_of_birth):
   code_answers = []
   date_answers = []
   if race_code:
     code_answers.append(('race', Concept(PPI_SYSTEM, race_code)))
   if gender_code:
     code_answers.append(('genderIdentity', Concept(PPI_SYSTEM, gender_code)))
   if date_of_birth:
     date_answers.append(('dateOfBirth', date_of_birth))
   if state:
     code_answers.append(('state', Concept(PPI_SYSTEM, state)))
   qr = make_questionnaire_response_json(
       participant_id,
       questionnaire_id,
       code_answers=code_answers,
       date_answers=date_answers)
   self.send_post('Participant/%s/QuestionnaireResponse' % participant_id, qr)
Ejemplo n.º 6
0
 def _submit_empty_questionnaire_response(self, participant_id,
                                          questionnaire_id):
   qr = make_questionnaire_response_json(participant_id, questionnaire_id)
   self.send_post('Participant/%s/QuestionnaireResponse' % participant_id, qr)
Ejemplo n.º 7
0
 def _submit_consent_questionnaire_response(
     self, participant_id, questionnaire_id, ehr_consent_answer):
   code_answers = [('ehrConsent', Concept(PPI_SYSTEM, ehr_consent_answer))]
   qr = make_questionnaire_response_json(
       participant_id, questionnaire_id, code_answers=code_answers)
   self.send_post('Participant/%s/QuestionnaireResponse' % participant_id, qr)