def _pre_exit_callback(self): """The client is about to (be) shut down. Shutdown will not proceed before this returns. """ if self.__pat is None: return True # if self.__encounter_modified(): # do_save_enc = gmGuiHelpers.gm_show_question ( # aMessage = _( # 'You have modified the details\n' # 'of the current encounter.\n' # '\n' # 'Do you want to save those changes ?' # ), # aTitle = _('Starting new encounter') # ) # if do_save_enc: # if not self.save_encounter(): # gmDispatcher.send(signal = u'statustext', msg = _('Error saving current encounter.'), beep = True) saved = self._NB_soap_editors.save_all_editors ( emr = self.__pat.emr, episode_name_candidates = [ gmTools.none_if(self._TCTRL_aoe.GetValue().strip(), ''), gmTools.none_if(self._TCTRL_rfe.GetValue().strip(), '') ] ) if not saved: gmDispatcher.send(signal = 'statustext', msg = _('Cannot save all editors. Some were kept open.'), beep = True) return True
def _pre_exit_callback(self): """The client is about to (be) shut down. Shutdown will not proceed before this returns. """ if self.__pat is None: return True # if self.__encounter_modified(): # do_save_enc = gmGuiHelpers.gm_show_question ( # aMessage = _( # 'You have modified the details\n' # 'of the current encounter.\n' # '\n' # 'Do you want to save those changes ?' # ), # aTitle = _('Starting new encounter') # ) # if do_save_enc: # if not self.save_encounter(): # gmDispatcher.send(signal = u'statustext', msg = _('Error saving current encounter.'), beep = True) saved = self._NB_soap_editors.save_all_editors ( emr = self.__pat.emr, episode_name_candidates = [ gmTools.none_if(self._TCTRL_aoe.GetValue().strip(), ''), gmTools.none_if(self._TCTRL_rfe.GetValue().strip(), '') ] ) if not saved: gmDispatcher.send(signal = 'statustext', msg = _('Cannot save all editors. Some were kept open.'), beep = True) return True
def _on_save_note_button_pressed(self, event): self._NB_soap_editors.save_current_editor ( emr = self.__pat.emr, episode_name_candidates = [ gmTools.none_if(self._TCTRL_aoe.GetValue().strip(), ''), gmTools.none_if(self._TCTRL_rfe.GetValue().strip(), '') ] ) event.Skip()
def _on_save_note_button_pressed(self, event): self._NB_soap_editors.save_current_editor ( emr = self.__pat.emr, episode_name_candidates = [ gmTools.none_if(self._TCTRL_aoe.GetValue().strip(), ''), gmTools.none_if(self._TCTRL_rfe.GetValue().strip(), '') ] ) event.Skip()
def _save_as_new(self): # FIXME: filter out dupes ? self._PRW_patient.person.put_on_waiting_list ( urgency = self._SPCTRL_urgency.GetValue(), comment = gmTools.none_if(self._TCTRL_comment.GetValue().strip(), ''), zone = gmTools.none_if(self._PRW_zone.GetValue().strip(), '') ) # dummy: self.data = {'pk_identity': self._PRW_patient.person.ID, 'comment': None, 'waiting_zone': None, 'urgency': 0} return True
def _save_as_new(self): # FIXME: filter out dupes ? self._PRW_patient.person.put_on_waiting_list ( urgency = self._SPCTRL_urgency.GetValue(), comment = gmTools.none_if(self._TCTRL_comment.GetValue().strip(), ''), zone = gmTools.none_if(self._PRW_zone.GetValue().strip(), '') ) # dummy: self.data = {'pk_identity': self._PRW_patient.person.ID, 'comment': None, 'waiting_zone': None, 'urgency': 0} return True
def _save_as_new(self): enc_type = gmEMRStructItems.create_encounter_type( description=gmTools.none_if(self._TCTRL_name.GetValue().strip(), ''), l10n_description=gmTools.coalesce( gmTools.none_if(self._TCTRL_l10n_name.GetValue().strip(), ''), self._TCTRL_name.GetValue().strip())) if enc_type is None: return False self.data = enc_type return True
def _save_all_button_pressed_bottom_half(self): emr = self.__pat.emr saved = self._NB_soap_editors.save_all_editors ( emr = emr, episode_name_candidates = [ gmTools.none_if(self._TCTRL_aoe.GetValue().strip(), ''), gmTools.none_if(self._TCTRL_rfe.GetValue().strip(), '') ] ) if not saved: gmDispatcher.send(signal = 'statustext', msg = _('Cannot save all editors. Some were kept open.'), beep = True)
def _save_all_button_pressed_bottom_half(self): emr = self.__pat.emr saved = self._NB_soap_editors.save_all_editors ( emr = emr, episode_name_candidates = [ gmTools.none_if(self._TCTRL_aoe.GetValue().strip(), ''), gmTools.none_if(self._TCTRL_rfe.GetValue().strip(), '') ] ) if not saved: gmDispatcher.send(signal = 'statustext', msg = _('Cannot save all editors. Some were kept open.'), beep = True)
def _save_as_new(self): enc_type = gmEMRStructItems.create_encounter_type ( description = gmTools.none_if(self._TCTRL_name.GetValue().strip(), u''), l10n_description = gmTools.coalesce ( gmTools.none_if(self._TCTRL_l10n_name.GetValue().strip(), u''), self._TCTRL_name.GetValue().strip() ) ) if enc_type is None: return False self.data = enc_type return True
def save(self): if not self.__is_valid_for_save(): return False self.__encounter['pk_type'] = self._PRW_encounter_type.GetData() self.__encounter['started'] = self._PRW_start.GetData().get_pydt() self.__encounter['last_affirmed'] = self._PRW_end.GetData().get_pydt() self.__encounter['reason_for_encounter'] = gmTools.none_if(self._TCTRL_rfe.GetValue().strip(), '') self.__encounter['assessment_of_encounter'] = gmTools.none_if(self._TCTRL_aoe.GetValue().strip(), '') self.__encounter.save_payload() # FIXME: error checking self.__encounter.generic_codes_rfe = [ c['data'] for c in self._PRW_rfe_codes.GetData() ] self.__encounter.generic_codes_aoe = [ c['data'] for c in self._PRW_aoe_codes.GetData() ] return True
def save(self): if not self.__is_valid_for_save(): return False self.__encounter['pk_type'] = self._PRW_encounter_type.GetData() self.__encounter['started'] = self._PRW_start.GetData().get_pydt() self.__encounter['last_affirmed'] = self._PRW_end.GetData().get_pydt() self.__encounter['reason_for_encounter'] = gmTools.none_if(self._TCTRL_rfe.GetValue().strip(), u'') self.__encounter['assessment_of_encounter'] = gmTools.none_if(self._TCTRL_aoe.GetValue().strip(), u'') self.__encounter.save_payload() # FIXME: error checking self.__encounter.generic_codes_rfe = [ c['data'] for c in self._PRW_rfe_codes.GetData() ] self.__encounter.generic_codes_aoe = [ c['data'] for c in self._PRW_aoe_codes.GetData() ] return True
def _on_leaving_country(self): self.__perhaps_invalidate_address_searcher(self._PRW_country, 'l10n_country') country = gmTools.none_if(self._PRW_country.GetValue().strip(), '') self._PRW_region.set_context(context = 'country', val = country) return True
def _refresh_dupe_warning(self): lname = self._PRW_lastname.GetValue().strip() if lname == '': self._LBL_person_exists.SetLabel('') return dob = self._PRW_dob.GetData() if dob is None: self._LBL_person_exists.SetLabel('') return #fname = gmTools.none_if(self._PRW_firstnames.GetValue().strip()[:1], '') fname = gmTools.none_if(self._PRW_firstnames.GetValue().strip(), '') no_of_dupes = gmPerson.get_potential_person_dupes(lastnames=lname, firstnames=fname, dob=dob) if no_of_dupes == 0: lbl = '' elif no_of_dupes == 1: lbl = _('A (one) "%s, %s (%s)" already exists.') % ( lname, gmTools.coalesce( fname, '?', '%s %%s%s %s' % (gmTools.u_ellipsis, gmTools.u_ellipsis, gmTools.u_ellipsis)), gmDateTime.pydt_strftime(dob, '%Y %b %d', 'utf8')) else: lbl = _('%s "%s, %s (%s)" already exist.') % ( no_of_dupes, lname, gmTools.coalesce( fname, '?', '%s %%s%s %s' % (gmTools.u_ellipsis, gmTools.u_ellipsis, gmTools.u_ellipsis)), gmDateTime.pydt_strftime(dob, '%Y %b %d', 'utf8')) self._LBL_person_exists.SetLabel(lbl)
def _refresh_dupe_warning(self): lname = self._PRW_lastname.GetValue().strip() if lname == '': self._LBL_person_exists.SetLabel('') return dob = self._PRW_dob.GetData() if dob is None: self._LBL_person_exists.SetLabel('') return fname = gmTools.none_if(self._PRW_firstnames.GetValue().strip()[:1], '') no_of_dupes = gmPerson.get_potential_person_dupes(lastnames = lname, firstnames = fname, dob = dob) if no_of_dupes == 0: lbl = '' elif no_of_dupes == 1: lbl = _('One "%s, %s (%s)" already exists !') % ( lname, gmTools.coalesce(fname, '?', '%s %%s. %s' % (gmTools.u_ellipsis, gmTools.u_ellipsis)), gmDateTime.pydt_strftime(dob, '%Y %b %d', 'utf8') ) else: lbl = _('%s "%s, %s (%s)" already exist !') % ( no_of_dupes, lname, gmTools.coalesce(fname, '?', '%s %%s. %s' % (gmTools.u_ellipsis, gmTools.u_ellipsis)), gmDateTime.pydt_strftime(dob, '%Y %b %d', 'utf8') ) self._LBL_person_exists.SetLabel(lbl)
def _on_leaving_country(self): self.__perhaps_invalidate_address_searcher(self._PRW_country, 'l10n_country') country = gmTools.none_if(self._PRW_country.GetValue().strip(), '') self._PRW_region.set_context(context='country', val=country) return True
def update_in_waiting_list(self, pk = None, urgency = 0, comment = None, zone = None): cmd = u""" update clin.waiting_list set urgency = %(urg)s, comment = %(cmt)s, area = %(zone)s where pk = %(pk)s""" args = { 'pk': pk, 'urg': urgency, 'cmt': gmTools.none_if(comment, u''), 'zone': gmTools.none_if(zone, u'') } gmPG2.run_rw_queries(queries = [{'cmd': cmd, 'args': args}])
def update_in_waiting_list(self, pk = None, urgency = 0, comment = None, zone = None): cmd = u""" update clin.waiting_list set urgency = %(urg)s, comment = %(cmt)s, area = %(zone)s where pk = %(pk)s""" args = { 'pk': pk, 'urg': urgency, 'cmt': gmTools.none_if(comment, u''), 'zone': gmTools.none_if(zone, u'') } gmPG2.run_rw_queries(queries = [{'cmd': cmd, 'args': args}])
def _save_as_update(self): # do not update existing address, rather # create new one or get corresponding # address should it exist try: created_or_loaded_address = gmDemographicRecord.create_address( country_code=self._PRW_country.GetData(), region_code=self._PRW_state.GetData(), urb=self._PRW_urb.GetValue().strip(), suburb=gmTools.none_if(self._PRW_suburb.GetValue().strip(), u''), postcode=self._PRW_zip.GetValue().strip(), street=self._PRW_street.GetValue().strip(), number=self._TCTRL_number.GetValue().strip(), subunit=gmTools.none_if(self._TCTRL_subunit.GetValue().strip(), u'')) except: _log.exception('cannot save address') gmGuiHelpers.gm_show_error( _('Cannot save address.\n\n' 'Does the region [%s]\n' 'exist in country [%s] ?') % (self._PRW_state.GetValue().strip(), self._PRW_country.GetValue().strip()), _('Saving address')) return False # link address to holder (there better be one) linked_address = self.address_holder.link_address( id_type=self._PRW_type.GetData(), address=created_or_loaded_address) if linked_address['pk_address'] != created_or_loaded_address[ 'pk_address']: raise ValueError('problem linking address to person or org') created_or_loaded_address['notes_street'] = gmTools.none_if( self._TCTRL_notes_street.GetValue().strip(), u'') created_or_loaded_address['notes_subunit'] = gmTools.none_if( self._TCTRL_notes_subunit.GetValue().strip(), u'') created_or_loaded_address.save_payload() linked_address.refetch_payload() self.data = linked_address return True
def _on_save_note_under_button_pressed(self, event): encounter = gmEncounterWidgets.select_encounters ( parent = self, patient = self.__pat, single_selection = True ) # cancelled or None selected: if encounter is None: return self._NB_soap_editors.save_current_editor ( emr = self.__pat.emr, encounter = encounter['pk_encounter'], episode_name_candidates = [ gmTools.none_if(self._TCTRL_aoe.GetValue().strip(), ''), gmTools.none_if(self._TCTRL_rfe.GetValue().strip(), '') ] ) event.Skip()
def _on_leaving_zip(self): self.__perhaps_invalidate_address_searcher(self._PRW_zip, 'postcode') zip_code = gmTools.none_if(self._PRW_zip.GetValue().strip(), '') self._PRW_street.set_context(context = 'zip', val = zip_code) self._PRW_urb.set_context(context = 'zip', val = zip_code) self._PRW_region.set_context(context = 'zip', val = zip_code) self._PRW_country.set_context(context = 'zip', val = zip_code) return True
def _on_save_note_under_button_pressed(self, event): encounter = gmEncounterWidgets.select_encounters ( parent = self, patient = self.__pat, single_selection = True ) # cancelled or None selected: if encounter is None: return self._NB_soap_editors.save_current_editor ( emr = self.__pat.emr, encounter = encounter['pk_encounter'], episode_name_candidates = [ gmTools.none_if(self._TCTRL_aoe.GetValue().strip(), ''), gmTools.none_if(self._TCTRL_rfe.GetValue().strip(), '') ] ) event.Skip()
def _on_leaving_zip(self): self.__perhaps_invalidate_address_searcher(self._PRW_zip, 'postcode') zip_code = gmTools.none_if(self._PRW_zip.GetValue().strip(), '') self._PRW_street.set_context(context='zip', val=zip_code) self._PRW_urb.set_context(context='zip', val=zip_code) self._PRW_region.set_context(context='zip', val=zip_code) self._PRW_country.set_context(context='zip', val=zip_code) return True
def _save_as_update(self): # do not update existing address, rather # create new one or get corresponding # address should it exist try: created_or_loaded_address = gmDemographicRecord.create_address ( country_code = self._PRW_country.GetData(), region_code = self._PRW_state.GetData(), urb = self._PRW_urb.GetValue().strip(), suburb = gmTools.none_if(self._PRW_suburb.GetValue().strip(), ''), postcode = self._PRW_zip.GetValue().strip(), street = self._PRW_street.GetValue().strip(), number = self._TCTRL_number.GetValue().strip(), subunit = gmTools.none_if(self._TCTRL_subunit.GetValue().strip(), '') ) except: _log.exception('cannot save address') gmGuiHelpers.gm_show_error ( _('Cannot save address.\n\n' 'Does the region [%s]\n' 'exist in country [%s] ?' ) % ( self._PRW_state.GetValue().strip(), self._PRW_country.GetValue().strip() ), _('Saving address') ) return False # link address to holder (there better be one) linked_address = self.address_holder.link_address(id_type = self._PRW_type.GetData(), address = created_or_loaded_address) if linked_address['pk_address'] != created_or_loaded_address['pk_address']: raise ValueError('problem linking address to person or org') created_or_loaded_address['notes_street'] = gmTools.none_if(self._TCTRL_notes_street.GetValue().strip(), '') created_or_loaded_address['notes_subunit'] = gmTools.none_if(self._TCTRL_notes_subunit.GetValue().strip(), '') created_or_loaded_address.save_payload() linked_address.refetch_payload() self.data = linked_address return True
def __identity_valid_for_save(self): error = False # name fields if self._PRW_lastname.GetValue().strip() == '': error = True gmDispatcher.send(signal='statustext', msg=_('Must enter lastname.')) self._PRW_lastname.display_as_valid(False) else: self._PRW_lastname.display_as_valid(True) if self._PRW_firstnames.GetValue().strip() == '': error = True gmDispatcher.send(signal='statustext', msg=_('Must enter first name.')) self._PRW_firstnames.display_as_valid(False) else: self._PRW_firstnames.display_as_valid(True) # gender if self._PRW_gender.GetData() is None: error = True gmDispatcher.send(signal='statustext', msg=_('Must select gender.')) self._PRW_gender.display_as_valid(False) else: self._PRW_gender.display_as_valid(True) # dob validation if not _validate_dob_field(self._PRW_dob): error = True # TOB validation if _validate_tob_field(self._TCTRL_tob): self.display_ctrl_as_valid(ctrl=self._TCTRL_tob, valid=True) else: error = True self.display_ctrl_as_valid(ctrl=self._TCTRL_tob, valid=False) # uniqueness if gmPerson.this_person_exists( self._PRW_lastname.GetValue().strip(), self._PRW_firstnames.GetValue().strip(), self._PRW_dob.GetData(), gmTools.none_if(self._TCTRL_comment.GetValue().strip(), u'')): error = True self.StatusText = _( 'Duplicate person. Modify name and/or DOB or use comment to make unique.' ) return (not error)
def create_address(country_code=None, region_code=None, urb=None, suburb=None, postcode=None, street=None, number=None, subunit=None): if suburb is not None: suburb = gmTools.none_if(suburb.strip(), u'') pk_address = address_exists ( country_code = country_code, region_code = region_code, urb = urb, # suburb = suburb, postcode = postcode, street = street, number = number, subunit = subunit ) if pk_address is not None: return cAddress(aPK_obj = pk_address) cmd = u""" SELECT dem.create_address ( %(number)s, %(street)s, %(postcode)s, %(urb)s, %(region_code)s, %(country_code)s, %(subunit)s )""" args = { 'number': number, 'street': street, 'postcode': postcode, 'urb': urb, 'region_code': region_code, 'country_code': country_code, 'subunit': subunit } queries = [{'cmd': cmd, 'args': args}] rows, idx = gmPG2.run_rw_queries(queries = queries, return_data = True) adr = cAddress(aPK_obj = rows[0][0]) if suburb is not None: queries = [{ # CAVE: suburb will be ignored if there already is one 'cmd': u"UPDATE dem.street SET suburb = %(suburb)s WHERE id = %(pk_street)s AND suburb IS NULL", 'args': {'suburb': suburb, 'pk_street': adr['pk_street']} }] rows, idx = gmPG2.run_rw_queries(queries = queries) return adr
def create_address(country_code=None, region_code=None, urb=None, suburb=None, postcode=None, street=None, number=None, subunit=None): if suburb is not None: suburb = gmTools.none_if(suburb.strip(), '') pk_address = address_exists ( country_code = country_code, region_code = region_code, urb = urb, # suburb = suburb, postcode = postcode, street = street, number = number, subunit = subunit ) if pk_address is not None: return cAddress(aPK_obj = pk_address) cmd = """ SELECT dem.create_address ( %(number)s, %(street)s, %(postcode)s, %(urb)s, %(region_code)s, %(country_code)s, %(subunit)s )""" args = { 'number': number, 'street': street, 'postcode': postcode, 'urb': urb, 'region_code': region_code, 'country_code': country_code, 'subunit': subunit } queries = [{'cmd': cmd, 'args': args}] rows, idx = gmPG2.run_rw_queries(queries = queries, return_data = True) adr = cAddress(aPK_obj = rows[0][0]) if suburb is not None: queries = [{ # CAVE: suburb will be ignored if there already is one 'cmd': "UPDATE dem.street SET suburb = %(suburb)s WHERE id = %(pk_street)s AND suburb IS NULL", 'args': {'suburb': suburb, 'pk_street': adr['pk_street']} }] rows, idx = gmPG2.run_rw_queries(queries = queries) return adr
def _on_enlist_button_pressed(self, evt): # sanity checks if self._TXT_password.GetValue() != self._TXT_password_again.GetValue(): gmGuiHelpers.gm_show_error ( aMessage = _('Password entries do not match. Please type in the passwords again to rule out typos.'), aTitle = _('Adding GNUmed user') ) self._TXT_password.SetValue('') self._TXT_password_again.SetValue('') return False if self._TXT_password.GetValue().strip() == '': really_wants_empty_password = gmGuiHelpers.gm_show_question ( aMessage = _( 'Are you positively sure you want to create\n' 'a user with an empty password ?\n' '\n' 'Think about the record access implications !' ), aTitle = _('Adding GNUmed user') ) if not really_wants_empty_password: return False # connect as "gm-dbo" conn = gmAuthWidgets.get_dbowner_connection ( procedure = _('Enlisting person as user.'), dbo_password = gmTools.none_if(self._TXT_dbo_password.GetValue(), '') ) if conn is None: return False # create new user success, msg = gmStaff.create_staff ( conn = conn, db_account = self._TXT_account.GetValue(), password = self._TXT_password.GetValue(), identity = gmPerson.gmCurrentPatient().ID, short_alias = self._TXT_short_alias.GetValue().strip() ) conn.close() if not success: gmGuiHelpers.gm_show_error(aMessage = msg, aTitle = _('Adding GNUmed user')) return False if self.IsModal(): self.EndModal(wx.ID_OK) else: self.Close()
def __identity_valid_for_save(self): error = False # name fields if self._PRW_lastname.GetValue().strip() == '': error = True gmDispatcher.send(signal = 'statustext', msg = _('Must enter lastname.')) self._PRW_lastname.display_as_valid(False) else: self._PRW_lastname.display_as_valid(True) if self._PRW_firstnames.GetValue().strip() == '': error = True gmDispatcher.send(signal = 'statustext', msg = _('Must enter first name.')) self._PRW_firstnames.display_as_valid(False) else: self._PRW_firstnames.display_as_valid(True) # gender if self._PRW_gender.GetData() is None: error = True gmDispatcher.send(signal = 'statustext', msg = _('Must select gender.')) self._PRW_gender.display_as_valid(False) else: self._PRW_gender.display_as_valid(True) # dob validation if not _validate_dob_field(self._PRW_dob): error = True # TOB validation if _validate_tob_field(self._TCTRL_tob): self.display_ctrl_as_valid(ctrl = self._TCTRL_tob, valid = True) else: error = True self.display_ctrl_as_valid(ctrl = self._TCTRL_tob, valid = False) # uniqueness if gmPerson.this_person_exists ( self._PRW_lastname.GetValue().strip(), self._PRW_firstnames.GetValue().strip(), self._PRW_dob.GetData(), gmTools.none_if(self._TCTRL_comment.GetValue().strip(), u'') ): error = True self.status_message = _('Duplicate person. Modify name and/or DOB or use comment to make unique.') return (not error)
def _on_enlist_button_pressed(self, evt): # sanity checks if self._TXT_password.GetValue() != self._TXT_password_again.GetValue( ): gmGuiHelpers.gm_show_error(aMessage=_( 'Password entries do not match. Please type in the passwords again to rule out typos.' ), aTitle=_('Adding GNUmed user')) self._TXT_password.SetValue('') self._TXT_password_again.SetValue('') return False if self._TXT_password.GetValue().strip() == '': really_wants_empty_password = gmGuiHelpers.gm_show_question( aMessage=_('Are you positively sure you want to create\n' 'a user with an empty password ?\n' '\n' 'Think about the record access implications !'), aTitle=_('Adding GNUmed user')) if not really_wants_empty_password: return False # connect as "gm-dbo" conn = gmAuthWidgets.get_dbowner_connection( procedure=_('Enlisting person as user.'), dbo_password=gmTools.none_if(self._TXT_dbo_password.GetValue(), '')) if conn is None: return False # create new user success, msg = gmStaff.create_staff( conn=conn, db_account=self._TXT_account.GetValue(), password=self._TXT_password.GetValue(), identity=gmPerson.gmCurrentPatient().ID, short_alias=self._TXT_short_alias.GetValue().strip()) conn.close() if not success: gmGuiHelpers.gm_show_error(aMessage=msg, aTitle=_('Adding GNUmed user')) return False if self.IsModal(): self.EndModal(wx.ID_OK) else: self.Close()
def _save_as_new(self): if self._PRW_dob.GetValue().strip() == '': if not _empty_dob_allowed(): self._PRW_dob.display_as_valid(False) self._PRW_dob.SetFocus() return False # identity new_identity = gmPerson.create_identity( gender=self._PRW_gender.GetData(), dob=self._PRW_dob.GetData(), lastnames=self._PRW_lastname.GetValue().strip(), firstnames=self._PRW_firstnames.GetValue().strip(), comment=gmTools.none_if(self._TCTRL_comment.GetValue().strip(), '')) if new_identity is None: gmGuiHelpers.gm_show_error( title=_('Creating person.'), error=_('Failed to create person. Does it already exist ?\n' '\n' 'If so you need to add a unique comment.')) return False _log.info('identity created: %s' % new_identity) new_identity['dob_is_estimated'] = self._CHBOX_estimated_dob.GetValue() val = self._TCTRL_tob.GetValue().strip() if val != '': new_identity['tob'] = pydt.time(int(val[:2]), int(val[3:5])) new_identity['title'] = gmTools.none_if( self._PRW_title.GetValue().strip()) prov = self._PRW_primary_provider.GetData() if prov is not None: new_identity['pk_primary_provider'] = prov #new_identity['comment'] = gmTools.none_if(self._TCTRL_comment.GetValue().strip(), '') new_identity.save() _log.info('new identity updated: %s' % new_identity) new_identity.set_nickname(nickname=gmTools.none_if( self._PRW_nickname.GetValue().strip(), '')) _log.info('nickname set on new identity: %s' % new_identity) # address # if we reach this the address cannot be completely empty is_valid = self.__address_valid_for_save(empty_address_is_valid=False) if is_valid is True: # because we currently only check for non-emptiness # we must still deal with database errors try: new_identity.link_address( number=self._TCTRL_number.GetValue().strip(), street=self._PRW_street.GetValue().strip(), postcode=self._PRW_zip.GetValue().strip(), urb=self._PRW_urb.GetValue().strip(), region_code=self._PRW_region.GetData(), country_code=self._PRW_country.GetData(), subunit=gmTools.none_if( self._TCTRL_unit.GetValue().strip(), ''), id_type=self._PRW_type.GetData()) except gmPG2.dbapi.InternalError: _log.debug('number: >>%s<<', self._TCTRL_number.GetValue().strip()) _log.debug('(sub)unit: >>%s<<', self._TCTRL_unit.GetValue().strip()) _log.debug('street: >>%s<<', self._PRW_street.GetValue().strip()) _log.debug('postcode: >>%s<<', self._PRW_zip.GetValue().strip()) _log.debug('urb: >>%s<<', self._PRW_urb.GetValue().strip()) _log.debug('region: >>%s<<', self._PRW_region.GetData().strip()) _log.debug('country: >>%s<<', self._PRW_country.GetData().strip()) _log.exception('cannot link address') gmGuiHelpers.gm_show_error( aTitle=_('Saving address'), aMessage=_( 'Cannot save this address.\n' '\n' 'You will have to add it via the Demographics plugin.\n' )) elif is_valid is False: gmGuiHelpers.gm_show_error( aTitle=_('Saving address'), aMessage=_( 'Address not saved.\n' '\n' 'You will have to add it via the Demographics plugin.\n')) # else it is None which means empty address which we ignore # phone channel_name = self._PRW_channel_type.GetValue().strip() pk_channel_type = self._PRW_channel_type.GetData() if pk_channel_type is None: if channel_name == '': channel_name = 'homephone' new_identity.link_comm_channel( comm_medium=channel_name, pk_channel_type=pk_channel_type, url=gmTools.none_if(self._TCTRL_phone.GetValue().strip(), ''), is_confidential=False) # external ID pk_type = self._PRW_external_id_type.GetData() id_value = self._TCTRL_external_id_value.GetValue().strip() if (pk_type is not None) and (id_value != ''): new_identity.add_external_id(value=id_value, pk_type=pk_type) # occupation new_identity.link_occupation(occupation=gmTools.none_if( self._PRW_occupation.GetValue().strip(), '')) self.data = new_identity return True
def _save_as_new(self): if self._PRW_dob.GetValue().strip() == '': if not _empty_dob_allowed(): self._PRW_dob.display_as_valid(False) self._PRW_dob.SetFocus() return False # identity new_identity = gmPerson.create_identity ( gender = self._PRW_gender.GetData(), dob = self._PRW_dob.GetData(), lastnames = self._PRW_lastname.GetValue().strip(), firstnames = self._PRW_firstnames.GetValue().strip(), comment = gmTools.none_if(self._TCTRL_comment.GetValue().strip(), '') ) if new_identity is None: gmGuiHelpers.gm_show_error ( title = _('Creating person.'), error = _( 'Failed to create person. Does it already exist ?\n' '\n' 'If so you need to add a unique comment.' ) ) return False _log.info('identity created: %s' % new_identity) new_identity['dob_is_estimated'] = self._CHBOX_estimated_dob.GetValue() val = self._TCTRL_tob.GetValue().strip() if val != '': new_identity['tob'] = pydt.time(int(val[:2]), int(val[3:5])) new_identity['title'] = gmTools.none_if(self._PRW_title.GetValue().strip()) prov = self._PRW_primary_provider.GetData() if prov is not None: new_identity['pk_primary_provider'] = prov #new_identity['comment'] = gmTools.none_if(self._TCTRL_comment.GetValue().strip(), '') new_identity.save() _log.info('new identity updated: %s' % new_identity) new_identity.set_nickname(nickname = gmTools.none_if(self._PRW_nickname.GetValue().strip(), '')) _log.info('nickname set on new identity: %s' % new_identity) # address # if we reach this the address cannot be completely empty is_valid = self.__address_valid_for_save(empty_address_is_valid = False) if is_valid is True: # because we currently only check for non-emptiness # we must still deal with database errors try: new_identity.link_address ( number = self._TCTRL_number.GetValue().strip(), street = self._PRW_street.GetValue().strip(), postcode = self._PRW_zip.GetValue().strip(), urb = self._PRW_urb.GetValue().strip(), region_code = self._PRW_region.GetData(), country_code = self._PRW_country.GetData(), subunit = gmTools.none_if(self._TCTRL_unit.GetValue().strip(), ''), id_type = self._PRW_type.GetData() ) except gmPG2.dbapi.InternalError: _log.debug('number: >>%s<<', self._TCTRL_number.GetValue().strip()) _log.debug('(sub)unit: >>%s<<', self._TCTRL_unit.GetValue().strip()) _log.debug('street: >>%s<<', self._PRW_street.GetValue().strip()) _log.debug('postcode: >>%s<<', self._PRW_zip.GetValue().strip()) _log.debug('urb: >>%s<<', self._PRW_urb.GetValue().strip()) _log.debug('region: >>%s<<', self._PRW_region.GetData().strip()) _log.debug('country: >>%s<<', self._PRW_country.GetData().strip()) _log.exception('cannot link address') gmGuiHelpers.gm_show_error ( aTitle = _('Saving address'), aMessage = _( 'Cannot save this address.\n' '\n' 'You will have to add it via the Demographics plugin.\n' ) ) elif is_valid is False: gmGuiHelpers.gm_show_error ( aTitle = _('Saving address'), aMessage = _( 'Address not saved.\n' '\n' 'You will have to add it via the Demographics plugin.\n' ) ) # else it is None which means empty address which we ignore # phone channel_name = self._PRW_channel_type.GetValue().strip() pk_channel_type = self._PRW_channel_type.GetData() if pk_channel_type is None: if channel_name == '': channel_name = 'homephone' new_identity.link_comm_channel ( comm_medium = channel_name, pk_channel_type = pk_channel_type, url = gmTools.none_if(self._TCTRL_phone.GetValue().strip(), ''), is_confidential = False ) # external ID pk_type = self._PRW_external_id_type.GetData() id_value = self._TCTRL_external_id_value.GetValue().strip() if (pk_type is not None) and (id_value != ''): new_identity.add_external_id(value = id_value, pk_type = pk_type) # occupation new_identity.link_occupation ( occupation = gmTools.none_if(self._PRW_occupation.GetValue().strip(), '') ) self.data = new_identity return True