mbu-dev-shared-components 1.2.1__tar.gz → 2.0.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (60) hide show
  1. {mbu_dev_shared_components-1.2.1 → mbu_dev_shared_components-2.0.1}/PKG-INFO +1 -1
  2. mbu_dev_shared_components-2.0.1/mbu_dev_shared_components/solteqtand/__init__.py +8 -0
  3. mbu_dev_shared_components-2.0.1/mbu_dev_shared_components/solteqtand/application/__init__.py +4 -0
  4. mbu_dev_shared_components-2.0.1/mbu_dev_shared_components/solteqtand/application/app_handler.py +123 -0
  5. mbu_dev_shared_components-2.0.1/mbu_dev_shared_components/solteqtand/application/appointment.py +333 -0
  6. mbu_dev_shared_components-2.0.1/mbu_dev_shared_components/solteqtand/application/base_ui.py +100 -0
  7. mbu_dev_shared_components-2.0.1/mbu_dev_shared_components/solteqtand/application/clinic.py +75 -0
  8. mbu_dev_shared_components-2.0.1/mbu_dev_shared_components/solteqtand/application/document.py +399 -0
  9. mbu_dev_shared_components-2.0.1/mbu_dev_shared_components/solteqtand/application/edi_portal.py +132 -0
  10. mbu_dev_shared_components-2.0.1/mbu_dev_shared_components/solteqtand/application/event.py +51 -0
  11. mbu_dev_shared_components-2.0.1/mbu_dev_shared_components/solteqtand/application/exceptions.py +20 -0
  12. mbu_dev_shared_components-2.0.1/mbu_dev_shared_components/solteqtand/application/handler_base.py +13 -0
  13. mbu_dev_shared_components-2.0.1/mbu_dev_shared_components/solteqtand/application/patient.py +264 -0
  14. mbu_dev_shared_components-2.0.1/mbu_dev_shared_components/solteqtand/database/__init__.py +1 -0
  15. {mbu_dev_shared_components-1.2.1/mbu_dev_shared_components/solteqtand → mbu_dev_shared_components-2.0.1/mbu_dev_shared_components/solteqtand/database}/db_handler.py +38 -6
  16. {mbu_dev_shared_components-1.2.1 → mbu_dev_shared_components-2.0.1}/mbu_dev_shared_components.egg-info/PKG-INFO +1 -1
  17. {mbu_dev_shared_components-1.2.1 → mbu_dev_shared_components-2.0.1}/mbu_dev_shared_components.egg-info/SOURCES.txt +13 -3
  18. {mbu_dev_shared_components-1.2.1 → mbu_dev_shared_components-2.0.1}/pyproject.toml +1 -1
  19. mbu_dev_shared_components-1.2.1/mbu_dev_shared_components/solteqtand/app_handler.py +0 -1668
  20. mbu_dev_shared_components-1.2.1/mbu_dev_shared_components/solteqtand/helper_functions.py +0 -107
  21. mbu_dev_shared_components-1.2.1/mbu_dev_shared_components/utils/__init__.py +0 -0
  22. {mbu_dev_shared_components-1.2.1 → mbu_dev_shared_components-2.0.1}/LICENSE +0 -0
  23. {mbu_dev_shared_components-1.2.1 → mbu_dev_shared_components-2.0.1}/README.md +0 -0
  24. {mbu_dev_shared_components-1.2.1 → mbu_dev_shared_components-2.0.1}/mbu_dev_shared_components/database/__init__.py +0 -0
  25. {mbu_dev_shared_components-1.2.1 → mbu_dev_shared_components-2.0.1}/mbu_dev_shared_components/database/constants.py +0 -0
  26. {mbu_dev_shared_components-1.2.1 → mbu_dev_shared_components-2.0.1}/mbu_dev_shared_components/database/logging.py +0 -0
  27. {mbu_dev_shared_components-1.2.1 → mbu_dev_shared_components-2.0.1}/mbu_dev_shared_components/database/utility.py +0 -0
  28. {mbu_dev_shared_components-1.2.1 → mbu_dev_shared_components-2.0.1}/mbu_dev_shared_components/getorganized/__init__.py +0 -0
  29. {mbu_dev_shared_components-1.2.1 → mbu_dev_shared_components-2.0.1}/mbu_dev_shared_components/getorganized/auth.py +0 -0
  30. {mbu_dev_shared_components-1.2.1 → mbu_dev_shared_components-2.0.1}/mbu_dev_shared_components/getorganized/cases.py +0 -0
  31. {mbu_dev_shared_components-1.2.1 → mbu_dev_shared_components-2.0.1}/mbu_dev_shared_components/getorganized/contacts.py +0 -0
  32. {mbu_dev_shared_components-1.2.1 → mbu_dev_shared_components-2.0.1}/mbu_dev_shared_components/getorganized/documents.py +0 -0
  33. {mbu_dev_shared_components-1.2.1 → mbu_dev_shared_components-2.0.1}/mbu_dev_shared_components/getorganized/objects.py +0 -0
  34. {mbu_dev_shared_components-1.2.1 → mbu_dev_shared_components-2.0.1}/mbu_dev_shared_components/google/__init__.py +0 -0
  35. {mbu_dev_shared_components-1.2.1 → mbu_dev_shared_components-2.0.1}/mbu_dev_shared_components/google/api/__init__.py +0 -0
  36. {mbu_dev_shared_components-1.2.1 → mbu_dev_shared_components-2.0.1}/mbu_dev_shared_components/google/api/auth.py +0 -0
  37. {mbu_dev_shared_components-1.2.1 → mbu_dev_shared_components-2.0.1}/mbu_dev_shared_components/google/workspace/__init__.py +0 -0
  38. {mbu_dev_shared_components-1.2.1 → mbu_dev_shared_components-2.0.1}/mbu_dev_shared_components/google/workspace/alerts.py +0 -0
  39. {mbu_dev_shared_components-1.2.1 → mbu_dev_shared_components-2.0.1}/mbu_dev_shared_components/msoffice365/__init__.py +0 -0
  40. {mbu_dev_shared_components-1.2.1 → mbu_dev_shared_components-2.0.1}/mbu_dev_shared_components/msoffice365/excel/__init__.py +0 -0
  41. {mbu_dev_shared_components-1.2.1 → mbu_dev_shared_components-2.0.1}/mbu_dev_shared_components/msoffice365/excel/excel_reader.py +0 -0
  42. {mbu_dev_shared_components-1.2.1 → mbu_dev_shared_components-2.0.1}/mbu_dev_shared_components/msoffice365/sharepoint_api/__init__.py +0 -0
  43. {mbu_dev_shared_components-1.2.1 → mbu_dev_shared_components-2.0.1}/mbu_dev_shared_components/msoffice365/sharepoint_api/files.py +0 -0
  44. {mbu_dev_shared_components-1.2.1 → mbu_dev_shared_components-2.0.1}/mbu_dev_shared_components/os2forms/__init__.py +0 -0
  45. {mbu_dev_shared_components-1.2.1 → mbu_dev_shared_components-2.0.1}/mbu_dev_shared_components/os2forms/documents.py +0 -0
  46. {mbu_dev_shared_components-1.2.1 → mbu_dev_shared_components-2.0.1}/mbu_dev_shared_components/os2forms/forms.py +0 -0
  47. {mbu_dev_shared_components-1.2.1 → mbu_dev_shared_components-2.0.1}/mbu_dev_shared_components/romexis/__init__.py +0 -0
  48. {mbu_dev_shared_components-1.2.1 → mbu_dev_shared_components-2.0.1}/mbu_dev_shared_components/romexis/db_handler.py +0 -0
  49. {mbu_dev_shared_components-1.2.1 → mbu_dev_shared_components-2.0.1}/mbu_dev_shared_components/romexis/helper_functions.py +0 -0
  50. {mbu_dev_shared_components-1.2.1 → mbu_dev_shared_components-2.0.1}/mbu_dev_shared_components/sap/__init__.py +0 -0
  51. {mbu_dev_shared_components-1.2.1 → mbu_dev_shared_components-2.0.1}/mbu_dev_shared_components/sap/create_invoice.py +0 -0
  52. {mbu_dev_shared_components-1.2.1/mbu_dev_shared_components/solteqtand → mbu_dev_shared_components-2.0.1/mbu_dev_shared_components/utils}/__init__.py +0 -0
  53. {mbu_dev_shared_components-1.2.1 → mbu_dev_shared_components-2.0.1}/mbu_dev_shared_components/utils/db_stored_procedure_executor.py +0 -0
  54. {mbu_dev_shared_components-1.2.1 → mbu_dev_shared_components-2.0.1}/mbu_dev_shared_components/utils/fernet_encryptor.py +0 -0
  55. {mbu_dev_shared_components-1.2.1 → mbu_dev_shared_components-2.0.1}/mbu_dev_shared_components/utils/file_handler.py +0 -0
  56. {mbu_dev_shared_components-1.2.1 → mbu_dev_shared_components-2.0.1}/mbu_dev_shared_components/utils/json_handler.py +0 -0
  57. {mbu_dev_shared_components-1.2.1 → mbu_dev_shared_components-2.0.1}/mbu_dev_shared_components.egg-info/dependency_links.txt +0 -0
  58. {mbu_dev_shared_components-1.2.1 → mbu_dev_shared_components-2.0.1}/mbu_dev_shared_components.egg-info/requires.txt +0 -0
  59. {mbu_dev_shared_components-1.2.1 → mbu_dev_shared_components-2.0.1}/mbu_dev_shared_components.egg-info/top_level.txt +0 -0
  60. {mbu_dev_shared_components-1.2.1 → mbu_dev_shared_components-2.0.1}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: mbu_dev_shared_components
