コード例 #1
0
ファイル: touchcare.py プロジェクト: SEL-Columbia/touchforms
def filter_cases(content):
    try: 
        modified_xpath = "join(',', instance('casedb')/casedb/case%(filters)s/@case_id)" % \
                {"filters": content["filter_expr"]}
            
        api_auth = content.get('hq_auth')
        session_data = content.get("session_data", {})
        ccInstances = CCInstances(session_data, api_auth)
        caseInstance = ExternalDataInstance("jr://instance/casedb", "casedb")
        caseInstance.initialize(ccInstances, "casedb")
        instances = to_hashtable({"casedb": caseInstance})
        case_list = XPathFuncExpr.toString(XPathParseTool.parseXPath(modified_xpath)\
            .eval(EvaluationContext(None, instances)))
        return {'cases': filter(lambda x: x,case_list.split(","))}
    except Exception, e:
        return {'error': str(e)}
コード例 #2
0
ファイル: touchcare.py プロジェクト: SEL-Columbia/touchforms
def filter_cases(content):
    try:
        modified_xpath = "join(',', instance('casedb')/casedb/case%(filters)s/@case_id)" % \
                {"filters": content["filter_expr"]}

        api_auth = content.get('hq_auth')
        session_data = content.get("session_data", {})
        ccInstances = CCInstances(session_data, api_auth)
        caseInstance = ExternalDataInstance("jr://instance/casedb", "casedb")
        caseInstance.initialize(ccInstances, "casedb")
        instances = to_hashtable({"casedb": caseInstance})
        case_list = XPathFuncExpr.toString(XPathParseTool.parseXPath(modified_xpath)\
            .eval(EvaluationContext(None, instances)))
        return {'cases': filter(lambda x: x, case_list.split(","))}
    except Exception, e:
        return {'error': str(e)}
コード例 #3
0
    try:
        caseInstance.initialize(ccInstances, "casedb")
    except (HTTPError, URLError), e:
        raise TouchFormsUnauthorized('Unable to connect to HQ: %s' % str(e))

    instances = to_hashtable({"casedb": caseInstance})

    # load any additional instances needed
    for extra_instance_config in session_data.get('extra_instances', []):
        data_instance = ExternalDataInstance(extra_instance_config['src'], extra_instance_config['id'])
        data_instance.initialize(ccInstances, extra_instance_config['id'])
        instances[extra_instance_config['id']] = data_instance

    try:
        case_list = XPathFuncExpr.toString(
            XPathParseTool.parseXPath(modified_xpath).eval(
                EvaluationContext(None, instances)))
        return {'cases': filter(lambda x: x, case_list.split(","))}
    except (XPathException, XPathSyntaxException), e:
        raise TouchcareInvalidXPath('Error querying cases with xpath %s: %s' % (filter_expr, str(e)))


def query_case_ids(q, criteria=None):
    criteria = copy(criteria) or {}  # don't modify the passed in dict
    criteria["ids_only"] = 'true'
    query_url = '%s?%s' % (settings.CASE_API_URL, urllib.urlencode(criteria))
    return [id for id in q(query_url)]


def query_cases(q, criteria=None):
    query_url = '%s?%s' % (settings.CASE_API_URL, urllib.urlencode(criteria)) \
コード例 #4
0
ファイル: touchcare.py プロジェクト: Hanuman97/touchforms
        caseInstance.initialize(ccInstances, "casedb")
    except (HTTPError, URLError), e:
        raise TouchFormsUnauthorized('Unable to connect to HQ: %s' % str(e))

    instances = to_hashtable({"casedb": caseInstance})

    # load any additional instances needed
    for extra_instance_config in session_data.get('extra_instances', []):
        data_instance = ExternalDataInstance(extra_instance_config['src'],
                                             extra_instance_config['id'])
        data_instance.initialize(ccInstances, extra_instance_config['id'])
        instances[extra_instance_config['id']] = data_instance

    try:
        case_list = XPathFuncExpr.toString(
            XPathParseTool.parseXPath(modified_xpath).eval(
                EvaluationContext(None, instances)))
        return {'cases': filter(lambda x: x, case_list.split(","))}
    except (XPathException, XPathSyntaxException), e:
        raise TouchcareInvalidXPath('Error querying cases with xpath %s: %s' %
                                    (filter_expr, str(e)))


def query_case_ids(q, criteria=None):
    criteria = copy(criteria) or {}  # don't modify the passed in dict
    criteria["ids_only"] = 'true'
    query_url = '%s?%s' % (settings.CASE_API_URL, urllib.urlencode(criteria))
    return [id for id in q(query_url)]


def query_cases(q, criteria=None):