Example #1
0
    def __update_age_label(self):

        # no patient
        if not self.curr_pat.connected:
            self._LBL_age.SetLabel(_('<Age>'))
            self._LBL_age.SetToolTip(_('no patient selected'))
            return

        # gender is always known
        tt = _('Gender: %s (%s) - %s\n') % (self.curr_pat.gender_symbol,
                                            gmTools.coalesce(
                                                self.curr_pat['gender'], '?'),
                                            self.curr_pat.gender_string)

        # dob is not known
        if self.curr_pat['dob'] is None:
            age = '%s  %s' % (self.curr_pat.gender_symbol,
                              self.curr_pat.get_formatted_dob())
            self._LBL_age.SetLabel(age)
            self._LBL_age.SetToolTip(tt)
            return

        tt += _('Born: %s\n') % self.curr_pat.get_formatted_dob(
            format='%d %b %Y')

        # patient is dead
        if self.curr_pat['deceased'] is not None:
            tt += _('Died: %s\n') % gmDateTime.pydt_strftime(
                self.curr_pat['deceased'], '%d %b %Y')
            tt += _('At age: %s\n') % self.curr_pat['medical_age']
            age = '%s  %s - %s (%s)' % (
                self.curr_pat.gender_symbol,
                self.curr_pat.get_formatted_dob(format='%d %b %Y'),
                gmDateTime.pydt_strftime(
                    self.curr_pat['deceased'],
                    '%d %b %Y'), self.curr_pat['medical_age'])
            if self.curr_pat['dob_is_estimated']:
                tt += _(' (date of birth and age are estimated)\n')
            self._LBL_age.SetLabel(age)
            self._LBL_age.SetToolTip(tt)
            return

        # patient alive
        now = gmDateTime.pydt_now_here()

        # patient birthday ?
        if self.curr_pat.get_formatted_dob(
                format='%m-%d',
                honor_estimation=False) == now.strftime('%m-%d'):
            template = _('%(sex)s  %(dob)s (%(age)s today !)')
            tt += _("\nToday is the patient's birthday !\n\n")
            tt += _('Age: %s\n') % self.curr_pat['medical_age']
        else:
            tt += _('Age: %s, birthday:\n') % self.curr_pat['medical_age']
            if self.curr_pat.current_birthday_passed is True:
                template = '%(sex)s  %(dob)s%(l_arr)s (%(age)s)'
                tt += ' ' + _('last: %s ago (this year)'
                              ) % gmDateTime.format_apparent_age_medically(
                                  age=gmDateTime.calculate_apparent_age(
                                      start=self.curr_pat.birthday_this_year,
                                      end=now)) + '\n'
                tt += ' ' + _(
                    'next: in %s (next year)'
                ) % gmDateTime.format_apparent_age_medically(
                    age=gmDateTime.calculate_apparent_age(
                        start=now,
                        end=self.curr_pat.birthday_next_year)) + '\n'
            elif self.curr_pat.current_birthday_passed is False:
                template = '%(sex)s  %(r_arr)s%(dob)s (%(age)s)'
                tt += ' ' + _(
                    'next: in %s (this year)'
                ) % gmDateTime.format_apparent_age_medically(
                    age=gmDateTime.calculate_apparent_age(
                        start=now,
                        end=self.curr_pat.birthday_this_year)) + '\n'
                tt += ' ' + _('last: %s ago (last year)'
                              ) % gmDateTime.format_apparent_age_medically(
                                  age=gmDateTime.calculate_apparent_age(
                                      start=self.curr_pat.birthday_last_year,
                                      end=now)) + '\n'
            else:  # None, unknown
                template = '%(sex)s  %(dob)s (%(age)s)'

        # FIXME: if the age is below, say, 2 hours we should fire
        # a timer here that updates the age in increments of 1 minute ... :-)
        age = template % {
            'sex': self.curr_pat.gender_symbol,
            'dob': self.curr_pat.get_formatted_dob(format='%d %b %Y'),
            'age': self.curr_pat['medical_age'],
            'r_arr': gmTools.u_arrow2right,
            'l_arr': gmTools.u_left_arrow
        }

        # Easter Egg ;-)
        if self.curr_pat['lastnames'] == 'Leibner':
            if self.curr_pat['firstnames'] == 'Steffi':
                if self.curr_pat['preferred'] == 'Wildfang':
                    age = '%s %s' % (gmTools.u_black_heart, age)

        if self.curr_pat['dob_is_estimated']:
            tt += _(' (date of birth and age are estimated)\n')

        self._LBL_age.SetLabel(age)
        self._LBL_age.SetToolTip(tt)