3
- Version: 1.2.1
3
+ Version: 2.0.1
4
4
  Summary: Shared components to use in RPA projects
5
5
  Author-email: MBU <rpa@mbu.aarhus.dk>
6
6
  Classifier: Programming Language :: Python :: 3
@@ -0,0 +1,8 @@
1
+ # mbu_dev_shared_components/solteqtand/__init__.py
2
+ from .application import SolteqTandApp
3
+ from .database import SolteqTandDatabase
4
+
5
+ __all__ = [
6
+ "SolteqTandApp",
7
+ "SolteqTandDatabase",
8
+ ]
@@ -0,0 +1,4 @@
1
+ # mbu_dev_shared_components/solteqtand/application/__init__.py
2
+ from .app_handler import SolteqTandApp
3
+
4
+ __all__ = ["SolteqTandApp"]
@@ -0,0 +1,123 @@
1
+ """This module contains the PatientHandler class, which manages patient-related actions in the Solteq Tand application."""
2
+ import os
3
+ import uiautomation as auto
4
+
5
+ from .base_ui import BaseUI
6
+
7
+
8
+ class SolteqTandApp(BaseUI):
9
+ """
10
+ Main application handler for Solteq Tand, integrating various components.
11
+ Inherits from BaseUI for core UI methods, and composes all feature handlers.
12
+ """
13
+
14
+ def __init__(self, app_path: str, username: str = None, password: str = None):
15
+ """
16
+ Initializes the Solteq Tand application handler.
17
+ Args:
18
+ app_path (str): Path to the Solteq Tand application executable.
19
+ username (str): Username for login.
20
+ password (str): Password for login.
21
+ """
22
+ super().__init__()
23
+ self.app_path = app_path
24
+ self.username = username
25
+ self.password = password
26
+ self.app_window = None
27
+
28
+ # Compose feature handlers, passing this App as parent
29
+ from .patient import PatientHandler
30
+ from .appointment import AppointmentHandler
31
+ from .document import DocumentHandler
32
+ from .edi_portal import EDIHandler
33
+ from .clinic import ClinicHandler
34
+ from .event import EventHandler
35
+
36
+ self.patient = PatientHandler(self)
37
+ self.appointment = AppointmentHandler(self)
38
+ self.document = DocumentHandler(self)
39
+ self.edi = EDIHandler(self)
40
+ self.clinic = ClinicHandler(self)
41
+ self.event = EventHandler(self)
42
+
43
+ def start_application(self):
44
+ """
45
+ Starts the application using the specified path.
46
+ """
47
+ os.startfile(self.app_path)
48
+
49
+ def login(self):
50
+ """
51
+ Logs into the application by entering the username and password.
52
+ Checks if the login window is open and ready.
53
+ Checks if the main window is opened and ready.
54
+ """
55
+ self.app_window = self.wait_for_control(
56
+ auto.WindowControl,
57
+ {'AutomationId': 'FormLogin'},
58
+ search_depth=3,
59
+ timeout=60
60
+ )
61
+ self.app_window.SetFocus()
62
+
63
+ username_box = self.app_window.EditControl(AutomationId="TextLogin")
64
+ username_box.SendKeys(text=self.username)
65
+
66
+ password_box = self.app_window.EditControl(AutomationId="TextPwd")
67
+ password_box.SendKeys(text=self.password)
68
+
69
+ login_button = self.app_window.PaneControl(AutomationId="ButtonLogin")
70
+ login_button.SetFocus()
71
+ login_button.SendKeys('{ENTER}')
72
+
73
+ self.app_window = self.wait_for_control(
74
+ auto.WindowControl,
75
+ {'AutomationId': 'FormFront'},
76
+ search_depth=2,
77
+ timeout=60
78
+ )
79
+
80
+ def open_sub_tab(self, sub_tab_name: str):
81
+ """
82
+ Opens a specific sub-tab in the patient's main card.
83
+
84
+ Args:
85
+ sub_tab_name (str): The name of the sub-tab to open (e.g., "Dokumenter").
86
+ """
87
+ sub_tab_button = self.app_window.TabItemControl(Name=sub_tab_name)
88
+ is_sub_tab_selected = sub_tab_button.GetPattern(10010).IsSelected
89
+
90
+ if not is_sub_tab_selected:
91
+ sub_tab_button.SetFocus()
92
+ sub_tab_button.SendKeys('{ENTER}')
93
+
94
+ def open_tab(self, tab_name: str):
95
+ """
96
+ Opens a specific tab in the patient's main card.
97
+ Poosibly functionality on other parts of Solteq with tabs as well.
98
+
99
+ Args:
100
+ tab_name (str): The name of the tab to open (e.g., "Frit valg").
101
+ """
102
+ match tab_name:
103
+ case "Stamkort":
104
+ tab_name_modified = "S&tamkort"
105
+ case "Fritvalg":
106
+ tab_name_modified = "F&ritvalg"
107
+ case "Journal":
108
+ tab_name_modified = "&Journal"
109
+ case "Oversigt":
110
+ tab_name_modified = "O&versigt"
111
+ case _:
112
+ tab_name_modified = tab_name
113
+
114
+ tab_button = self.find_element_by_property(
115
+ control=self.app_window,
116
+ control_type=auto.ControlType.TabItemControl,
117
+ name=tab_name_modified
118
+ )
119
+ is_tab_selected = tab_button.GetPattern(10010).IsSelected
120
+
121
+ if not is_tab_selected:
122
+ tab_button.SetFocus()
123
+ tab_button.SendKeys('{ENTER}')
@@ -0,0 +1,333 @@
1
+ import uiautomation as auto
2
+
3
+ from .handler_base import HandlerBase
4
+ from .exceptions import ManualProcessingRequiredError
5
+
6
+
7
+ class AppointmentHandler(HandlerBase):
8
+ """
9
+ Handles appointment-related UI interactions.
10
+ """
11
+ def get_list_of_appointments(self) -> dict:
12
+ """
13
+ Gets list of appointments as found in patient window
14
+
15
+ Returns
16
+ booking_list_dict (dict): Dictionary with appointments and informations
17
+ booking_list_ctrls (list): List with the control related to each appointment
18
+
19
+ Todo: Assure that view is on patient
20
+ """
21
+ # Open "Stamkort"
22
+ self.open_tab("Stamkort")
23
+
24
+ # Read elements in list and check that expected element exists
25
+ # First get the list of appointments
26
+ list_parent = self.find_element_by_property(
27
+ control=self.app_window,
28
+ automation_id='ControlBookingDay'
29
+ )
30
+ booking_list_ctrl = self.find_element_by_property(
31
+ control=list_parent,
32
+ control_type=50008
33
+ )
34
+ # Initiate dictionary for list elements
35
+ booking_list = {'controls': []}
36
+ # Initiate list to hold headers
37
+ booking_list_keys = []
38
+ rowcount = 0
39
+
40
+ # Check for header
41
+ if booking_list_ctrl.GetFirstChildControl().ControlType == 50034:
42
+ # Loop through all elements in list
43
+ for elem in booking_list_ctrl.GetChildren():
44
+ # If header, then add each item to list of headers
45
+ if elem.ControlType == 50034:
46
+ for colname in elem.GetChildren():
47
+ booking_list_keys.append(colname.Name)
48
+ booking_list[colname.Name] = []
49
+ # If listitem, then add each item to dict
50
+ if elem.ControlType == 50007:
51
+ booking_list['controls'].append(elem) # Adds the control to accessed later
52
+ vals = elem.GetChildren() # Extracts all information from control
53
+
54
+ for headercount, val in enumerate(vals):
55
+ booking_list[booking_list_keys[headercount]].append(val.Name)
56
+ rowcount += 1
57
+
58
+ return booking_list
59
+
60
+ def change_appointment_status(
61
+ self,
62
+ appointment_control: auto.ControlType,
63
+ set_status: str,
64
+ send_msg: bool = False
65
+ ):
66
+ """
67
+ Changes status of appointment and optionally sends message
68
+
69
+ Args:
70
+ appointment_control (Control): Control element that identifies the appointment to be changed
71
+ set_status (str): The status which the appointment should be changed to.
72
+ send_msg (bool, optional): Indicates whether message should be sent when status is changed.
73
+ """
74
+ appointment_control.GetInvokePattern().Invoke()
75
+
76
+ # Find booking control
77
+ booking_control = self.wait_for_control(
78
+ control_type=auto.PaneControl,
79
+ search_params={
80
+ 'AutomationId': 'ManageBookingControl'
81
+ },
82
+ search_depth=3
83
+ )
84
+
85
+ # Find appointment status dropdown
86
+ status_control = self.find_element_by_property(
87
+ control=booking_control,
88
+ control_type=50003,
89
+ name='Status'
90
+ )
91
+ # Get current status to reset if warning on save
92
+ current_status = status_control.GetValuePattern().Value
93
+
94
+ # Open dropdown
95
+ self.find_element_by_property(
96
+ control=status_control,
97
+ control_type=50000
98
+ ).GetInvokePattern().Invoke()
99
+
100
+ # Get list control for all status options
101
+ status_list_ctrl = self.wait_for_control(
102
+ control_type=auto.ListControl,
103
+ search_params={
104
+ 'ClassName': 'ComboLBox'
105
+ }
106
+ )
107
+ # Load status options into dict with controls, names and lowercase names
108
+ status_dict = {
109
+ 'ctrls' : [elem for elem in status_list_ctrl.GetChildren() if elem.ControlType == 50007],
110
+ 'names' : [elem.Name for elem in status_list_ctrl.GetChildren() if elem.ControlType == 50007],
111
+ 'names_lo': [elem.Name.lower() for elem in status_list_ctrl.GetChildren() if elem.ControlType == 50007]
112
+ }
113
+
114
+ # Set new status if valid, otherwise return error
115
+ if set_status.lower() in status_dict['names_lo']:
116
+ list_no = status_dict['names_lo'].index(set_status.lower())
117
+ status_dict['ctrls'][list_no].GetInvokePattern().Invoke()
118
+ # Click "Gem og udsend"
119
+ self.app_window = booking_control
120
+ if send_msg:
121
+ save_button = self.find_element_by_property(
122
+ control=booking_control,
123
+ automation_id = "ButtonSavePrint"
124
+ )
125
+ else:
126
+ save_button = self.find_element_by_property(
127
+ control=booking_control,
128
+ automation_id = "ButtonOk"
129
+ )
130
+ save_button.SendKeys('{ENTER}')
131
+ # Check for notification window pop up
132
+ try:
133
+ notification_ctrl = self.wait_for_control(
134
+ control_type=auto.PaneControl,
135
+ search_params={
136
+ 'AutomationId': 'BookingNotificationsControl'
137
+ },
138
+ search_depth=3,
139
+ timeout=5
140
+ )
141
+ close_button = self.find_element_by_property(
142
+ control=notification_ctrl,
143
+ automation_id="ButtonCancel"
144
+ )
145
+ close_button.SendKeys('{ENTER}')
146
+ return
147
+ except TimeoutError:
148
+ pass
149
+
150
+ # Check for warning window pop up
151
+ try:
152
+ self.handle_error_on_booking_save(slct_button="ButtonChangeManual")
153
+ # Wait for status list to reappear
154
+ booking_control = self.wait_for_control(
155
+ control_type=auto.PaneControl,
156
+ search_params={
157
+ 'AutomationId': 'ManageBookingControl'
158
+ },
159
+ search_depth=3
160
+ )
161
+ # Open dropdown
162
+ self.find_element_by_property(
163
+ control=status_control,
164
+ control_type=50000
165
+ ).GetInvokePattern().Invoke()
166
+ # Reset to original value
167
+ list_no = status_dict['names_lo'].index(current_status.lower())
168
+ status_dict['ctrls'][list_no].GetInvokePattern().Invoke()
169
+ # Save original status
170
+ save_button = self.find_element_by_property(
171
+ control=booking_control,
172
+ automation_id = "ButtonOk"
173
+ )
174
+ save_button.SendKeys('{ENTER}')
175
+ # Accept despite warning
176
+ self.handle_error_on_booking_save(slct_button="ButtonOk")
177
+
178
+ raise ManualProcessingRequiredError
179
+ except TimeoutError:
180
+ pass
181
+
182
+ # If warning when sending: press "ret manuelt" -> "annuler" -> return warning error
183
+
184
+ return None
185
+ else:
186
+ print(f"{set_status} not in list. Possible status choices are: {', '.join(status_dict['names'])}")
187
+ raise Exception
188
+
189
+ def handle_error_on_booking_save(self, slct_button: str):
190
+ """Handle error window when saving booking. Select button to press"""
191
+ buttons = [
192
+ "ButtonFindNewTimeSlot",
193
+ "ButtonOk",
194
+ "ButtonChangeManual"
195
+ ]
196
+ if slct_button not in buttons:
197
+ print(f"{slct_button} not in buttons. Available buttons are {' '.join(buttons)}")
198
+ raise ValueError
199
+ warning_window = self.wait_for_control(
200
+ control_type=auto.WindowControl,
201
+ search_params={
202
+ "AutomationId": "FormBookingWarnings"
203
+ },
204
+ search_depth=5
205
+ )
206
+ button = self.find_element_by_property(
207
+ control=warning_window,
208
+ control_type=50033,
209
+ automation_id=slct_button
210
+ )
211
+ button.SendKeys("{ENTER}")
212
+
213
+ def get_appointments_aftalebog(
214
+ self,
215
+ close_after: bool = False,
216
+ headers_to_keep: list | None = None
217
+ ) -> dict:
218
+ """Function to retrive data on appointments in view in aftalebog"""
219
+
220
+ # Get list control
221
+ list_box = self.wait_for_control(
222
+ control_type=auto.GroupControl,
223
+ search_params={
224
+ "AutomationId": "GroupBoxView"
225
+ },
226
+ search_depth=5
227
+ )
228
+
229
+ appointment_list = self.find_element_by_property(
230
+ control=list_box,
231
+ control_type=50008
232
+ )
233
+
234
+ # Extract headers
235
+ appointment_headers = [
236
+ header.Name
237
+ for header in appointment_list.GetFirstChildControl().GetChildren()
238
+ ]
239
+
240
+ # Extract ListItem controls
241
+ appointment_ctrls = [
242
+ ctrl
243
+ for ctrl in appointment_list.GetChildren()
244
+ if ctrl.ControlType == 50007
245
+ ]
246
+
247
+ # Package data in dictionary
248
+ # Keep only selected headers if any selected.
249
+ if not headers_to_keep:
250
+ headers_to_keep = appointment_headers
251
+
252
+ appointment_data = {
253
+ j: {
254
+ k: v.Name
255
+ for k, v in zip(appointment_headers, ctrl.GetChildren())
256
+ if k in headers_to_keep
257
+ }
258
+ for j, ctrl in enumerate(appointment_ctrls)
259
+ }
260
+
261
+ if close_after:
262
+ # Should maybe be in a method of its own?
263
+ list_box.SendKeys('{Control}{F4}')
264
+ self.wait_for_control_to_disappear(
265
+ control_type=auto.WindowControl,
266
+ search_params={
267
+ "AutomationId": "FormBooking"
268
+ }
269
+ )
270
+
271
+ return appointment_data
272
+
273
+ def create_booking_reminder(self, booking_reminder_data: dict):
274
+ """
275
+ Creates a booking reminder for the patient.
276
+ """
277
+ try:
278
+ self.open_tab("Stamkort")
279
+
280
+ create_booking_button = self.wait_for_control(
281
+ auto.PaneControl,
282
+ {"AutomationId": "ButtonBookingNew"},
283
+ search_depth=14
284
+ )
285
+ create_booking_button.GetLegacyIAccessiblePattern().DoDefaultAction()
286
+
287
+ booking_window = self.wait_for_control(
288
+ auto.WindowControl,
289
+ {"AutomationId": "MainFrame"},
290
+ search_depth=2
291
+ )
292
+
293
+ # Fill out ressourcer group
294
+ manage_booking = booking_window.PaneControl(AutomationId="viewPortPanel").PaneControl(AutomationId="ManageBookingControl")
295
+ resources_group = manage_booking.GroupControl(AutomationId="Ressourcer")
296
+
297
+ for child in resources_group.GetChildren():
298
+ if child.ControlTypeName == "ComboBoxControl":
299
+ match child.Name:
300
+ case "Aftaletype":
301
+ child.GetPattern(auto.PatternId.ValuePattern).SetValue(booking_reminder_data["comboBoxBookingType"])
302
+ case "Behandler":
303
+ child.GetPattern(auto.PatternId.ValuePattern).SetValue(booking_reminder_data["comboBoxDentist"])
304
+ case "Stol":
305
+ child.GetPattern(auto.PatternId.ValuePattern).SetValue(booking_reminder_data["comboBoxChair"])
306
+
307
+ # Fill out date and time
308
+ date_and_time_group = manage_booking.GroupControl(AutomationId="GroupBox4")
309
+
310
+ for child in date_and_time_group.GetChildren():
311
+ match child.AutomationId:
312
+ case "DateTimePickerStartTime":
313
+ child.SendKeys(booking_reminder_data["dateTimePickerStartTime"])
314
+ case "TextBoxDuration":
315
+ if child.GetPattern(auto.PatternId.ValuePattern).Value != booking_reminder_data["textBoxDuration"]:
316
+ child.GetPattern(auto.PatternId.ValuePattern).SetValue(booking_reminder_data["textBoxDuration"])
317
+ case "ComboBoxStatus":
318
+ if child.GetPattern(auto.PatternId.ValuePattern).Value != booking_reminder_data["comboBoxStatus"]:
319
+ child.GetPattern(auto.PatternId.ValuePattern).SetValue(booking_reminder_data["comboBoxStatus"])
320
+ case "DateTimePickerDate":
321
+ child.SendKeys(booking_reminder_data["futureDate"])
322
+
323
+ manage_booking.PaneControl(AutomationId="ButtonOk").Click(simulateMove=True, waitTime=0)
324
+
325
+ booking_window_warning = self.wait_for_control(
326
+ auto.WindowControl,
327
+ {"AutomationId": "FormBookingWarnings"},
328
+ search_depth=4
329
+ )
330
+ booking_window_warning.PaneControl(AutomationId="ButtonOk").Click(simulateMove=True, waitTime=0)
331
+ except Exception as e:
332
+ print(f"Error while creating booking reminder: {e}")
333
+ raise
@@ -0,0 +1,100 @@
1
+ """Base UI-Automation helper methods for SolteqTand project."""
2
+ import time
3
+ import uiautomation as auto
4
+
5
+
6
+ class BaseUI:
7
+ """Base UI-Automation helper methods."""
8
+
9
+ def find_element_by_property(self, control, control_type=None, automation_id=None, name=None, class_name=None) -> auto.Control:
10
+ """
11
+ Uses GetChildren to traverse through controls and find an element based on the specified properties.
12
+
13
+ Args:
14
+ control (Control): The root control to search from (e.g., main window or pane).
15
+ control_type (ControlType, optional): ControlType to search for.
16
+ automation_id (str, optional): AutomationId of the target element.
17
+ name (str, optional): Name of the target element.
18
+ class_name (str, optional): ClassName of the target element.
19
+
20
+ Returns:
21
+ Control: The found element or None if no match is found.
22
+ """
23
+ children = control.GetChildren()
24
+
25
+ for child in children:
26
+ if (control_type is None or child.ControlType == control_type) and \
27
+ (automation_id is None or child.AutomationId == automation_id) and \
28
+ (name is None or child.Name == name) and \
29
+ (class_name is None or child.ClassName == class_name):
30
+ return child
31
+
32
+ found = self.find_element_by_property(child, control_type, automation_id, name, class_name)
33
+ if found:
34
+ return found
35
+
36
+ return None
37
+
38
+ def wait_for_control(self, control_type, search_params, search_depth=1, timeout=30, retry_interval=0.5):
39
+ """
40
+ Waits for a given control type to become available with the specified search parameters.
41
+
42
+ Args:
43
+ control_type: The type of control, e.g., auto.WindowControl, auto.ButtonControl, etc.
44
+ search_params (dict): Search parameters used to identify the control.
45
+ The keys must match the properties used in the control type, e.g., 'AutomationId', 'Name'.
46
+ search_depth (int): How deep to search in the user interface.
47
+ timeout (int): Maximum time to wait for the control, in seconds.
48
+ retry_interval (float): Time to wait between retries, in seconds.
49
+
50
+ Returns:
51
+ Control: The control object if found, otherwise raises TimeoutError.
52
+
53
+ Raises:
54
+ TimeoutError: If the control is not found within the timeout period.
55
+ """
56
+ end_time = time.time() + timeout
57
+ while time.time() < end_time:
58
+ try:
59
+ control = control_type(searchDepth=search_depth, **search_params)
60
+ if control.Exists(0, 0):
61
+ return control
62
+ except Exception as e:
63
+ print(f"Error while searching for control: {e}")
64
+
65
+ time.sleep(retry_interval)
66
+ print(f"Retrying to find control: {search_params}...")
67
+
68
+ raise TimeoutError(f"Control with parameters {search_params} was not found within the {timeout} second timeout.")
69
+
70
+ def wait_for_control_to_disappear(self, control_type, search_params, search_depth=1, timeout=30):
71
+ """
72
+ Waits for a given control type to disappear with the specified search parameters.
73
+
74
+ Args:
75
+ control_type: The type of control, e.g., auto.WindowControl, auto.ButtonControl, etc.
76
+ search_params (dict): Search parameters used to identify the control.
77
+ The keys must match the properties used in the control type, e.g., 'AutomationId', 'Name'.
78
+ search_depth (int): How deep to search in the user interface.
79
+ timeout (int): How long to wait, in seconds.
80
+
81
+ Returns:
82
+ bool: True if the control disappeared within the timeout period, otherwise False.
83
+ """
84
+ end_time = time.time() + timeout
85
+ while time.time() < end_time:
86
+ try:
87
+ control = control_type(searchDepth=search_depth, **search_params)
88
+ if not control.Exists(0, 0):
89
+ return True
90
+ except Exception as e:
91
+ print(f"Error while searching for control: {e}")
92
+
93
+ time.sleep(0.5)
94
+ print(f"Retrying to find control: {search_params}...")
95
+
96
+ raise TimeoutError(f"Control with parameters {search_params} did not disappear within the timeout period.")
97
+
98
+ def close_window(self, window_to_close: auto.WindowControl) -> None:
99
+ """Closes specified window by sending CTRL+F4 keystroke."""
100
+ window_to_close.SendKeys(text="^({F4})")
@@ -0,0 +1,75 @@
1
+ import uiautomation as auto
2
+
3
+ from .handler_base import HandlerBase
4
+
5
+
6
+ class ClinicHandler(HandlerBase):
7
+ """
8
+ Handles changing the primart clinic for a patient (if it's not "Tandplejen Aarhus").
9
+ """
10
+
11
+ def change_primary_clinic(self, current_primary_clinic: str, is_field_locked: bool):
12
+ """
13
+ Changes the primary clinic for the patient.
14
+ """
15
+ try:
16
+ self.open_tab("Stamkort")
17
+
18
+ if current_primary_clinic != "Tandplejen Aarhus":
19
+ if is_field_locked:
20
+ locked_field = self.wait_for_control(
21
+ auto.CheckBoxControl,
22
+ {'AutomationId': 'CheckPatientClinicRegLocked'},
23
+ search_depth=9
24
+ )
25
+
26
+ if locked_field.GetPattern(auto.PatternId.TogglePattern).ToggleState:
27
+ locked_field.GetPattern(auto.PatternId.TogglePattern).Toggle()
28
+ locked_field.SendKeys('{Ctrl}s', waitTime=0)
29
+
30
+ box_clinic_parent = self.wait_for_control(
31
+ auto.GroupControl,
32
+ {'AutomationId': 'GroupBoxPatientDentalInfo'},
33
+ search_depth=8
34
+ )
35
+ box_clinic = box_clinic_parent.PaneControl(
36
+ searchDepth=2,
37
+ AutomationId="ControlClinicSelectorPatientClinicReg"
38
+ ).PaneControl(
39
+ searchDepth=2,
40
+ AutomationId="PictureBoxClinic"
41
+ )
42
+ box_clinic.Click(simulateMove=False, waitTime=0)
43
+
44
+ clinic_list = self.wait_for_control(
45
+ auto.WindowControl,
46
+ {'AutomationId': 'FormFindClinics'},
47
+ search_depth=2
48
+ )
49
+
50
+ clinic_list_items = clinic_list.ListControl(AutomationId="ListClinics").ListItemControl(Name="Tandplejen Aarhus")
51
+ clinic_list_items.GetPattern(10017).ScrollIntoView()
52
+ clinic_list_items.SetFocus()
53
+ clinic_list_items.DoubleClick(simulateMove=False, waitTime=0)
54
+
55
+ locked_field = self.wait_for_control(
56
+ auto.CheckBoxControl,
57
+ {'AutomationId': 'CheckPatientClinicRegLocked'},
58
+ search_depth=9
59
+ )
60
+
61
+ if locked_field.GetPattern(auto.PatternId.TogglePattern).ToggleState == 0:
62
+ locked_field.GetPattern(auto.PatternId.TogglePattern).Toggle()
63
+ locked_field.SendKeys('{Ctrl}s', waitTime=0)
64
+
65
+ self.wait_for_control(
66
+ auto.TextControl,
67
+ {'Name': 'Patient er gemt.'},
68
+ search_depth=3
69
+ )
70
+
71
+ print("Primary clinic changed successfully.")
72
+ print("Patient already has the primary clinic set to 'Tandplejen Aarhus'")
73
+ except Exception as e:
74
+ print(f"Error while changing primary clinic: {e}")
75
+ raise