Exemplo n.º 1
0
	def __refresh_inbox(self, patient=None):
		list_items = []
		list_data = []
		highlight_list = []
		line_idx = -1

		overdue_messages = patient.overdue_messages
		if len(overdue_messages) > 0:
			highlight_list.extend(range(len(overdue_messages)))
		for msg in overdue_messages:
			line_idx += 1
			list_items.append(_('overdue %s: %s') % (
				gmDateTime.format_interval_medically(msg['interval_due']),
				gmTools.coalesce(msg['comment'], '?')
			))
			list_data.append(msg)

		for msg in patient.get_messages(order_by = 'due_date NULLS LAST, importance DESC, received_when DESC'):
			# already displayed above ?
			if msg['is_overdue']:
				continue
			# not relevant anymore ?
			if msg['is_expired']:
				continue
			line_idx += 1
			if msg['due_date'] is None:
				label = '%s%s' % (
					msg['l10n_type'],
					gmTools.coalesce(msg['comment'], '', ': %s')
				)
			else:
				label = _('due in %s%s') % (
					gmDateTime.format_interval_medically(msg['interval_due']),
					gmTools.coalesce(msg['comment'], '', ': %s')
				)
			list_items.append(label)
			list_data.append(msg)

		pk_enc = patient.emr.active_encounter['pk_encounter']
		for hint in patient._get_dynamic_hints(pk_encounter = pk_enc):
			line_idx += 1
			list_items.append(hint['title'])
			list_data.append(hint)
			if hint['highlight_as_priority']:
				highlight_list.append(line_idx)

		hints = patient.suppressed_hints
		if len(hints) > 0:
			list_items.append((_("suppr'd (%s):") % len(hints)) + ' ' + ','.join([h['title'][:7] + gmTools.u_ellipsis for h in hints]))
			list_data.append(_('Suppressed hints:\n') + '\n'.join(['%s: %s' % (hints.index(h) + 1, h['title']) for h in hints]))

		self._LCTRL_inbox.set_string_items(items = list_items)
		self._LCTRL_inbox.set_data(data = list_data)

		for idx in highlight_list:
			self._LCTRL_inbox.SetItemTextColour(idx, wx.Colour('RED'))
Exemplo n.º 2
0
	def __refresh_inbox(self, patient=None):
		list_items = []
		list_data = []
		highlight_list = []
		line_idx = -1

		overdue_messages = patient.overdue_messages
		if len(overdue_messages) > 0:
			highlight_list.extend(range(len(overdue_messages)))
		for msg in overdue_messages:
			line_idx += 1
			list_items.append(_('overdue %s: %s') % (
				gmDateTime.format_interval_medically(msg['interval_due']),
				gmTools.coalesce(msg['comment'], '?')
			))
			list_data.append(msg)

		for msg in patient.get_messages(order_by = 'due_date NULLS LAST, importance DESC, received_when DESC'):
			# already displayed above ?
			if msg['is_overdue']:
				continue
			# not relevant anymore ?
			if msg['is_expired']:
				continue
			line_idx += 1
			if msg['due_date'] is None:
				label = '%s%s' % (
					msg['l10n_type'],
					gmTools.coalesce(msg['comment'], '', ': %s')
				)
			else:
				label = _('due in %s%s') % (
					gmDateTime.format_interval_medically(msg['interval_due']),
					gmTools.coalesce(msg['comment'], '', ': %s')
				)
			list_items.append(label)
			list_data.append(msg)

		pk_enc = patient.emr.active_encounter['pk_encounter']
		for hint in patient._get_dynamic_hints(pk_encounter = pk_enc):
			line_idx += 1
			list_items.append(hint['title'])
			list_data.append(hint)
			if hint['highlight_as_priority']:
				highlight_list.append(line_idx)

		hints = patient.suppressed_hints
		if len(hints) > 0:
			list_items.append((_("suppr'd (%s):") % len(hints)) + ' ' + ','.join([h['title'][:7] + gmTools.u_ellipsis for h in hints]))
			list_data.append(_('Suppressed hints:\n') + '\n'.join(['%s: %s' % (hints.index(h) + 1, h['title']) for h in hints]))

		self._LCTRL_inbox.set_string_items(items = list_items)
		self._LCTRL_inbox.set_data(data = list_data)

		for idx in highlight_list:
			self._LCTRL_inbox.SetItemTextColour(idx, wx.Colour('RED'))
Exemplo n.º 3
0
	def __refresh_results(self, patient=None):
		list_items = []
		list_data = []

		emr = patient.get_emr()
		most_recent = emr.get_most_recent_results(no_of_results = 1)
		if most_recent is None:
			self._LCTRL_results.set_string_items(items = [])
			self._LCTRL_results.set_data(data = [])
			return

		now = gmDateTime.pydt_now_here()
		list_items.append(_('Latest: %s ago (%s %s%s%s%s)') % (
			gmDateTime.format_interval_medically(now - most_recent['clin_when']),
			most_recent['unified_abbrev'],
			most_recent['unified_val'],
			gmTools.coalesce(most_recent['val_unit'], u'', u' %s'),
			gmTools.coalesce(most_recent['abnormality_indicator'], u'', u' %s'),
			gmTools.bool2subst(most_recent['reviewed'], u'', (u' %s' % gmTools.u_writing_hand))
		))
		list_data.append(most_recent)
		most_recent_needs_red = False
		if most_recent.is_considered_abnormal is True:
			if most_recent['is_clinically_relevant']:
				most_recent_needs_red = True

		unsigned = emr.get_unsigned_results(order_by = u"(trim(coalesce(abnormality_indicator), '') <> '') DESC NULLS LAST, unified_abbrev")
		no_of_reds = 0
		for result in unsigned:
			if result['pk_test_result'] == most_recent['pk_test_result']:
				continue
			if result['abnormality_indicator'] is not None:
				if result['abnormality_indicator'].strip() != u'':
					no_of_reds += 1
			list_items.append(_('%s %s%s%s (%s ago, %s)') % (
				result['unified_abbrev'],
				result['unified_val'],
				gmTools.coalesce(result['val_unit'], u'', u' %s'),
				gmTools.coalesce(result['abnormality_indicator'], u'', u' %s'),
				gmDateTime.format_interval_medically(gmDateTime.pydt_now_here() - result['clin_when']),
				gmTools.u_writing_hand
			))
			list_data.append(result)

		self._LCTRL_results.set_string_items(items = list_items)
		self._LCTRL_results.set_data(data = list_data)

		if most_recent_needs_red:
			self._LCTRL_results.SetItemTextColour(0, wx.NamedColour('RED'))
		if no_of_reds > 0:
			for idx in range(1, no_of_reds + 1):
				self._LCTRL_results.SetItemTextColour(idx, wx.NamedColour('RED'))
Exemplo n.º 4
0
	def __refresh_results(self, patient=None):
		list_items = []
		list_data = []

		emr = patient.emr
		most_recent = emr.get_most_recent_results(no_of_results = 1)
		if most_recent is None:
			self._LCTRL_results.set_string_items(items = [])
			self._LCTRL_results.set_data(data = [])
			return

		now = gmDateTime.pydt_now_here()
		list_items.append(_('Latest: %s ago (%s %s%s%s%s)') % (
			gmDateTime.format_interval_medically(now - most_recent['clin_when']),
			most_recent['unified_abbrev'],
			most_recent['unified_val'],
			gmTools.coalesce(most_recent['val_unit'], '', ' %s'),
			gmTools.coalesce(most_recent['abnormality_indicator'], '', ' %s'),
			gmTools.bool2subst(most_recent['reviewed'], '', (' %s' % gmTools.u_writing_hand))
		))
		list_data.append(most_recent)
		most_recent_needs_red = False
		if most_recent.is_considered_abnormal is True:
			if most_recent['is_clinically_relevant']:
				most_recent_needs_red = True

		unsigned = emr.get_unsigned_results(order_by = "(trim(coalesce(abnormality_indicator), '') <> '') DESC NULLS LAST, unified_abbrev")
		no_of_reds = 0
		for result in unsigned:
			if result['pk_test_result'] == most_recent['pk_test_result']:
				continue
			if result['abnormality_indicator'] is not None:
				if result['abnormality_indicator'].strip() != '':
					no_of_reds += 1
			list_items.append(_('%s %s%s%s (%s ago, %s)') % (
				result['unified_abbrev'],
				result['unified_val'],
				gmTools.coalesce(result['val_unit'], '', ' %s'),
				gmTools.coalesce(result['abnormality_indicator'], '', ' %s'),
				gmDateTime.format_interval_medically(gmDateTime.pydt_now_here() - result['clin_when']),
				gmTools.u_writing_hand
			))
			list_data.append(result)

		self._LCTRL_results.set_string_items(items = list_items)
		self._LCTRL_results.set_data(data = list_data)

		if most_recent_needs_red:
			self._LCTRL_results.SetItemTextColour(0, wx.Colour('RED'))
		if no_of_reds > 0:
			for idx in range(1, no_of_reds + 1):
				self._LCTRL_results.SetItemTextColour(idx, wx.Colour('RED'))