Example #2
0
	def __update_age_label(self):

		# no patient
		if not self.curr_pat.connected:
			self._LBL_age.SetLabel(_('<Age>'))
			self._LBL_age.SetToolTipString(_('no patient selected'))
			return

		# gender is always known
		tt = _(u'Gender: %s (%s) - %s\n') % (
			self.curr_pat.gender_symbol,
			gmTools.coalesce(self.curr_pat[u'gender'], u'?'),
			self.curr_pat.gender_string
		)

		# dob is not known
		if self.curr_pat['dob'] is None:
			age = u'%s  %s' % (
				self.curr_pat.gender_symbol,
				self.curr_pat.get_formatted_dob()
			)
			self._LBL_age.SetLabel(age)
			self._LBL_age.SetToolTipString(tt)
			return

		tt += _('Born: %s\n') % self.curr_pat.get_formatted_dob(format = '%d %b %Y', encoding = gmI18N.get_encoding())

		# patient is dead
		if self.curr_pat['deceased'] is not None:
			tt += _('Died: %s\n') % gmDateTime.pydt_strftime(self.curr_pat['deceased'], '%d %b %Y')
			tt += _('At age: %s\n') % self.curr_pat['medical_age']
			age = u'%s  %s - %s (%s)' % (
				self.curr_pat.gender_symbol,
				self.curr_pat.get_formatted_dob(format = '%d %b %Y', encoding = gmI18N.get_encoding()),
				gmDateTime.pydt_strftime(self.curr_pat['deceased'], '%d %b %Y'),
				self.curr_pat['medical_age']
			)
			if self.curr_pat['dob_is_estimated']:
				tt += _(' (date of birth and age are estimated)\n')
			self._LBL_age.SetLabel(age)
			self._LBL_age.SetToolTipString(tt)
			return

		# patient alive
		now = gmDateTime.pydt_now_here()

		# patient birthday ?
		if self.curr_pat.get_formatted_dob(format = '%m-%d') == now.strftime('%m-%d'):
			template = _('%(sex)s  %(dob)s (%(age)s today !)')
			tt += _("\nToday is the patient's birthday !\n\n")
		else:
			if self.curr_pat.current_birthday_passed():
				template = u'%(sex)s  %(dob)s%(l_arr)s (%(age)s)'
				tt += _(u'Birthday: %s ago\n') % gmDateTime.format_apparent_age_medically (
					age = gmDateTime.calculate_apparent_age(start = self.curr_pat.birthday_this_year, end = now)
				)
			else:
				template = u'%(sex)s  %(r_arr)s%(dob)s (%(age)s)'
				tt += _(u'Birthday: in %s\n') % gmDateTime.format_apparent_age_medically (
					age = gmDateTime.calculate_apparent_age(start = now, end = self.curr_pat.birthday_this_year)
				)

		tt += _('Age: %s\n') % self.curr_pat['medical_age']

		# FIXME: if the age is below, say, 2 hours we should fire
		# a timer here that updates the age in increments of 1 minute ... :-)
		age = template % {
			u'sex': self.curr_pat.gender_symbol,
			u'dob': self.curr_pat.get_formatted_dob(format = '%d %b %Y', encoding = gmI18N.get_encoding()),
			u'age': self.curr_pat['medical_age'],
			u'r_arr': gmTools.u_right_arrow,
			u'l_arr': gmTools.u_left_arrow
		}

		# Easter Egg ;-)
		if self.curr_pat['lastnames'] == u'Leibner':
			if self.curr_pat['firstnames'] == u'Steffi':
				if self.curr_pat['preferred'] == u'Wildfang':
					age = u'%s %s' % (gmTools.u_black_heart, age)

		if self.curr_pat['dob_is_estimated']:
			tt += _(' (date of birth and age are estimated)\n')

		self._LBL_age.SetLabel(age)
		self._LBL_age.SetToolTipString(tt)
