Wednesday, July 07, 2010

GNUmed plugin development - how to access the current patient

Chances are you want to access the data of the currently active patient in your plugin. There is an app for that (TM) . I mean there are some convenience functions for that. This is called middleware. No matter if the database ever changes. The way to access the data is abstracted and will remain stable.
from Gnumed.business import gmPerson

pat = gmPerson.gmCurrentPatient()
text = patient['firstnames']
text = patient['lastnames']
text = patient['dob']
text = patient['gender']
This should be pretty self explainatory. For convenience use patient['dob'].isoformat() for a string representation of the datetime object.

To work with the patient's emr you can access it like this:

emr = pat.get_emr()
Let's say you want to get the current episode and if none create one.

                if episode is None:
                        all_epis = emr.get_episodes()
                        # FIXME: what to do here ? probably create dummy episode
                        if len(all_epis) == 0:
                                episode = emr.add_episode(episode_name = _('Cardiac echo exam'), is_open = False)
                        else:
                                dlg = gmEMRStructWidgets.cEpisodeListSelectorDlg(parent = parent, id = -1, episodes = all_epis)
                                dlg.SetTitle(_('Select the episode under which to file the document ...'))
                                btn_pressed = dlg.ShowModal()
                                episode = dlg.get_selected_item_data(only_one = True)
                                dlg.Destroy()

                                if (btn_pressed == wx.ID_CANCEL) or (episode is None):
                                        if unlock_patient:
                                                pat.locked = False
                                        return None

No comments: