Ejemplo n.º 1
0
def create_app(config_filename="config/easyris.cfg",
               database_cfg="config/database.cfg",
               **kwargs):

    app = EasyRis(__name__)
    app.config.from_pyfile(config_filename)

    kwargs = {k.upper(): v for k, v in kwargs.iteritems()}
    app.config.update(**kwargs)

    from datetime import timedelta
    app.config['PERMANENT_SESSION_LIFETIME'] = timedelta(
        hours=int(app.config['PERMANENT_SESSION_LIFETIME']))

    # This is to prevent bad url in frontend
    app.url_map.strict_slashes = False

    # Add basic apis
    app.add_url_rule('/', 'entry', entry)
    app.add_url_rule('/debug', 'debug', debug)

    from easyris.utils.api import cities
    from easyris.patient.api import patient
    from easyris.user.api import login_
    from easyris.examination.api.typology import typology
    from easyris.report.api import report
    from easyris.examination.api.base import examination
    from easyris.log.api import event

    # Register blueprint from other modules
    app.register_blueprint(patient, url_prefix='/patient')
    app.register_blueprint(cities, url_prefix='/cities')
    app.register_blueprint(typology, url_prefix='/typology')
    app.register_blueprint(examination, url_prefix='/examination')
    app.register_blueprint(login_, url_prefix='')
    app.register_blueprint(report, url_prefix="/report")
    app.register_blueprint(event, url_prefix="/event")

    from flask_debugtoolbar import DebugToolbarExtension
    app.toolbar = DebugToolbarExtension(app)

    app.login_manager = LoginManager()
    app.login_manager.init_app(app)

    app.before_request(before_request)

    def load_user(userid):
        # Return an instance of the User model
        return app.get_user(userid)

    app.login_manager.user_loader(load_user)

    # Database connection
    from easyris.base.database import parse_db_config, easyris_connect
    db_config = parse_db_config(database_cfg)
    db_client = easyris_connect(**db_config)
    app.config['DB_CLIENT'] = db_client

    return app
Ejemplo n.º 2
0
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()
Ejemplo n.º 3
0
 def setUp(self, n_loaded=5, **kwargs):
     # TODO: Check overriding in other classes
     from easyris.base.database import parse_db_config, \
                                         restore_db,\
                                         easyris_connect
     db_filename = "config/database_test.cfg"
     db_config = parse_db_config(db_filename)
     conn = easyris_connect(**db_config)
     self.client = conn      
       
     restore_db(db_filename)
Ejemplo n.º 4
0
def run(database_config="config/database.cfg", **kwargs):

    from easyris.base.database import parse_db_config, easyris_connect
    db_config = parse_db_config(database_config)
    print db_config
    conn = easyris_connect(**db_config)
    db_name = db_config['database_name']

    # Always delete database
    if db_name in conn.database_names():
        print "Database found. Deleting it!"
        conn.drop_database(db_name)
    else:
        print "Database not found..."

    print " ---- Database population ---"
    path = os.path.dirname(os.path.realpath(__file__))
    # Import city
    import_csv(db_name, 'city', os.path.join(path,
                                             "files/codicicomuni2015.csv"))

    print "Import patient.csv"
    if 'n_loaded' in kwargs.keys():
        n_loaded = kwargs['n_loaded']
    else:
        n_loaded = 100

    if 'n_patient' in kwargs.keys():
        n_loaded = kwargs['n_patient']
    patient_db.run(database_config, n_loaded=n_loaded)

    # Import priority_db.csv
    import_csv(db_name, 'priority', os.path.join(path,
                                                 "files/priority_db.csv"))

    # Import nomenclatura_esami.csv
    import_csv(db_name, 'typology',
               os.path.join(path, "files/nomenclatura_esami.csv"))

    print "Populating users, permissions and roles."
    user_db.run(database_config)

    print "Creating dummy examinations."
    if 'n_examination' in kwargs.keys():
        n_loaded = kwargs['n_examination']
    examination_db.run(database_config, n_loaded=n_loaded * 2)

    print "Creating dummy reports."
    if 'n_report' in kwargs.keys():
        n_loaded = kwargs['n_report']
    report_db.run(database_config, n_loaded=n_loaded)

    return
Ejemplo n.º 5
0
def save_event(event_dict):

    from easyris.base.database import parse_db_config, easyris_connect

    db_config = parse_db_config("config/database.cfg")
    db_config['database_name'] = 'easyris_log'
    db_client = easyris_connect(**db_config)

    print event_dict

    event = Event(**event_dict)
    event.save()

    return "Event saved!"
