Example #1
0
	def _populate_with_data(self):
		pat = gmPerson.gmCurrentPatient()
		if not pat.connected:
			return True

		wx.BeginBusyCursor()
		try:
			self.__tl_file = gmTimelineExporter.create_timeline_file(patient = pat)
			self._PNL_timeline.open_timeline(self.__tl_file)
		except Exception:		# more specifically: TimelineIOError
			_log.exception('cannot load EMR from timeline XML')
			self._PNL_timeline.clear_timeline()
			self.__tl_file = gmTimelineExporter.create_fake_timeline_file(patient = pat)
			self._PNL_timeline.open_timeline(self.__tl_file)
			return True
		finally:
			wx.EndBusyCursor()

		return True
Example #2
0
	def _populate_with_data(self):
		pat = gmPerson.gmCurrentPatient()
		if not pat.connected:
			return True

		wx.BeginBusyCursor()
		try:
			self.__tl_file = gmTimelineExporter.create_timeline_file(patient = pat)
			self._PNL_timeline.open_timeline(self.__tl_file)
		except Exception:		# more specifically: TimelineIOError
			_log.exception('cannot load EMR from timeline XML')
			self._PNL_timeline.clear_timeline()
			self.__tl_file = gmTimelineExporter.create_fake_timeline_file(patient = pat)
			self._PNL_timeline.open_timeline(self.__tl_file)
			return True
		finally:
			wx.EndBusyCursor()

		return True
Example #3
0
def run_tool():
    tool = _cfg.get(option='--tool', source_order=[('cli', 'return')])
    if tool is None:
        # not running a tool
        return None

    if tool not in _known_tools:
        _log.error('unknown tool requested: %s', tool)
        print('GNUmed startup: Unknown tool [%s] requested.' % tool)
        print('GNUmed startup: Known tools: %s' % _known_tools)
        return -1

    print('')
    print('==============================================')
    print('Running tool: %s' % tool)
    print('----------------------------------------------')
    print('')

    if tool == 'check_enc_epi_xref':
        from Gnumed.business import gmEMRStructItems
        return gmEMRStructItems.check_fk_encounter_fk_episode_x_ref()

    if tool == 'export_pat_emr_structure':
        # setup praxis
        from Gnumed.business import gmPraxis
        praxis = gmPraxis.gmCurrentPraxisBranch(
            branch=gmPraxis.get_praxis_branches()[0])
        # get patient
        from Gnumed.business import gmPersonSearch
        pat = gmPersonSearch.ask_for_patient()
        # setup exporters
        from Gnumed.business import gmEMRStructItems
        from Gnumed.exporters import gmTimelineExporter
        from Gnumed.exporters import gmPatientExporter
        while pat is not None:
            print('patient:', pat['description_gender'])
            # as EMR structure
            fname = os.path.expanduser('~/gnumed/gm-emr_structure-%s.txt' %
                                       pat.subdir_name)
            print(
                'EMR structure:',
                gmEMRStructItems.export_emr_structure(patient=pat,
                                                      filename=fname))
            # as timeline
            fname = os.path.expanduser('~/gnumed/gm-emr-%s.timeline' %
                                       pat.subdir_name)
            try:
                print(
                    'EMR timeline:',
                    gmTimelineExporter.create_timeline_file(
                        patient=pat,
                        filename=fname,
                        include_documents=True,
                        include_vaccinations=True,
                        include_encounters=True))
            finally:
                pass
            # as journal by encounter
            exporter = gmPatientExporter.cEMRJournalExporter()
            fname = os.path.expanduser(
                '~/gnumed/gm-emr-journal_by_encounter-%s.txt' %
                pat.subdir_name)
            print(
                'EMR journal (by encounter):',
                exporter.save_to_file_by_encounter(patient=pat,
                                                   filename=fname))
            # as journal by mod time
            fname = os.path.expanduser(
                '~/gnumed/gm-emr-journal_by_mod_time-%s.txt' % pat.subdir_name)
            print(
                'EMR journal (by mod time):',
                exporter.save_to_file_by_mod_time(patient=pat, filename=fname))
            # as statistical summary
            fname = os.path.expanduser('~/gnumed/gm-emr-statistics-%s.txt' %
                                       pat.subdir_name)
            output_file = io.open(fname,
                                  mode='wt',
                                  encoding='utf8',
                                  errors='replace')
            emr = pat.emr
            output_file.write(emr.format_statistics())
            output_file.close()
            print('EMR statistics:', fname)
            # as text file
            exporter = gmPatientExporter.cEmrExport(patient=pat)
            fname = os.path.expanduser('~/gnumed/gm-emr-text_export-%s.txt' %
                                       pat.subdir_name)
            output_file = io.open(fname,
                                  mode='wt',
                                  encoding='utf8',
                                  errors='replace')
            exporter.set_output_file(output_file)
            exporter.dump_constraints()
            exporter.dump_demographic_record(True)
            exporter.dump_clinical_record()
            exporter.dump_med_docs()
            output_file.close()
            print('EMR text file:', fname)
            # another patient ?
            pat = gmPersonSearch.ask_for_patient()

        return 0

    # tool export_patient_as (vcf, gdt, ...)
    #if tool == 'export_pat_demographics':

    # should not happen (because checked against _known_tools)
    return -1
