DataOpsHub 6.2.0__py3-none-any.whl
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.
- DataOpsHub/__init__.py +48 -0
- DataOpsHub/constants/__init__.py +29 -0
- DataOpsHub/constants/error_messages.py +30 -0
- DataOpsHub/constants/table_mappings.py +15 -0
- DataOpsHub/data_entry_forms/__init__.py +34 -0
- DataOpsHub/data_entry_forms/forms/__init__.py +13 -0
- DataOpsHub/data_entry_forms/forms/forms.py +27 -0
- DataOpsHub/data_entry_forms/validators/__init__.py +53 -0
- DataOpsHub/data_entry_forms/validators/form_field_validations.py +513 -0
- DataOpsHub/databases/__init__.py +10 -0
- DataOpsHub/databases/database_handler.py +878 -0
- DataOpsHub/databases/upload_data.py +118 -0
- DataOpsHub/models/__init__.py +17 -0
- DataOpsHub/models/base.py +82 -0
- DataOpsHub/models/user.py +110 -0
- DataOpsHub/security/__init__.py +15 -0
- DataOpsHub/security/automated_passwords.py +54 -0
- DataOpsHub/security/config.py +86 -0
- DataOpsHub/security/exceptions.py +56 -0
- DataOpsHub/services/__init__.py +14 -0
- DataOpsHub/services/user_service.py +213 -0
- dataopshub-6.2.0.dist-info/METADATA +160 -0
- dataopshub-6.2.0.dist-info/RECORD +25 -0
- dataopshub-6.2.0.dist-info/WHEEL +5 -0
- dataopshub-6.2.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
# -*- coding: utf-8 -*-
|
|
3
|
+
|
|
4
|
+
"""
|
|
5
|
+
User Service Module
|
|
6
|
+
|
|
7
|
+
This module provides services for user management operations.
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
# Import modules #
|
|
11
|
+
#----------------#
|
|
12
|
+
|
|
13
|
+
from datetime import datetime, timedelta
|
|
14
|
+
from typing import Dict, List, Optional, Union
|
|
15
|
+
|
|
16
|
+
from sqlalchemy.exc import SQLAlchemyError
|
|
17
|
+
from sqlalchemy.orm import Session
|
|
18
|
+
|
|
19
|
+
# Import project modules #
|
|
20
|
+
#------------------------#
|
|
21
|
+
|
|
22
|
+
from DataOpsHub.databases import database_handler
|
|
23
|
+
from DataOpsHub.models.user import User, VitalSigns, LabResults, MedicationsHistory
|
|
24
|
+
|
|
25
|
+
# Define classes #
|
|
26
|
+
#----------------#
|
|
27
|
+
|
|
28
|
+
class UserService:
|
|
29
|
+
"""
|
|
30
|
+
Service class for handling user-related operations.
|
|
31
|
+
"""
|
|
32
|
+
|
|
33
|
+
def __init__(self, session: Session):
|
|
34
|
+
"""
|
|
35
|
+
Initialize the UserService.
|
|
36
|
+
|
|
37
|
+
Args:
|
|
38
|
+
session (Session): SQLAlchemy database session
|
|
39
|
+
"""
|
|
40
|
+
self.session = session
|
|
41
|
+
self.db_ops = database_handler(session)
|
|
42
|
+
|
|
43
|
+
def create_user(self, user_data: dict) -> dict:
|
|
44
|
+
"""
|
|
45
|
+
Create a new user.
|
|
46
|
+
|
|
47
|
+
Args:
|
|
48
|
+
user_data (dict): Dictionary containing user data
|
|
49
|
+
|
|
50
|
+
Returns:
|
|
51
|
+
dict: Response containing status and message
|
|
52
|
+
"""
|
|
53
|
+
try:
|
|
54
|
+
user = User(**user_data)
|
|
55
|
+
self.session.add(user)
|
|
56
|
+
self.session.commit()
|
|
57
|
+
return {"status": "success", "message": "User created successfully"}
|
|
58
|
+
except SQLAlchemyError as e:
|
|
59
|
+
self.session.rollback()
|
|
60
|
+
raise ValueError(f"Error creating user: {str(e)}")
|
|
61
|
+
|
|
62
|
+
def get_user(self, user_id: str) -> User:
|
|
63
|
+
"""
|
|
64
|
+
Get a user by ID.
|
|
65
|
+
|
|
66
|
+
Args:
|
|
67
|
+
user_id (str): User ID
|
|
68
|
+
|
|
69
|
+
Returns:
|
|
70
|
+
User: User object
|
|
71
|
+
"""
|
|
72
|
+
user = self.session.query(User).filter(User.user_id == user_id).first()
|
|
73
|
+
if not user:
|
|
74
|
+
raise ValueError(f"User with ID {user_id} not found")
|
|
75
|
+
return user
|
|
76
|
+
|
|
77
|
+
def update_user(self, user_id: str, user_data: dict) -> dict:
|
|
78
|
+
"""
|
|
79
|
+
Update a user.
|
|
80
|
+
|
|
81
|
+
Args:
|
|
82
|
+
user_id (str): User ID
|
|
83
|
+
user_data (dict): Dictionary containing updated user data
|
|
84
|
+
|
|
85
|
+
Returns:
|
|
86
|
+
dict: Response containing status and message
|
|
87
|
+
"""
|
|
88
|
+
try:
|
|
89
|
+
user = self.get_user(user_id)
|
|
90
|
+
for key, value in user_data.items():
|
|
91
|
+
setattr(user, key, value)
|
|
92
|
+
self.session.commit()
|
|
93
|
+
return {"status": "success", "message": "User updated successfully"}
|
|
94
|
+
except SQLAlchemyError as e:
|
|
95
|
+
self.session.rollback()
|
|
96
|
+
raise ValueError(f"Error updating user: {str(e)}")
|
|
97
|
+
|
|
98
|
+
def delete_user(self, user_id: str) -> dict:
|
|
99
|
+
"""
|
|
100
|
+
Delete a user.
|
|
101
|
+
|
|
102
|
+
Args:
|
|
103
|
+
user_id (str): User ID
|
|
104
|
+
|
|
105
|
+
Returns:
|
|
106
|
+
dict: Response containing status and message
|
|
107
|
+
"""
|
|
108
|
+
try:
|
|
109
|
+
user = self.get_user(user_id)
|
|
110
|
+
self.session.delete(user)
|
|
111
|
+
self.session.commit()
|
|
112
|
+
return {
|
|
113
|
+
"status": "success",
|
|
114
|
+
"message": "User deleted successfully",
|
|
115
|
+
}
|
|
116
|
+
except SQLAlchemyError as e:
|
|
117
|
+
self.session.rollback()
|
|
118
|
+
raise ValueError(f"Error deleting user: {str(e)}")
|
|
119
|
+
|
|
120
|
+
def get_all_users(self) -> list:
|
|
121
|
+
"""
|
|
122
|
+
Get all users.
|
|
123
|
+
|
|
124
|
+
Returns:
|
|
125
|
+
list: List of User objects
|
|
126
|
+
"""
|
|
127
|
+
return self.session.query(User).all()
|
|
128
|
+
|
|
129
|
+
def get_user_with_related_data(self, user_id: str) -> Dict:
|
|
130
|
+
"""
|
|
131
|
+
Get a user's complete record including related data.
|
|
132
|
+
|
|
133
|
+
Parameters
|
|
134
|
+
----------
|
|
135
|
+
user_id : str
|
|
136
|
+
The ID of the user to retrieve.
|
|
137
|
+
|
|
138
|
+
Returns
|
|
139
|
+
-------
|
|
140
|
+
dict
|
|
141
|
+
Complete user record including related data.
|
|
142
|
+
|
|
143
|
+
Raises
|
|
144
|
+
------
|
|
145
|
+
ValueError
|
|
146
|
+
If no user with the specified ID exists.
|
|
147
|
+
"""
|
|
148
|
+
# Get base user data
|
|
149
|
+
user = self.session.query(User).filter(User.user_id == user_id).first()
|
|
150
|
+
if not user:
|
|
151
|
+
raise ValueError(f"User with ID {user_id} not found")
|
|
152
|
+
|
|
153
|
+
# Get related data
|
|
154
|
+
vital_signs = self.session.query(VitalSigns).filter(VitalSigns.user_id == user_id).all()
|
|
155
|
+
lab_results = self.session.query(LabResults).filter(LabResults.user_id == user_id).all()
|
|
156
|
+
medications = self.session.query(MedicationsHistory).filter(MedicationsHistory.user_id == user_id).all()
|
|
157
|
+
|
|
158
|
+
return {
|
|
159
|
+
"user": user,
|
|
160
|
+
"vital_signs": vital_signs,
|
|
161
|
+
"lab_results": lab_results,
|
|
162
|
+
"medications": medications
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
def get_users(self, filters: Optional[Dict] = None) -> List[Dict]:
|
|
166
|
+
"""
|
|
167
|
+
Get users with optional filtering.
|
|
168
|
+
|
|
169
|
+
Parameters
|
|
170
|
+
----------
|
|
171
|
+
filters : dict, optional
|
|
172
|
+
Dictionary of filters to apply to the query.
|
|
173
|
+
|
|
174
|
+
Returns
|
|
175
|
+
-------
|
|
176
|
+
list
|
|
177
|
+
List of user records matching the filters.
|
|
178
|
+
"""
|
|
179
|
+
# Get filtered users
|
|
180
|
+
users = self.session.query(User).filter_by(**(filters or {})).all()
|
|
181
|
+
return [self.get_user_with_related_data(user.user_id) for user in users]
|
|
182
|
+
|
|
183
|
+
def get_user_measurements(self, user_id: str, days: int = 30) -> Dict:
|
|
184
|
+
"""
|
|
185
|
+
Get a user's measurements over time.
|
|
186
|
+
|
|
187
|
+
Parameters
|
|
188
|
+
----------
|
|
189
|
+
user_id : str
|
|
190
|
+
The ID of the user to retrieve measurements for.
|
|
191
|
+
days : int, optional
|
|
192
|
+
Number of days to look back, defaults to 30.
|
|
193
|
+
|
|
194
|
+
Returns
|
|
195
|
+
-------
|
|
196
|
+
dict
|
|
197
|
+
Dictionary containing measurement data.
|
|
198
|
+
"""
|
|
199
|
+
# Get measurement data
|
|
200
|
+
vital_signs = self.session.query(VitalSigns).filter(
|
|
201
|
+
VitalSigns.user_id == user_id,
|
|
202
|
+
VitalSigns.timestamp >= datetime.now() - timedelta(days=days)
|
|
203
|
+
).all()
|
|
204
|
+
|
|
205
|
+
lab_results = self.session.query(LabResults).filter(
|
|
206
|
+
LabResults.user_id == user_id,
|
|
207
|
+
LabResults.timestamp >= datetime.now() - timedelta(days=days)
|
|
208
|
+
).all()
|
|
209
|
+
|
|
210
|
+
return {
|
|
211
|
+
"vital_signs": vital_signs,
|
|
212
|
+
"lab_results": lab_results
|
|
213
|
+
}
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: DataOpsHub
|
|
3
|
+
Version: 6.2.0
|
|
4
|
+
Summary: A Python toolkit for streamlined data operations and database management
|
|
5
|
+
Home-page: https://github.com/EusDancerDev/DataOpsHub
|
|
6
|
+
Author: Jon Ander Gabantxo
|
|
7
|
+
Author-email: jagabantxo@gmail.com
|
|
8
|
+
License: MIT
|
|
9
|
+
Project-URL: Bug Reports, https://github.com/EusDancerDev/DataOpsHub/issues
|
|
10
|
+
Project-URL: Source, https://github.com/EusDancerDev/DataOpsHub
|
|
11
|
+
Project-URL: Documentation, https://github.com/EusDancerDev/DataOpsHub#readme
|
|
12
|
+
Keywords: database,data operations,security,web automation
|
|
13
|
+
Classifier: Development Status :: 4 - Beta
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: Topic :: Database
|
|
16
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
17
|
+
Classifier: Programming Language :: Python :: 3
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
22
|
+
Classifier: Operating System :: OS Independent
|
|
23
|
+
Requires-Python: >=3.9
|
|
24
|
+
Description-Content-Type: text/markdown
|
|
25
|
+
Requires-Dist: sqlalchemy>=2.0.0
|
|
26
|
+
Requires-Dist: pandas>=1.3.0
|
|
27
|
+
Requires-Dist: filewise>=3.7.0
|
|
28
|
+
Requires-Dist: pygenutils>=15.10.0
|
|
29
|
+
Requires-Dist: paramlib>=3.4.0
|
|
30
|
+
Requires-Dist: email_validator>=2.0.0
|
|
31
|
+
Requires-Dist: selenium>=4.0.0
|
|
32
|
+
Provides-Extra: dev
|
|
33
|
+
Requires-Dist: pytest>=7.0.0; extra == "dev"
|
|
34
|
+
Requires-Dist: pytest-cov>=4.0.0; extra == "dev"
|
|
35
|
+
Requires-Dist: black>=22.0.0; extra == "dev"
|
|
36
|
+
Requires-Dist: flake8>=5.0.0; extra == "dev"
|
|
37
|
+
Dynamic: author
|
|
38
|
+
Dynamic: author-email
|
|
39
|
+
Dynamic: classifier
|
|
40
|
+
Dynamic: description
|
|
41
|
+
Dynamic: description-content-type
|
|
42
|
+
Dynamic: home-page
|
|
43
|
+
Dynamic: keywords
|
|
44
|
+
Dynamic: license
|
|
45
|
+
Dynamic: project-url
|
|
46
|
+
Dynamic: provides-extra
|
|
47
|
+
Dynamic: requires-dist
|
|
48
|
+
Dynamic: requires-python
|
|
49
|
+
Dynamic: summary
|
|
50
|
+
|
|
51
|
+
# DataOpsHub
|
|
52
|
+
|
|
53
|
+
**DataOpsHub** is a comprehensive Python package designed to streamline data operations, database management, and web automation tasks. It provides a robust framework for handling data entry, user management, and secure database operations.
|
|
54
|
+
|
|
55
|
+
## Features
|
|
56
|
+
|
|
57
|
+
- **Database Management**:
|
|
58
|
+
- Advanced database operations and data handling
|
|
59
|
+
- Efficient data upload and retrieval mechanisms
|
|
60
|
+
- Comprehensive database connection management
|
|
61
|
+
- **User Management**:
|
|
62
|
+
- Complete user service implementation
|
|
63
|
+
- User model with extensive functionality
|
|
64
|
+
- Secure user authentication and authorisation
|
|
65
|
+
- **Data Entry Forms**:
|
|
66
|
+
- Form validation and processing
|
|
67
|
+
- Custom form implementations
|
|
68
|
+
- Data integrity checks
|
|
69
|
+
- **Security Features**:
|
|
70
|
+
- Automated password management
|
|
71
|
+
- Security configuration management
|
|
72
|
+
- Custom security exceptions handling
|
|
73
|
+
- **Web Automation**:
|
|
74
|
+
- Browser automation support (Firefox and Chrome)
|
|
75
|
+
- Web driver setup and configuration
|
|
76
|
+
- **Constants and Configuration**:
|
|
77
|
+
- Centralised error message management
|
|
78
|
+
- Table mapping configurations
|
|
79
|
+
- System-wide constants
|
|
80
|
+
|
|
81
|
+
---
|
|
82
|
+
|
|
83
|
+
## Installation Guide
|
|
84
|
+
|
|
85
|
+
### Dependency Notice
|
|
86
|
+
|
|
87
|
+
Before installing, please ensure the following dependencies are available on your system:
|
|
88
|
+
|
|
89
|
+
- **Required Third-Party Libraries**:
|
|
90
|
+
- SQLAlchemy
|
|
91
|
+
- Flask
|
|
92
|
+
- Selenium
|
|
93
|
+
- PyYAML
|
|
94
|
+
- cryptography
|
|
95
|
+
|
|
96
|
+
You can install them via pip:
|
|
97
|
+
|
|
98
|
+
```bash
|
|
99
|
+
pip install SQLAlchemy Flask selenium PyYAML cryptography
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
Or via Anaconda (recommended channel: `conda-forge`):
|
|
103
|
+
|
|
104
|
+
```bash
|
|
105
|
+
conda install -c conda-forge sqlalchemy flask selenium pyyaml cryptography
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
### Installation Instructions
|
|
109
|
+
|
|
110
|
+
Install the package using pip:
|
|
111
|
+
|
|
112
|
+
```bash
|
|
113
|
+
pip install dataopshub
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
### Package Updates
|
|
117
|
+
|
|
118
|
+
To stay up-to-date with the latest version of this package, simply run:
|
|
119
|
+
|
|
120
|
+
```bash
|
|
121
|
+
pip install --upgrade dataopshub
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
---
|
|
125
|
+
|
|
126
|
+
## Project Structure
|
|
127
|
+
|
|
128
|
+
The package is organised into several sub-packages:
|
|
129
|
+
|
|
130
|
+
- **databases/**: Core database operations and management
|
|
131
|
+
- `database_handler.py`: Main database operations and connection management
|
|
132
|
+
- `upload_data.py`: Data upload utilities
|
|
133
|
+
|
|
134
|
+
- **models/**: Data models and base classes
|
|
135
|
+
- `user.py`: User model implementation
|
|
136
|
+
- `base.py`: Base model definitions
|
|
137
|
+
|
|
138
|
+
- **services/**: Business logic and service implementations
|
|
139
|
+
- `user_service.py`: User management services
|
|
140
|
+
|
|
141
|
+
- **data_entry_forms/**: Form handling and validation
|
|
142
|
+
- `forms/`: Custom form implementations
|
|
143
|
+
- `validators/`: Form validation utilities
|
|
144
|
+
|
|
145
|
+
- **security/**: Security-related functionality
|
|
146
|
+
- `automated_passwords.py`: Password management
|
|
147
|
+
- `config.py`: Security configuration
|
|
148
|
+
- `exceptions.py`: Security-related exceptions
|
|
149
|
+
|
|
150
|
+
- **web_automation/**: Web automation tools
|
|
151
|
+
- `webdriver_Firefox-Chrome_setup_test.py`: Browser automation setup
|
|
152
|
+
|
|
153
|
+
- **constants/**: System-wide constants and configurations
|
|
154
|
+
- `error_messages.py`: Error message definitions
|
|
155
|
+
- `table_mappings.py`: Database table mappings
|
|
156
|
+
|
|
157
|
+
For detailed version history and changes, please refer to:
|
|
158
|
+
|
|
159
|
+
- `CHANGELOG.md`: Comprehensive list of changes for each version
|
|
160
|
+
- `VERSIONING.md`: Versioning policy and guidelines
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
DataOpsHub/__init__.py,sha256=rjtq2cQSQ9_ZfektweqodTa2Cn5GF-X4cG36p4ZckgQ,1241
|
|
2
|
+
DataOpsHub/constants/__init__.py,sha256=LAqDpp3nUzb30qBXFoVbobU2aaOTl48DK23mn45gba0,761
|
|
3
|
+
DataOpsHub/constants/error_messages.py,sha256=B0BOEeAqVIN2VIQQY2Z1pRKKLM2p3RB1-ozTYyDWO0A,2092
|
|
4
|
+
DataOpsHub/constants/table_mappings.py,sha256=oGq7sz-5GG9c8Nk25i6WiLm_Ixi8ewJo_T4GYTa49LQ,265
|
|
5
|
+
DataOpsHub/data_entry_forms/__init__.py,sha256=C2DbLx8kdF0cY5yD6r4ajvNuezTtGo-6JZl5x4gBH9g,879
|
|
6
|
+
DataOpsHub/data_entry_forms/forms/__init__.py,sha256=B88NgwVtwN-JQmTSuJb-vv_XYJh51mAFThOFxAfN06U,287
|
|
7
|
+
DataOpsHub/data_entry_forms/forms/forms.py,sha256=qb72pUptuZU6i3GEydd5xKg41nikBew005O6VjaFYRU,743
|
|
8
|
+
DataOpsHub/data_entry_forms/validators/__init__.py,sha256=UDZ3ZQ7GSR-VcXy2nOmgcnPrbyQpIdH23VM_YBuMx8s,1427
|
|
9
|
+
DataOpsHub/data_entry_forms/validators/form_field_validations.py,sha256=ARYacrxO8LN740kVyBbCU_pxZY0-Yg2biEZy6Rnfrbk,15633
|
|
10
|
+
DataOpsHub/databases/__init__.py,sha256=92YFsiZYUZgAwdcR1LTEK1kFOYzqxScfigl0fwv5KAI,222
|
|
11
|
+
DataOpsHub/databases/database_handler.py,sha256=03sHP1SISoHimvcLMMaccY_SW6Ajtfz1hXU0hHwlU7c,29469
|
|
12
|
+
DataOpsHub/databases/upload_data.py,sha256=Gr3ZLlCzxtt0evyT3TrLFYfWWmVMsMOswofCE3gcsO4,3651
|
|
13
|
+
DataOpsHub/models/__init__.py,sha256=UCejRX_HT33IYKXcor3Br8q9UhJbQKZwMtS8SAKj7HI,339
|
|
14
|
+
DataOpsHub/models/base.py,sha256=5g7ANPLBW5UEoEs6mzKMbq_SUyorg-c0aEiZwXl9DA4,2273
|
|
15
|
+
DataOpsHub/models/user.py,sha256=02VUSN0tS9GdxPfrlh0iwGEDETiQDTZhjI5u0LlSsT8,3292
|
|
16
|
+
DataOpsHub/security/__init__.py,sha256=tJ2gUuo_inog4nb7HKZPMsToeZ55igyPVdbUfUnhIAc,307
|
|
17
|
+
DataOpsHub/security/automated_passwords.py,sha256=RHoB0rGsl3zm4aHSHEz0cDGMzxJ3cJtFng2xP017CSk,1437
|
|
18
|
+
DataOpsHub/security/config.py,sha256=2Mk3aTfrlsyA8yj6_Yrt1TLdiYcRNiV-HyOaD3kT9mY,3215
|
|
19
|
+
DataOpsHub/security/exceptions.py,sha256=zsKMfiR7pgAfiIygyTq4zffmSTcSy6OCNAgUzVFjRwc,1078
|
|
20
|
+
DataOpsHub/services/__init__.py,sha256=3h6TNNgJR--XYGgKLYVwDWqiVmIKZktaVm8VusNFckI,303
|
|
21
|
+
DataOpsHub/services/user_service.py,sha256=GaL9t5_VzhUwz4xXOL4cpwJzZbM4X_QuNisf9-Rw_o0,6206
|
|
22
|
+
dataopshub-6.2.0.dist-info/METADATA,sha256=NB4AggHsq8oYbqzcQ8iMp1CuPvl0HJderZ0jvbE82Pw,4936
|
|
23
|
+
dataopshub-6.2.0.dist-info/WHEEL,sha256=wXxTzcEDnjrTwFYjLPcsW_7_XihufBwmpiBeiXNBGEA,91
|
|
24
|
+
dataopshub-6.2.0.dist-info/top_level.txt,sha256=ldWxLwGkBVgibVhoT1TqhVK-BT2xmFcw0jqiUNbJhHg,11
|
|
25
|
+
dataopshub-6.2.0.dist-info/RECORD,,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
DataOpsHub
|