Exemplo n.º 1
0
    def test_close(self):
        user = User.objects(username='******').first()
        self.controller.user = user
        query = dict()
        report = Report.objects().first()
        query['id'] = str(report.id)
        query['user'] = '******'
        message = self.controller.close(**query)

        report = Report.objects(id=report.id).first()

        assert report.status_name == 'closed'
        assert message.header.code == 500
        assert len(report.action_list) == 2
        assert report.action_list[-1].action == 'close'
Exemplo n.º 2
0
    def delete(self, **query):

        # Cancellare il report
        report = Report.objects(**query)
        #report = db_wrapper.query('report', **query)

        if report.count() == 0:
            message = Message(
                ReportErrorHeader(message="No Reports in database"),
                data=report)
            return message

        report = report.first()

        e_controller = ExaminationController(user=self.user)
        for ex_ in report.id_examination:
            if ex_.status_name != 'closed':
                _ = e_controller.eject(id=str(ex_.id))
            else:
                message = Message(
                    ReportErrorHeader(message='Cannot delete the report'))
                return message

        try:
            report.delete()
        except Exception, err:
            message = Message(ReportErrorHeader(message="Error in deleting"),
                              data=report)
            return message
Exemplo n.º 3
0
    def _get_report(self, id_report):
        """Deprecated: to be subsituted with a function in a superclass"""
        report = Report.objects(id=str(id_report))

        if report == None:
            message = 'No report with this id'
            Message(ReportErrorHeader(message=message), data=None)
            logger.error(message)
            return message

        self._currentReport = report.first()
        return report
Exemplo n.º 4
0
    def update(self, **query):

        query['user'] = self.user

        if 'id_examination' in query.keys():
            _ = query.pop('id_examination')

        query = self._check_fields(query)

        if isinstance(query, Message):
            return query

        logger.debug(query)

        action = query.pop('action')
        user = query.pop('user')
        id_report = query.pop('id')

        report = self._get_report(id_report).first()

        if isinstance(report, Message):
            return report

        if report.status_name == 'closed':
            message = "The report is closed"
            return Message(ReportErrorHeader(message=message), data=None)

        if not report.modify(**query):
            message = Message(ReportErrorHeader(message='Error in modifying'))
            logger.error(message.header.message)
            return message

        message = self._update_log(user, action, report)

        if message != None:
            return message

        # Porto gli esami a closed
        e_controller = ExaminationController(user=self.user)
        for ex_ in report.id_examination:
            if ex_.status_name == 'closed':
                break
            _ = e_controller.close(id=str(ex_.id))

        self._currentReport = report
        report = Report.objects(id=str(id_report))
        #report = db_wrapper.query('report', **query)
        message = "Report correctly updated"
        message = Message(ReportCorrectHeader(message=message), data=report)

        return message
Exemplo n.º 5
0
    def read(self, **query):

        if query != {}:
            logger.debug(query)

        report = Report.objects(**query)
        #report = db_wrapper.query('report', **query)

        if report.count() == 0:
            message = Message(
                ReportErrorHeader(message="No Reports in database"),
                data=report)
            return message

        message = Message(ReportCorrectHeader(message="Reports loaded"),
                          data=report)
        return message
Exemplo n.º 6
0
    def create(self, **query):

        query['user'] = self.user

        logger.debug(query)

        query = self._check_fields(query)

        if isinstance(query, Message):
            logger.debug("I'm a message!")
            return query

        query['action_list'] = [self._create_action(query)]

        if isinstance(query['action_list'], Message):
            return query['action_list']

        query['id_patient'] = query['id_examination'][0].id_patient.id_patient

        logger.debug(query)

        report = Report(**query)
        # report = db_wrapper.insert('report', **query)
        try:
            report.save()
        except (FieldDoesNotExist, NotUniqueError, SaveConditionError) as err:

            txt_message = "Report cannot be saved: %s " % (err.message)
            logger.error(txt_message)
            message = Message(ReportErrorHeader(message=txt_message))
            return message

        # Porto gli esami a reported
        e_controller = ExaminationController(user=self.user)
        for ex_ in report.id_examination:
            _ = e_controller.eject(id=str(ex_.id))

        self._currentReport = report

        message = "Report correctly created"
        report = Report.objects(id=report.id)
        # query = {'id':report.id}
        # report = db_wrapper.query('report', **query)
        message = Message(ReportCorrectHeader(message=message), data=report)

        return message