Exemplo n.º 5
0
	def __refresh_inbox(self, patient=None):
		list_items = []
		list_data = []

		overdue_messages = patient.overdue_messages
		no_of_overdues = len(overdue_messages)
		for msg in overdue_messages:
			list_items.append(_('overdue %s: %s') % (
				gmDateTime.format_interval_medically(msg['interval_due']),
				gmTools.coalesce(msg['comment'], u'?')
			))
			list_data.append(msg)

		for msg in patient.get_messages(order_by = u'due_date NULLS LAST, importance DESC, received_when DESC'):
			# already displayed above ?
			if msg['is_overdue']:
				continue
			# not relevant anymore ?
			if msg['is_expired']:
				continue
			if msg['due_date'] is None:
				label = u'%s%s' % (
					msg['l10n_type'],
					gmTools.coalesce(msg['comment'], u'', u': %s')
				)
			else:
				label = _('due in %s%s') % (
					gmDateTime.format_interval_medically(msg['interval_due']),
					gmTools.coalesce(msg['comment'], u'', u': %s')
				)

			list_items.append(label)
			list_data.append(msg)

		for hint in patient.dynamic_hints:
			list_items.append(hint['title'])
			list_data.append(hint)

		hints = patient.suppressed_hints
		if len(hints) > 0:
			list_items.append(_("suppr'd:") + u' ' + u','.join([h['title'][:7] + gmTools.u_ellipsis for h in hints]))
			list_data.append(_('Suppressed hints:\n') + u'\n'.join([h['title'] for h in hints]))

		self._LCTRL_inbox.set_string_items(items = list_items)
		self._LCTRL_inbox.set_data(data = list_data)

		if no_of_overdues > 0:
			for idx in range(no_of_overdues):
				self._LCTRL_inbox.SetItemTextColour(idx, wx.NamedColour('RED'))
Exemplo n.º 6
0
	def format(self, with_patient=True):
		tt = '%s: %s%s\n' % (
			gmDateTime.pydt_strftime (
				self._payload[self._idx['received_when']],
				format = '%A, %Y %b %d, %H:%M',
				accuracy = gmDateTime.acc_minutes
			),
			gmTools.bool2subst(self._payload[self._idx['is_virtual']], _('virtual message'), _('message')),
			gmTools.coalesce(self._payload[self._idx['pk_inbox_message']], '', ' #%s ')
		)

		tt += '%s: %s\n' % (
			self._payload[self._idx['l10n_category']],
			self._payload[self._idx['l10n_type']]
		)

		tt += '%s %s %s\n' % (
			self._payload[self._idx['modified_by']],
			gmTools.u_arrow2right,
			gmTools.coalesce(self._payload[self._idx['provider']], _('everyone'))
		)

		tt += '\n%s%s%s\n\n' % (
			gmTools.u_left_double_angle_quote,
			self._payload[self._idx['comment']],
			gmTools.u_right_double_angle_quote
		)

		if with_patient and (self._payload[self._idx['pk_patient']] is not None):
			tt += _('Patient: %s, %s%s %s   #%s\n' % (
				self._payload[self._idx['lastnames']],
				self._payload[self._idx['firstnames']],
				gmTools.coalesce(self._payload[self._idx['l10n_gender']], '', ' (%s)'),
				gmDateTime.pydt_strftime(self._payload[self._idx['dob']], '%Y %b %d', none_str = ''),
				self._payload[self._idx['pk_patient']]
			))

		if self._payload[self._idx['due_date']] is not None:
			if self._payload[self._idx['is_overdue']]:
				template = _('Due: %s (%s ago)\n')
			else:
				template = _('Due: %s (in %s)\n')
			tt += template % (
				gmDateTime.pydt_strftime(self._payload[self._idx['due_date']], '%Y %b %d'),
				gmDateTime.format_interval_medically(self._payload[self._idx['interval_due']])
			)

		if self._payload[self._idx['expiry_date']] is not None:
			if self._payload[self._idx['is_expired']]:
				template = _('Expired: %s\n')
			else:
				template = _('Expires: %s\n')
			tt += template % gmDateTime.pydt_strftime(self._payload[self._idx['expiry_date']], '%Y %b %d')

		if self._payload[self._idx['data']] is not None:
			tt += self._payload[self._idx['data']][:150]
			if len(self._payload[self._idx['data']]) > 150:
				tt += gmTools.u_ellipsis

		return tt
Exemplo n.º 7
0
	def _on_get_list_tooltip(self, entry):

		dob = gmTools.coalesce (
			gmTools.coalesce(entry['dob'], '', function_initial = ('strftime', '%d %b %Y')),
			'',
			' (%s)'
		)

		tt = _(
			'%s patients are waiting.\n'
			'\n'
			'Doubleclick to activate (entry will stay in list).'
		) % self._LCTRL_patients.GetItemCount()

		tt += _(
			'\n'
			'%s\n'
			'Patient: %s%s\n'
			'%s'
			'Urgency: %s\n'
			'Time: %s\n'
			'%s'
		) % (
			gmTools.u_box_horiz_single * 50,
			'%s, %s (%s)' % (entry['lastnames'], entry['firstnames'], entry['l10n_gender']),
			dob,
			gmTools.coalesce(entry['waiting_zone'], '', _('Zone: %s\n')),
			entry['urgency'],
			gmDateTime.format_interval_medically(entry['waiting_time']),
			gmTools.coalesce(entry['comment'], '', '\n%s')
		)

		return tt
Exemplo n.º 8
0
	def _on_leave_year_noted(self, *args, **kwargs):

		if not self._PRW_year_noted.IsModified():
			return True

		year_noted = self._PRW_year_noted.GetData()

		if year_noted is None:
			if self._PRW_year_noted.GetValue().strip() == '':
				self._PRW_year_noted.display_as_valid(True)
				return True
			self._PRW_year_noted.display_as_valid(False)
			return True

		year_noted = year_noted.get_pydt()

		if year_noted >= pydt.datetime.now(tz = year_noted.tzinfo):
			self.status_message = _('Condition diagnosed in the future.')
			self._PRW_year_noted.display_as_valid(False)
			return True

		self._PRW_year_noted.display_as_valid(True)

		pat = gmPerson.gmCurrentPatient()
		if pat['dob'] is not None:
			issue_age = year_noted - pat['dob']
			age_str = gmDateTime.format_interval_medically(interval = issue_age)
			self._PRW_age_noted.SetText(age_str, issue_age, True)

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

		if not self._PRW_year_noted.IsModified():
			return True

		year_noted = self._PRW_year_noted.GetData()

		if year_noted is None:
			if self._PRW_year_noted.GetValue().strip() == '':
				self._PRW_year_noted.display_as_valid(True)
				return True
			self._PRW_year_noted.display_as_valid(False)
			return True

		year_noted = year_noted.get_pydt()

		if year_noted >= pydt.datetime.now(tz = year_noted.tzinfo):
			self.StatusText = _('Condition diagnosed in the future.')
			self._PRW_year_noted.display_as_valid(False)
			return True

		self._PRW_year_noted.display_as_valid(True)

		pat = gmPerson.gmCurrentPatient()
		if pat['dob'] is not None:
			issue_age = year_noted - pat['dob']
			age_str = gmDateTime.format_interval_medically(interval = issue_age)
			self._PRW_age_noted.SetText(age_str, issue_age, True)

		return True
Exemplo n.º 10
0
	def _on_get_list_tooltip(self, entry):

		dob = gmTools.coalesce (
			gmTools.coalesce(entry['dob'], '', function_initial = ('strftime', '%d %b %Y')),
			'',
			' (%s)'
		)

		tt = _(
			'%s patients are waiting.\n'
			'\n'
			'Doubleclick to activate (entry will stay in list).'
		) % self._LCTRL_patients.GetItemCount()

		tt += _(
			'\n'
			'%s\n'
			'Patient: %s%s\n'
			'%s'
			'Urgency: %s\n'
			'Time: %s\n'
			'%s'
		) % (
			gmTools.u_box_horiz_single * 50,
			'%s, %s (%s)' % (entry['lastnames'], entry['firstnames'], entry['l10n_gender']),
			dob,
			gmTools.coalesce(entry['waiting_zone'], '', _('Zone: %s\n')),
			entry['urgency'],
			gmDateTime.format_interval_medically(entry['waiting_time']),
			gmTools.coalesce(entry['comment'], '', '\n%s')
		)

		return tt
