Exemplo n.º 1
0
 def get_next_item(event_id, question_list):
     for question_ in question_list:
         item_ = get_question_item(self._domain_name, event_id,
                                   question_)
         if item_:
             return item_
     return None
Exemplo n.º 2
0
 def subject_rows(self):
     audit_log_id = 0  # To exclude audit logs, set `custom.openclinica.const.AUDIT_LOGS = False`
     for case in self.get_subject_cases():
         subject = Subject(getattr(case, CC_SUBJECT_KEY), getattr(case, CC_STUDY_SUBJECT_ID), self.domain)
         for form in originals_first(case.get_forms()):
             updates = form.form['case'].get('update', {})
             if updates:
                 for question, answer in updates.iteritems():
                     item = get_question_item(self.domain, form.xmlns, question)
                     if item is None:
                         # This is a CommCare-only question or form
                         continue
                     audit_log_id += 1
                     subject.add_item(item, form, question, oc_format_date(answer), audit_log_id)
                 subject.close_form(form)
         yield subject
Exemplo n.º 3
0
    def add_data(self, data, form, event_case, audit_log_id_ref):
        def get_next_item(event_id, question_list):
            for question_ in question_list:
                item_ = get_question_item(self._domain_name, event_id,
                                          question_)
                if item_:
                    return item_
            return None

        event_id = getattr(event_case, 'event_type')
        # If a CommCare form is an OpenClinica repeating item group, then we would need to add a new item
        # group.
        for key, value in six.iteritems(data):
            if key in _reserved_keys:
                continue
            if isinstance(value, list):
                # Repeat group
                # NOTE: We need to assume that repeat groups can't be edited in later form submissions
                item = get_next_item(event_id, value)
                if item is None:
                    # None of the questions in this group are OpenClinica items
                    continue
                self.add_item_group(item, form)
                for v in value:
                    if not isinstance(v, dict):
                        raise OpenClinicaIntegrationError(
                            'CommCare question value is an unexpected data type. Form XMLNS: "{}"'
                            .format(form.xmlns))
                    self.add_data(v, form, event_case, audit_log_id_ref)
            elif isinstance(value, dict):
                # Group
                self.add_data(value, form, event_case, audit_log_id_ref)
            else:
                # key is a question and value is its answer
                item = get_question_item(self._domain_name, event_id, key)
                if item is None:
                    # This is a CommCare-only question or form
                    continue
                case_id = event_case.get_id
                self.add_item(item, form, case_id, key, value,
                              audit_log_id_ref)
Exemplo n.º 4
0
    def add_data(self, data, form, audit_log_id_ref):
        def get_next_item(question_list):
            for question_ in question_list:
                item_ = get_question_item(self._domain, form.xmlns, question_)
                if item_:
                    return item_
            return None

        # If a CommCare form is an OpenClinica repeating item group, then we would need to add a new item
        # group. This isn't relevant for this project.
        # if form.xmlns in REPEATING_ITEM_GROUP_FORMS:
        #     pass
        for key, value in data.iteritems():
            if key in _reserved_keys:
                continue
            if isinstance(value, list):
                # Repeat group
                # NOTE: We need to assume that repeat groups can't be edited in later form submissions
                item = get_next_item(value)
                if item is None:
                    # None of the questions in this group are OpenClinica items
                    continue
                self.add_item_group(item, form)
                for v in value:
                    # TODO: More testing
                    if not isinstance(v, dict):
                        raise OpenClinicaIntegrationError(
                            'CommCare question value is an unexpected data type. Form XMLNS: "{}"'.format(
                                form.xmlns))
                    self.add_data(v, form, audit_log_id_ref)
            elif isinstance(value, dict):
                # Group
                self.add_data(value, form, audit_log_id_ref)
            else:
                # key is a question and value is its answer
                item = get_question_item(self._domain, form.xmlns, key)
                if item is None:
                    # This is a CommCare-only question or form
                    continue
                self.add_item(item, form, key, oc_format_date(value), audit_log_id_ref)
Exemplo n.º 5
0
    def add_data(self, data, form, event_case, audit_log_id_ref):
        def get_next_item(event_id, question_list):
            for question_ in question_list:
                item_ = get_question_item(self._domain_name, event_id, question_)
                if item_:
                    return item_
            return None

        event_id = getattr(event_case, 'event_type')
        # If a CommCare form is an OpenClinica repeating item group, then we would need to add a new item
        # group.
        for key, value in six.iteritems(data):
            if key in _reserved_keys:
                continue
            if isinstance(value, list):
                # Repeat group
                # NOTE: We need to assume that repeat groups can't be edited in later form submissions
                item = get_next_item(event_id, value)
                if item is None:
                    # None of the questions in this group are OpenClinica items
                    continue
                self.add_item_group(item, form)
                for v in value:
                    if not isinstance(v, dict):
                        raise OpenClinicaIntegrationError(
                            'CommCare question value is an unexpected data type. Form XMLNS: "{}"'.format(
                                form.xmlns))
                    self.add_data(v, form, event_case, audit_log_id_ref)
            elif isinstance(value, dict):
                # Group
                self.add_data(value, form, event_case, audit_log_id_ref)
            else:
                # key is a question and value is its answer
                item = get_question_item(self._domain_name, event_id, key)
                if item is None:
                    # This is a CommCare-only question or form
                    continue
                case_id = event_case.get_id
                self.add_item(item, form, case_id, key, value, audit_log_id_ref)
Exemplo n.º 6
0
 def get_next_item(question_list):
     for question_ in question_list:
         item_ = get_question_item(self._domain, form.xmlns, question_)
         if item_:
             return item_
     return None
Exemplo n.º 7
0
 def get_next_item(event_id, question_list):
     for question_ in question_list:
         item_ = get_question_item(self._domain_name, event_id, question_)
         if item_:
             return item_
     return None