コード例 #1
0
    def save(self):
        """Save data into backend."""

        # fill progress_note for import
        progress_note = []
        aoe = ''
        rfe = ''
        has_rfe = False
        soap_lines_contents = self.GetValue()
        for line_content in soap_lines_contents.values():
            if line_content.text.strip() == '':
                continue
            progress_note.append({
                gmSOAPimporter.soap_bundle_SOAP_CAT_KEY:
                line_content.data.soap_cat,
                gmSOAPimporter.soap_bundle_TYPES_KEY:
                [],  # these types need to come from the editor
                gmSOAPimporter.soap_bundle_TEXT_KEY:
                line_content.text.rstrip()
            })
            if line_content.data.is_rfe:
                has_rfe = True
                rfe += line_content.text.rstrip()
            if line_content.data.soap_cat == 'a':
                aoe += line_content.text.rstrip()

        emr = self.__pat.emr

        # - new episode, must get name from narrative (or user)
        if (self.__problem is None) or (self.__problem['type'] == 'issue'):
            # work out episode name
            epi_name = ''
            if len(aoe) != 0:
                epi_name = aoe
            else:
                epi_name = rfe

            dlg = wx.TextEntryDialog(
                parent=self,
                message=_('Enter a descriptive name for this new problem:'),
                caption=_(
                    'Creating a problem (episode) to save the notelet under ...'
                ),
                defaultValue=epi_name.replace('\r', '//').replace('\n', '//'),
                style=wx.OK | wx.CANCEL | wx.CENTRE)
            decision = dlg.ShowModal()
            if decision != wx.ID_OK:
                return False

            epi_name = dlg.GetValue().strip()
            if epi_name == '':
                gmGuiHelpers.gm_show_error(
                    _('Cannot save a new problem without a name.'),
                    _('saving progress note'))
                return False

            # new unassociated episode
            new_episode = emr.add_episode(episode_name=epi_name[:45],
                                          pk_health_issue=None,
                                          is_open=True)

            if self.__problem is not None:
                issue = emr.problem2issue(self.__problem)
                if not gmEMRStructWidgets.move_episode_to_issue(
                        episode=new_episode,
                        target_issue=issue,
                        save_to_backend=True):
                    print("error moving episode to issue")

            epi_id = new_episode['pk_episode']
        else:
            epi_id = self.__problem['pk_episode']

        # set up clinical context in progress note
        encounter = emr.active_encounter
        staff_id = gmStaff.gmCurrentProvider()['pk_staff']
        clin_ctx = {
            gmSOAPimporter.soap_bundle_EPISODE_ID_KEY: epi_id,
            gmSOAPimporter.soap_bundle_ENCOUNTER_ID_KEY:
            encounter['pk_encounter'],
            gmSOAPimporter.soap_bundle_STAFF_ID_KEY: staff_id
        }
        for line in progress_note:
            line[gmSOAPimporter.soap_bundle_CLIN_CTX_KEY] = clin_ctx

        # dump progress note to backend
        importer = gmSOAPimporter.cSOAPImporter()
        if not importer.import_soap(progress_note):
            gmGuiHelpers.gm_show_error(_('Error saving progress note.'),
                                       _('saving progress note'))
            return False

        # dump embedded data to backend
        if not self.__embedded_data_holder.save():
            gmGuiHelpers.gm_show_error(_('Error saving embedded data.'),
                                       _('saving progress note'))
            return False
        self.__embedded_data_holder.clear()

        return True