Example #3
0
def create_timeline_file(patient=None, filename=None, include_documents=False, include_vaccinations=False, include_encounters=False):

	emr = patient.emr
	global now
	now = gmDateTime.pydt_now_here()

	if filename is None:
		timeline_fname = gmTools.get_unique_filename(prefix = 'gm-', suffix = '.timeline')	# .timeline required ...
	else:
		timeline_fname = filename
	_log.debug('exporting EMR as timeline into [%s]', timeline_fname)
	timeline = io.open(timeline_fname, mode = 'wt', encoding = 'utf8', errors = 'xmlcharrefreplace')

	if patient['dob'] is None:
		lifespan_start = format_pydt(now.replace(year = now.year - 100))
	else:
		lifespan_start = format_pydt(patient['dob'])

	if patient['deceased'] is None:
		life_ends2day = 'True'
		lifespan_end = format_pydt(now)
	else:
		life_ends2day = 'False'
		lifespan_end = format_pydt(patient['deceased'])

	earliest_care_date = emr.earliest_care_date
	most_recent_care_date = emr.most_recent_care_date
	if most_recent_care_date is None:
		most_recent_care_date = lifespan_end
		care_ends2day = life_ends2day
	else:
		most_recent_care_date = format_pydt(most_recent_care_date)
		care_ends2day = 'False'

	timeline.write(xml_start % (
		# era: life span of patient
		_('Lifespan'),
		lifespan_start,
		lifespan_end,
		life_ends2day,
		ERA_NAME_CARE_PERIOD,
		format_pydt(earliest_care_date),
		most_recent_care_date,
		care_ends2day,
		# categories
		_('Health issues'),
		_('Episodes'),
		_('Encounters'),
		_('Hospital stays'),
		_('Procedures'),
		_('Documents'),
		_('Vaccinations'),
		_('Substances'),
		_('Life events')
	))
	# birth
	if patient['dob'] is None:
		start = now.replace(year = now.year - 100)
		timeline.write(__xml_encounter_template % (
			format_pydt(start),
			format_pydt(start),
			'?',
			_('Life events'),
			_('Date of birth unknown'),
			'True'
		))
	else:
		start = patient['dob']
		timeline.write(__xml_encounter_template % (
			format_pydt(patient['dob']),
			format_pydt(patient['dob']),
			'*',
			_('Life events'),
			_('Birth: %s') % patient.get_formatted_dob(format = '%Y %b %d %H:%M', honor_estimation = True),
			'True'
		))

	# start of care
	timeline.write(__xml_encounter_template % (
		format_pydt(earliest_care_date),
		format_pydt(earliest_care_date),
		gmTools.u_heavy_greek_cross,
		_('Life events'),
		_('Start of Care: %s\n(the earliest recorded event of care in this praxis)') % format_pydt(earliest_care_date, format = '%Y %b %d'),
		'True'
	))

	# containers must be defined before their
	# subevents, so put health issues first
	timeline.write('\n		<!-- ========================================\n Health issues\n======================================== -->')
	for issue in emr.health_issues:
		timeline.write(__format_health_issue_as_timeline_xml(issue, patient, emr))

	timeline.write('\n		<!-- ========================================\n Episodes\n======================================== -->')
	for epi in emr.get_episodes(order_by = 'pk_health_issue'):
		timeline.write(__format_episode_as_timeline_xml(epi, patient))

	if include_encounters:
		timeline.write(u'\n<!--\n========================================\n Encounters\n======================================== -->')
		for enc in emr.get_encounters(skip_empty = True):
			timeline.write(__format_encounter_as_timeline_xml(enc, patient))

	timeline.write('\n<!--\n========================================\n Hospital stays\n======================================== -->')
	for stay in emr.hospital_stays:
		timeline.write(__format_hospital_stay_as_timeline_xml(stay))

	timeline.write('\n<!--\n========================================\n Procedures\n======================================== -->')
	for proc in emr.performed_procedures:
		timeline.write(__format_procedure_as_timeline_xml(proc))

	if include_vaccinations:
		timeline.write(u'\n<!--\n========================================\n Vaccinations\n======================================== -->')
		for vacc in emr.vaccinations:
			timeline.write(__format_vaccination_as_timeline_xml(vacc))

	timeline.write('\n<!--\n========================================\n Substance intakes\n======================================== -->')
	for intake in emr.get_current_medications(include_inactive = True, include_unapproved = False):
		timeline.write(__format_intake_as_timeline_xml(intake))

	if include_documents:
		timeline.write(u'\n<!--\n========================================\n Documents\n======================================== -->')
		for doc in patient.document_folder.documents:
			timeline.write(__format_document_as_timeline_xml(doc))

	# allergies ?
	# - unclear where and how to place
	# test results ?
	# - too many events, at most "day sample drawn"

	# death
	if patient['deceased'] is None:
		end = now
	else:
		end = patient['deceased']
		death_ago = gmDateTime.format_apparent_age_medically (
			age = gmDateTime.calculate_apparent_age(start = end, end = now)
		)
		timeline.write(__xml_encounter_template % (
			format_pydt(end),
			format_pydt(end),
			gmTools.u_dagger,
			_('Life events'),
			_('Death: %s\n(%s ago at age %s)') % (
				format_pydt(end, format = '%Y %b %d %H:%M'),
				death_ago,
				patient.get_medical_age()
			),
			'True'
		))

	# display range
	if end.month == 2:
		if end.day == 29:
			# leap years aren't consecutive
			end = end.replace(day = 28)
	target_year = end.year + 1
	end = end.replace(year = target_year)
	timeline.write(xml_end % (
		format_pydt(start),
		format_pydt(end)
	))

	timeline.close()
	return timeline_fname
