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'
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
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
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
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
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
def run(database_config, n_loaded=50): db_config = parse_db_config(database_config) _ = easyris_connect(**db_config) Report.drop_collection() user = User.objects(username='******').first() examination_list = Examination.objects(status_name='completed', data_inserimento=datetime.datetime(year=2016, month=02, day=02)) # Trovo i pazienti con piu esami id_patient_list = [e.id_patient.id_patient for e in examination_list] counter = collections.Counter(id_patient_list) if len(counter) < n_loaded: n_loaded = len(counter) / 2 print n_loaded for i in range(n_loaded): id_patient = counter.keys()[i] patient = Patient.objects(id_patient=id_patient).first() patient_examination = Examination.objects(id_patient=patient.id, status_name='completed', data_inserimento=datetime.datetime(year=2016, month=02, day=02)) dates_ = np.unique([e.data_inserimento for e in patient_examination]) for d_ in dates_: data_ = datetime.datetime(d_.year, d_.month, d_.day) same_date_examination = Examination.objects(id_patient=patient.id, data_inserimento=data_, status_name='completed') report_log = ReportAction( user=user, action='create' ) report = Report( id_examination = [e for e in same_date_examination], report_text = "Il paziente bla bla bla", action_list = [report_log], id_patient = id_patient, status=SuspendedReportStatus(), status_name='suspended' ) report.save() for e in same_date_examination: e.modify(status=ClosedExaminationStatus(), status_name='closed') e.save()