Exemplo n.º 11
0
    def format(self, with_patient=True):
        tt = '%s: %s%s\n' % (
            gmDateTime.pydt_strftime(self._payload[self._idx['received_when']],
                                     format='%A, %Y %b %d, %H:%M',
                                     accuracy=gmDateTime.acc_minutes),
            gmTools.bool2subst(self._payload[self._idx['is_virtual']],
                               _('virtual message'), _('message')),
            gmTools.coalesce(self._payload[self._idx['pk_inbox_message']], '',
                             ' #%s '))

        tt += '%s: %s\n' % (self._payload[self._idx['l10n_category']],
                            self._payload[self._idx['l10n_type']])

        tt += '%s %s %s\n' % (
            self._payload[self._idx['modified_by']], gmTools.u_arrow2right,
            gmTools.coalesce(self._payload[self._idx['provider']],
                             _('everyone')))

        tt += '\n%s%s%s\n\n' % (gmTools.u_left_double_angle_quote,
                                self._payload[self._idx['comment']],
                                gmTools.u_right_double_angle_quote)

        if with_patient and (self._payload[self._idx['pk_patient']]
                             is not None):
            tt += _(
                'Patient: %s, %s%s %s   #%s\n' %
                (self._payload[self._idx['lastnames']],
                 self._payload[self._idx['firstnames']],
                 gmTools.coalesce(self._payload[self._idx['l10n_gender']], '',
                                  ' (%s)'),
                 gmDateTime.pydt_strftime(
                     self._payload[self._idx['dob']], '%Y %b %d',
                     none_str=''), self._payload[self._idx['pk_patient']]))

        if self._payload[self._idx['due_date']] is not None:
            if self._payload[self._idx['is_overdue']]:
                template = _('Due: %s (%s ago)\n')
            else:
                template = _('Due: %s (in %s)\n')
            tt += template % (gmDateTime.pydt_strftime(
                self._payload[self._idx['due_date']], '%Y %b %d'),
                              gmDateTime.format_interval_medically(
                                  self._payload[self._idx['interval_due']]))

        if self._payload[self._idx['expiry_date']] is not None:
            if self._payload[self._idx['is_expired']]:
                template = _('Expired: %s\n')
            else:
                template = _('Expires: %s\n')
            tt += template % gmDateTime.pydt_strftime(
                self._payload[self._idx['expiry_date']], '%Y %b %d')

        if self._payload[self._idx['data']] is not None:
            tt += self._payload[self._idx['data']][:150]
            if len(self._payload[self._idx['data']]) > 150:
                tt += gmTools.u_ellipsis

        return tt
Exemplo n.º 12
0
 def refresh(lctrl):
     reminders = gmProviderInbox.get_reminders(pk_patient=patient)
     items = [[
         gmTools.bool2subst(r['is_overdue'], _('overdue for %s'),
                            _('due in %s')) %
         gmDateTime.format_interval_medically(r['interval_due']),
         r['comment'], r['pk_inbox_message']
     ] for r in reminders]
     lctrl.set_string_items(items)
     lctrl.set_data(reminders)
Exemplo n.º 13
0
	def __refresh_results(self, patient=None):

		emr = patient.emr
		most_recent = emr.get_most_recent_results_for_patient()
		if len(most_recent) == 0:
			self._LCTRL_results.set_string_items(items = [])
			self._LCTRL_results.set_data(data = [])
			return
		most_recent = most_recent[0]

		list_items = []
		list_data = []
		now = gmDateTime.pydt_now_here()

		list_items.append(_('Most recent lab work: %s ago (%s)') % (
			gmDateTime.format_interval_medically(now - most_recent['clin_when']),
			gmDateTime.pydt_strftime(most_recent['clin_when'], format = '%Y %b %d')
		))
		list_data.append(most_recent)

		unsigned = emr.get_unsigned_results(order_by = "(trim(coalesce(abnormality_indicator), '') <> '') DESC NULLS LAST, unified_abbrev")
		no_of_reds = 0
		for result in unsigned:
			if result['abnormality_indicator'] is not None:
				if result['abnormality_indicator'].strip() != '':
					no_of_reds += 1
			list_items.append(_('%s %s%s%s (%s ago, %s)') % (
				result['unified_abbrev'],
				result['unified_val'],
				gmTools.coalesce(result['val_unit'], '', ' %s'),
				gmTools.coalesce(result['abnormality_indicator'], '', ' %s'),
				gmDateTime.format_interval_medically(gmDateTime.pydt_now_here() - result['clin_when']),
				gmTools.u_writing_hand
			))
			list_data.append(result)

		self._LCTRL_results.set_string_items(items = list_items)
		self._LCTRL_results.set_data(data = list_data)

		if no_of_reds > 0:
			for idx in range(1, no_of_reds + 1):
				self._LCTRL_results.SetItemTextColour(idx, wx.Colour('RED'))
Exemplo n.º 14
0
	def __refresh_results(self, patient=None):

		emr = patient.emr
		most_recent = emr.get_most_recent_results_for_patient()
		if len(most_recent) == 0:
			self._LCTRL_results.set_string_items(items = [])
			self._LCTRL_results.set_data(data = [])
			return
		most_recent = most_recent[0]

		list_items = []
		list_data = []
		now = gmDateTime.pydt_now_here()

		list_items.append(_('Most recent lab work: %s ago (%s)') % (
			gmDateTime.format_interval_medically(now - most_recent['clin_when']),
			gmDateTime.pydt_strftime(most_recent['clin_when'], format = '%Y %b %d')
		))
		list_data.append(most_recent)

		unsigned = emr.get_unsigned_results(order_by = "(trim(coalesce(abnormality_indicator), '') <> '') DESC NULLS LAST, unified_abbrev")
		no_of_reds = 0
		for result in unsigned:
			if result['abnormality_indicator'] is not None:
				if result['abnormality_indicator'].strip() != '':
					no_of_reds += 1
			list_items.append(_('%s %s%s%s (%s ago, %s)') % (
				result['unified_abbrev'],
				result['unified_val'],
				gmTools.coalesce(result['val_unit'], '', ' %s'),
				gmTools.coalesce(result['abnormality_indicator'], '', ' %s'),
				gmDateTime.format_interval_medically(gmDateTime.pydt_now_here() - result['clin_when']),
				gmTools.u_writing_hand
			))
			list_data.append(result)

		self._LCTRL_results.set_string_items(items = list_items)
		self._LCTRL_results.set_data(data = list_data)

		if no_of_reds > 0:
			for idx in range(1, no_of_reds + 1):
				self._LCTRL_results.SetItemTextColour(idx, wx.Colour('RED'))
Exemplo n.º 15
0
def _display_clinical_reminders():

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

    # reminders
    for msg in pat.overdue_messages:
        if msg['expiry_date'] is None:
            exp = ''
        else:
            exp = _(' - expires %s') % gmDateTime.pydt_strftime(
                msg['expiry_date'], '%Y %b %d', accuracy=gmDateTime.acc_days)
        txt = _('Due for %s (since %s%s):\n'
                '%s'
                '%s'
                '\n'
                'Patient: %s\n'
                'Reminder by: %s') % (
                    gmDateTime.format_interval_medically(msg['interval_due']),
                    gmDateTime.pydt_strftime(msg['due_date'],
                                             '%Y %b %d',
                                             accuracy=gmDateTime.acc_days),
                    exp, gmTools.coalesce(msg['comment'], '', '\n%s\n'),
                    gmTools.coalesce(msg['data'], '', '\n%s\n'),
                    pat.description_gender, msg['modified_by'])
        gmGuiHelpers.gm_show_warning(aTitle=_('Clinical reminder'),
                                     aMessage=txt)

    # dynamic hints
    hints2aggregate = []
    emr = pat.emr
    hint_dlg = cDynamicHintDlg(wx.GetApp().GetTopWindow(), -1)
    # single-hint popups
    for hint in emr.dynamic_hints:
        if hint['popup_type'] == 0:
            continue
        if hint['popup_type'] == 2:
            hints2aggregate.append(hint)
            continue
        hint_dlg.hint = hint
        if hint_dlg.ShowModal() == wx.ID_APPLY:
            hint.suppress(rationale=hint_dlg.rationale.strip(),
                          pk_encounter=emr.current_encounter['pk_encounter'])
    hint_dlg.DestroyLater()
    # aggregate popup
    if len(hints2aggregate) > 0:
        hints_dlg = cDynamicHintListDlg(wx.GetApp().GetTopWindow(), -1)
        hints_dlg.pk_encounter = emr.current_encounter['pk_encounter']
        hints_dlg.hints = hints2aggregate
        hints_dlg.ShowModal()
        hints_dlg.DestroyLater()

    return
Exemplo n.º 16
0
	def refresh(lctrl):
		reminders = gmProviderInbox.get_reminders(pk_patient = patient)
		items = [ [
			gmTools.bool2subst (
				r['is_overdue'],
				_('overdue for %s'),
				_('due in %s')
			) % gmDateTime.format_interval_medically(r['interval_due']),
			r['comment'],
			r['pk_inbox_message']
		] for r in reminders ]
		lctrl.set_string_items(items)
		lctrl.set_data(reminders)
