def _get_data_tooltip(self): if self.GetData() is None: return None enc = gmEMRStructItems.cEncounter( aPK_obj=list(self._data.values())[0]['data']) return enc.format(with_docs=False, with_tests=False, with_vaccinations=False, with_family_history=False)
def test_encounter_edit_area_panel(): app = wx.PyWidgetTester(size=(200, 300)) #emr = pat.emr #enc = emr.active_encounter enc = gmEMRStructItems.cEncounter(1) #pnl = cEncounterEditAreaPnl(app.frame, -1, encounter=enc) app.frame.Show(True) app.MainLoop()
def test_encounter_edit_area_dialog(): app = wx.PyWidgetTester(size=(200, 300)) #emr = pat.emr #enc = emr.active_encounter enc = gmEMRStructItems.cEncounter(1) dlg = cEncounterEditAreaDlg(parent=app.frame, id=-1, size=(400, 400), encounter=enc) dlg.ShowModal()
def _get_data_tooltip(self): if self.GetData() is None: return None enc = gmEMRStructItems.cEncounter(aPK_obj = self._data.values()[0]['data']) return enc.format ( with_docs = False, with_tests = False, with_vaccinations = False, with_family_history = False )
def _get_very_recent_encounter(pk_identity): cfg_db = gmCfg.cCfgSQL() min_ttl = cfg_db.get2 ( option = u'encounter.minimum_ttl', workplace = gmPraxis.gmCurrentPraxisBranch().active_workplace, bias = u'user', default = u'1 hour 30 minutes' ) cmd = u""" SELECT pk_encounter FROM clin.v_most_recent_encounters WHERE pk_patient = %s and last_affirmed > (now() - %s::interval) ORDER BY last_affirmed DESC""" rows, idx = gmPG2.run_ro_queries(queries = [{'cmd': cmd, 'args': [pk_identity, min_ttl]}]) if len(rows) == 0: _log.debug('no <very recent> encounter (younger than [%s]) found' % min_ttl) return None _log.debug('"very recent" encounter [%s] found and re-activated', rows[0][0]) return gmEMRStructItems.cEncounter(aPK_obj = rows[0][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)
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)