def test_migrate_institution(self): engine = self._get_temp_db(2) t_db = TransactionDB(engine) last_message = { 'data': { 'dicom_info': { 't1': { 'header': { 'InstitutionName': 'MockInstitution' } } } } } tr_1 = Transaction() tr_1.last_message = json.dumps(last_message) t_id = t_db.create_transaction(tr_1) # remove institution field session = t_db.session tr_2 = t_db.get_transaction(t_id) tr_2.institution = '' session.commit() self.assertEqual('', t_db.get_transaction(t_id).institution) # execute migrate python script model = get_transaction_model(engine) migrations.migrate_institution(session, model) session.commit() tr_2 = t_db.get_transaction(t_id) self.assertEqual('MockInstitution', tr_2.institution) t_db.close()
def test_migrate_report_qa_2(self): engine = self._get_temp_db(5) t_db = TransactionDB(engine) last_message = { 'data': { 'report_qa_score_outcomes': { 'mdbrain_nd': 'good', 'mdbrain_ms': 'acceptable' } } } tr_1 = Transaction() tr_1.last_message = json.dumps(last_message) t_id = t_db.create_transaction(tr_1) tr_1 = t_db.get_transaction(t_id) # by default TransactionsDB doesn't set this field self.assertEqual(None, tr_1.qa_score) # execute migrate python script model = get_transaction_model(engine) migrations.migrate_qa_scores(t_db.session, model) t_db.session.commit() tr_2 = t_db.get_transaction(t_id) self.assertTrue('mdbrain_ms:acceptable' in tr_2.qa_score) self.assertTrue('mdbrain_nd:good' in tr_2.qa_score) t_db.close()
def test_migrate_analysis_type_2(self): engine = self._get_temp_db(5) t_db = TransactionDB(engine) last_message = { 'data': { 'report_pdf_paths': { 'mdbrain_nd': 'path1', 'mdbrain_ms': 'path2' } } } tr_1 = Transaction() tr_1.last_message = json.dumps(last_message) t_id = t_db.create_transaction(tr_1) tr_1 = t_db.get_transaction(t_id) # by default TransactionsDB doesn't set this field self.assertEqual(None, tr_1.analysis_type) # execute migrate python script model = get_transaction_model(engine) migrations.migrate_analysis_types(t_db.session, model) t_db.session.commit() tr_2 = t_db.get_transaction(t_id) self.assertTrue('mdbrain_ms' in tr_2.analysis_type) self.assertTrue('mdbrain_nd' in tr_2.analysis_type) t_db.close()
def test_migrate_study_date(self): engine = self._get_temp_db(4) t_db = TransactionDB(engine) last_message = { 'data': { 'dicom_info': { 't1': { 'header': { 'StudyDate': '20190101' } } } } } tr_1 = Transaction() tr_1.last_message = json.dumps(last_message) t_id = t_db.create_transaction(tr_1) tr_1 = t_db.get_transaction(t_id) # by default TransactionsDB doesn't set this field self.assertEqual(None, tr_1.study_date) # execute migrate python script model = get_transaction_model(engine) migrations.migrate_study_date(t_db.session, model) t_db.session.commit() tr_2 = t_db.get_transaction(t_id) self.assertEqual('20190101', tr_2.study_date) t_db.close()
def test_migrate_version(self): engine = self._get_temp_db(5) t_db = TransactionDB(engine) last_message = {'data': {'version': '2.2.1'}} tr_1 = Transaction() tr_1.last_message = json.dumps(last_message) t_id = t_db.create_transaction(tr_1) tr_1 = t_db.get_transaction(t_id) # by default TransactionsDB doesn't set this field self.assertEqual(None, tr_1.version) # execute migrate python script model = get_transaction_model(engine) migrations.migrate_version(t_db.session, model) t_db.session.commit() tr_2 = t_db.get_transaction(t_id) self.assertEqual('2.2.1', tr_2.version) t_db.close()
def test_migrate_sequences(self): engine = self._get_temp_db(3) t_db = TransactionDB(engine) last_message = { 'data': { 'dicom_info': { 't1': { 'header': { 'SeriesDescription': 'T1_sequence' } }, 't2': { 'header': { 'SeriesDescription': 'T2_sequence' } } } } } tr_1 = Transaction() tr_1.last_message = json.dumps(last_message) t_id = t_db.create_transaction(tr_1) # remove sequences field session = t_db.session tr_2 = t_db.get_transaction(t_id) tr_2.institution = '' session.commit() self.assertEqual('', t_db.get_transaction(t_id).institution) # execute migrate python script model = get_transaction_model(engine) migrations.migrate_sequences(session, model) session.commit() tr_2 = t_db.get_transaction(t_id) self.assertEqual('T1_sequence;T2_sequence', tr_2.sequences) t_db.close()