Exemplo n.º 1
0
def create_new_person(parent=None, activate=False):

    if parent is None:
        parent = wx.GetApp().GetTopWindow()

    if activate:  # meaning we will switch away from the current patient if any
        msg = _('Before creating a new person review the encounter details\n'
                'of the patient you just worked on:\n')
        gmEncounterWidgets.sanity_check_encounter_of_active_patient(
            parent=parent, msg=msg)

        msg = _(
            'Edit the current encounter of the patient you are ABOUT TO LEAVE:'
        )

    def_region = gmCfgDB.get4user(
        option='person.create.default_region',
        workplace=gmPraxis.gmCurrentPraxisBranch().active_workplace)
    def_country = None

    if def_region is None:
        def_country = gmCfgDB.get4user(
            option='person.create.default_country',
            workplace=gmPraxis.gmCurrentPraxisBranch().active_workplace)
    else:
        countries = gmDemographicRecord.get_country_for_region(
            region=def_region)
        if len(countries) == 1:
            def_country = countries[0]['code_country']

    ea = cNewPatientEAPnl(parent, -1, country=def_country, region=def_region)
    dlg = gmEditArea.cGenericEditAreaDlg2(parent,
                                          -1,
                                          edit_area=ea,
                                          single_entry=True)
    dlg.SetTitle(_('Adding new person'))
    ea._PRW_lastname.SetFocus()
    result = dlg.ShowModal()
    pat = ea.data
    dlg.DestroyLater()

    if result != wx.ID_OK:
        return False

    _log.debug('created new person [%s]', pat.ID)

    if activate:
        from Gnumed.wxpython import gmPatSearchWidgets
        gmPatSearchWidgets.set_active_patient(patient=pat)

    gmDispatcher.send(signal='display_widget',
                      name='gmNotebookedPatientEditionPlugin')

    return True
Exemplo n.º 2
0
    def __init__(self, *args, **kwargs):

        try:
            self.problem = kwargs['problem']
            del kwargs['problem']
        except KeyError:
            self.problem = None

        wxgProgressNotesEAPnl.wxgProgressNotesEAPnl.__init__(
            self, *args, **kwargs)

        self.__use_soap_fields = gmCfgDB.get4user(
            option='horstspace.soap_editor.use_one_field_per_soap_category',
            workplace=gmPraxis.gmCurrentPraxisBranch().active_workplace,
            default=True)

        self.__soap_fields = [
            self._TCTRL_Soap, self._TCTRL_sOap, self._TCTRL_soAp,
            self._TCTRL_soaP
        ]

        self.__init_ui()
        self.__register_interests()

        return
Exemplo n.º 3
0
    def __get_lab_panel(self):
        # get panel to use
        pk_panel = gmCfgDB.get4user(
            option=u'horstspace.top_panel.lab_panel',
            workplace=gmPraxis.gmCurrentPraxisBranch().active_workplace,
        )
        if pk_panel is None:
            return None

        try:
            panel = gmPathLab.cTestPanel(aPK_obj=pk_panel)
        except gmExceptions.ConstructorError:
            _log.exception('cannot load configured test panel')
            panel = None
        if panel is not None:
            return panel

        _log.error(
            'Cannot load test panel [#%s] configured for patient pane (horstspace.top_panel.lab_panel).',
            pk_panel)
        gmGuiHelpers.gm_show_error(
            title=_('GNUmed startup'),
            error=_('Cannot load test panel [#%s] configured\n'
                    'for the top pane with option\n'
                    '\n'
                    ' <horstspace.top_panel.lab_panel>\n'
                    '\n'
                    'Please reconfigure.') % pk_panel)
        return None
Exemplo n.º 4
0
 def new():
     enc_type = gmCfgDB.get4user(
         option='encounter.default_type',
         workplace=gmPraxis.gmCurrentPraxisBranch().active_workplace)
     if enc_type is None:
         enc_type = gmEMRStructItems.get_most_commonly_used_encounter_type()
     if enc_type is None:
         enc_type = 'in surgery'
     enc = gmEMRStructItems.create_encounter(fk_patient=patient.ID,
                                             enc_type=enc_type)
     saved = edit_encounter(parent=parent, encounter=enc)
     if saved:
         return True
     gmEMRStructItems.delete_encounter(pk_encounter=enc['pk_encounter'])
     return False
