Beispiel #1
0
def party_get_query(data, debug=True):
    """
    Queries the demographics/party/query endpoint
    to retrieve party information based on the data
    specified with two keys: 'maxHits' which should
    have an integer value specifying the maximum 
    number of party records to return and; 'parameters'
    which should be a string specified as
    'key1=value1&key2=value2...keyn=valuen'
    Query method is GET
    If the query is successful, response['meta']['href'] will
    contain a link to the query results on the OpenEHR server
    and response['action'] will be set to 'RETRIEVE'.
    response['parties'] will contain an array of dictionary
    party objects returned from the query
    """
    method = 'GET'
    url_values = urllib.parse.urlencode(data)
    headers = {'Content-Type': 'application/json'}

    url = service_url + 'demographics/party/query/?' + url_values
    if debug: print('Retrieving ', url)

    response = run_rest_query(url, method, False, headers)
    return response
Beispiel #2
0
def create_new_ehr(subject_id,
                   subject_namespace=default_namespace,
                   committer_name='OpenEHR-Py',
                   committer_id=1,
                   debug=True):
    """
    Queries the ehr endpoint on the OpenEHR server to
    create a new ehr record.
    Query method is POST and subject_id should be provided as a
    string object.
    Returns a dictionary response object. If the query is
    successful, response['meta']['href'] will contain
    a link to the ehr on the OpenEHR server
    and response['action'] will be set to 'RETRIEVE'.
    response['ehrId'] will contain the ehr_id for the subject
    """

    method = 'POST'
    data = {
        'subjectId': subject_id,
        'subjectNamespace': subject_namespace,
    }
    url_values = urllib.parse.urlencode(data)

    url = service_url + 'ehr?' + url_values

    if debug: print('Retrieving ' + url)

    response = run_rest_query(url, method)
    return response
Beispiel #3
0
def get_ehr_by_subject_id(subject_id,
                          subject_namespace=default_namespace,
                          debug=False):
    """
    Queries the ehr REST API endpoint on the OpenEHR server
    for a given subject id in the given subject namespace.
    Query method is GET. Subject id and subject namespace
    should be provided as string objects
    Returns a dictionary response object. If the query is
    successful, response['meta']['href'] will contain
    a link to the ehr on the OpenEHR server
    and response['action'] will be set to 'RETRIEVE'.
    response['ehrId'] will contain the ehr_id for the subject
    and response['ehrStatus'] will contain the remainder of 
    the ehr record
    """
    data = {
        'subjectId': subject_id,
        'subjectNamespace': subject_namespace,
    }
    url_values = urllib.parse.urlencode(data)

    url = service_url + 'ehr?' + url_values

    if debug: print('Retrieving ' + url)

    response = run_rest_query(url)
    return response
Beispiel #4
0
def party_post_query(data, limit=10, debug=True):
    """
    Queries the demographics/party/query endpoint
    to retrieve party information based on the filters
    provided. Query method is POST and the query is provided
    in the first parameter as an array of dictionary items
    containing two keys: 'key' and 'value'.
    For example: [ {"key" : "lastNames",
    "value" : "Wilson" },...]. 'limit' is specified as an
    integer value to limit the number of results returned:
    set this value to '0' if no limit is required.
    If the query is successful, response['meta']['href'] will
    contain a link to the query results on the OpenEHR server
    and response['action'] will be set to 'RETRIEVE'.
    response['parties'] will contain an array of dictionary
    party objects returned from the query
    """
    method = 'POST'
    headers = {'Content-Type': 'application/json'}
    url = service_url + 'demographics/party/query'

    if limit:
        limit = {"maxHits": limit}
        url_values = urllib.parse.urlencode(limit)
        url = url + '?' + url_values
    if debug: print('Retrieving ', url)

    response = run_rest_query(url, method, data, headers)
    return response
Beispiel #5
0
def delete_demographic_party(party_id, debug=True):
    """
    Queries the demographics/party/{partyId} endpoint
    to delete the specified demographic party record.
    Query method is DELETE and party id should be specified
    as an integer value
    If the query is successful, response['action'] will
    be set to 'RETRIEVE'.
    """
    method = 'DELETE'
    url = service_url + 'demographics/party/' + party_id
    if debug: print('Retrieving ', url)
    response = run_rest_query(url, method)
    return response
Beispiel #6
0
def get_party_info(ehrid, debug=False):
    """
    Queries the demographics/ehr/{ehrid}/party endpoint
    to retrieve party information for the specified ehrid.
    Query method is GET and erhid should be specified as
    a string value.
    If the query is successful, response['meta']['href'] will
    contain a link to the party information on the OpenEHR server
    and response['action'] will be set to 'RETRIEVE'.
    response['party'] will contain the party information in
    a dictionary object
    """
    url = service_url + 'demographics/ehr/' + ehrid + '/party'
    if debug: print('Retrieving ', url)

    response = run_rest_query(url)
    return response
Beispiel #7
0
def add_party_info(party_data, debug=True):
    """
    Queries the demographics/party REST API endpoint
    on the OpenEHR server to add new party information.
    Query method is POST and party data should be provided
    as a dictionary object
    Returns a dictionary response object. If the query is 
    successful, response['meta']['href'] will contain
    a link to the party information on the OpenEHR server 
    and response['action'] will be set to 'CREATE'
    """
    method = 'POST'
    url = service_url + 'demographics/party'
    headers = {'Content-Type': 'application/json;charset=UTF-8'}

    response = run_rest_query(url, method, party_data, headers)
    return response
Beispiel #8
0
def get_ehr_by_id(ehrid, debug=False):
    """
    Queries the ehr/{ehrid} endpoint on the OpenEHR server
    for a given ehrid.
    Query method is GET and ehrid should be provided as a
    string object.
    Returns a dictionary response object. If the query is
    successful, response['meta']['href'] will contain
    a link to the ehr on the OpenEHR server
    and response['action'] will be set to 'RETRIEVE'.
    response['ehrId'] will contain the ehr_id for the subject
    and response['ehrStatus'] will contain the remainder of
    the ehr record
    """
    url = service_url + 'ehr/' + ehrid
    if debug: print('Retrieving ', url)

    response = run_rest_query(url)
    return response
Beispiel #9
0
def update_ehr_status(ehrid, ehr_status, debug=True):
    """
    Queries the ehr/{ehrId}/status endpoint on the OpenEHR
    server to update the ehr status for the given ehrid.
    Query method is PUT. ehrid should be provided as a
    string object and ehr_status as a dictionary object
    with the following keys: 'subjectId', 'subjectNamespace',
    'queryable', 'modifiable'.
    Returns a dictionary response object. If the query is
    successful, response['meta']['href'] will contain
    a link to the ehr on the OpenEHR server
    and response['action'] will be set to 'UPDATE'.
    """
    method = 'PUT'
    url = service_url + 'ehr/' + ehrid + '/status'
    headers = {'Content-Type': 'application/json;charset=UTF-8'}

    if debug: print('Retrieving ' + url)

    response = run_rest_query(url, method, ehr_status, headers)
    return response