forked from IntelliSOFT-Consulting/RapidPro-connector
-
Notifications
You must be signed in to change notification settings - Fork 1
/
models.py
114 lines (99 loc) · 3.72 KB
/
models.py
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
#MOdels file
import json
from api_urls import CONTACTS_URL, BROADCASTS_URL
from abstract_request import AbstractSimpleRequest, AbstractDataRequest
from settings import CONNECTOR_DB_SETTINGS, OPENMRS_DB_SETTINGS
class Database:
""" database class """
def __init__(self, hostname=None, name=None, password=None, database=None):
self.hostname = hostname
self.name = name
self.password = password
self.database = database
def get_connector_db(self):
""" return connector database object """
setting = CONNECTOR_DB_SETTINGS
self.hostname = setting.get('HOSTNAME')
self.username = setting.get('USERNAME')
self.password = setting.get('PASSWORD')
self.database = setting.get('DB_NAME')
return self
def get_openmrs_db(self):
""" return openmrs database object """
setting = OPENMRS_DB_SETTINGS
self.hostname = setting.get('HOSTNAME')
self.username = setting.get('USERNAME')
self.password = setting.get('PASSWORD')
self.database = setting.get('DB_NAME')
return self
class ContactNumber:
""" Model class that holds contact number """
def __init__(self, username, number, timestamp=None):
self.username = username
self.number = number
self.timestamp = timestamp
def __repr__(self):
""" readable model representation """
repr_name = '{} {}'.format(self.username, self.number)
return repr_name.strip()
class OpenMRSContact:
""" Model that holds contact from openmrs """
def __init__(self, name, number, date_created=None, program_name=None):
""" Constructor """
self.name = name
self.number = number
self.date_created = date_created
self.program_name = program_name
def __repr__(self):
""" readable model representation """
repr_name = '{} {}'.format(self.name, self.number)
return repr_name.strip()
class AppointmentContact:
""" Model that holds contacts for appointment scheduling """
def __init__(self, name, number,start_date, provider_name, date_created=None, program_name=None):
""" Constructor """
self.name = name
self.number = number
self.start_date = start_date
self.provider_name = provider_name
self.date_created = date_created
self.program_name = program_name
def __repr__(self):
""" readable model representation """
repr_name = '{} {}'.format(self.name, self.number)
return repr_name.strip()
class Contact:
""" Contact class """
def __init__(self, name=None, urns=None, fields=None, language='eng', ):
""" Constructor"""
self.name = name
self.urns = urns
if fields:
self.fields = fields
language = language
def save_contact(self):
""" Send contact to rapid pro contact list """
data = json.dumps(self.__dict__)
request = AbstractDataRequest(CONTACTS_URL, data)
response = request.post()
return response
def get_all_contacts(self):
""" Get all contacts """
request = AbstractSimpleRequest(CONTACTS_URL)
response = request.get()
return response
class BroadCast:
""" Abstract broadcast model class """
def __init__(self, urns, contacts, text, broadcast_id=None):
""" Constructor """
self.urns = urns
self.contacts = contacts
self.text = text
if broadcast_id:
self.broadcast_id = broadcast_id
def post(self):
""" Send message broadcast """
data = json.dumps(self.__dict__)
request = AbstractDataRequest(BROADCASTS_URL, data)
response = request.post()
return response