def __import_narrative(self, soap_entry): """Import soap entry into GNUmed backend. @param soap_entry: dictionary containing information related to one SOAP input line @type soap_entry: dictionary with keys 'soap', 'types', 'text' FIXME: Later we may want to allow for explicitly setting a staff ID to be FIXME: used for import. This would allow to import data "on behalf of" someone. """ if not self.__verify_soap_entry(soap_entry=soap_entry): _log.error('cannot verify soap entry') return False # obtain clinical context information emr = gmPerson.gmCurrentPatient().emr epi_id = soap_entry[soap_bundle_CLIN_CTX_KEY][soap_bundle_EPISODE_ID_KEY] try: enc_id = soap_entry[soap_bundle_CLIN_CTX_KEY][soap_bundle_ENCOUNTER_ID_KEY] except KeyError: enc = emr.active_encounter enc_id = enc['pk_encounter'] # create narrative row narr = gmClinNarrative.create_narrative_item ( narrative = soap_entry[soap_bundle_TEXT_KEY], soap_cat = soap_entry[soap_bundle_SOAP_CAT_KEY], episode_id = epi_id, encounter_id = enc_id ) # # attach types # if soap_bundle_TYPES_KEY in soap_entry: # print "code missing to attach types to imported narrative" return (narr is not None)
def create_narr(): # don't worry about which patient we chose, just be consistent cmd = "select pk_episode, pk_encounter from v_pat_narrative limit 1" data = gmPG.run_ro_query('historica', cmd) narr = gmClinNarrative.create_narrative_item(narrative=magic_string, soap_cat='s', episode_id=data[0][0], encounter_id=data[0][1]) return narr
def create_narr(): # don't worry about which patient we chose, just be consistent cmd = "select pk_episode, pk_encounter from v_pat_narrative limit 1" data = gmPG.run_ro_query('historica', cmd) narr = gmClinNarrative.create_narrative_item ( narrative = magic_string, soap_cat = 's', episode_id = data[0][0], encounter_id = data[0][1] ) return narr
def edit_narrative(parent=None, narrative=None, single_entry=False): assert isinstance(narrative, gmClinNarrative.cNarrative), '<narrative> must be of type <cNarrative>' title = _('Editing progress note') if narrative['modified_by_raw'] == gmStaff.gmCurrentProvider()['db_user']: msg = _('Your original progress note:') else: msg = _('Original progress note by %s [%s]\n(will be notified of changes):') % ( narrative['modified_by'], narrative['modified_by_raw'] ) if parent is None: parent = wx.GetApp().GetTopWindow() dlg = gmGuiHelpers.cMultilineTextEntryDlg ( parent, -1, title = title, msg = msg, data = narrative.format(left_margin = ' ', fancy = True), text = narrative['narrative'].strip() ) decision = dlg.ShowModal() val = dlg.value.strip() dlg.DestroyLater() if decision != wx.ID_SAVE: return False if val == '': return False if val == narrative['narrative'].strip(): return False if narrative['modified_by_raw'] == gmStaff.gmCurrentProvider()['db_user']: narrative['narrative'] = val narrative.save_payload() return True q = _( 'Original progress note written by someone else:\n' '\n' ' %s (%s)\n' '\n' 'Upon saving changes that person will be notified.\n' '\n' 'Consider saving as a new progress note instead.' ) % ( narrative['modified_by_raw'], narrative['modified_by'] ) buttons = [ {'label': _('Save changes'), 'default': True}, {'label': _('Save new note')}, {'label': _('Discard')} ] dlg = gmGuiHelpers.c3ButtonQuestionDlg(parent = parent, caption = title, question = q, button_defs = buttons) decision = dlg.ShowModal() dlg.DestroyLater() if decision not in [wx.ID_YES, wx.ID_NO]: return False if decision == wx.ID_NO: # create new progress note within the same context as the original one gmClinNarrative.create_narrative_item ( narrative = val, soap_cat = narrative['soap_cat'], episode_id = narrative['pk_episode'], encounter_id = narrative['pk_encounter'] ) return True # notify original provider msg = gmProviderInbox.create_inbox_message ( staff = narrative.staff_id, message_type = _('Change notification'), message_category = 'administrative', subject = _('A progress note of yours has been edited.'), patient = narrative['pk_patient'] ) msg['data'] = _( 'Original (by [%s]):\n' '%s\n' '\n' 'Edited (by [%s]):\n' '%s' ) % ( narrative['modified_by'], narrative['narrative'].strip(), gmStaff.gmCurrentProvider()['short_alias'], val ) msg.save() # notify /me about the staff member notification #gmProviderInbox.create_inbox_message ( # staff = curr_prov['pk_staff'], # message_type = _('Privacy notice'), # message_category = 'administrative', # subject = _('%s: Staff member %s has been notified of your chart access.') % (prov, pat) #) # save narrative change narrative['narrative'] = val narrative.save() return True