예제 #1
0
        def _test():
            form, case = _save_form_and_case(self)
            process_indicators_for_case(['mvp_indicators'], case.domain, case.to_json())
            updated_form = IndicatorXForm.get(form._id)
            self.addCleanup(updated_form.delete)
            computed = updated_form.computed_['mvp_indicators']
            self.assertEqual(29, len(computed))
            self.assertEqual('child_visit_form', computed['child_visit_form']['value'])

            process_indicators_for_form(['mvp_indicators'], form.domain, form.to_json())
            updated_form = IndicatorXForm.get(form._id)
            updated_computed = updated_form.computed_['mvp_indicators']
            self.assertEqual(29, len(updated_computed))
            self.assertEqual('child_visit_form', updated_computed['child_visit_form']['value'])
예제 #2
0
        def _test():
            form, case = _save_form_and_case(self)
            process_indicators_for_case(['mvp_indicators'], case.domain, case.to_json())
            updated_form = IndicatorXForm.get(form._id)
            self.addCleanup(updated_form.delete)
            computed = updated_form.computed_['mvp_indicators']
            self.assertEqual(29, len(computed))
            self.assertEqual('child_visit_form', computed['child_visit_form']['value'])

            process_indicators_for_form(['mvp_indicators'], form.domain, form.to_json())
            updated_form = IndicatorXForm.get(form._id)
            updated_computed = updated_form.computed_['mvp_indicators']
            self.assertEqual(29, len(updated_computed))
            self.assertEqual('child_visit_form', updated_computed['child_visit_form']['value'])
예제 #3
0
    def test_form_pillow_indicators(self):
        since = get_current_seq(XFormInstance.get_db())
        form_id = self._save_doc_to_db('indicator_form.json', XFormInstance)
        form_instance = XFormInstance.get(form_id)

        # Form Label Indicator
        form_label = FormLabelIndicatorDefinition.increment_or_create_unique(
            INDICATOR_TEST_NAMESPACE,
            INDICATOR_TEST_DOMAIN,
            slug='create_form',
            xmlns='http://openrosa.org/formdesigner/indicator-create-xmlns',
        )
        form_label.save()

        # Form Alias
        form_alias = FormDataAliasIndicatorDefinition.increment_or_create_unique(
            INDICATOR_TEST_NAMESPACE,
            INDICATOR_TEST_DOMAIN,
            slug='club_name',
            question_id='location.club',
            xmlns='http://openrosa.org/formdesigner/indicator-create-xmlns',
        )
        form_alias.save()
        self.form_pillow.process_changes(since=since, forever=False)

        indicator_form = IndicatorXForm.get(form_id)
        self.assertNotEqual(indicator_form.get_db().dbname,
                            form_instance.get_db().dbname)
        self.assertNotEqual(indicator_form.computed_, {})
예제 #4
0
    def test_form_pillow_indicators(self):
        form_id = self._save_doc_to_db('indicator_form.json', XFormInstance)
        form_instance = XFormInstance.get(form_id)

        # Form Label Indicator
        form_label = FormLabelIndicatorDefinition.increment_or_create_unique(
            INDICATOR_TEST_NAMESPACE,
            INDICATOR_TEST_DOMAIN,
            slug='create_form',
            xmlns='http://openrosa.org/formdesigner/indicator-create-xmlns',
        )
        form_label.save()

        # Form Alias
        form_alias = FormDataAliasIndicatorDefinition.increment_or_create_unique(
            INDICATOR_TEST_NAMESPACE,
            INDICATOR_TEST_DOMAIN,
            slug='club_name',
            question_id='location.club',
            xmlns='http://openrosa.org/formdesigner/indicator-create-xmlns',
        )
        form_alias.save()
        self.form_pillow.process_changes(since=None, forever=False)

        indicator_form = IndicatorXForm.get(form_id)
        self.assertNotEqual(
            indicator_form.get_db().dbname, form_instance.get_db().dbname
        )
        self.assertNotEqual(indicator_form.computed_, {})
예제 #5
0
    def test_form_pillow_indicators(self):
        form_id = self._save_doc_to_db("indicator_form.json", XFormInstance)
        form_instance = XFormInstance.get(form_id)

        # Form Label Indicator
        form_label = FormLabelIndicatorDefinition.increment_or_create_unique(
            INDICATOR_TEST_NAMESPACE,
            INDICATOR_TEST_DOMAIN,
            slug="create_form",
            xmlns="http://openrosa.org/formdesigner/indicator-create-xmlns",
        )
        form_label.save()

        # Form Alias
        form_alias = FormDataAliasIndicatorDefinition.increment_or_create_unique(
            INDICATOR_TEST_NAMESPACE,
            INDICATOR_TEST_DOMAIN,
            slug="club_name",
            question_id="location.club",
            xmlns="http://openrosa.org/formdesigner/indicator-create-xmlns",
        )
        form_alias.save()

        self.form_pillow.run_burst()

        indicator_form = IndicatorXForm.get(form_id)
        self.assertNotEqual(indicator_form.get_db().dbname, form_instance.get_db().dbname)
        self.assertNotEqual(indicator_form.computed_, {})
예제 #6
0
        def _test():
            form, case = _save_form_and_case()
            MVPCaseIndicatorPillow().change_transform(case.to_json())
            updated_form = IndicatorXForm.get(form._id)
            computed = updated_form.computed_['mvp_indicators']
            self.assertEqual(29, len(computed))
            self.assertEqual('child_visit_form', computed['child_visit_form']['value'])

            MVPFormIndicatorPillow().change_transform(form.to_json())
            updated_form = IndicatorXForm.get(form._id)
            updated_computed = updated_form.computed_['mvp_indicators']
            self.assertEqual(29, len(updated_computed))
            self.assertEqual('child_visit_form', updated_computed['child_visit_form']['value'])

            # cleanup
            updated_form.delete()
            form.delete()
            case.delete()