Exemplo n.º 17
0
	def format(self, left_margin=0, include_episode=False, include_comment=False, include_codes=False):

		line = '%s%s' % (
			(' ' * left_margin),
			self._payload[self._idx['l10n_relation']]
		)
		if self._payload[self._idx['age_of_death']] is not None:
			line += ' (%s %s)' % (
				gmTools.u_latin_cross,
				gmDateTime.format_interval_medically(self._payload[self._idx['age_of_death']])
			)
		line += ': %s' % self._payload[self._idx['condition']]
		if self._payload[self._idx['age_noted']] is not None:
			line += gmTools.coalesce(self._payload[self._idx['age_noted']], '', ' (@ %s)')
		if self._payload[self._idx['contributed_to_death']]:
			line += ' %s %s' % (
				gmTools.u_arrow2right,
				gmTools.u_skull_and_crossbones
			)

		if include_episode:
			line += '\n%s  %s: %s' % (
				(' ' * left_margin),
				_('Episode'),
				self._payload[self._idx['episode']]
			)

		if include_comment:
			if self._payload[self._idx['comment']] is not None:
				line += '\n%s  %s' % (
					(' ' * left_margin),
					self._payload[self._idx['comment']]
				)

		if include_codes:
			codes = self.generic_codes
			if len(codes) > 0:
				line += '\n'
			for c in codes:
				line += '%s  %s: %s (%s - %s)\n' % (
					(' ' * left_margin),
					c['code'],
					c['term'],
					c['name_short'],
					c['version']
				)
			del codes

		return line
Exemplo n.º 18
0
	def format(self, left_margin=0, include_episode=False, include_comment=False, include_codes=False):

		line = u'%s%s' % (
			(u' ' * left_margin),
			self._payload[self._idx['l10n_relation']]
		)
		if self._payload[self._idx['age_of_death']] is not None:
			line += u' (%s %s)' % (
				gmTools.u_latin_cross,
				gmDateTime.format_interval_medically(self._payload[self._idx['age_of_death']])
			)
		line += u': %s' % self._payload[self._idx['condition']]
		if self._payload[self._idx['age_noted']] is not None:
			line += gmTools.coalesce(self._payload[self._idx['age_noted']], u'', u' (@ %s)')
		if self._payload[self._idx['contributed_to_death']]:
			line += u' %s %s' % (
				gmTools.u_right_arrow,
				gmTools.u_skull_and_crossbones
			)

		if include_episode:
			line += u'\n%s  %s: %s' % (
				(u' ' * left_margin),
				_('Episode'),
				self._payload[self._idx['episode']]
			)

		if include_comment:
			if self._payload[self._idx['comment']] is not None:
				line += u'\n%s  %s' % (
					(u' ' * left_margin),
					self._payload[self._idx['comment']]
				)

		if include_codes:
			codes = self.generic_codes
			if len(codes) > 0:
				line += u'\n'
			for c in codes:
				line += u'%s  %s: %s (%s - %s)\n' % (
					(u' ' * left_margin),
					c['code'],
					c['term'],
					c['name_short'],
					c['version']
				)
			del codes

		return line
Exemplo n.º 19
0
	def __refresh_indications(self):
		self._TCTRL_indications.SetValue('')
		vaccine = self._PRW_vaccine.GetData(as_instance = True)
		if vaccine is None:
			return
		lines = []
		emr = gmPerson.gmCurrentPatient().emr
		latest_vaccs = emr.get_latest_vaccinations (
			atc_indications = [ i['atc_indication'] for i in vaccine['indications'] ]
		)
		for l10n_ind in [ i['l10n_indication'] for i in vaccine['indications'] ]:
			try:
				no_of_shots4ind, latest_vacc4ind = latest_vaccs[l10n_ind]
				ago = gmDateTime.format_interval_medically(gmDateTime.pydt_now_here() - latest_vacc4ind['date_given'])
				lines.append(_('%s  (most recent shot of %s: %s ago)') % (l10n_ind, no_of_shots4ind, ago))
			except KeyError:
				lines.append(_('%s  (no previous vaccination recorded)') % l10n_ind)

		self._TCTRL_indications.SetValue(_('Protects against:\n ') + '\n '.join(lines))
Exemplo n.º 20
0
	def __refresh_indications(self):
		self._TCTRL_indications.SetValue('')
		vaccine = self._PRW_vaccine.GetData(as_instance = True)
		if vaccine is None:
			return
		lines = []
		emr = gmPerson.gmCurrentPatient().emr
		latest_vaccs = emr.get_latest_vaccinations (
			atc_indications = [ i['atc_indication'] for i in vaccine['indications'] ]
		)
		for l10n_ind in [ i['l10n_indication'] for i in vaccine['indications'] ]:
			try:
				no_of_shots4ind, latest_vacc4ind = latest_vaccs[l10n_ind]
				ago = gmDateTime.format_interval_medically(gmDateTime.pydt_now_here() - latest_vacc4ind['date_given'])
				lines.append(_('%s  (most recent shot of %s: %s ago)') % (l10n_ind, no_of_shots4ind, ago))
			except KeyError:
				lines.append(_('%s  (no previous vaccination recorded)') % l10n_ind)

		self._TCTRL_indications.SetValue(_('Protects against:\n ') + '\n '.join(lines))
Exemplo n.º 21
0
def _display_clinical_reminders():

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

        # reminders
    for msg in pat.overdue_messages:
        if msg["expiry_date"] is None:
            exp = u""
        else:
            exp = _(" - expires %s") % gmDateTime.pydt_strftime(
                msg["expiry_date"], "%Y %b %d", accuracy=gmDateTime.acc_days
            )
        txt = _("Due for %s (since %s%s):\n" "%s" "%s" "\n" "Patient: %s\n" "Reminder by: %s") % (
            gmDateTime.format_interval_medically(msg["interval_due"]),
            gmDateTime.pydt_strftime(msg["due_date"], "%Y %b %d", accuracy=gmDateTime.acc_days),
            exp,
            gmTools.coalesce(msg["comment"], u"", u"\n%s\n"),
            gmTools.coalesce(msg["data"], u"", u"\n%s\n"),
            pat["description_gender"],
            msg["modified_by"],
        )
        gmGuiHelpers.gm_show_warning(aTitle=_("Clinical reminder"), aMessage=txt)

        # dynamic hints
    hint_dlg = cDynamicHintDlg(wx.GetApp().GetTopWindow(), -1)
    for hint in pat._get_dynamic_hints(include_suppressed_needing_invalidation=True):
        if hint["rationale4suppression"] == u"magic_tag::please_invalidate_suppression":
            _log.debug("database asks for invalidation of suppression of hint [%s]", hint)
            hint.invalidate_suppression(pk_encounter=pat.emr.current_encounter["pk_encounter"])
            continue
        hint_dlg.hint = hint
        if hint_dlg.ShowModal() == wx.ID_APPLY:
            hint.suppress(rationale=hint_dlg.rationale.strip(), pk_encounter=pat.emr.current_encounter["pk_encounter"])
    hint_dlg.Destroy()

    return
Exemplo n.º 22
0
def _display_clinical_reminders():

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

	# reminders
	for msg in pat.overdue_messages:
		if msg['expiry_date'] is None:
			exp = ''
		else:
			exp = _(' - expires %s') % gmDateTime.pydt_strftime (
				msg['expiry_date'],
				'%Y %b %d',
				accuracy = gmDateTime.acc_days
			)
		txt = _(
			'Due for %s (since %s%s):\n'
			'%s'
			'%s'
			'\n'
			'Patient: %s\n'
			'Reminder by: %s'
		) % (
			gmDateTime.format_interval_medically(msg['interval_due']),
			gmDateTime.pydt_strftime(msg['due_date'], '%Y %b %d', accuracy = gmDateTime.acc_days),
			exp,
			gmTools.coalesce(msg['comment'], '', '\n%s\n'),
			gmTools.coalesce(msg['data'], '', '\n%s\n'),
			pat['description_gender'],
			msg['modified_by']
		)
		gmGuiHelpers.gm_show_warning (
			aTitle = _('Clinical reminder'),
			aMessage = txt
		)

	# dynamic hints
	hints2aggregate = []
	emr = pat.emr
	hint_dlg = cDynamicHintDlg(wx.GetApp().GetTopWindow(), -1)
	# single-hint popups
	for hint in emr.dynamic_hints:
		if hint['popup_type'] == 0:
			continue
		if hint['popup_type'] == 2:
			hints2aggregate.append(hint)
			continue
		hint_dlg.hint = hint
		if hint_dlg.ShowModal() == wx.ID_APPLY:
			hint.suppress (
				rationale = hint_dlg.rationale.strip(),
				pk_encounter = emr.current_encounter['pk_encounter']
			)
	hint_dlg.DestroyLater()
	# aggregate popup
	if len(hints2aggregate) > 0:
		hints_dlg = cDynamicHintListDlg(wx.GetApp().GetTopWindow(), -1)
		hints_dlg.pk_encounter = emr.current_encounter['pk_encounter']
		hints_dlg.hints = hints2aggregate
		hints_dlg.ShowModal()
		hints_dlg.DestroyLater()

	return