Exemplo n.º 5
0
def sanity_check_encounter_of_active_patient(parent=None, msg=None):

    # FIXME: should consult a centralized security provider
    # secretaries cannot edit encounters
    if gmStaff.gmCurrentProvider()['role'] == 'secretary':
        return True

    pat = gmPerson.gmCurrentPatient()
    if not pat.connected:
        return True

    check_enc = gmCfgDB.get4user(
        option='encounter.show_editor_before_patient_change',
        workplace=gmPraxis.gmCurrentPraxisBranch().active_workplace,
        default=True  # True: if needed, not always unconditionally
    )

    if not check_enc:
        return True

    emr = pat.emr
    enc = emr.active_encounter
    # did we add anything to the EMR ?
    has_narr = enc.has_narrative()
    has_docs = enc.has_documents()
    if (not has_narr) and (not has_docs):
        return True

    empty_aoe = (gmTools.coalesce(enc['assessment_of_encounter'],
                                  '').strip() == '')
    zero_duration = (enc['last_affirmed'] == enc['started'])
    # all is well anyway
    if (not empty_aoe) and (not zero_duration):
        return True

    if zero_duration:
        enc['last_affirmed'] = pydt.datetime.now(
            tz=gmDateTime.gmCurrentLocalTimezone)
    # no narrative, presumably only import of docs and done
    if not has_narr:
        if empty_aoe:
            enc['assessment_of_encounter'] = _('only documents added')
        enc['pk_type'] = gmEMRStructItems.get_encounter_type(
            description='chart review')[0]['pk']
        # "last_affirmed" should be latest modified_at of relevant docs but that's a lot more involved
        enc.save_payload()
        return True

    # does have narrative
    if empty_aoe:
        # - work out suitable default
        epis = emr.get_episodes_by_encounter()
        if len(epis) > 0:
            enc['assessment_of_encounter'] = '; '.join(
                [e['description'] for e in epis])
    enc.save_payload()
    if msg is None:
        msg = _(
            'Edit the encounter details of the active patient before moving on:'
        )
    if parent is None:
        parent = wx.GetApp().GetTopWindow()
    _log.debug('sanity-check editing encounter [%s] for patient [%s]',
               enc['pk_encounter'], enc['pk_patient'])
    edit_encounter(parent=parent, encounter=enc, msg=msg)
    return True
Exemplo n.º 6
0
 def _on_post_patient_selection(self, **kwargs):
     default_plugin = gmCfgDB.get4user(
         option='patient_search.plugin_to_raise_after_search',
         workplace=gmPraxis.gmCurrentPraxisBranch().active_workplace,
         default='gmPatientOverviewPlugin')
     gmDispatcher.send(signal='display_widget', name=default_plugin)
