示例#1
0
    def recv_handler(self, msg, server, connection):
        msg = msg.decode('utf-8')
        logger.debug('RECV: %s', msg.replace(CR, '\n'))
        # Logic here - parse the message HL7
        # perform required validation
        # Send ack / error message that message received.
        # If enhanced mode, do the requisite steps to store then ack 
        try:
            msg = hl7.parse(msg)
        except:
            logger.exception('Error parsing message')
            if self.postmortem:
                pdb.post_mortem()
            resp = responses.hl7NAK('AE', 'UNABLE TO PARSE REQUEST')
            logger.debug('SEND: %s', unicode(resp).replace(CR, '\n'))
            server._write_frame(connection, unicode(resp).encode('utf-8'))
            return

        try:
            # DISPATCH MESSAGE HERE. Expect an acknowledgement response message - 
            resp = self.dispatcher.dispatch(msg)
            if resp is None:
                raise Exception('Application returned and invalid response (None) - response required')
            logger.debug('SEND: %s', unicode(resp).replace(CR, '\n'))
            server._write_frame(connection, unicode(resp).encode('utf-8'))
            return
        except:
            logger.exception('Error dispatching message')
            if self.postmortem:
                pdb.post_mortem()
            resp = responses.hl7NAK('AE', 'INTERNAL ERROR PROCESSING REQUEST')
            logger.debug('SEND: %s', unicode(resp).replace(CR, '\n'))
            server._write_frame(connection, unicode(resp).encode('utf-8'))
            return
示例#2
0
    def dispatch(self, request):
        path = '%s/%s/%s' % (unicode(request['MSH'][0][8]),
            request['MSH'][0][4], request['MSH'][0][5])
        for pattern in self.root:
            match = pattern.regex.search(path)
            if match:
                kwargs = match.groupdict()
                if kwargs:
                    args = ()
                else:
                    args = match.groups()
                # In both cases, pass any extra_kwargs as **kwargs.
                kwargs.update(pattern.kwargs)
                return pattern.callback(request, args, kwargs)

        return responses.hl7NAK('AE', 'No handler configured to handle request %s, app %s, facility %s' % 
            (unicode(request['MSH'][0][8]), request['MSH'][0][4], request['MSH'][0][5]))
    def dispatch(self, request):
        path = '%s/%s/%s' % (unicode(
            request['MSH'][0][8]), request['MSH'][0][4], request['MSH'][0][5])
        for pattern in self.root:
            match = pattern.regex.search(path)
            if match:
                kwargs = match.groupdict()
                if kwargs:
                    args = ()
                else:
                    args = match.groups()
                # In both cases, pass any extra_kwargs as **kwargs.
                kwargs.update(pattern.kwargs)
                return pattern.callback(request, args, kwargs)

        return responses.hl7NAK(
            'AE',
            'No handler configured to handle request %s, app %s, facility %s' %
            (unicode(request['MSH'][0][8]), request['MSH'][0][4],
             request['MSH'][0][5]))