Beispiel #1
0
    def post(self):
        try:
            data = json.loads(self.request.body.decode())
        except Exception as e:
            return self.answer(f'Could not upload json {e}', error=True)

        content = data.get('data', None)
        if content is None:
            return self.answer(f'No CSV content', error=True)

        sync = synchronizer.CSVSynchcronizer(self.db)
        sync_fns = {
            'user': sync.sync_users_from_csv,
            'icu': sync.sync_icus_from_csv
        }
        objtype = data.get('objtype', None)
        sync_fn = sync_fns.get(objtype, None)
        if sync_fn is None:
            return self.answer('Cannot find proper synchronization method.',
                               error=True)

        try:
            num_updates = sync_fn(io.StringIO(content), force_update=True)
            return self.answer(f'Updated {num_updates} {objtype}')
        except:
            return self.answer('Failing while syncing csv content', error=True)
Beispiel #2
0
def main(args=None):
    cfg = config.Config(FLAGS.config,
                        mode=FLAGS.mode,
                        env_path=FLAGS.dotenv_path)
    store_factory = db_store.create_store_factory_for_sqlite_db(cfg)
    store = store_factory.create()
    csv_synchronizer = synchronizer.CSVSynchcronizer(store)
    add_pre_icubam_bed_counts(FLAGS.pre_icubam_data_path, csv_synchronizer)
Beispiel #3
0
def main(args=None):
  cfg = config.Config(
    FLAGS.config, mode=FLAGS.mode, env_path=FLAGS.dotenv_path
  )
  store_factory = db_store.create_store_factory_for_sqlite_db(cfg)
  db = store_factory.create()

  csv = synchronizer.CSVSynchcronizer(db)

  out_buf = csv.export_icus()
  if FLAGS.output:
    with open(FLAGS.output, 'w') as f_out:
      f_out.write(out_buf)
  else:
    print(out_buf)
Beispiel #4
0
def main(args=None):
    cfg = config.Config(FLAGS.config,
                        mode=FLAGS.mode,
                        env_path=FLAGS.dotenv_path)
    store_factory = db_store.create_store_factory_for_sqlite_db(cfg)
    store = store_factory.create()
    csv = synchronizer.CSVSynchcronizer(store)

    if FLAGS.icus_csv:
        print(f"Loading ICU CSV from: {FLAGS.icus_csv}")
        with open(FLAGS.icus_csv) as icus_f:
            csv.sync_icus_from_csv(icus_f, FLAGS.force_update)

    if FLAGS.users_csv:
        print(f"Loading user CSV from: {FLAGS.users_csv}")
        with open(FLAGS.users_csv) as users_f:
            csv.sync_users_from_csv(users_f, FLAGS.force_update)
Beispiel #5
0
 def setUp(self):
   store_factory = store.StoreFactory(
     sqla.create_engine("sqlite:///:memory:", echo=True)
   )
   self.db = store_factory.create()
   self.csv = synchronizer.CSVSynchcronizer(self.db)