Exemplo n.º 23
0
	def refresh(lctrl):

		items = []
		data = []
		if latest_only:
			latest_vaccs = emr.get_latest_vaccinations()
			for indication in sorted(latest_vaccs.keys()):
				no_of_shots4ind, latest_vacc4ind = latest_vaccs[indication]
				items.append ([
					indication,
					_('%s (latest of %s: %s ago)') % (
						gmDateTime.pydt_strftime(latest_vacc4ind['date_given'], format = '%Y %b'),
						no_of_shots4ind,
						gmDateTime.format_interval_medically(gmDateTime.pydt_now_here() - latest_vacc4ind['date_given'])
					),
					latest_vacc4ind['vaccine'],
					latest_vacc4ind['batch_no'],
					gmTools.coalesce(latest_vacc4ind['site'], ''),
					gmTools.coalesce(latest_vacc4ind['reaction'], ''),
					gmTools.coalesce(latest_vacc4ind['comment'], '')
				])
				data.append(latest_vacc4ind)
		else:
			shots = emr.get_vaccinations(order_by = 'date_given DESC, pk_vaccination')
			if expand_indications:
				shots_by_ind = {}
				for shot in shots:
					for ind in shot['indications']:
						try:
							shots_by_ind[ind['l10n_indication']].append(shot)
						except KeyError:
							shots_by_ind[ind['l10n_indication']] = [shot]
				for ind in sorted(shots_by_ind.keys()):
					idx = len(shots_by_ind[ind])
					for shot in shots_by_ind[ind]:
						items.append ([
							'%s (#%s)' % (ind, idx),
							_('%s (%s ago)') % (
								gmDateTime.pydt_strftime(shot['date_given'], '%Y %b %d'),
								gmDateTime.format_interval_medically(gmDateTime.pydt_now_here() - shot['date_given'])
							),
							shot['vaccine'],
							shot['batch_no'],
							gmTools.coalesce(shot['site'], ''),
							gmTools.coalesce(shot['reaction'], ''),
							gmTools.coalesce(shot['comment'], '')
						])
						idx -= 1
						data.append(shot)
			else:
				items = [ [
					gmDateTime.pydt_strftime(s['date_given'], '%Y %b %d'),
					s['vaccine'],
					', '.join([ i['l10n_indication'] for i in s['indications'] ]),
					s['batch_no'],
					gmTools.coalesce(s['site'], ''),
					gmTools.coalesce(s['reaction'], ''),
					gmTools.coalesce(s['comment'], '')
				] for s in shots ]
				data = shots

		lctrl.set_string_items(items)
		lctrl.set_data(data)
Exemplo n.º 24
0
	def __refresh_waiting_list(self):
		self.__id_most_recently_activated_patient = None
		col, ascending = self._LCTRL_patients.GetSortState()	# preserve sorting order

		praxis = gmPraxis.gmCurrentPraxisBranch()
		pats = praxis.waiting_list_patients

		# set matcher to all zones currently in use
		zones = {}
		zones.update([ [p['waiting_zone'], None] for p in pats if p['waiting_zone'] is not None ])
		self._PRW_zone.update_matcher(items = zones.keys())

		# filter patient list by zone and set waiting list
		self.__current_zone = self._PRW_zone.GetValue().strip()
		if self.__current_zone == '':
			pats = [ p for p in pats ]
		else:
			pats = [ p for p in pats if p['waiting_zone'] == self.__current_zone ]

		# filter by "active patient only"
		curr_pat = gmPerson.gmCurrentPatient()
		if curr_pat.connected:
			if self._CHBOX_active_patient_only.IsChecked():
				pats = [ p for p in pats if p['pk_identity'] == curr_pat.ID ]

		old_pks = [ d['pk_waiting_list'] for d in self._LCTRL_patients.get_selected_item_data() ]
		self._LCTRL_patients.set_string_items (
			[ [
				gmTools.coalesce(p['waiting_zone'], ''),
				p['urgency'],
				gmDateTime.pydt_strftime(p['registered'], format='%Y %b %d %H:%M'),
				gmDateTime.format_interval_medically(p['waiting_time']),
				'%s, %s (%s)' % (p['lastnames'], p['firstnames'], p['l10n_gender']),
				gmTools.coalesce (
					gmTools.coalesce (p['dob'], '', function_initial = ('strftime', '%d %b %Y')),
					''
				),
				gmTools.coalesce(p['comment'], '').split('\n')[0]
			] for p in pats ]
		)
		self._LCTRL_patients.set_column_widths()
		self._LCTRL_patients.set_data(pats)
		new_selections = []
		new_pks = [ p['pk_waiting_list'] for p in pats ]
		for old_pk in old_pks:
			if old_pk in new_pks:
				new_selections.append(new_pks.index(old_pk))
		self._LCTRL_patients.selections = new_selections
		self._LCTRL_patients.Refresh()
		self._LCTRL_patients.SortListItems(col, ascending) # re-sort

		self._LBL_no_of_patients.SetLabel(_('(%s patients)') % len(pats))

		if len(pats) == 0:
			self._BTN_activate.Enable(False)
			self._BTN_activateplus.Enable(False)
			self._BTN_remove.Enable(False)
			self._BTN_edit.Enable(False)
			self._BTN_up.Enable(False)
			self._BTN_down.Enable(False)
		else:
			self._BTN_activate.Enable(True)
			self._BTN_activateplus.Enable(True)
			self._BTN_remove.Enable(True)
			self._BTN_edit.Enable(True)
		if len(pats) > 1:
			self._BTN_up.Enable(True)
			self._BTN_down.Enable(True)
Exemplo n.º 25
0
	def __refresh_history(self, patient=None):
		emr = patient.emr

		sort_key_list = []
		date_format4sorting = '%Y %m %d %H %M %S'
		now = gmDateTime.pydt_now_here()
		data = {}

		# undated entries
		# pregnancy
		edc = emr.EDC
		if edc is not None:
			sort_key = '99999 edc'
			if emr.EDC_is_fishy:
				label = _('EDC (!?!): %s') % gmDateTime.pydt_strftime(edc, format = '%Y %b %d')
				tt = _(
					'The Expected Date of Confinement is rather questionable.\n'
					'\n'
					'Please check patient age, patient gender, time until/since EDC.'
				)
			else:
				label = _('EDC: %s') % gmDateTime.pydt_strftime(edc, format = '%Y %b %d')
				tt = ''
			sort_key_list.append(sort_key)
			data[sort_key] = [label, tt]

		# family history
		fhxs = emr.get_family_history()
		for fhx in fhxs:
			sort_key = '99998 %s::%s' % (fhx['l10n_relation'], fhx['pk_family_history'])
			sort_key_list.append(sort_key)
			#gmDateTime.pydt_strftime(fhx['when_known_to_patient'], format = '%Y %m %d %H %M %S')
			label = '%s%s: %s' % (fhx['l10n_relation'], gmTools.coalesce(fhx['age_noted'], '', ' (@ %s)'), fhx['condition'])
			data[sort_key] = [label, fhx]
		del fhxs

		# dated entries
		issues = [
			i for i in emr.get_health_issues()
			if ((i['clinically_relevant'] is False) or (i['is_active'] is False))
		]
		for issue in issues:
			last_encounter = emr.get_last_encounter(issue_id = issue['pk_health_issue'])
			linked_encounter = gmEMRStructItems.cEncounter(issue['pk_encounter'])
			when_candidates = [issue['modified_when'], linked_encounter['last_affirmed']]
			if last_encounter is not None:
				when_candidates.append(last_encounter['last_affirmed'])
			if (patient['dob'] is not None) and (issue['age_noted'] is not None):
				when_candidates.append(patient['dob'] + issue['age_noted'])
			if issue['is_active']:
				# sort active issues by time of most recent clinical access, which
				# means the most recent of:
				# issue.modified_when
				# last_encounter.last_affirmed
				# linked_encounter.last_affirmed
				# dob + age
				relevant_date = max(when_candidates)
			else:
				# sort IN-active issues by best guess of real clinical start
				# means either:
				# - dob + age
				# or the earliest of:
				# - issue.modified_when
				# - last_encounter.last_affirmed
				# - linked_encounter.last_affirmed
				if (patient['dob'] is not None) and (issue['age_noted'] is not None):
					relevant_date = patient['dob'] + issue['age_noted']
				else:
					relevant_date = min(when_candidates)
			sort_key = '%s::%s' % (gmDateTime.pydt_strftime(relevant_date, format = date_format4sorting), issue['pk_health_issue'])
			relevant_date_str = gmDateTime.pydt_strftime(relevant_date, format = '%Y %b')
			if issue['age_noted'] is None:
				encounter = gmEMRStructItems.cEncounter(issue['pk_encounter'])
				age = _(' (entered %s ago)') % gmDateTime.format_interval_medically(now - encounter['started'])
			else:
				age = ' (@ %s)' % gmDateTime.format_interval_medically(issue['age_noted'])
			sort_key_list.append(sort_key)
			data[sort_key] = ['%s %s%s' % (relevant_date_str, issue['description'], age), issue]
		del issues

		stays = emr.get_hospital_stays()
		for stay in stays:
			sort_key = '%s::%s' % (gmDateTime.pydt_strftime(stay['admission'], format = date_format4sorting), stay['pk_hospital_stay'])
			label = '%s %s: %s (%s)' % (
				gmDateTime.pydt_strftime(stay['admission'], format = '%Y %b'),
				stay['hospital'],
				stay['episode'],
				_('%s ago') % gmDateTime.format_interval_medically(now - stay['admission'])
			)
			sort_key_list.append(sort_key)
			data[sort_key] = [label, stay]
		del stays

		procs = emr.get_performed_procedures()
		for proc in procs:
			sort_key = '%s::%s' % (gmDateTime.pydt_strftime(proc['clin_when'], format = date_format4sorting), proc['pk_procedure'])
			label = '%s%s %s (%s @ %s)' % (
				gmDateTime.pydt_strftime(proc['clin_when'], format = '%Y %b'),
				gmTools.bool2subst(proc['is_ongoing'], gmTools.u_ellipsis, '', ''),
				proc['performed_procedure'],
				_('%s ago') % gmDateTime.format_interval_medically(now - proc['clin_when']),
				gmDateTime.format_interval_medically(proc['clin_when'] - patient['dob'])
			)
			sort_key_list.append(sort_key)
			data[sort_key] = [label, proc]
		del procs

		vaccs = emr.get_latest_vaccinations()
		for ind, tmp in vaccs.items():
			no_of_shots, vacc = tmp
			sort_key = '%s::%s::%s' % (gmDateTime.pydt_strftime(vacc['date_given'], format = date_format4sorting), vacc['pk_vaccination'], ind)
			label = _('%s Vacc: %s (latest of %s: %s ago)') % (
				gmDateTime.pydt_strftime(vacc['date_given'], format = '%Y %b'),
				ind,
				no_of_shots,
				gmDateTime.format_interval_medically(now - vacc['date_given'])
			)
			sort_key_list.append(sort_key)
			data[sort_key] = [label, vacc]
		del vaccs

		for abuse in [ a for a in emr.abused_substances if a['use_type'] == gmMedication.USE_TYPE_PREVIOUSLY_ADDICTED ]:
			sort_key = '%s::%s' % (gmDateTime.pydt_strftime(abuse['last_checked_when'], format = date_format4sorting), abuse['substance'])
			label = _('Hx of addiction: %s') % abuse['substance']
			sort_key_list.append(sort_key)
			data[sort_key] = [label, abuse]

		sort_key_list.sort()
		sort_key_list.reverse()
		list_items = []
		list_data = []
		for key in sort_key_list:
			label, item = data[key]
			list_items.append(label)
			list_data.append(item)

		self._LCTRL_history.set_string_items(items = list_items)
		self._LCTRL_history.set_data(data = list_data)
