def _extract_case_blocks(data, path=None, form_id=Ellipsis): """ helper for extract_case_blocks data must be json representing a node in an xform submission """ from corehq.form_processor.utils import extract_meta_instance_id if form_id is Ellipsis: form_id = extract_meta_instance_id(data) path = path or [] if isinstance(data, list): for item in data: for case_block in _extract_case_blocks(item, path=path, form_id=form_id): yield case_block elif isinstance(data, dict) and not is_device_report(data): for key, value in data.items(): new_path = path + [key] if const.CASE_TAG == key: # it's a case block! Stop recursion and add to this value if isinstance(value, list): case_blocks = value else: case_blocks = [value] for case_block in case_blocks: if has_case_id(case_block): validate_phone_datetime( case_block.get('@date_modified'), none_ok=True, form_id=form_id ) yield CaseBlockWithPath(caseblock=case_block, path=path) else: for case_block in _extract_case_blocks(value, path=new_path, form_id=form_id): yield case_block