def __init__(self, fastInit=0, queryCfgSource = None): """initialize static variables""" self.mVars = {} # variables usable for mapping self.__mQueryGroups = {} self.__mQueryGroupHandlers = {} self.__fastInit=0 # get static database handle if not already initialized by other instance of Drug object if Drug._db is None: try: Drug._db = gmPG.ConnectionPool() except: exc = sys.exc_info() _log.LogException("Failed to initialize ConnectionPool handle.", exc, fatal=1) # reraise the exception here raise # get queries from configuration source (currently only files are supported) if queryCfgSource is None: _log.Log(gmLog.lWarn, "No query configuration source specified") # we want to return an error here # in that case we'll have to raise an exception... can't return # anything else than None from an __init__ method raise TypeError, "No query configuration source specified" else: self.__mQueryCfgSource = queryCfgSource if not self.__getQueries(): raise IOError, "cannot load queries" # try to fetch all data at once if fastInit is true self.__fastInit = fastInit if fastInit: self.getAllData()
def __init__(self, dbbroker=None): if dbbroker is None: dbbroker = gmPG.ConnectionPool() self._dbbroker = dbbroker # a gmPG database broker object self._dirty = 0 # true if the data has been modified self._loaded = 0 # true if the panel has been filled with data loaded from the backend self._data = { } # a dictionary containing the data displayed in this panel;
def __init__(self, parent, doctor=None): wxPanel.__init__(self, parent, -1) self.dbpool = gmPG.ConnectionPool() self.db = self.dbpool.GetConnection('appointments') cur = self.db.cursor() cur.execute(doctorquery) self.doctors = gmPG.dictResult(cur) #print self.doctors self.doctor = doctor self.doctorindex = {} #to look up a doctor's id depending on the index in the combo box #as combo box Set/Get client data seems buggy self.szrMain = wxBoxSizer(wxVERTICAL) self.szrTopRow = wxBoxSizer(wxHORIZONTAL) session_interval = 15 self.schedule = gmScheduleGrid.ScheduleGrid( self, session_interval=session_interval) self.szrButtons = wxBoxSizer(wxHORIZONTAL) self.szrMain.AddSizer(self.szrTopRow, 0, wxGROW | wxALIGN_TOP | wxLEFT | wxRIGHT, 5) self.szrMain.AddWindow(self.schedule, 1, wxGROW | wxALIGN_CENTER_VERTICAL, 3) self.szrMain.AddSizer(self.szrButtons, 0, wxALIGN_TOP | wxLEFT | wxRIGHT, 1) txt = wxStaticText(self, -1, _("with:"), wxDefaultPosition, wxDefaultSize, 0) self.szrTopRow.AddWindow(txt, 0, wxALIGN_CENTER_VERTICAL, 5) self.cbStaffSelection = wxComboBox(self, ID_COMBO_STAFF, "", wxDefaultPosition, wxSize(70, -1), [], wxCB_DROPDOWN) EVT_COMBOBOX(self, ID_COMBO_STAFF, self.OnStaffSelected) self.szrTopRow.AddWindow(self.cbStaffSelection, 1, wxGROW | wxALIGN_CENTER_VERTICAL, 5) self.FillComboStaff(self.doctors) if self.doctor is not None: #print "Setting Doctor", self.doctor self.SetDoctor(self.doctor) #print "Blocking days for ", self.doctor self.BlockDays(self.doctor) self.SetSizer(self.szrMain) self.SetAutoLayout(true) self.szrMain.Fit(self) self.szrMain.SetSizeHints(self) self.schedule.GoToDateTime()
def __init__(self, db=None): #reference our class hierarchy level "singleton" cache self.cache = CachedPerson.__dbcache #make sure we allocte the default database connection #in case no connection has been passed as parameter if db is None and self.cache.db is None: conn = gmPG.ConnectionPool() self.cache.db = conn.GetConnection('demographica') gmDBCache.CachedDBObject.__init__( self, self.cache, id=-1, db=db, querystr="select * from v_active_persons where id = %d")
c.execute('COMMIT') def process_record(rec, db): """process one MDW demographic record by inserting it's field values into the gnumed database""" person_id = import_person(rec, db) addr_id = import_address(rec, db) link_person_address(person_id, addr_id, db) # open the dBase based demographic MDW file db = gmdbf.dbf('PATIENTS.DBF'); #request the appropriate service from the gnumed database broker pgpool = gmPG.ConnectionPool() pdb = pgpool.GetConnection('personalia') #loop through all records in the demographic MDW file i=0 for n in xrange(db.nrecs): print i process_record(db.dictresult(n), pdb) i+=1 #=============================================================== # $Log: gmMDWImporter.py,v $ # Revision 1.1 2004-07-06 13:44:15 ncq # - moved here from main tree # # Revision 1.1 2004/04/13 14:24:08 ncq # - first version here
self._save() #--------------------------------------------- def undo(self): """reset the state ofthe row to the state it has on the backend""" if self._fetched: self._fetch() else: print "Undo for new objects not impemented yet" #============================================================== if __name__ == "__main__": import sys, gmPG, gmLoginInfo login = gmLoginInfo.LoginInfo(user="******", passwd='') db = gmPG.ConnectionPool(login) db.SetFetchReturnsList(1) #request a writeable connection and create test tables con = db.GetConnection('default', readonly = 0) cursor = con.cursor() try: cursor.execute("drop sequence test_pgo_id_seq;") con.commit() cursor.execute("drop table test_pgo;"); con.commit() except: pass try:
for x in queries: print x cursor.execute(x) def update_person(self, personMap, db): queries = [] queries.append( """update v_active_persons set title='%(title)s', lastnames='%(lastnames)s', firstnames='%(firstnames)s', gender= '%(gender)s', dob='%(dob)s' where id=%(id)d""" % personMap) cursor = db.cursor() for x in queries: print x cursor.execute(x) self.reset() self.notify() if __name__ == "__main__": import gmPG conn = gmPG.ConnectionPool() db = conn.GetConnection('demographica') p = CachedPerson(db) (data, ) = p.get(id=1) for a in data: print a print p.dictresult()
def __init__(self, parent, doctor_id=None, hour_start=9, hour_end=18, session_interval=15, exclude=None, date=None, days=7, log=sys.stdout): wxGrid.__init__(self, parent, -1, style=wxWANTS_CHARS | wxSIMPLE_BORDER) ##wxGridAutoEditMixin.__init__(self) pool = gmPG.ConnectionPool() self.db = pool.GetConnection('personalia') self.doctor_id = doctor_id self.log = log self.days = days self.hour_start = hour_start self.hour_end = hour_end self.session_interval = session_interval self.exclude = exclude self.moveTo = None self.idx_date2column = {} self.idx_column2date = {} self.idx_column2weekday = {} self.idx_time2row = {} self.idx_row2time = {} #list of day-of-week indices, starting with Monday=0 self.blocked_days = [] #list of tuples: (day (Y-m-d),time_from (H:M), time_to (H:M)); if day=None, then blocked on all days self.blocked_time = [] if date is None: self.Date = time.localtime() else: self.Date = date self.clr_appointed = wxColour(240, 220, 140) self.clr_blocked = wxLIGHT_GREY self.clr_today = wxColour(255, 255, 125) self.clr_selected_day = wxColour(190, 225, 255) self.clr_weekend = wxColour(240, 210, 210) self.MakeGrid() self.GoToDateTime() #EVT_IDLE(self, self.OnIdle) # test all the events EVT_CHAR(self.GetGridWindow(), self.OnChar) #EVT_GRID_CELL_LEFT_CLICK(self, self.OnCellLeftClick) EVT_GRID_CELL_RIGHT_CLICK(self, self.OnCellRightClick) #EVT_GRID_CELL_LEFT_DCLICK(self, self.OnCellLeftDClick) #EVT_GRID_CELL_RIGHT_DCLICK(self, self.OnCellRightDClick) #EVT_GRID_LABEL_LEFT_CLICK(self, self.OnLabelLeftClick) #EVT_GRID_LABEL_RIGHT_CLICK(self, self.OnLabelRightClick) #EVT_GRID_LABEL_LEFT_DCLICK(self, self.OnLabelLeftDClick) #EVT_GRID_LABEL_RIGHT_DCLICK(self, self.OnLabelRightDClick) #EVT_GRID_ROW_SIZE(self, self.OnRowSize) #EVT_GRID_COL_SIZE(self, self.OnColSize) #EVT_GRID_RANGE_SELECT(self, self.OnRangeSelect) EVT_GRID_CELL_CHANGE(self, self.OnCellChange) #EVT_GRID_SELECT_CELL(self, self.OnSelectCell) #EVT_GRID_EDITOR_SHOWN(self, self.OnEditorShown) #EVT_GRID_EDITOR_HIDDEN(self, self.OnEditorHidden) #EVT_GRID_EDITOR_CREATED(self, self.OnEditorCreated) EVT_KEY_DOWN(self, self.OnKeyDown)
def getDB(self): backend = gmPG.ConnectionPool() db = backend.GetConnection('personalia') return db