Exemplo n.º 26
0
	def __refresh_waiting_list(self):
		self.__id_most_recently_activated_patient = None
		col, ascending = self._LCTRL_patients.GetSortState()	# preserve sorting order

		praxis = gmPraxis.gmCurrentPraxisBranch()
		pats = praxis.waiting_list_patients

		# set matcher to all zones currently in use
		zones = {}
		zones.update([ [p['waiting_zone'], None] for p in pats if p['waiting_zone'] is not None ])
		self._PRW_zone.update_matcher(items = zones.keys())

		# filter patient list by zone and set waiting list
		self.__current_zone = self._PRW_zone.GetValue().strip()
		if self.__current_zone == '':
			pats = [ p for p in pats ]
		else:
			pats = [ p for p in pats if p['waiting_zone'] == self.__current_zone ]

		# filter by "active patient only"
		curr_pat = gmPerson.gmCurrentPatient()
		if curr_pat.connected:
			if self._CHBOX_active_patient_only.IsChecked():
				pats = [ p for p in pats if p['pk_identity'] == curr_pat.ID ]

		old_pks = [ d['pk_waiting_list'] for d in self._LCTRL_patients.get_selected_item_data() ]
		self._LCTRL_patients.set_string_items (
			[ [
				gmTools.coalesce(p['waiting_zone'], ''),
				p['urgency'],
				gmDateTime.pydt_strftime(p['registered'], format='%Y %b %d %H:%M'),
				gmDateTime.format_interval_medically(p['waiting_time']),
				'%s, %s (%s)' % (p['lastnames'], p['firstnames'], p['l10n_gender']),
				gmTools.coalesce (
					gmTools.coalesce (p['dob'], '', function_initial = ('strftime', '%d %b %Y')),
					''
				),
				gmTools.coalesce(p['comment'], '').split('\n')[0]
			] for p in pats ]
		)
		self._LCTRL_patients.set_column_widths()
		self._LCTRL_patients.set_data(pats)
		new_selections = []
		new_pks = [ p['pk_waiting_list'] for p in pats ]
		for old_pk in old_pks:
			if old_pk in new_pks:
				new_selections.append(new_pks.index(old_pk))
		self._LCTRL_patients.selections = new_selections
		self._LCTRL_patients.Refresh()
		self._LCTRL_patients.SortListItems(col, ascending) # re-sort

		self._LBL_no_of_patients.SetLabel(_('(%s patients)') % len(pats))

		if len(pats) == 0:
			self._BTN_activate.Enable(False)
			self._BTN_activateplus.Enable(False)
			self._BTN_remove.Enable(False)
			self._BTN_edit.Enable(False)
			self._BTN_up.Enable(False)
			self._BTN_down.Enable(False)
		else:
			self._BTN_activate.Enable(True)
			self._BTN_activateplus.Enable(True)
			self._BTN_remove.Enable(True)
			self._BTN_edit.Enable(True)
		if len(pats) > 1:
			self._BTN_up.Enable(True)
			self._BTN_down.Enable(True)
Exemplo n.º 27
0
	def __refresh_encounters(self, patient=None):

		emr = patient.emr

		list_items = []
		list_data = []

		is_waiting = False
		wlist = patient.get_waiting_list_entry()
		if len(wlist) > 0:
			is_waiting = True
			list_items.append(_('Currently %s entries in waiting list') % len(wlist))
			tt = []
			for w in wlist:
				tt.append('%s %s%s%s' % (
					gmTools.u_triangular_bullet,
					gmDateTime.format_interval_medically(w['waiting_time']),
					gmTools.coalesce(w['waiting_zone'], '', ' in "%s"'),
					gmTools.coalesce(w['comment'], '', ': %s')
				))
			if len(tt) > 0:
				tt = '\n'.join(tt)
			else:
				tt = None
			list_data.append({'wlist': tt})

		first = emr.get_first_encounter()
		if first is not None:
			list_items.append (
				_('first (in GMd): %s, %s') % (
					gmDateTime.pydt_strftime (
						first['started'],
						format = '%Y %b %d',
						accuracy = gmDateTime.acc_days
					),
					first['l10n_type']
				)
			)
			list_data.append(first)

		last = emr.get_last_but_one_encounter()
		if last is not None:
			list_items.append (
				_('last: %s, %s') % (
					gmDateTime.pydt_strftime (
						last['started'],
						format = '%Y %b %d',
						accuracy = gmDateTime.acc_days
					),
					last['l10n_type']
				)
			)
			list_data.append(last)

		encs = emr.get_encounter_stats_by_type()
		for enc in encs:
			item = ' %s x %s' % (enc['frequency'], enc['l10n_type'])
			list_items.append(item)
			list_data.append(item)

		stays = emr.get_hospital_stay_stats_by_hospital()
		for stay in stays:
			item = ' %s x %s' % (
				stay['frequency'],
				stay['hospital']
			)
			list_items.append(item)
			list_data.append({'stay': item})

		self._LCTRL_encounters.set_string_items(items = list_items)
		self._LCTRL_encounters.set_data(data = list_data)
		if is_waiting:
			self._LCTRL_encounters.SetItemTextColour(0, wx.Colour('RED'))
Exemplo n.º 28
0
	def __refresh_encounters(self, patient=None):

		emr = patient.emr

		list_items = []
		list_data = []

		is_waiting = False
		wlist = patient.get_waiting_list_entry()
		if len(wlist) > 0:
			is_waiting = True
			list_items.append(_('Currently %s entries in waiting list') % len(wlist))
			tt = []
			for w in wlist:
				tt.append('%s %s%s%s' % (
					gmTools.u_triangular_bullet,
					gmDateTime.format_interval_medically(w['waiting_time']),
					gmTools.coalesce(w['waiting_zone'], '', ' in "%s"'),
					gmTools.coalesce(w['comment'], '', ': %s')
				))
			if len(tt) > 0:
				tt = '\n'.join(tt)
			else:
				tt = None
			list_data.append({'wlist': tt})

		first = emr.get_first_encounter()
		if first is not None:
			list_items.append (
				_('first (in GMd): %s, %s') % (
					gmDateTime.pydt_strftime (
						first['started'],
						format = '%Y %b %d',
						accuracy = gmDateTime.acc_days
					),
					first['l10n_type']
				)
			)
			list_data.append(first)

		last = emr.get_last_but_one_encounter()
		if last is not None:
			list_items.append (
				_('last: %s, %s') % (
					gmDateTime.pydt_strftime (
						last['started'],
						format = '%Y %b %d',
						accuracy = gmDateTime.acc_days
					),
					last['l10n_type']
				)
			)
			list_data.append(last)

		encs = emr.get_encounter_stats_by_type()
		for enc in encs:
			item = ' %s x %s' % (enc['frequency'], enc['l10n_type'])
			list_items.append(item)
			list_data.append(item)

		stays = emr.get_hospital_stay_stats_by_hospital()
		for stay in stays:
			item = ' %s x %s' % (
				stay['frequency'],
				stay['hospital']
			)
			list_items.append(item)
			list_data.append({'stay': item})

		self._LCTRL_encounters.set_string_items(items = list_items)
		self._LCTRL_encounters.set_data(data = list_data)
		if is_waiting:
			self._LCTRL_encounters.SetItemTextColour(0, wx.Colour('RED'))
