(case_db, xforms)
return touched_cases
Get all cases affected by the forms. Includes new cases, updated cases.
Get all cases affected by the forms. Includes new cases, updated cases.
Get all cases affected by the forms . Includes new cases updated cases .
def get_cases_from_forms(case_db, xforms):
        """Get all cases affected by the forms. Includes new cases, updated cases.
        """
        touched_cases = {}
        if len(xforms) > 1:
            domain = xforms[0].domain
            affected_cases = set()
            deprecated_form = None
            for xform in xforms:
                if xform.is_deprecated:
                    deprecated_form = xform
                if not (xform.is_deprecated and xform.problem):
                    # don't process deprecated forms which have errors.
                    # see http://manage.dimagi.com/default.asp?243382 for context.
                    # note that we have to use .problem instead of .is_error because applying
                    # the state=DEPRECATED overrides state=ERROR
                    affected_cases.update(case_update.id for case_update in get_case_updates(xform))

            rebuild_detail = FormEditRebuild(deprecated_form_id=deprecated_form.form_id)
            for case_id in affected_cases:
                case = case_db.get(case_id)
                is_creation = False
                if not case:
                    case = CommCareCaseSQL(domain=domain, case_id=case_id)
                    is_creation = True
                    case_db.set(case_id, case)
                previous_owner = case.owner_id
                case, _ = FormProcessorSQL._rebuild_case_from_transactions(
                    case, rebuild_detail, updated_xforms=xforms
                )
                if case:
                    touched_cases[case.case_id] = CaseUpdateMetadata(
                        case=case, is_creation=is_creation, previous_owner_id=previous_owner,
                        actions={const.CASE_ACTION_REBUILD}
                    )
        else:
            xform = xforms[0]
            for case_update in get_case_updates(xform):
                case_update_meta = case_db.get_case_from_case_update(case_update, xform)
                if case_update_meta.case:
                    case_id = case_update_meta.case.case_id
                    if case_id in touched_cases:
                        touched_cases[case_id] = touched_cases[case_id].merge(case_update_meta)
                    else:
                        touched_cases[case_id] = case_update_meta
                else:
                    logging.error(
                        "XForm %s had a case block that wasn't able to create a case! "
                        "This usually means it had a missing ID" % xform.get_id
                    )

        return touched_cases
def get_cases_from_forms ( case_db , xforms ) : touched_cases = { } if len ( xforms ) > 1 : domain = xforms [ 0 ] . domain affected_cases = set ( ) deprecated_form = None for xform in xforms : if xform . is_deprecated : deprecated_form = xform if not ( xform . is_deprecated and xform . problem ) : # don't process deprecated forms which have errors. # see http://manage.dimagi.com/default.asp?243382 for context. # note that we have to use .problem instead of .is_error because applying # the state=DEPRECATED overrides state=ERROR affected_cases . update ( case_update . id for case_update in get_case_updates ( xform ) ) rebuild_detail = FormEditRebuild ( deprecated_form_id = deprecated_form . form_id ) for case_id in affected_cases : case = case_db . get ( case_id ) is_creation = False if not case : case = CommCareCaseSQL ( domain = domain , case_id = case_id ) is_creation = True case_db . set ( case_id , case ) previous_owner = case . owner_id case , _ = FormProcessorSQL . _rebuild_case_from_transactions ( case , rebuild_detail , updated_xforms = xforms ) if case : touched_cases [ case . case_id ] = CaseUpdateMetadata ( case = case , is_creation = is_creation , previous_owner_id = previous_owner , actions = { const . CASE_ACTION_REBUILD } ) else : xform = xforms [ 0 ] for case_update in get_case_updates ( xform ) : case_update_meta = case_db . get_case_from_case_update ( case_update , xform ) if case_update_meta . case : case_id = case_update_meta . case . case_id if case_id in touched_cases : touched_cases [ case_id ] = touched_cases [ case_id ] . merge ( case_update_meta ) else : touched_cases [ case_id ] = case_update_meta else : logging . error ( "XForm %s had a case block that wasn't able to create a case! " "This usually means it had a missing ID" % xform . get_id ) return touched_cases