Skip to main content
Join the official 2020 Python Developers SurveyStart the survey!

No project description provided

Project description

from .patients import patients
from pylib.falcon.jsonmiddlerware import RequireJSON, JSONTranslator

import falcon

# setup required middleware
api = falcon.API(middleware=[

# our custom error serializer
def __json_error_serializer(req, exception):
return ('application/json', exception.to_json())


from pylib.schema import validators
from pylib.falcon import Collection

from marshmallow import Schema
from marshmallow.fields import Int, Str, Date

all_patients = []
counter = 0

def authenticate(req, resp, res, params):

def authorize(req, resp, res, params):

class PatientSchema(Schema):
id = Int()
firstname = Str(required=True)
surname = Str()
dob = Date()
homephone = Str(validate=validators.phone_check)

patients = Collection(
'/api/patients', 'pid',
PatientSchema(), before=[authenticate])

def has_same_key_predicate(key, query):
def predicate(patient):
value = patient.get(key)
return value and value.startswith(query)
return predicate[authorize])
def search(query, query_type, **kwargs):
if query is None:
return all_patients

query_type = 'firstname' if query_type is None else query_type
return list(filter(
has_same_key_predicate(query_type, query),

def create(patient, **kwargs):
return len(all_patients) - 1[authorize])
def get(pid):
if pid < len(all_patients):
return all_patients[pid]

def update(pid, patient):
if pid < len(all_patients):
all_patients[pid] = patient
return patient

def delete(pid):
if pid < len(all_patients):
patient = all_patients[pid]
return patient


Project details

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page