Exemplo n.º 29
0
	def __refresh_history(self, patient=None):
		emr = patient.emr

		sort_key_list = []
		date_format4sorting = '%Y %m %d %H %M %S'
		now = gmDateTime.pydt_now_here()
		data = {}

		# undated entries
		# pregnancy
		edc = emr.EDC
		if edc is not None:
			sort_key = '99999 edc'
			if emr.EDC_is_fishy:
				label = _('EDC (!?!): %s') % gmDateTime.pydt_strftime(edc, format = '%Y %b %d')
				tt = _(
					'The Expected Date of Confinement is rather questionable.\n'
					'\n'
					'Please check patient age, patient gender, time until/since EDC.'
				)
			else:
				label = _('EDC: %s') % gmDateTime.pydt_strftime(edc, format = '%Y %b %d')
				tt = ''
			sort_key_list.append(sort_key)
			data[sort_key] = [label, tt]

		# family history
		fhxs = emr.get_family_history()
		for fhx in fhxs:
			sort_key = '99998 %s::%s' % (fhx['l10n_relation'], fhx['pk_family_history'])
			sort_key_list.append(sort_key)
			#gmDateTime.pydt_strftime(fhx['when_known_to_patient'], format = '%Y %m %d %H %M %S')
			label = '%s%s: %s' % (fhx['l10n_relation'], gmTools.coalesce(fhx['age_noted'], '', ' (@ %s)'), fhx['condition'])
			data[sort_key] = [label, fhx]
		del fhxs

		# dated entries
		issues = [
			i for i in emr.get_health_issues()
			if ((i['clinically_relevant'] is False) or (i['is_active'] is False))
		]
		for issue in issues:
			last_encounter = emr.get_last_encounter(issue_id = issue['pk_health_issue'])
			linked_encounter = gmEMRStructItems.cEncounter(issue['pk_encounter'])
			when_candidates = [issue['modified_when'], linked_encounter['last_affirmed']]
			if last_encounter is not None:
				when_candidates.append(last_encounter['last_affirmed'])
			if (patient['dob'] is not None) and (issue['age_noted'] is not None):
				when_candidates.append(patient['dob'] + issue['age_noted'])
			if issue['is_active']:
				# sort active issues by time of most recent clinical access, which
				# means the most recent of:
				# issue.modified_when
				# last_encounter.last_affirmed
				# linked_encounter.last_affirmed
				# dob + age
				relevant_date = max(when_candidates)
			else:
				# sort IN-active issues by best guess of real clinical start
				# means either:
				# - dob + age
				# or the earliest of:
				# - issue.modified_when
				# - last_encounter.last_affirmed
				# - linked_encounter.last_affirmed
				if (patient['dob'] is not None) and (issue['age_noted'] is not None):
					relevant_date = patient['dob'] + issue['age_noted']
				else:
					relevant_date = min(when_candidates)
			sort_key = '%s::%s' % (gmDateTime.pydt_strftime(relevant_date, format = date_format4sorting), issue['pk_health_issue'])
			relevant_date_str = gmDateTime.pydt_strftime(relevant_date, format = '%Y %b')
			if issue['age_noted'] is None:
				encounter = gmEMRStructItems.cEncounter(issue['pk_encounter'])
				age = _(' (entered %s ago)') % gmDateTime.format_interval_medically(now - encounter['started'])
			else:
				age = ' (@ %s)' % gmDateTime.format_interval_medically(issue['age_noted'])
			sort_key_list.append(sort_key)
			data[sort_key] = ['%s %s%s' % (relevant_date_str, issue['description'], age), issue]
		del issues

		stays = emr.get_hospital_stays()
		for stay in stays:
			sort_key = '%s::%s' % (gmDateTime.pydt_strftime(stay['admission'], format = date_format4sorting), stay['pk_hospital_stay'])
			label = '%s %s: %s (%s)' % (
				gmDateTime.pydt_strftime(stay['admission'], format = '%Y %b'),
				stay['hospital'],
				stay['episode'],
				_('%s ago') % gmDateTime.format_interval_medically(now - stay['admission'])
			)
			sort_key_list.append(sort_key)
			data[sort_key] = [label, stay]
		del stays

		procs = emr.get_performed_procedures()
		for proc in procs:
			sort_key = '%s::%s' % (gmDateTime.pydt_strftime(proc['clin_when'], format = date_format4sorting), proc['pk_procedure'])
			label = '%s%s %s (%s @ %s)' % (
				gmDateTime.pydt_strftime(proc['clin_when'], format = '%Y %b'),
				gmTools.bool2subst(proc['is_ongoing'], gmTools.u_ellipsis, '', ''),
				proc['performed_procedure'],
				_('%s ago') % gmDateTime.format_interval_medically(now - proc['clin_when']),
				gmDateTime.format_interval_medically(proc['clin_when'] - patient['dob'])
			)
			sort_key_list.append(sort_key)
			data[sort_key] = [label, proc]
		del procs

		vaccs = emr.get_latest_vaccinations()
		for ind, tmp in vaccs.items():
			no_of_shots, vacc = tmp
			sort_key = '%s::%s::%s' % (gmDateTime.pydt_strftime(vacc['date_given'], format = date_format4sorting), vacc['pk_vaccination'], ind)
			label = _('%s Vacc: %s (latest of %s: %s ago)') % (
				gmDateTime.pydt_strftime(vacc['date_given'], format = '%Y %b'),
				ind,
				no_of_shots,
				gmDateTime.format_interval_medically(now - vacc['date_given'])
			)
			sort_key_list.append(sort_key)
			data[sort_key] = [label, vacc]
		del vaccs

		for abuse in [ a for a in emr.abused_substances if a['harmful_use_type'] == 3 ]:
			sort_key = '%s::%s' % (gmDateTime.pydt_strftime(abuse['last_checked_when'], format = date_format4sorting), abuse['substance'])
			label = _('Hx of addiction: %s') % abuse['substance']
			sort_key_list.append(sort_key)
			data[sort_key] = [label, abuse]

		sort_key_list.sort()
		sort_key_list.reverse()
		list_items = []
		list_data = []
		for key in sort_key_list:
			label, item = data[key]
			list_items.append(label)
			list_data.append(item)

		self._LCTRL_history.set_string_items(items = list_items)
		self._LCTRL_history.set_data(data = list_data)
