def run(database_config, n_loaded=50): db_config = parse_db_config(database_config) _ = easyris_connect(**db_config) #client = connect(database, port=port) Examination.drop_collection() priority_list = Priority.objects() typology_list = Typology.objects() patient_list = Patient.objects() user1 = User.objects(username='******').first() user2 = User.objects(username='******').first() for _ in range(n_loaded): ip = random.randint(0, len(patient_list) - 1) it = random.randint(0, len(typology_list) - 1) ipr = random.randint(0, len(priority_list) - 1) patient = patient_list[ip] typology = typology_list[it] priority = priority_list[ipr] random_number = random.randint(1, 10) if random_number > 5: now = datetime.now() date_ = datetime(year=now.year, month=now.month, day=now.day) if random_number == 8: status_name = 'completed' status = CompletedExaminationStatus() else: status_name = 'new' status = NewExaminationStatus() else: date_ = datetime(year=2016, month=02, day=02) status_name = 'completed' status = CompletedExaminationStatus() examination = Examination(id_patient=patient, medico_richiedente='Mauro Caffarini', data_inserimento=date_, id_priority=priority, id_typology=typology, id_technician=user2, id_creator=user1, status_name=status_name, status=status, codice_esenzione='67577568', examination_note='ok') examination.save()
def test_model(self): print "---- Testing Examination ----" patient1 = Patient.objects(first_name="Tecla").first() user1 = User.objects(username='******').first() user2 = User.objects(username='******').first() typology = Typology.objects(modality='MR').first() priority = Priority.objects(priority_name='ALTA').first() examination = Examination(id_patient=patient1, medico_richiedente='Pinco Pallo', data_inserimento=datetime(year=2016, day=02, month=02), id_priority=priority, id_typology=typology, id_creator=user1, id_technician=user2, accession_number='12345665', codice_esenzione='67577568', examination_note='ok') print '----------------------' examination.save() assert examination.status.name == 'new' print '------ Object saved -----------' examination.status.start(examination) assert examination.status_name == 'scheduled' examination.status.go(examination) examination.status.pause(examination) assert examination.status_name == 'incomplete' examination.status.start(examination) examination.status.go(examination) assert examination.status_name == 'running' examination.status.eject(examination) examination.status.stop(examination) assert examination.status_name == 'rescheduled' examination.status.start(examination) assert examination.status_name == 'rescheduled' examination.status.go(examination) examination.status.finish(examination) assert examination.status_name == 'completed' examination.status.eject(examination) assert examination.status_name == 'reported'
def test_accession_number(self): print "---- Testing Examination ----" patient1 = Patient.objects(first_name="Tecla").first() user1 = User.objects(username='******').first() user2 = User.objects(username='******').first() typology_qs = Typology.objects(room='RM1.5T', distretto_corporeo='TESTA/COLLO') typology1 = typology_qs[0] typology2 = typology_qs[1] assert typology1.examination_name != typology2.examination_name priority = Priority.objects(priority_name='ALTA').first() examination1 = Examination( id_patient=patient1, medico_richiedente='Pinco Pallo', data_inserimento=datetime(year=2016, day=05, month=02), id_priority=priority, id_typology=typology1, id_creator=user1, id_technician=user2, #accession_number='12345665', codice_esenzione='67577568', examination_note='ok') examination2 = Examination( id_patient=patient1, medico_richiedente='Pinco Pallo', data_inserimento=datetime(year=2016, day=05, month=02), id_priority=priority, id_typology=typology2, id_creator=user1, id_technician=user2, #accession_number='12345665', codice_esenzione='67577568', examination_note='ok') examination1.save() examination2.save() assert examination1.accession_number == examination2.accession_number examination3 = Examination( id_patient=patient1, medico_richiedente='Pinco Pallo', data_inserimento=datetime(year=2016, day=05, month=03), id_priority=priority, id_typology=typology2, id_creator=user1, id_technician=user2, #accession_number='12345665', codice_esenzione='67577568', examination_note='ok') examination3.save() assert examination2.accession_number != examination3.accession_number return
def create(self, **query): pt_controller = PatientController() pt_message = pt_controller.read(id_patient=query['id_patient']) if pt_message.header.code == 101: return pt_message query['id_patient'] = pt_message.data[0] logger.debug(pt_message.data[0].first_name) if 'data_inserimento' in query.keys(): query['data_inserimento'] = parse_date(query['data_inserimento']) logger.debug(query['data_inserimento']) query['id_creator'] = User.objects(username=query['id_creator']).first() list_examination = query.pop('exams') if len(list_examination) == 0: message = Message(ExaminationErrorHeader(message='No Examination in Request')) logger.error(message.header.message) return message examination = None for i, exam_ in enumerate(list_examination): typology = Typology.objects(examination_name=exam_['nome']).first() priority = Priority.objects(priority_name=exam_['priority']).first() query = self._check_fields(query, id_priority=priority, id_typology=typology, ) if not isinstance(query, dict): # It is a message! return query qs = Examination.objects(**query) logger.debug(query) logger.debug("No. of examinations: "+str(len(qs))) if len(qs) != 0: continue examination = Examination(**query) pacs_data = _build_pacs_data(examination) send_to_pacs.apply_async(link_error=pacs_error_handler.s(), kwargs={'data':pacs_data}, ) #send_to_pacs(pacs_data) try: examination.save() except (FieldDoesNotExist, NotUniqueError, SaveConditionError) as err: txt_message = "On %s examination: %s" % (str(i+1), err.message) logger.error(txt_message) message = Message(ExaminationErrorHeader(message=txt_message)) return message logger.debug("Examination created: "+str(examination.data_inserimento)) examination = self._get_examination(examination.id) examination.status = NewExaminationStatus(examination) if examination == None: message = "Examination already stored" examination = qs else: message = 'Examination created correctly' message = Message(ExaminationCorrectHeader(message=message), data=examination) self._currentExamination = examination return message