Example #4
0
def run_tool():
    """Run a console tool.

	Exit codes as per man page:
		   0: normal termination of the client
		 < 0: some error occurred while trying to run a console tool
			  -1: an unknown console tool was requested
			< -1: an error occurred while a console tool was run
		-999: hard abort of the client

	One of these needs to be returned from this function (and,
	by extension from the tool having been run, if any).
	"""
    tool = _cfg.get(option='--tool', source_order=[('cli', 'return')])
    if tool is None:
        # not running a tool
        return None

    if tool not in _known_tools:
        _log.error('unknown tool requested: %s', tool)
        print('GNUmed startup: Unknown tool [%s] requested.' % tool)
        print('GNUmed startup: Known tools: %s' % _known_tools)
        return -1

    print('')
    print('==============================================')
    print('Running tool: %s' % tool)
    print('----------------------------------------------')
    print('')

    if tool == 'generate_man_page':
        man_page_fname = os.path.abspath(os.path.join('.', 'gnumed.1'))
        man_page_file = open(man_page_fname, mode='wt', encoding='utf8')
        man_page_file.write(__doc__ % datetime.date.today().strftime('%x'))
        man_page_file.close()
        print('MAN page saved as:', man_page_fname)
        return 0

    login, creds = gmPG2.request_login_params()
    pool = gmConnectionPool.gmConnectionPool()
    pool.credentials = creds
    print('')

    if tool == 'read_all_rows_of_table':
        result = gmPG2.read_all_rows_of_table()
        if result in [None, True]:
            print('Success.')
            return 0
        print('Failed. Check the log for details.')
        return -2

    if tool == 'check_mimetypes_in_archive':
        from Gnumed.business import gmDocuments
        return gmDocuments.check_mimetypes_in_archive()

    if tool == 'check_enc_epi_xref':
        from Gnumed.business import gmEMRStructItems
        return gmEMRStructItems.check_fk_encounter_fk_episode_x_ref()

    if tool == 'fingerprint_db':
        fname = 'db-fingerprint.txt'
        result = gmPG2.get_db_fingerprint(fname=fname, with_dump=True)
        if result == fname:
            print('Success: %s' % fname)
            return 0
        print('Failed. Check the log for details.')
        return -2

    if tool == 'export_pat_emr_structure':
        # setup praxis
        from Gnumed.business import gmPraxis
        praxis = gmPraxis.gmCurrentPraxisBranch(
            branch=gmPraxis.get_praxis_branches()[0])
        # get patient
        from Gnumed.business import gmPersonSearch
        pat = gmPersonSearch.ask_for_patient()
        # setup exporters
        from Gnumed.business import gmEMRStructItems
        from Gnumed.exporters import gmTimelineExporter
        from Gnumed.exporters import gmPatientExporter
        while pat is not None:
            print('patient:', pat.description_gender)
            # as EMR structure
            fname = os.path.expanduser('~/gnumed/gm-emr_structure-%s.txt' %
                                       pat.subdir_name)
            print(
                'EMR structure:',
                gmEMRStructItems.export_emr_structure(patient=pat,
                                                      filename=fname))
            # as timeline
            fname = os.path.expanduser('~/gnumed/gm-emr-%s.timeline' %
                                       pat.subdir_name)
            try:
                print(
                    'EMR timeline:',
                    gmTimelineExporter.create_timeline_file(
                        patient=pat,
                        filename=fname,
                        include_documents=True,
                        include_vaccinations=True,
                        include_encounters=True))
            finally:
                pass
            # as journal by encounter
            exporter = gmPatientExporter.cEMRJournalExporter()
            fname = os.path.expanduser(
                '~/gnumed/gm-emr-journal_by_encounter-%s.txt' %
                pat.subdir_name)
            print(
                'EMR journal (by encounter):',
                exporter.save_to_file_by_encounter(patient=pat,
                                                   filename=fname))
            # as journal by mod time
            fname = os.path.expanduser(
                '~/gnumed/gm-emr-journal_by_mod_time-%s.txt' % pat.subdir_name)
            print(
                'EMR journal (by mod time):',
                exporter.save_to_file_by_mod_time(patient=pat, filename=fname))
            # as statistical summary
            fname = os.path.expanduser('~/gnumed/gm-emr-statistics-%s.txt' %
                                       pat.subdir_name)
            output_file = open(fname,
                               mode='wt',
                               encoding='utf8',
                               errors='replace')
            emr = pat.emr
            output_file.write(emr.format_statistics())
            output_file.close()
            print('EMR statistics:', fname)
            # as text file
            exporter = gmPatientExporter.cEmrExport(patient=pat)
            fname = os.path.expanduser('~/gnumed/gm-emr-text_export-%s.txt' %
                                       pat.subdir_name)
            output_file = open(fname,
                               mode='wt',
                               encoding='utf8',
                               errors='replace')
            exporter.set_output_file(output_file)
            exporter.dump_constraints()
            exporter.dump_demographic_record(True)
            exporter.dump_clinical_record()
            exporter.dump_med_docs()
            output_file.close()
            print('EMR text file:', fname)
            # another patient ?
            pat = gmPersonSearch.ask_for_patient()
        return 0

    # tool export_patient_as (vcf, gdt, ...)
    #if tool == 'export_pat_demographics':

    # should not happen (because checked against _known_tools)
    return -1