Exemplo n.º 30
0
    def __populate_inbox(self):
        _log.debug('populating provider inbox')

        # calculate constraints
        pk_patient = None
        if self._CHBOX_active_patient.IsChecked():
            _log.debug('restricting to active patient')
            curr_pat = gmPerson.gmCurrentPatient()
            if curr_pat.connected:
                pk_patient = curr_pat.ID

        include_without_provider = True
        if self._CHBOX_active_provider.IsChecked():
            _log.debug('restricting to active provider directly')
            include_without_provider = False

        # get which messages to show
        if self._RBTN_relevant_messages.GetValue():
            _log.debug('loading relevant messages')
            self.__msgs = self.provider.inbox.get_relevant_messages(
                pk_patient=pk_patient,
                include_without_provider=include_without_provider)
        elif self._RBTN_all_messages.GetValue():
            _log.debug('loading all but expired messages')
            self.__msgs = self.provider.inbox.get_messages(
                pk_patient=pk_patient,
                include_without_provider=include_without_provider,
                exclude_expired=True,
                expired_only=False,
                overdue_only=False,
                unscheduled_only=False,
                exclude_unscheduled=False)
        elif self._RBTN_overdue_messages.GetValue():
            _log.debug('loading overdue messages only')
            self.__msgs = self.provider.inbox.get_messages(
                pk_patient=pk_patient,
                include_without_provider=include_without_provider,
                exclude_expired=True,
                expired_only=False,
                overdue_only=True,
                unscheduled_only=False,
                exclude_unscheduled=True,
                order_by=u'due_date, importance DESC, received_when DESC')
        elif self._RBTN_scheduled_messages.GetValue():
            _log.debug('loading scheduled messages only')
            self.__msgs = self.provider.inbox.get_messages(
                pk_patient=pk_patient,
                include_without_provider=include_without_provider,
                exclude_expired=True,
                expired_only=False,
                overdue_only=False,
                unscheduled_only=False,
                exclude_unscheduled=True,
                order_by=u'due_date, importance DESC, received_when DESC')
        elif self._RBTN_unscheduled_messages.GetValue():
            _log.debug('loading unscheduled messages only')
            self.__msgs = self.provider.inbox.get_messages(
                pk_patient=pk_patient,
                include_without_provider=include_without_provider,
                exclude_expired=True,
                expired_only=False,
                overdue_only=False,
                unscheduled_only=True,
                exclude_unscheduled=False)
        elif self._RBTN_expired_messages.GetValue():
            _log.debug('loading expired messages only')
            self.__msgs = self.provider.inbox.get_messages(
                pk_patient=pk_patient,
                include_without_provider=include_without_provider,
                exclude_expired=False,
                expired_only=True,
                overdue_only=False,
                unscheduled_only=False,
                exclude_unscheduled=True,
                order_by=
                u'expiry_date DESC, importance DESC, received_when DESC')

        _log.debug('total # of inbox msgs: %s', len(self.__msgs))

        items = []
        for m in self.__msgs:
            item = [_indicator[m['importance']]]
            item.append(
                u'%s: %s%s%s' %
                (gmDateTime.pydt_strftime(m['received_when'], '%Y-%m-%d'),
                 m['modified_by'], gmTools.u_arrow2right,
                 gmTools.coalesce(m['provider'], _(u'all'))))
            if m['due_date'] is None:
                item.append(u'')
            else:
                if m['is_expired'] is True:
                    item.append(_('expired'))
                else:
                    if m['is_overdue'] is True:
                        item.append(
                            _('%s overdue') %
                            gmDateTime.format_interval_medically(
                                m['interval_due']))
                    else:
                        item.append(
                            _('due in %s') %
                            gmDateTime.format_interval_medically(
                                m['interval_due']))
            item.append(u'%s - %s' % (m['l10n_category'], m['l10n_type']))
            item.append(m['comment'])
            items.append(item)

        _log.debug('# of list items created from msgs: %s', len(items))
        self._LCTRL_provider_inbox.set_string_items(items=items)
        self._LCTRL_provider_inbox.set_data(data=self.__msgs)
        self._LCTRL_provider_inbox.set_column_widths()
        self._TXT_inbox_item_comment.SetValue(u'')
        self.__update_greeting(len(items))
Exemplo n.º 31
0
	def refresh(lctrl):

		items = []
		data = []
		if latest_only:
			latest_vaccs = emr.get_latest_vaccinations()
			for indication in sorted(latest_vaccs):
				no_of_shots4ind, latest_vacc4ind = latest_vaccs[indication]
				items.append ([
					indication,
					_('%s (latest of %s: %s ago)') % (
						gmDateTime.pydt_strftime(latest_vacc4ind['date_given'], format = '%Y %b'),
						no_of_shots4ind,
						gmDateTime.format_interval_medically(gmDateTime.pydt_now_here() - latest_vacc4ind['date_given'])
					),
					latest_vacc4ind['vaccine'],
					latest_vacc4ind['batch_no'],
					gmTools.coalesce(latest_vacc4ind['site'], ''),
					gmTools.coalesce(latest_vacc4ind['reaction'], ''),
					gmTools.coalesce(latest_vacc4ind['comment'], '')
				])
				data.append(latest_vacc4ind)
		else:
			shots = emr.get_vaccinations(order_by = 'date_given DESC, pk_vaccination')
			if expand_indications:
				shots_by_ind = {}
				for shot in shots:
					for ind in shot['indications']:
						try:
							shots_by_ind[ind['l10n_indication']].append(shot)
						except KeyError:
							shots_by_ind[ind['l10n_indication']] = [shot]
				for ind in sorted(shots_by_ind):
					idx = len(shots_by_ind[ind])
					for shot in shots_by_ind[ind]:
						items.append ([
							'%s (#%s)' % (ind, idx),
							_('%s (%s ago)') % (
								gmDateTime.pydt_strftime(shot['date_given'], '%Y %b %d'),
								gmDateTime.format_interval_medically(gmDateTime.pydt_now_here() - shot['date_given'])
							),
							shot['vaccine'],
							shot['batch_no'],
							gmTools.coalesce(shot['site'], ''),
							gmTools.coalesce(shot['reaction'], ''),
							gmTools.coalesce(shot['comment'], '')
						])
						idx -= 1
						data.append(shot)
			else:
				items = [ [
					gmDateTime.pydt_strftime(s['date_given'], '%Y %b %d'),
					s['vaccine'],
					', '.join([ i['l10n_indication'] for i in s['indications'] ]),
					s['batch_no'],
					gmTools.coalesce(s['site'], ''),
					gmTools.coalesce(s['reaction'], ''),
					gmTools.coalesce(s['comment'], '')
				] for s in shots ]
				data = shots

		lctrl.set_string_items(items)
		lctrl.set_data(data)
Exemplo n.º 32
0
	def __populate_inbox(self):
		_log.debug('populating provider inbox')

		# calculate constraints
		pk_patient = None
		if self._CHBOX_active_patient.IsChecked():
			_log.debug('restricting to active patient')
			curr_pat = gmPerson.gmCurrentPatient()
			if curr_pat.connected:
				pk_patient = curr_pat.ID

		include_without_provider = True
		if self._CHBOX_active_provider.IsChecked():
			_log.debug('restricting to active provider directly')
			include_without_provider = False

		# get which messages to show
		if self._RBTN_relevant_messages.GetValue():
			_log.debug('loading relevant messages')
			self.__msgs = self.provider.inbox.get_relevant_messages (
				pk_patient = pk_patient,
				include_without_provider = include_without_provider
			)
		elif self._RBTN_all_messages.GetValue():
			_log.debug('loading all but expired messages')
			self.__msgs = self.provider.inbox.get_messages (
				pk_patient = pk_patient,
				include_without_provider = include_without_provider,
				exclude_expired = True,
				expired_only = False,
				overdue_only = False,
				unscheduled_only = False,
				exclude_unscheduled = False
			)
		elif self._RBTN_overdue_messages.GetValue():
			_log.debug('loading overdue messages only')
			self.__msgs = self.provider.inbox.get_messages (
				pk_patient = pk_patient,
				include_without_provider = include_without_provider,
				exclude_expired = True,
				expired_only = False,
				overdue_only = True,
				unscheduled_only = False,
				exclude_unscheduled = True,
				order_by = u'due_date, importance DESC, received_when DESC'
			)
		elif self._RBTN_scheduled_messages.GetValue():
			_log.debug('loading scheduled messages only')
			self.__msgs = self.provider.inbox.get_messages (
				pk_patient = pk_patient,
				include_without_provider = include_without_provider,
				exclude_expired = True,
				expired_only = False,
				overdue_only = False,
				unscheduled_only = False,
				exclude_unscheduled = True,
				order_by = u'due_date, importance DESC, received_when DESC'
			)
		elif self._RBTN_unscheduled_messages.GetValue():
			_log.debug('loading unscheduled messages only')
			self.__msgs = self.provider.inbox.get_messages (
				pk_patient = pk_patient,
				include_without_provider = include_without_provider,
				exclude_expired = True,
				expired_only = False,
				overdue_only = False,
				unscheduled_only = True,
				exclude_unscheduled = False
			)
		elif self._RBTN_expired_messages.GetValue():
			_log.debug('loading expired messages only')
			self.__msgs = self.provider.inbox.get_messages (
				pk_patient = pk_patient,
				include_without_provider = include_without_provider,
				exclude_expired = False,
				expired_only = True,
				overdue_only = False,
				unscheduled_only = False,
				exclude_unscheduled = True,
				order_by = u'expiry_date DESC, importance DESC, received_when DESC'
			)

		_log.debug('total # of inbox msgs: %s', len(self.__msgs))

		items = []
		for m in self.__msgs:
			item = [_indicator[m['importance']]]
			item.append(u'%s: %s%s%s' % (
				gmDateTime.pydt_strftime(m['received_when'], '%Y-%m-%d'),
				m['modified_by'],
				gmTools.u_right_arrow,
				gmTools.coalesce(m['provider'], _(u'all'))
			))
			if m['due_date'] is None:
				item.append(u'')
			else:
				if m['is_expired'] is True:
					item.append(_('expired'))
				else:
					if m['is_overdue'] is True:
						item.append(_('%s overdue') % gmDateTime.format_interval_medically(m['interval_due']))
					else:
						item.append(_('due in %s') % gmDateTime.format_interval_medically(m['interval_due']))
			item.append(u'%s - %s' % (m['l10n_category'], m['l10n_type']))
			item.append(m['comment'])
			items.append(item)

		_log.debug('# of list items created from msgs: %s', len(items))
		self._LCTRL_provider_inbox.set_string_items(items = items)
		self._LCTRL_provider_inbox.set_data(data = self.__msgs)
		self._LCTRL_provider_inbox.set_column_widths()
		self._TXT_inbox_item_comment.SetValue(u'')
		self.__update_greeting(len(items))