Exemplo n.º 7
0
def edit_visual_progress_note(filename=None,
                              episode=None,
                              discard_unmodified=False,
                              doc_part=None,
                              health_issue=None):
    """This assumes <filename> contains an image which can be handled by the configured image editor."""

    if doc_part is not None:
        filename = doc_part.save_to_file()
        if filename is None:
            gmDispatcher.send(
                signal='statustext',
                msg=_('Cannot export visual progress note to file.'))
            return None

    editor = gmCfgDB.get4user(
        option='external.tools.visual_soap_editor_cmd',
        workplace=gmPraxis.gmCurrentPraxisBranch().active_workplace)

    if editor is None:
        _log.error(
            'no editor for visual progress notes configured, trying mimetype editor'
        )
        gmDispatcher.send(
            signal='statustext',
            msg=_('Editor for visual progress note not configured.'),
            beep=False)
        mimetype = gmMimeLib.guess_mimetype(filename=filename)
        editor = gmMimeLib.get_editor_cmd(mimetype=mimetype, filename=filename)
        if editor is None:
            _log.error(
                'no editor for mimetype <%s> configured, trying mimetype viewer',
                mimetype)
            success, msg = gmMimeLib.call_viewer_on_file(aFile=filename,
                                                         block=True)
            if not success:
                _log.debug('problem running mimetype <%s> viewer', mimetype)
                gmGuiHelpers.gm_show_error(
                    _('There is no editor for visual progress notes defined.\n'
                      'Also, there is no editor command defined for the file type\n'
                      '\n'
                      ' [%s].\n'
                      '\n'
                      'Therefor GNUmed attempted to at least *show* this\n'
                      'visual progress note. That failed as well, however:\n'
                      '\n'
                      '%s') % (mimetype, msg),
                    _('Editing visual progress note'))
                editor = configure_visual_progress_note_editor()
                if editor is None:
                    gmDispatcher.send(
                        signal='statustext',
                        msg=_(
                            'Editor for visual progress note not configured.'),
                        beep=True)
                    return None

    if '%(img)s' in editor:
        editor = editor % {'img': filename}
    else:
        editor = '%s %s' % (editor, filename)

    if discard_unmodified:
        original_stat = os.stat(filename)
        original_md5 = gmTools.file2md5(filename)

    success = gmShellAPI.run_command_in_shell(editor, blocking=True)
    if not success:
        success, msg = gmMimeLib.call_viewer_on_file(aFile=filename,
                                                     block=True)
        if not success:
            _log.debug('problem running mimetype <%s> viewer', mimetype)
            gmGuiHelpers.gm_show_error(
                _('There was a problem running the editor\n'
                  '\n'
                  ' [%s] (%s)\n'
                  '\n'
                  'on the visual progress note.\n'
                  '\n'
                  'Therefor GNUmed attempted to at least *show* it.\n'
                  'That failed as well, however:\n'
                  '\n'
                  '%s') % (editor, mimetype, msg),
                _('Editing visual progress note'))
            editor = configure_visual_progress_note_editor()
            if editor is None:
                gmDispatcher.send(
                    signal='statustext',
                    msg=_('Editor for visual progress note not configured.'),
                    beep=True)
        return None

    try:
        open(filename, 'r').close()
    except Exception:
        _log.exception('problem accessing visual progress note file [%s]',
                       filename)
        gmGuiHelpers.gm_show_error(
            _('There was a problem reading the visual\n'
              'progress note from the file:\n'
              '\n'
              ' [%s]\n'
              '\n') % filename, _('Saving visual progress note'))
        return None

    if discard_unmodified:
        modified_stat = os.stat(filename)
        # same size ?
        if original_stat.st_size == modified_stat.st_size:
            modified_md5 = gmTools.file2md5(filename)
            # same hash ?
            if original_md5 == modified_md5:
                _log.debug('visual progress note (template) not modified')
                # ask user to decide
                msg = _(
                    'You either created a visual progress note from a template\n'
                    'in the database (rather than from a file on disk) or you\n'
                    'edited an existing visual progress note.\n'
                    '\n'
                    'The template/original was not modified at all, however.\n'
                    '\n'
                    'Do you still want to save the unmodified image as a\n'
                    'visual progress note into the EMR of the patient ?\n')
                save_unmodified = gmGuiHelpers.gm_show_question(
                    msg, _('Saving visual progress note'))
                if not save_unmodified:
                    _log.debug('user discarded unmodified note')
                    return

    if doc_part is not None:
        _log.debug('updating visual progress note')
        doc_part.update_data_from_file(fname=filename)
        doc_part.set_reviewed(technically_abnormal=False,
                              clinically_relevant=True)
        return None

    if not isinstance(episode, gmEMRStructItems.cEpisode):
        if episode is None:
            episode = _('visual progress notes')
        pat = gmPerson.gmCurrentPatient()
        emr = pat.emr
        episode = emr.add_episode(episode_name=episode.strip(),
                                  pk_health_issue=health_issue,
                                  is_open=False)

    doc = gmDocumentWidgets.save_file_as_new_document(
        filename=filename,
        document_type=gmDocuments.DOCUMENT_TYPE_VISUAL_PROGRESS_NOTE,
        episode=episode,
        unlock_patient=False,
        pk_org_unit=gmPraxis.gmCurrentPraxisBranch()['pk_org_unit'],
        date_generated=gmDateTime.pydt_now_here())
    doc.set_reviewed(technically_abnormal=False, clinically_relevant=True)

    return doc