[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Gnumed-devel] re: should these be committed?
From: |
catmat |
Subject: |
[Gnumed-devel] re: should these be committed? |
Date: |
Thu, 16 Dec 2004 11:53:58 +1100 |
User-agent: |
Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.3) Gecko/20040913 |
currently , the add health issue and add episode nodes on EMR browser
makes the cvs tree differ,
and I'm not sure if I should commit . The diff files are attached.
Index: gnumed/client/business/gmClinicalRecord.py
===================================================================
RCS file: /cvsroot/gnumed/gnumed/gnumed/client/business/gmClinicalRecord.py,v
retrieving revision 1.150
diff -r1.150 gmClinicalRecord.py
1364a1365
>
1373,1385c1374,1375
< h_iss = issue_id
< epis = episode_id
< if issue_id is not None:
< h_iss = [issue_id]
< if episode_id is not None:
< epis = [episode_id]
< encounters = self.get_encounters(issues=h_iss, episodes=epis)
< if encounters is None or len(encounters) == 0:
< _log.Log(gmLog.lErr, 'cannot retrieve first encounter
for episodes [%s], issues [%s] (patient ID [%s])' % (str(episodes),
str(issues), self.id_patient))
< return None
< # FIXME: this does not scale particularly well
< encounters.sort(lambda x,y: cmp(x['started'], y['started']))
< return encounters[0]
---
> return self._get_encounters()[0]
>
1393a1384,1387
> return self._get_encounters()[-1]
>
> #--------------------------------------------------------
> def _get_encounters(self, issue_id=None, episode_id=None):
1402,1403c1396,1399
< _log.Log(gmLog.lErr, 'cannot retrieve last encounter
for episodes [%s], issues [%s]. Patient ID [%s]' %(str(episodes), str(issues),
self.id_patient))
< return None
---
> episodes = epis
> issues = h_iss
> _log.Log(gmLog.lErr, 'cannot retrieve first encounter
> for episodes [%s], issues [%s] (patient ID [%s])' % (str(episodes),
> str(issues), self.id_patient))
> return [None]
1406c1402
< return encounters[-1]
---
> return encounters
Index: gnumed/client/wxpython/gmEMRBrowser.py
===================================================================
RCS file: /cvsroot/gnumed/gnumed/gnumed/client/wxpython/gmEMRBrowser.py,v
retrieving revision 1.6
diff -r1.6 gmEMRBrowser.py
48a49,50
>
> self.__init_popup()
104c106
<
---
>
124a127,131
>
>
> self.popup.SetPopupContext(sel_item)
>
>
181a189,213
> def get_emr_tree(self):
> return self.__emr_tree
>
> def get_EMR_item(self, selected_tree_item):
> return self.__emr_tree.GetPyData(selected_tree_item)
>
> def get_parent_EMR_item(self, selected_tree_item):
> return
> self.__emr_tree.GetPyData(self.__emr_tree.GetItemParent(selected_tree_item))
>
> def repopulate(self):
> self._populate_with_data()
>
> #------------POPUP methods -------------------------------
> def __init_popup(self):
> """
> initializes the popup for the tree
> """
> self.popup=gmPopupMenuEMRBrowser(self)
> wx.EVT_RIGHT_DOWN(self.__emr_tree, self.__show_popup)
>
>
>
> def __show_popup(self, event):
> self.PopupMenu(self.popup, (event.GetX(), event.GetY() ))
>
216a249,310
>
>
>
> import Queue
>
> class gmPopupMenuEMRBrowser(wx.wxMenu):
> """
> popup menu for updating the EMR tree.
> """
> def __init__(self , browser):
> wx.wxMenu.__init__(self)
> self.ID_NEW_ENCOUNTER=1
> self.ID_NEW_HEALTH_ISSUE=2
> self.ID_NEW_EPISODE=3
> self.__browser = browser
> self.__mediator = NarrativeTreeItemMediator1(browser)
> wx.EVT_MENU(self.__browser, self.ID_NEW_HEALTH_ISSUE ,
> self.__mediator.new_health_issue)
> wx.EVT_MENU(self.__browser, self.ID_NEW_EPISODE ,
> self.__mediator.new_episode)
>
> def Clear(self):
> for item in self.GetMenuItems():
> self.Remove(item.GetId())
>
> def SetPopupContext( self, sel_item):
>
> self.Clear()
>
> sel_item_obj = self.__browser.get_EMR_item(sel_item)
>
> if(isinstance(sel_item_obj, gmEMRStructItems.cEncounter)):
> header = _('Encounter\n=========\n\n')
>
>
> self.__append_new_encounter_menuitem(episode=self.__browser.get_parent_EMR_item(sel_item)
> )
>
>
> elif (isinstance(sel_item_obj, gmEMRStructItems.cEpisode)):
> header = _('Episode\n=======\n\n')
>
>
> self.__append_new_encounter_menuitem(episode=self.__browser.get_EMR_item(sel_item)
> )
>
>
> self.__append_new_episode_menuitem(health_issue=self.__browser.get_parent_EMR_item(sel_item))
>
>
> elif (isinstance(sel_item_obj, gmEMRStructItems.cHealthIssue)):
> header = _('Health Issue\n============\n\n')
>
>
> self.__append_new_episode_menuitem(health_issue=self.__browser.get_EMR_item(sel_item))
>
> self.Append(self.ID_NEW_HEALTH_ISSUE, "New Health
> Issue")
>
>
> else:
> header = _('Summary\n=======\n\n')
> self.Append(self.ID_NEW_HEALTH_ISSUE, "New Health
> Issue")
>
>
> def __append_new_encounter_menuitem(self, episode):
> self.Append(self.ID_NEW_ENCOUNTER, "New Encounter (of episode
> '%s')" % episode['description'] )
>
> def __append_new_episode_menuitem(self, health_issue):
> self.Append(self.ID_NEW_EPISODE, "New Episode(of health issue
> '%s')" % health_issue['description'] )
>
217a312,480
>
> class NarrativeTreeItemMediator1:
> """
> handler for popup menu actions.
> Handles the unchanged new item problem , where no tree events are
> fired, by listening
> on the edit control events.
> """
> def __init__(self, browser):
> self.q, self.q_edit = Queue.Queue(), Queue.Queue()
> self.__browser = browser
> wx.EVT_TREE_END_LABEL_EDIT(self.get_emr_tree(),
> self.get_emr_tree().GetId(), self.__end_label_edit)
>
> self.HEALTH_ISSUE_START_LABEL="NEW HEALTH ISSUE"
> self.EPISODE_START_LABEL="NEW EPISODE"
>
> def get_browser(self):
> return self.__browser
>
>
> def get_emr_tree(self):
> return self.__browser.get_emr_tree()
>
> def new_health_issue(self, menu_event):
> """
> entry from MenuItem New Health Issue
> """
> self.start_edit_root_node( self.HEALTH_ISSUE_START_LABEL)
>
> def new_episode(self, menu_event):
> """
> entry from MenuItem New Episode Issue
> """
> self.start_edit_child_node( self.EPISODE_START_LABEL)
>
> def start_edit_child_node(self, start_edit_text):
> root_node = self.get_emr_tree().GetSelection()
> if start_edit_text == self.EPISODE_START_LABEL and \
> isinstance(self.get_browser().get_EMR_item(root_node),
> gmEMRStructItems.cEpisode):
> root_node = self.get_emr_tree().GetItemParent(root_node)
>
> self.q_edit.put( (root_node, start_edit_text) )
> wx.wxCallAfter( self.start_edit_node) #, root_node,
> start_edit_text)
>
> def start_edit_root_node(self, start_edit_text ):
> """
> this handles the problem of no event fired if label unchanged.
> By detecting for the return key on the edit control, the start
> text
> can be compared, and if no change, the node is deleted
> in the __key_down handler
> """
> root_node = self.get_emr_tree().GetRootItem()
>
> self.q_edit.put( (root_node, start_edit_text) )
> wx.wxCallAfter(self.start_edit_node) #, root_node,
> start_edit_text)
>
>
> def start_edit_node(self): # , node, start_edit_text)
> node = None
> while True:
> try:
> print "removed edit request"
> old_node = node
> (node, start_edit_text) =
> self.q_edit.get_nowait()
>
> if not old_node is None:
> print "request on old root_node
> discarded : ", old_node, start_edit_text
>
> except Queue.Empty:
> break
>
> if not node is None:
> root_node = node
> node= self.get_emr_tree().AppendItem(root_node,
> start_edit_text)
> self.get_emr_tree().EnsureVisible(node)
> self.get_emr_tree().EditLabel(node)
> self.edit_control = self.get_emr_tree().GetEditControl()
> print self.edit_control
> self.start_edit_text = start_edit_text
> self.edit_node = node
> wx.EVT_KEY_DOWN( self.edit_control, self.__key_down)
> wx.EVT_KILL_FOCUS(self.edit_control, self.__kill_focus)
> else:
> print "No node was found"
>
> def __end_label_edit(self, tree_event):
> """
> check to see if editing cancelled , and if not, then do update
> for each kind of label
> """
> print "end label edit Handled"
> print "tree_event is ", tree_event
> print "after ", tree_event.__dict__
> print "label is ", tree_event.GetLabel()
>
>
> if tree_event.IsEditCancelled() or
> len(tree_event.GetLabel().strip()) == 0:
> tree_event.Skip()
> #self.__item_to_delete = tree_event.GetItem()
> self.q.put(tree_event.GetItem())
> wx.wxCallAfter(self.__delete_item)
> else:
> if self.start_edit_text ==
> self.HEALTH_ISSUE_START_LABEL:
>
> wx.wxCallAfter(self.__add_new_health_issue_to_record)
>
> elif self.start_edit_text == self.EPISODE_START_LABEL:
>
> wx.wxCallAfter(self.__add_new_episode_to_record)
>
> def __key_down(self, event):
> """
> this event on the EditControl needs to be handled because
> 1) pressing enter whilst no change in label , does not fire any
> END_LABEL event, so tentative
> tree items cannot be deleted.
>
> .
> """
> print "Item is ", event.GetKeyCode()
> event.Skip()
>
> if event.GetKeyCode() == wx.WXK_RETURN:
> self.__check_for_unchanged_item()
>
>
>
> def __kill_focus(self, event):
> print "kill focuse"
>
> self.__check_for_unchanged_item()
> event.Skip()
>
> def __check_for_unchanged_item(self):
> text = self.edit_control.GetValue().strip()
> print "Text was ", text
> print "Text unchanged ", text == self.start_edit_text
>
> #if the text is unchanged, then delete the new node.
> if self.edit_node and text == self.start_edit_text:
> self.q.put( self.edit_node )
> self.edit_node =None
> wx.wxCallAfter(self.__delete_item)
>
> def __delete_item(self):
> while not self.q.empty():
> try:
> item = self.q.get_nowait()
> self.get_emr_tree().Delete(item)
> except Queue.Empty:
> break
>
> def __add_new_health_issue_to_record(self):
> print "add new health issue to record"
> pat = gmPatient.gmCurrentPatient()
> rec = pat.get_clinical_record()
> issue = rec.add_health_issue(
> self.get_emr_tree().GetItemText(self.edit_node).strip() )
> if not issue is None and isinstance(issue,
> gmEMRStructItems.cHealthIssue):
> self.get_emr_tree().SetPyData( self.edit_node, issue)
>
>
>
> def __add_new_episode_to_record(self):
> print "add new episode to record"
> pat = gmPatient.gmCurrentPatient()
> rec = pat.get_clinical_record()
> print "health_issue pk = ",
> self.get_browser().get_parent_EMR_item(self.edit_node).pk_obj
> print "text = ",
> self.get_emr_tree().GetItemText(self.edit_node).strip()
>
> episode = rec.add_episode(
> self.get_emr_tree().GetItemText(self.edit_node).strip(),
> self.get_browser().get_parent_EMR_item(self.edit_node).pk_obj )
>
> if not episode is None and isinstance(episode,
> gmEMRStructItems.cEpisode):
> self.get_emr_tree().SetPyData( self.edit_node, episode)
>
Index: gnumed/client/business/gmEMRStructItems.py
===================================================================
RCS file: /cvsroot/gnumed/gnumed/gnumed/client/business/gmEMRStructItems.py,v
retrieving revision 1.24
diff -r1.24 gmEMRStructItems.py
237a238,239
> #print "found episode on select = ", episode
>
243,244c245,253
< cmd = "insert into clin_episode (fk_patient, fk_health_issue,
description) values (%s, %s, %s)"
< queries.append((cmd, [id_patient, pk_health_issue, episode_name]))
---
>
> # meet constraint standalone episode
> if not pk_health_issue is None: id_patient = None
>
> cmd = "insert into clin_episode (fk_patient, fk_health_issue) values
> (%s, %s)"
> print cmd, id_patient, pk_health_issue
>
> queries.append((cmd, [id_patient, pk_health_issue ]))
>
249a259,299
> print "got msg", msg
> return (False, msg)
>
> pk_episode = result[0][0]
>
>
> import gmPatient, gmClinNarrative
> pat = gmPatient.gmCurrentPatient()
> rec = pat.get_clinical_record()
>
> pkEncounter = rec.get_active_encounter().pk_obj
>
> #this doesn't work and is hard to debug, because tracing doesn't go
> back to the sql statement and error
> #narrative = gmClinNarrative.create_clin_narrative(str(episode_name),
> 'a', pk_episode, pkEncounter)
> #narrative['is_aoe'] = True
> #narrative.save_payload()
>
> queries2=[]
>
>
> cmd = """
> insert into clin_narrative(fk_encounter, fk_episode , narrative,
> soap_cat, is_aoe) values (
> %s, %s, %s, %s, true)
> """
> queries2.append((cmd, [pkEncounter,pk_episode, str(episode_name), 'a']))
> print "insert is ", cmd, [pkEncounter, pk_episode, str(episode_name),
> 'a']
>
>
> cmd = "update clin_episode set fk_clin_narrative = (select
> currval('clin_narrative_pk_seq')) where pk=%s"
>
> queries2.append( (cmd, [ pk_episode]) )
>
> #print "cmd is " , cmd, narrative['pk'], pk_episode
>
> #queries2.append( (cmd, [ narrative.pk_obj , pk_episode] ) )
>
>
>
> result, msg = gmPG.run_commit('historica', queries2, True)
> if result is None:
> print "msg=", msg
250a301
>
252c303
< episode = cEpisode(aPK_obj = result[0][0])
---
> episode = cEpisode(aPK_obj = pk_episode)
255a307,308
>
>
- [Gnumed-devel] re: should these be committed?,
catmat <=