예제 #7
0
        def _test():
            form, case = _save_form_and_case()
            MVPCaseIndicatorPillow().change_transform(case.to_json())
            updated_form = IndicatorXForm.get(form._id)
            computed = updated_form.computed_['mvp_indicators']
            self.assertEqual(29, len(computed))
            self.assertEqual('child_visit_form',
                             computed['child_visit_form']['value'])

            MVPFormIndicatorPillow().change_transform(form.to_json())
            updated_form = IndicatorXForm.get(form._id)
            updated_computed = updated_form.computed_['mvp_indicators']
            self.assertEqual(29, len(updated_computed))
            self.assertEqual('child_visit_form',
                             updated_computed['child_visit_form']['value'])

            # cleanup
            updated_form.delete()
            form.delete()
            case.delete()
예제 #8
0
def process_indicators_for_case(namespaces, domain, doc_dict):
    case_type = doc_dict.get('type')
    if not case_type:
        return

    case_indicator_defs = []
    for namespace in namespaces:
        case_indicator_defs.extend(CaseIndicatorDefinition.get_all(
            namespace,
            domain,
            case_type=case_type
        ))

    try:
        indicator_case = IndicatorCase.wrap_for_indicator_db(doc_dict)
        indicator_case.update_indicators_in_bulk(
            case_indicator_defs, logger=pillow_logging,
            save_on_update=False
        )
        indicator_case.save()
    except Exception as e:
        pillow_logging.error(
            "Error creating for MVP Indicator for form %(form_id)s: "
            "%(error)s" % {
                'form_id': doc_dict['_id'],
                'error': e,
            },
        )
        raise

    # Now Update Data From Case to All Related Xforms (ewwww)
    xform_ids = doc_dict.get('xform_ids', [])
    if not xform_ids:
        return

    for xform_id in xform_ids:
        related_xform_indicators = []
        try:
            # first try to get the doc from the indicator DB
            xform_doc = IndicatorXForm.get(xform_id)
        except ResourceNotFound:
            # if that fails fall back to the main DB
            try:
                xform_dict = XFormInstance.get_db().get(xform_id)
                xform_doc = IndicatorXForm.wrap_for_indicator_db(xform_dict)
                related_xform_indicators = get_form_indicators(namespaces, domain, xform_doc.xmlns)
            except ResourceNotFound:
                pillow_logging.error(
                    "Could not find an XFormInstance with id %(xform_id)s "
                    "related to Case %(case_id)s" % {
                        'xform_id': xform_id,
                        'case_id': doc_dict['_id'],
                    }
                )
                continue

        if not xform_doc.xmlns:
            continue

        for namespace in namespaces:
            related_xform_indicators.extend(
                CaseDataInFormIndicatorDefinition.get_all(
                    namespace,
                    domain,
                    xmlns=xform_doc.xmlns
                )
            )
        xform_doc.update_indicators_in_bulk(
            related_xform_indicators,
            logger=pillow_logging,
            save_on_update=False
        )
        xform_doc.save()
예제 #9
0
def process_indicators_for_case(namespaces, domain, doc_dict):
    case_type = doc_dict.get('type')
    if not case_type:
        return

    case_indicator_defs = []
    for namespace in namespaces:
        case_indicator_defs.extend(
            CaseIndicatorDefinition.get_all(namespace,
                                            domain,
                                            case_type=case_type))

    try:
        indicator_case = IndicatorCase.wrap_for_indicator_db(doc_dict)
        indicator_case.update_indicators_in_bulk(case_indicator_defs,
                                                 logger=pillow_logging,
                                                 save_on_update=False)
        indicator_case.save()
    except Exception as e:
        pillow_logging.error(
            "Error creating for MVP Indicator for form %(form_id)s: "
            "%(error)s" % {
                'form_id': doc_dict['_id'],
                'error': e,
            }, )
        raise

    # Now Update Data From Case to All Related Xforms (ewwww)
    xform_ids = doc_dict.get('xform_ids', [])
    if not xform_ids:
        return

    for xform_id in xform_ids:
        related_xform_indicators = []
        try:
            # first try to get the doc from the indicator DB
            xform_doc = IndicatorXForm.get(xform_id)
        except ResourceNotFound:
            # if that fails fall back to the main DB
            try:
                xform_dict = XFormInstance.get_db().get(xform_id)
                xform_doc = IndicatorXForm.wrap_for_indicator_db(xform_dict)
                related_xform_indicators = get_form_indicators(
                    namespaces, domain, xform_doc.xmlns)
            except ResourceNotFound:
                pillow_logging.error(
                    "Could not find an XFormInstance with id %(xform_id)s "
                    "related to Case %(case_id)s" % {
                        'xform_id': xform_id,
                        'case_id': doc_dict['_id'],
                    })
                continue

        if not xform_doc.xmlns:
            continue

        for namespace in namespaces:
            related_xform_indicators.extend(
                CaseDataInFormIndicatorDefinition.get_all(
                    namespace, domain, xmlns=xform_doc.xmlns))
        xform_doc.update_indicators_in_bulk(related_xform_indicators,
                                            logger=pillow_logging,
                                            save_on_update=False)
        xform_doc.save()