Ejemplo n.º 6
0
def run(database_config, n_loaded=100):

    db_config = parse_db_config(database_config)
    print db_config
    conn = easyris_connect(**db_config)
    database = db_config['database_name']
    db = conn.get_database(database)
    print db

    if 'city' not in db.collection_names():
        # We imported the short version
        # We think that we are testing the app!
        from easyris.utils.database_setup import import_csv
        path = os.path.dirname(os.path.realpath(__file__))
        # Import city
        print os.path.join(path, "files/codicicomuni_test.csv")
        print '------------'
        print '------------'
        print '------------'
        import_csv(database, 'city',
                   os.path.join(path, "files/codicicomuni_test.csv"))

    path = '/'.join(__file__.split('/')[:-1])
    print path
    filepath = os.path.join(path, 'files/db_test_population.csv')
    with open(filepath, 'rb') as csvfile:
        patient_csv = csv.reader(csvfile, delimiter=',')
        for i, row in enumerate(patient_csv):
            if i == 0:
                keys_ = [str.lower(r_) for r_ in row]
            elif i < n_loaded:
                fields_ = dict(zip(keys_, row))
                fields_['birthplace'] = str.upper(fields_['birthplace'])
                fields_['city'] = str.upper(fields_['city'])
                fields_['birthdate'] = datetime.strptime(
                    fields_['birthdate'], "%Y-%m-%d")
                fields_['province'] = None

                patient_ = Patient(**fields_)
                #print fields_

                patient_.save()
Ejemplo n.º 7
0
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()
Ejemplo n.º 8
0
def run(database_config):

    from easyris.base.database import parse_db_config, easyris_connect

    db_config = parse_db_config(database_config)
    conn = easyris_connect(**db_config)

    actions = ['create', 'read', 'update', 'delete']

    actions_examination_status = [
        'start', 'go', 'stop', 'pause', 'finish', 'eject'
    ]
    actions_report_status = ['close', 'save', 'print', 'open']
    resources = [
        'patient', 'examination', 'report', 'examination_status',
        'report_status'
    ]

    permission_ = itertools.product(resources, actions)
    Permission.drop_collection()
    permission_list = []
    for it in permission_:
        p = Permission(it[1], it[0])
        p.save()
        permission_list.append(p)

    ex_status_permission = itertools.product(['examination'],
                                             actions_examination_status)
    for it in ex_status_permission:
        p = Permission(it[1], it[0])
        p.save()
        permission_list.append(p)

    report_status_permission = itertools.product(['report'],
                                                 actions_report_status)
    for it in report_status_permission:
        p = Permission(it[1], it[0])
        p.save()
        permission_list.append(p)

    permission_dict = {
        'accettazione':
        np.array([1, 2, 3, 5, 6, 13, 14, 18, 30]) - 1,
        'tecnico':
        np.array([2, 6, 7, 8, 14, 15, 16, 18, 21, 22, 23, 24, 25]) - 1,
        'medico':
        np.array([2, 6, 9, 10, 11, 14, 17, 18, 19, 26, 27, 28, 29, 30]) - 1,
        'amministrazione':
        np.array([2, 6, 10, 14, 18]) - 1,
        'admin':
        np.arange(30)
    }

    Role.drop_collection()
    for key_, value_ in permission_dict.iteritems():
        role_ = Role(key_, [permission_list[i] for i in value_])
        role_.save()

    User.drop_collection()
    role_medico = Role.objects(role_name='medico').first()

    user1 = User(username='******',
                 password='******',
                 roles=[role_medico],
                 first_name='Massimo',
                 last_name='Caulo',
                 telephone_number='3289876543',
                 mobile_number='3212345678',
                 email='*****@*****.**')
    user1.save()

    role_acc = Role.objects(role_name='accettazione').first()
    user2 = User(username='******',
                 password='******',
                 roles=[role_acc],
                 first_name='Gaetano',
                 last_name='Di Gaetano',
                 telephone_number='3289876543',
                 mobile_number='3212345678',
                 email='*****@*****.**')
    user2.save()

    role_tecnico = Role.objects(role_name='tecnico').first()
    user3 = User(username='******',
                 password='******',
                 roles=[role_tecnico],
                 first_name='Daniele',
                 last_name='Petrucci',
                 telephone_number='3289876543',
                 mobile_number='3212345678',
                 email='*****@*****.**')

    user3.save()

    role_amministrazione = Role.objects(role_name='amministrazione').first()
    user4 = User(username='******',
                 password='******',
                 roles=[role_amministrazione],
                 first_name='Carlo',
                 last_name='Michetti',
                 telephone_number='3289876543',
                 mobile_number='3212345678',
                 email='*****@*****.**')

    user4.save()

    role_admin = Role.objects(role_name='admin').first()
    user5 = User(username='******',
                 password='******',
                 roles=[role_admin],
                 first_name='Piero',
                 last_name='Chiacchiaretta',
                 telephone_number='3289876543',
                 mobile_number='3212345678',
                 email='*****@*****.**')

    user5.save()

    user11 = User(username='******',
                  password='******',
                  roles=[role_medico],
                  first_name='Valentina',
                  last_name='Panara',
                  telephone_number='3289876543',
                  mobile_number='3212345678',
                  email='*****@*****.**')
    user11.save()