File: gmAMTS_BMPWidgets.py

package info (click to toggle)
gnumed-client 1.8.5%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 37,672 kB
  • sloc: python: 126,459; javascript: 6,113; sh: 1,192; xml: 36; makefile: 33
file content (153 lines) | stat: -rw-r--r-- 3,893 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
# -*- coding: utf-8 -*-

__doc__ = """GNUmed AMTS BMP handling widgets."""

#================================================================
__author__ = "Karsten Hilbert <Karsten.Hilbert@gmx.net>"
__license__ = "GPL v2 or later"

import logging
import sys
import os.path
import typing


import wx


if __name__ == '__main__':
	sys.path.insert(0, '../../')
	from Gnumed.pycommon import gmI18N
	gmI18N.activate_locale()
	gmI18N.install_domain(domain = 'gnumed')
from Gnumed.pycommon import gmTools


from Gnumed.business import gmAMTS_BMP


from Gnumed.wxpython import gmListWidgets
from Gnumed.wxpython import gmGuiHelpers


_log = logging.getLogger('gm.amts_bmp')

#================================================================
def import_amts_bmp_for_patient(parent=None, patient=None):
	# check for xml files in /gnumed and /.gnumed
	# check xml files for bmp
	# check bmps for potentially belonging to patient
	bmp_filename = 'current_pat_bmp.xml'
	import_amts_bmp(parent = parent, bmp_file = bmp_filename)

#----------------------------------------------------------------


#----------------------------------------------------------------
def import_amts_bmp(parent=None, bmp_filename:str=None) -> typing.Union[bool, None]:
	if bmp_filename is None:
		dlg = wx.FileDialog (
			parent = parent,
			message = _('Choose an AMTS BMP medication plan.'),
			defaultDir = os.path.expanduser(os.path.join('~', 'gnumed')),
			defaultFile = '',
			wildcard = "%s (*.xml)|*.xml|%s (*)|*" % (_('BMP files'), _('all files')),
			style = wx.FD_OPEN | wx.FD_FILE_MUST_EXIST
		)
		result = dlg.ShowModal()
		if result == wx.ID_CANCEL:
			return None
		bmp_filename = dlg.GetPath()
		dlg.DestroyLater()

	dlg_title = _('Importing AMTS BMP Medikationsplan')
	bmp = gmAMTS_BMP.cAmtsBmpFile(bmp_filename)
	if not bmp.valid():
		gmGuiHelpers.gm_show_error (
			title = dlg_title,
			error = _(
				'The file\n'
				'\n'
				' [%s]\n'
				'\n'
				'does not seem to be a Medikationsplan.'
			) % bmp_filename
		)
		return False

	dto = bmp.patient_as_dto
	person = dto.unambiguous_identity
	if person is None:
		candidates = dto.candidate_identities
		if len(candidates) == 0:
			# no match found -> ask for creation or ask whether to import for the current patient
			curr_pat = gmPerson.gmCurrentPatient()
			if curr_pat.is_connected:
				gmGuiHelpers.c3ButtonQuestionDlg (
					parent = parent,
					caption = dlg_title,
					question = _(
						'No matching patient found in GNUmed.\n'
						'\n'
						'The patient in the Medikationsplan is:\n'
						'\n'
						' %s\n'
						'\n'
						'Do you want to create that patient ?'
				) % dto.format(),
					button_defs = [
					]
				)
			else:
				gmGuiHelpers.gm_show_question (
					title = dlg_title,
					question = _(
						'No matching patient found in GNUmed.\n'
						'\n'
						'The patient in the Medikationsplan is:\n'
						'\n'
						' %s\n'
						'\n'
						'Do you want to create that patient ?'
					) % dto.format()
				)

		elif len(candidates) == 1:
			# one match found -> ask whether to import
			pass
		else:
			# several found -> ask which to use
			pass

#		msg = _('None or several matching patients found.')
#		gmGuiHelpers.gm_show_info (
#			title = _('Importing AMTS BMP Medikationsplan'),
#			info = msg + '\n\n' + bmp.format(eol = '\n')
#		)
	else:
		gmGuiHelpers.gm_show_info (
			title = _('Importing AMTS BMP Medikationsplan'),
			info = bmp.format(eol = '\n')
		)
	return True
	# - import patient
	# - import provider as praxis
	# - import bmp as document
	#		type AMTS BMP
	#		comment UID
	# - link provider as document source

	# - import allergies (confirm)
	# - import other notes (schwanger, stillend) - confirm

	# - import drugs from bmp


#================================================================
if __name__ == '__main__':

	if len(sys.argv) < 2:
		sys.exit()

	if sys.argv[1] != 'test':
		sys.exit()