本文整理汇总了Python中xmlrpclib.ServerProxy.patients_data方法的典型用法代码示例。如果您正苦于以下问题:Python ServerProxy.patients_data方法的具体用法?Python ServerProxy.patients_data怎么用?Python ServerProxy.patients_data使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类xmlrpclib.ServerProxy
的用法示例。
在下文中一共展示了ServerProxy.patients_data方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Client
# 需要导入模块: from xmlrpclib import ServerProxy [as 别名]
# 或者: from xmlrpclib.ServerProxy import patients_data [as 别名]
class Client(object):
"""A class abstracting the TherapyEdge XML-RPC away into something more
approachable and less temperamental"""
DEFAULT_SERVICE_URL = 'https://196.36.218.99/tools/ws/sms/patients/server.php'
# each request type is mapped to a dynamically generated class type
TYPE_MAP = {
'patientlist': 'Patient',
'patients_update': 'PatientUpdate',
'comingvisits': 'ComingVisit',
'missedvisits': 'MissedVisit',
'donevisits': 'DoneVisit',
'deletedvisits': 'DeletedVisit',
}
# cache for the generated classes
CLASS_CACHE = {}
def __init__(self, uri=None, verbose=False):
self.server = ServerProxy(uri or self.DEFAULT_SERVICE_URL, verbose=verbose)
def dict_to_class(self, name, dict):
"""
# create klass with getters & setters for parameter1 & parameter2
klass = dict_to_class('MyClass', {'parameter1':'val1', 'parameter2':'val2'})
# create an instance of klass with values val1 & val2
instance = klass._make('val1','val2')
instance.parameter1 => val1
instance.parameter2 => val2
"""
return self.CLASS_CACHE.setdefault(name, namedtuple(name, dict.keys()))
def rpc_call(self, request, clinic_id, since='', until=''):
"""Call the XML-RPC service, returns a list of dicts"""
# check if the given since & untils are date values, if so check their
# sequence and manipulate them to the right format
if isinstance(since, datetime) and isinstance(until, datetime):
if since > until:
raise IllegaleDateRange, 'since (%s) is greater than until (%s)' \
% (since, until)
since = since.strftime('%Y-%m-%d')
until = until.strftime('%Y-%m-%d')
return self.server.patients_data(request,
0, # Highly magical, no clue
since,
until,
3, # Highly magical, no clue
clinic_id)
def create_instances_of(self, klass, iterable):
"""This is sort of kludgy. We get a dict from TherapyEdge and in turn
read the values from that dict to populate a class instance. We're
expecting that TherapyEdge will not change the order of the dict and that
the order of the values are always consistent. This isn't true and as such
we should be populating the instances by explicitly passing in the values
instead of iterating over a list of unreliable ordering.
Ugh, this is sketchy at best
"""
for item in iterable:
# create empty instance with empty values
instance = klass._make(klass._fields)
# named tuples won't allow the setting of variables but will allow
# replacing them with a new set of vars and which returns a new
# instance of the named tuple
yield instance._replace(**item)
def call_method(self, request, *args, **kwargs):
"""Call a method on the XML-RPC service, returning them as named tuples"""
result_list = self.rpc_call(request, *args, **kwargs)
if result_list:
# convert 'patients_update' to 'PatientUpdate'
klass_name = self.TYPE_MAP[request]
# convert 'PatientUpdate' (str) into PatientUpdate (class)
klass = self.dict_to_class(klass_name, result_list[0])
# make list of dicts into PatientUpdate instances
return self.create_instances_of(klass, result_list)
return result_list
def get_all_patients(self, clinic_id, *args, **kwargs):
"""Get a list of all patients available at the clinic"""
return self.call_method('patientlist', clinic_id, *args, **kwargs)
def get_updated_patients(self, clinic_id, since, until=None):
"""Get a list of all patients updated between the date values given
specified in `since` and `until`. If until is not specified it defaults
to `datetime.now()`"""
until = until or datetime.now()
return self.call_method('patients_update', clinic_id, since, until)
def get_coming_visits(self, *args, **kwargs):
return self.call_method('comingvisits', *args, **kwargs)
def get_missed_visits(self, *args, **kwargs):
return self.call_method('missedvisits', *args, **kwargs)
#.........这里部分代码省略.........
示例2: Client
# 需要导入模块: from xmlrpclib import ServerProxy [as 别名]
# 或者: from xmlrpclib.ServerProxy import patients_data [as 别名]
class Client(object):
"""A class abstracting the TherapyEdge XML-RPC away into something more
approachable and less temperamental"""
DEFAULT_SERVICE_URL = 'https://196.36.218.99/tools/ws/sms/patients/server.php'
# each request type is mapped to a dynamically generated class type
TYPE_MAP = {
'patientlist': 'Patient',
'patients_update': 'PatientUpdate',
'comingvisits': 'ComingVisit',
'missedvisits': 'MissedVisit',
'donevisits': 'DoneVisit',
'deletedvisits': 'DeletedVisit',
}
# cache for the generated classes
CLASS_CACHE = {}
def __init__(self, uri=None, verbose=False):
self.server = ServerProxy(uri or self.DEFAULT_SERVICE_URL, verbose=verbose)
def dict_to_class(self, name, dict):
"""
# create klass with getters & setters for parameter1 & parameter2
klass = dict_to_class('MyClass', {'parameter1':'val1', 'parameter2':'val2'})
# create an instance of klass with values val1 & val2
instance = klass._make('val1','val2')
instance.parameter1 => val1
instance.parameter2 => val2
"""
return self.CLASS_CACHE.setdefault(name, namedtuple(name, dict.keys()))
def rpc_call(self, request, clinic_id, since='', until=''):
"""Call the XML-RPC service, returns a list of dicts"""
# check if the given since & untils are date values, if so check their
# sequence and manipulate them to the right format
if isinstance(since, datetime) and isinstance(until, datetime):
if since > until:
raise IllegaleDateRange, 'since (%s) is greater than until (%s)' \
% (since, until)
since = since.strftime('%Y-%m-%d')
until = until.strftime('%Y-%m-%d')
return self.server.patients_data(request,
0, # Highly magical, no clue
since,
until,
3, # Highly magical, no clue
clinic_id)
def create_instances_of(self, klass, iterable):
"""This is sort of kludgy. We get a dict from TherapyEdge and in turn
read the values from that dict to populate a class instance. We're
expecting that TherapyEdge will not change the order of the dict and that
the order of the values are always consistent. This isn't true and as such
we should be populating the instances by explicitly passing in the values
instead of iterating over a list of unreliable ordering.
Ugh, this is sketchy at best
"""
for item in iterable:
# create empty instance with empty values
instance = klass._make(klass._fields)
# named tuples won't allow the setting of variables but will allow
# replacing them with a new set of vars and which returns a new
# instance of the named tuple
yield instance._replace(**item)
def call_method(self, request, *args, **kwargs):
"""Call a method on the XML-RPC service, returning them as named tuples"""
result_list = self.rpc_call(request, *args, **kwargs)
if result_list:
# convert 'patients_update' to 'PatientUpdate'
klass_name = self.TYPE_MAP[request]
# convert 'PatientUpdate' (str) into PatientUpdate (class)
klass = self.dict_to_class(klass_name, result_list[0])
# make list of dicts into PatientUpdate instances
return self.create_instances_of(klass, result_list)
return result_list
def get_all_patients(self, clinic_id, *args, **kwargs):
"""Get a list of all patients available at the clinic"""
return self.call_method('patientlist', clinic_id, *args, **kwargs)
def get_updated_patients(self, clinic_id, since, until=None):
"""Get a list of all patients updated between the date values given
specified in `since` and `until`. If until is not specified it defaults
to `datetime.now()`"""
until = until or datetime.now()
return self.call_method('patients_update', clinic_id, since, until)
def get_coming_visits(self, *args, **kwargs):
return self.call_method('comingvisits', *args, **kwargs)
def get_missed_visits(self, *args, **kwargs):
# TherapyEdge will return scheduled but unattended future visits as missed
# So we can't ask for missed visits after midnight last night
#.........这里部分代码省略.........
示例3: test
# 需要导入模块: from xmlrpclib import ServerProxy [as 别名]
# 或者: from xmlrpclib.ServerProxy import patients_data [as 别名]
def test(request):
from xmlrpclib import ServerProxy, Error
SERVICE_URL = 'https://196.36.218.99/tools/ws/sms/patients/server.php'
server = ServerProxy(SERVICE_URL)
data = server.patients_data('patientlist', 0, '', '', 3, '02')
return HttpResponse(data)