Example #5
0
def run_tool():
	tool = _cfg.get(option = '--tool', source_order = [('cli', 'return')])
	if tool is None:
		# not running a tool
		return None

	if tool not in _known_tools:
		_log.error('unknown tool requested: %s', tool)
		print('GNUmed startup: Unknown tool [%s] requested.' % tool)
		print('GNUmed startup: Known tools: %s' % _known_tools)
		return -1

	print('')
	print('==============================================')
	print('Running tool: %s' % tool)
	print('----------------------------------------------')
	print('')

	if tool == 'check_enc_epi_xref':
		from Gnumed.business import gmEMRStructItems
		return gmEMRStructItems.check_fk_encounter_fk_episode_x_ref()

	if tool == 'export_pat_emr_structure':
		# setup praxis
		from Gnumed.business import gmPraxis
		praxis = gmPraxis.gmCurrentPraxisBranch(branch = gmPraxis.get_praxis_branches()[0])
		# get patient
		from Gnumed.business import gmPersonSearch
		pat = gmPersonSearch.ask_for_patient()
		# setup exporters
		from Gnumed.business import gmEMRStructItems
		from Gnumed.exporters import gmTimelineExporter
		from Gnumed.exporters import gmPatientExporter
		while pat is not None:
			print('patient:', pat['description_gender'])
			# as EMR structure
			fname = os.path.expanduser('~/gnumed/gm-emr_structure-%s.txt' % pat.subdir_name)
			print('EMR structure:', gmEMRStructItems.export_emr_structure(patient = pat, filename = fname))
			# as timeline
			fname = os.path.expanduser('~/gnumed/gm-emr-%s.timeline' % pat.subdir_name)
			try:
				print('EMR timeline:', gmTimelineExporter.create_timeline_file (
					patient = pat,
					filename = fname,
					include_documents = True,
					include_vaccinations = True,
					include_encounters = True
				))
			finally:
				pass
			# as journal by encounter
			exporter = gmPatientExporter.cEMRJournalExporter()
			fname = os.path.expanduser('~/gnumed/gm-emr-journal_by_encounter-%s.txt' % pat.subdir_name)
			print('EMR journal (by encounter):', exporter.save_to_file_by_encounter(patient = pat, filename = fname))
			# as journal by mod time
			fname = os.path.expanduser('~/gnumed/gm-emr-journal_by_mod_time-%s.txt' % pat.subdir_name)
			print('EMR journal (by mod time):', exporter.save_to_file_by_mod_time(patient = pat, filename = fname))
			# as statistical summary
			fname = os.path.expanduser('~/gnumed/gm-emr-statistics-%s.txt' % pat.subdir_name)
			output_file = io.open(fname, mode = 'wt', encoding = 'utf8', errors = 'replace')
			emr = pat.emr
			output_file.write(emr.format_statistics())
			output_file.close()
			print('EMR statistics:', fname)
			# as text file
			exporter = gmPatientExporter.cEmrExport(patient = pat)
			fname = os.path.expanduser('~/gnumed/gm-emr-text_export-%s.txt' % pat.subdir_name)
			output_file = io.open(fname, mode = 'wt', encoding = 'utf8', errors = 'replace')
			exporter.set_output_file(output_file)
			exporter.dump_constraints()
			exporter.dump_demographic_record(True)
			exporter.dump_clinical_record()
			exporter.dump_med_docs()
			output_file.close()
			print('EMR text file:', fname)
			# another patient ?
			pat = gmPersonSearch.ask_for_patient()

		return 0

	# tool export_patient_as (vcf, gdt, ...)
	#if tool == 'export_pat_demographics':

	# should not happen (because checked against _known_tools)
	return -1