Ejemplo n.º 1
0
    def read(self, request, *pargs, **kwargs):
        format = request.form.format
        query = request.dispatch_data
        # OpenMRS REST module specific
        if not query['identifier']:
            path = dispatch_reverse(_namespace,
                                    'subject',
                                    suffix='name',
                                    format=format)
            path += '{0}+{1}'.format(query.get('name.givenName', ''),
                                     query.get('name.familyName', ''))
        else:
            path = dispatch_reverse(_namespace,
                                    Dispatchable.SUBJECT,
                                    format=format)
            path += query['identifier']

        # auth for openmrs REST module
        if not _opener.has_rest_auth(request, path, *pargs, **kwargs):
            return FAIL(u'Authorization Failure')

        # have to make sure we decode/encode returned data correctly
        #TODO is there a better way to handle this?
        response = _opener.get(path=path).data['dispatch']
        if format == 'json':
            return SUCCESS(cjson.decode(response, True))
        elif format == 'xml':
            return SUCCESS(parse_patient_xml(response))
Ejemplo n.º 2
0
 def create(self, request, *pargs, **kwargs):
     path = dispatch_reverse(_namespace, Dispatchable.CLIENT, method='create')
     # execute upstream request
     result = _opener.open(path=path,
                           data=request.dispatch_form.dispatch_data)
     
     if re.search(_login_re, result.data['dispatch']):
         return SUCCESS( u'logged in to OpenMRS')
     else:
         return FAIL(u'could not log in to OpenMRS')
Ejemplo n.º 3
0
 def create(self, request, **kwargs):
     ''' Posts an encounter to the Sana queue in OpenMRS '''
     debug_api_request(self,'create', request)
     # Do an auth check first
     u = request.dispatch_form.data.get('username', None)
     p = request.dispatch_form.data.get('password', None)
     auth = { 'username': u, 'password':p} if u and p else None
     
     #TODO do a permissions servlet check??? --> would go to status create?
     path = dispatch_reverse(_namespace, Dispatchable.CLIENT)
     auth_form = ClientForm(data=auth)
     login = _opener.open(path, data=auth_form.dispatch_data)
     if login.status != Status.SUCCESS:
         return login
     
     # Execute post
     path = dispatch_reverse(_namespace, Dispatchable.ENCOUNTER, method='create')
     response = _opener.open(path=path,data=request.dispatch_data)
     return APIResponse(response.status, response.data) 
Ejemplo n.º 4
0
 def create(self, request, *pargs, **kwargs):
     ''' Post patient data '''
     debug_api_request(self,'create', request)
     data = request.dispatch_data
     u = data.get('username',None)
     p = data.get('password',None)
     auth = { 'username': u, 'password':p} if u and p else None
     
     # do a permissions servlet check??? --> should go to client create
     path = dispatch_reverse(_namespace, Dispatchable.CLIENT, method='create')
     login = _opener.open(path, data=auth)
     if login.status != Status.SUCCESS:
         return login
     
     # Execute patient post
     path = dispatch_reverse(_namespace, Dispatchable.SUBJECT, method='create')
     response = _opener.open(path=path,data=request.form.dispatch_data)
     debug_api_response(self,'create', response)
     return response
Ejemplo n.º 5
0
    def create(self, request, **kwargs):
        ''' Posts an encounter to the Sana queue in OpenMRS '''
        debug_api_request(self, 'create', request)
        # Do an auth check first
        u = request.dispatch_form.data.get('username', None)
        p = request.dispatch_form.data.get('password', None)
        auth = {'username': u, 'password': p} if u and p else None

        #TODO do a permissions servlet check??? --> would go to status create?
        path = dispatch_reverse(_namespace, Dispatchable.CLIENT)
        auth_form = ClientForm(data=auth)
        login = _opener.open(path, data=auth_form.dispatch_data)
        if login.status != Status.SUCCESS:
            return login

        # Execute post
        path = dispatch_reverse(_namespace,
                                Dispatchable.ENCOUNTER,
                                method='create')
        response = _opener.open(path=path, data=request.dispatch_data)
        return APIResponse(response.status, response.data)
Ejemplo n.º 6
0
    def create(self, request, *pargs, **kwargs):
        path = dispatch_reverse(_namespace,
                                Dispatchable.CLIENT,
                                method='create')
        # execute upstream request
        result = _opener.open(path=path,
                              data=request.dispatch_form.dispatch_data)

        if re.search(_login_re, result.data['dispatch']):
            return SUCCESS(u'logged in to OpenMRS')
        else:
            return FAIL(u'could not log in to OpenMRS')