Example #4
0
    def __update_lab(self):

        if not self.curr_pat.connected:
            self._LBL_lab.SetLabel('')
            self._LBL_lab.SetToolTip(None)
            return

        tests2show = []
        tooltip_lines = []

        RRs = self.curr_pat.emr.get_most_recent_results_in_loinc_group(
            loincs=gmLOINC.LOINC_rr_quantity, max_no_of_results=1)
        if len(RRs) == 0:
            tests2show.append(_('BP ?'))
        else:
            tests2show.append(RRs[0]['unified_val'])
            tooltip_lines.append(
                _('BP: %s ago') % gmDateTime.format_apparent_age_medically(
                    age=gmDateTime.calculate_apparent_age(
                        start=RRs[0]['clin_when'])))

        HRs = self.curr_pat.emr.get_most_recent_results_in_loinc_group(
            loincs=gmLOINC.LOINC_heart_rate_quantity, max_no_of_results=1)
        if len(HRs) > 0:
            tests2show.append('@ %s' % HRs[0]['unified_val'])
            tooltip_lines.append(
                _('%s (@) in bpm: %s ago') %
                (HRs[0]['abbrev_tt'],
                 gmDateTime.format_apparent_age_medically(
                     age=gmDateTime.calculate_apparent_age(
                         start=HRs[0]['clin_when']))))

        bmi = self.curr_pat.emr.bmi
        if bmi.numeric_value is not None:
            tests2show.append(
                _('BMI %s') %
                bmi.numeric_value.quantize(decimal.Decimal('1.')))
            tooltip_lines.append(
                _('BMI: %s ago') % gmDateTime.format_apparent_age_medically(
                    age=gmDateTime.calculate_apparent_age(
                        start=bmi.date_valid)))
        else:
            weights = self.curr_pat.emr.get_most_recent_results_in_loinc_group(
                loincs=gmLOINC.LOINC_weight, max_no_of_results=1)
            if len(weights) == 0:
                tests2show.append(_('BMI ?'))
            else:
                tests2show.append(
                    '%s%s' %
                    (weights[0]['unified_val'], weights[0]['val_unit']))
                tooltip_lines.append(
                    _('weight: %s ago') %
                    gmDateTime.format_apparent_age_medically(
                        age=gmDateTime.calculate_apparent_age(
                            start=weights[0]['clin_when'])))

        gfr_or_crea = self.curr_pat.emr.best_gfr_or_crea
        if gfr_or_crea is None:
            tests2show.append(_('GFR ?'))
        else:
            try:
                tests2show.append(
                    _('GFR %s') %
                    gfr_or_crea.numeric_value.quantize(decimal.Decimal('1.')))
                tooltip_lines.append(
                    _('GFR: %s ago') %
                    gmDateTime.format_apparent_age_medically(
                        age=gmDateTime.calculate_apparent_age(
                            start=gfr_or_crea.date_valid)))
            except AttributeError:
                tests2show.append(
                    '%s %s' %
                    (gfr_or_crea['abbrev_tt'], gfr_or_crea['unified_val']))
                tooltip_lines.append(
                    _('%s: %s ago') %
                    (gfr_or_crea['abbrev_tt'],
                     gmDateTime.format_apparent_age_medically(
                         age=gmDateTime.calculate_apparent_age(
                             start=gfr_or_crea['clin_when']))))

        edc = self.curr_pat.emr.EDC
        if edc is not None:
            if self.curr_pat.emr.EDC_is_fishy:
                tests2show.append(
                    _('?EDC %s') % gmDateTime.pydt_strftime(
                        edc, '%Y-%b-%d', accuracy=gmDateTime.acc_days))
            else:
                tests2show.append(
                    _('EDC %s') % gmDateTime.pydt_strftime(
                        edc, '%Y-%b-%d', accuracy=gmDateTime.acc_days))

        INRs = self.curr_pat.emr.get_most_recent_results_in_loinc_group(
            loincs=gmLOINC.LOINC_inr_quantity, max_no_of_results=1)
        if len(INRs) > 0:
            tests2show.append('%s %s' %
                              (INRs[0]['abbrev_tt'], INRs[0]['unified_val']))
            tooltip_lines.append(
                _('%s: %s ago') % (INRs[0]['abbrev_tt'],
                                   gmDateTime.format_apparent_age_medically(
                                       age=gmDateTime.calculate_apparent_age(
                                           start=INRs[0]['clin_when']))))

        # include panel if configured, only show if exist
        if self.__lab_panel is not None:
            for result in self.__lab_panel.get_most_recent_results(
                    pk_patient=self.curr_pat.ID,
                    order_by='unified_abbrev',
                    group_by_meta_type=True):
                tests2show.append('%s %s' %
                                  (result['abbrev_tt'], result['unified_val']))
                tooltip_lines.append(
                    _('%s: %s ago') %
                    (result['abbrev_tt'],
                     gmDateTime.format_apparent_age_medically(
                         age=gmDateTime.calculate_apparent_age(
                             start=result['clin_when']))))
        self._LBL_lab.Label = '; '.join(tests2show)
        self._LBL_lab.SetToolTip('\n'.join(tooltip_lines))