コード例 #2
0
	def __create_new_episode(self, emr=None, episode_name_candidates=None):

		episode_name_candidates.append(self._TCTRL_episode_summary.GetValue().strip())
		for candidate in episode_name_candidates:
			if candidate is None:
				continue
			epi_name = candidate.strip().replace('\r', '//').replace('\n', '//')
			break

		if self.problem is None:
			msg = _(
				'Enter a short working name for this new problem\n'
				'(which will become a new, unassociated episode):\n'
			)
		else:
			issue = emr.problem2issue(self.problem)
			msg = _(
				'Enter a short working name for this new\n'
				'episode under the existing health issue\n'
				'\n'
				'"%s":\n'
			) % issue['description']

		dlg = wx.TextEntryDialog (
			self, msg,
			caption = _('Creating problem (episode) to save notelet under ...'),
			value = epi_name,
			style = wx.OK | wx.CANCEL | wx.CENTRE
		)
		decision = dlg.ShowModal()
		if decision != wx.ID_OK:
			return None

		epi_name = dlg.GetValue().strip()
		if epi_name == '':
			gmGuiHelpers.gm_show_error(_('Cannot save a new problem without a name.'), _('saving progress note'))
			return None

		# create episode
		new_episode = emr.add_episode (
			episode_name = epi_name[:45],
			pk_health_issue = None,
			is_open = True,
			allow_dupes = True		# this ensures we get a new episode even if a same-name one already exists
		)
		new_episode['summary'] = self._TCTRL_episode_summary.GetValue().strip()
		new_episode.save()

		if self.problem is not None:
			issue = emr.problem2issue(self.problem)
			if not gmEMRStructWidgets.move_episode_to_issue(episode = new_episode, target_issue = issue, save_to_backend = True):
				gmGuiHelpers.gm_show_warning (
					_(
						'The new episode:\n'
						'\n'
						' "%s"\n'
						'\n'
						'will remain unassociated despite the editor\n'
						'having been invoked from the health issue:\n'
						'\n'
						' "%s"'
					) % (
						new_episode['description'],
						issue['description']
					),
					_('saving progress note')
				)

		return new_episode
コード例 #3
0
ファイル: gmSOAPWidgets.py プロジェクト: ncqgm/gnumed
	def save(self):
		"""Save data into backend."""

		# fill progress_note for import
		progress_note = []
		aoe = ''
		rfe = ''
		has_rfe = False
		soap_lines_contents = self.GetValue()
		for line_content in soap_lines_contents.values():
			if line_content.text.strip() == '':
				continue
			progress_note.append ({
				gmSOAPimporter.soap_bundle_SOAP_CAT_KEY: line_content.data.soap_cat,
				gmSOAPimporter.soap_bundle_TYPES_KEY: [],		# these types need to come from the editor
				gmSOAPimporter.soap_bundle_TEXT_KEY: line_content.text.rstrip()
			})
			if line_content.data.is_rfe:
				has_rfe = True
				rfe += line_content.text.rstrip()
			if line_content.data.soap_cat == 'a':
				aoe += line_content.text.rstrip()

		emr = self.__pat.emr

		# - new episode, must get name from narrative (or user)
		if (self.__problem is None) or (self.__problem['type'] == 'issue'):
			# work out episode name
			epi_name = ''
			if len(aoe) != 0:
				epi_name = aoe
			else:
				epi_name = rfe

			dlg = wx.TextEntryDialog (
				self,
				_('Enter a descriptive name for this new problem:'),
				caption = _('Creating a problem (episode) to save the notelet under ...'),
				value = epi_name.replace('\r', '//').replace('\n', '//'),
				style = wx.OK | wx.CANCEL | wx.CENTRE
			)
			decision = dlg.ShowModal()
			if decision != wx.ID_OK:
				return False

			epi_name = dlg.GetValue().strip()
			if epi_name == '':
				gmGuiHelpers.gm_show_error(_('Cannot save a new problem without a name.'), _('saving progress note'))
				return False

			# new unassociated episode
			new_episode = emr.add_episode(episode_name = epi_name[:45], pk_health_issue = None, is_open = True)

			if self.__problem is not None:
				issue = emr.problem2issue(self.__problem)
				if not gmEMRStructWidgets.move_episode_to_issue(episode = new_episode, target_issue = issue, save_to_backend = True):
					print("error moving episode to issue")

			epi_id = new_episode['pk_episode']
		else:
			epi_id = self.__problem['pk_episode']

		# set up clinical context in progress note
		encounter = emr.active_encounter
		staff_id = gmStaff.gmCurrentProvider()['pk_staff']
		clin_ctx = {
			gmSOAPimporter.soap_bundle_EPISODE_ID_KEY: epi_id,
			gmSOAPimporter.soap_bundle_ENCOUNTER_ID_KEY: encounter['pk_encounter'],
			gmSOAPimporter.soap_bundle_STAFF_ID_KEY: staff_id
		}
		for line in progress_note:
			line[gmSOAPimporter.soap_bundle_CLIN_CTX_KEY] = clin_ctx

		# dump progress note to backend
		importer = gmSOAPimporter.cSOAPImporter()
		if not importer.import_soap(progress_note):
			gmGuiHelpers.gm_show_error(_('Error saving progress note.'), _('saving progress note'))
			return False

		# dump embedded data to backend
		if not self.__embedded_data_holder.save():
			gmGuiHelpers.gm_show_error (
				_('Error saving embedded data.'),
				_('saving progress note')
			)
			return False
		self.__embedded_data_holder.clear()

		return True