Ejemplo n.º 7
0
    def has_rest_auth(self,request, path, *pargs, **kwargs):
        ''' Handles the rest authorization. Should only be called within a CRUD 
            method with request having a "form" attribute '''
        u = request.dispatch_form.args.get('username', None)
        pw = request.dispatch_form.args.get('password', None)
        auth = { "username": u, "password" : pw } if u and pw else None
        result = False
        
        # Have to be logged in and then post username and password to REST url
        client_form = ClientForm(initial=auth)
        client_path = dispatch_reverse(_namespace, Dispatchable.CLIENT, method='create')
        login = _opener.open(path=client_path,data=client_form.dispatch_data)

        #TODO From older code.  Why do we need this???
        status_path = dispatch_reverse(_namespace, 'status', method='create')
        rest = _opener.open(path=status_path,data=auth)
        
        if login.status == Status.SUCCESS:
            r = _opener.open(path, auth=auth)
            result = True if r.status == Status.SUCCESS else False
        return result
Ejemplo n.º 8
0
    def has_rest_auth(self, request, path, *pargs, **kwargs):
        ''' Handles the rest authorization. Should only be called within a CRUD 
            method with request having a "form" attribute '''
        u = request.dispatch_form.args.get('username', None)
        pw = request.dispatch_form.args.get('password', None)
        auth = {"username": u, "password": pw} if u and pw else None
        result = False

        # Have to be logged in and then post username and password to REST url
        client_form = ClientForm(initial=auth)
        client_path = dispatch_reverse(_namespace,
                                       Dispatchable.CLIENT,
                                       method='create')
        login = _opener.open(path=client_path, data=client_form.dispatch_data)

        #TODO From older code.  Why do we need this???
        status_path = dispatch_reverse(_namespace, 'status', method='create')
        rest = _opener.open(path=status_path, data=auth)

        if login.status == Status.SUCCESS:
            r = _opener.open(path, auth=auth)
            result = True if r.status == Status.SUCCESS else False
        return result
Ejemplo n.º 9
0
    def create(self, request, *pargs, **kwargs):
        ''' Post patient data '''
        debug_api_request(self, 'create', request)
        data = request.dispatch_data
        u = data.get('username', None)
        p = data.get('password', None)
        auth = {'username': u, 'password': p} if u and p else None

        # do a permissions servlet check??? --> should go to client create
        path = dispatch_reverse(_namespace,
                                Dispatchable.CLIENT,
                                method='create')
        login = _opener.open(path, data=auth)
        if login.status != Status.SUCCESS:
            return login

        # Execute patient post
        path = dispatch_reverse(_namespace,
                                Dispatchable.SUBJECT,
                                method='create')
        response = _opener.open(path=path, data=request.form.dispatch_data)
        debug_api_response(self, 'create', response)
        return response
Ejemplo n.º 10
0
 def read(self, request, *pargs, **kwargs):
     format = request.form.format
     query = request.dispatch_data
     # OpenMRS REST module specific
     if not query['identifier']:
         path = dispatch_reverse(_namespace, 'subject', suffix='name', 
                                 format=format)
         path += '{0}+{1}'.format(query.get('name.givenName',''),
                                  query.get('name.familyName',''))
     else:
         path = dispatch_reverse(_namespace, Dispatchable.SUBJECT, format=format)
         path += query['identifier']
         
     # auth for openmrs REST module
     if not _opener.has_rest_auth(request, path, *pargs, **kwargs):
         return FAIL(u'Authorization Failure')
     
     # have to make sure we decode/encode returned data correctly
     #TODO is there a better way to handle this?
     response = _opener.get(path=path).data['dispatch']
     if format == 'json':
         return SUCCESS(cjson.decode(response,True))
     elif format == 'xml':
         return SUCCESS(parse_patient_xml(response))
Ejemplo n.º 11
0
 def read(self, request, *pargs, **kwargs):
     debug_api_request(self, 'read', request)
     path = dispatch_reverse(_namespace, Dispatchable.STATUS)
     return _opener.get(path=path, data=request.form.dispatch_data)
Ejemplo n.º 12
0
 def create(self, request, *pargs, **kwargs):
     debug_api_request(self, 'create', request)
     path = dispatch_reverse(_namespace,
                             Dispatchable.STATUS,
                             method='create')
     return _opener.open(path=path, data=request.form.dispatch_data)
Ejemplo n.º 13
0
 def read(self, request, *pargs, **kwargs):
     debug_api_request(self,'read', request)
     path = dispatch_reverse(_namespace, Dispatchable.STATUS)
     return _opener.get(path=path,data=request.form.dispatch_data)
Ejemplo n.º 14
0
 def create(self, request, *pargs, **kwargs):
     debug_api_request(self,'create', request)
     path = dispatch_reverse(_namespace, Dispatchable.STATUS, method='create')
     return _opener.open(path=path,data=request.form.dispatch_data)