<s> from __future__ import absolute_import <EOL> import json <EOL> import os <EOL> import pokitdok <EOL> import requests <EOL> from requests_oauthlib import OAuth2Session <EOL> from oauthlib . oauth2 import BackendApplicationClient <EOL> class PokitDokClient ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , client_id , client_secret , base = "<STR_LIT>" , version = "<STR_LIT>" , <EOL> redirect_uri = None , scope = None , auto_refresh = False , token_refresh_callback = None , code = None ) : <EOL> """<STR_LIT>""" <EOL> self . base_headers = { <EOL> '<STR_LIT>' : '<STR_LIT>' . format ( pokitdok . __version__ , requests . utils . default_user_agent ( ) ) <EOL> } <EOL> self . json_headers = { <EOL> '<STR_LIT>' : '<STR_LIT:application/json>' , <EOL> } <EOL> self . json_headers . update ( self . base_headers ) <EOL> self . client_id = client_id <EOL> self . client_secret = client_secret <EOL> self . redirect_uri = redirect_uri <EOL> self . scope = scope <EOL> self . code = code <EOL> self . auto_refresh = auto_refresh <EOL> self . token_refresh_callback = token_refresh_callback <EOL> self . token = { } <EOL> self . url_base = "<STR_LIT>" . format ( base , version ) <EOL> self . token_url = "<STR_LIT>" . format ( base ) <EOL> self . authorize_url = "<STR_LIT>" . format ( base ) <EOL> self . api_client = None <EOL> self . fetch_access_token ( code = self . code ) <EOL> def initialize_auth_api_client ( self , refresh_url ) : <EOL> self . api_client = OAuth2Session ( self . client_id , redirect_uri = self . redirect_uri , scope = self . scope , <EOL> auto_refresh_url = refresh_url , token_updater = self . token_refresh_callback , <EOL> auto_refresh_kwargs = { <EOL> '<STR_LIT>' : self . client_id , <EOL> '<STR_LIT>' : self . client_secret } ) <EOL> def authorization_url ( self ) : <EOL> """<STR_LIT>""" <EOL> refresh_url = self . token_url if self . auto_refresh else None <EOL> self . initialize_auth_api_client ( refresh_url ) <EOL> return self . api_client . authorization_url ( self . authorize_url ) <EOL> def fetch_access_token ( self , code = None ) : <EOL> """<STR_LIT>""" <EOL> refresh_url = self . token_url if self . auto_refresh else None <EOL> if code is None : <EOL> self . api_client = OAuth2Session ( self . client_id , client = BackendApplicationClient ( self . client_id ) , <EOL> auto_refresh_url = refresh_url , token_updater = self . token_refresh_callback , <EOL> auto_refresh_kwargs = { <EOL> '<STR_LIT>' : self . client_id , <EOL> '<STR_LIT>' : self . client_secret } ) <EOL> self . token = self . api_client . fetch_token ( self . token_url , client_id = self . client_id , <EOL> client_secret = self . client_secret ) <EOL> else : <EOL> self . code = code <EOL> self . initialize_auth_api_client ( refresh_url ) <EOL> self . token = self . api_client . fetch_token ( self . token_url , code = code , client_id = self . client_id , <EOL> client_secret = self . client_secret , scope = self . scope ) <EOL> return self . token <EOL> def request ( self , path , method = '<STR_LIT>' , data = None , files = None , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> if data and not files : <EOL> headers = self . json_headers <EOL> request_data = json . dumps ( data ) <EOL> else : <EOL> headers = self . base_headers <EOL> request_data = data <EOL> request_url = "<STR_LIT>" . format ( self . url_base , path ) <EOL> request_method = getattr ( self . api_client , method ) <EOL> return request_method ( request_url , data = request_data , files = files , params = kwargs , headers = headers ) . json ( ) <EOL> def get ( self , path , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> return self . request ( path , method = '<STR_LIT>' , ** kwargs ) <EOL> def put ( self , path , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> return self . request ( path , method = '<STR_LIT>' , ** kwargs ) <EOL> def post ( self , path , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> return self . request ( path , method = '<STR_LIT>' , ** kwargs ) <EOL> def delete ( self , path , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> return self . request ( path , method = '<STR_LIT>' , ** kwargs ) <EOL> def activities ( self , activity_id = None , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> path = "<STR_LIT>" . format ( activity_id if activity_id else '<STR_LIT>' ) <EOL> return self . get ( path , ** kwargs ) <EOL> def cash_prices ( self , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> return self . get ( '<STR_LIT>' , ** kwargs ) <EOL> def ccd ( self , ccd_request ) : <EOL> """<STR_LIT>""" <EOL> return self . post ( '<STR_LIT>' , data = ccd_request ) <EOL> def claims ( self , claims_request ) : <EOL> """<STR_LIT>""" <EOL> return self . post ( '<STR_LIT>' , data = claims_request ) <EOL> def claims_status ( self , claims_status_request ) : <EOL> """<STR_LIT>""" <EOL> return self . post ( '<STR_LIT>' , data = claims_status_request ) <EOL> def mpc ( self , code = None , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> mpc_path = "<STR_LIT>" . format ( code if code else '<STR_LIT>' ) <EOL> return self . get ( mpc_path , ** kwargs ) <EOL> def icd_convert ( self , code ) : <EOL> """<STR_LIT>""" <EOL> return self . get ( "<STR_LIT>" . format ( code ) ) <EOL> def claims_convert ( self , x12_claims_file ) : <EOL> """<STR_LIT>""" <EOL> return self . post ( '<STR_LIT>' , files = { <EOL> '<STR_LIT:file>' : ( os . path . split ( x12_claims_file ) [ - <NUM_LIT:1> ] , open ( x12_claims_file , '<STR_LIT:rb>' ) , '<STR_LIT>' ) <EOL> } ) <EOL> def eligibility ( self , eligibility_request ) : <EOL> """<STR_LIT>""" <EOL> return self . post ( '<STR_LIT>' , data = eligibility_request ) <EOL> def enrollment ( self , enrollment_request ) : <EOL> """<STR_LIT>""" <EOL> return self . post ( '<STR_LIT>' , data = enrollment_request ) <EOL> def enrollment_snapshot ( self , trading_partner_id , x12_file ) : <EOL> """<STR_LIT>""" <EOL> return self . post ( '<STR_LIT>' , data = { '<STR_LIT>' : trading_partner_id } , <EOL> files = { <EOL> '<STR_LIT:file>' : ( os . path . split ( x12_file ) [ - <NUM_LIT:1> ] , open ( x12_file , '<STR_LIT:rb>' ) , '<STR_LIT>' ) <EOL> } ) <EOL> def enrollment_snapshots ( self , snapshot_id = None , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> path = "<STR_LIT>" . format ( '<STR_LIT>' . format ( snapshot_id ) if snapshot_id else '<STR_LIT>' ) <EOL> return self . get ( path , ** kwargs ) <EOL> def enrollment_snapshot_data ( self , snapshot_id , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> path = "<STR_LIT>" . format ( snapshot_id ) <EOL> return self . get ( path , ** kwargs ) <EOL> def files ( self , trading_partner_id , x12_file ) : <EOL> """<STR_LIT>""" <EOL> return self . post ( '<STR_LIT>' , data = { '<STR_LIT>' : trading_partner_id } , <EOL> files = { <EOL> '<STR_LIT:file>' : ( os . path . split ( x12_file ) [ - <NUM_LIT:1> ] , open ( x12_file , '<STR_LIT:rb>' ) , '<STR_LIT>' ) <EOL> } ) <EOL> def insurance_prices ( self , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> return self . get ( '<STR_LIT>' , ** kwargs ) <EOL> def payers ( self , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> return self . get ( '<STR_LIT>' , ** kwargs ) <EOL> def plans ( self , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> return self . get ( '<STR_LIT>' , ** kwargs ) <EOL> def providers ( self , npi = None , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> path = "<STR_LIT>" . format ( npi if npi else '<STR_LIT>' ) <EOL> return self . get ( path , ** kwargs ) <EOL> def trading_partners ( self , trading_partner_id = None ) : <EOL> """<STR_LIT>""" <EOL> path = "<STR_LIT>" . format ( trading_partner_id if trading_partner_id else '<STR_LIT>' ) <EOL> return self . get ( path ) <EOL> def referrals ( self , referral_request ) : <EOL> """<STR_LIT>""" <EOL> return self . post ( '<STR_LIT>' , data = referral_request ) <EOL> def authorizations ( self , authorizations_request ) : <EOL> """<STR_LIT>""" <EOL> return self . post ( '<STR_LIT>' , data = authorizations_request ) <EOL> def schedulers ( self , scheduler_uuid = None ) : <EOL> """<STR_LIT>""" <EOL> path = "<STR_LIT>" . format ( scheduler_uuid if scheduler_uuid else '<STR_LIT>' ) <EOL> return self . get ( path ) <EOL> def appointment_types ( self , appointment_type_uuid = None ) : <EOL> """<STR_LIT>""" <EOL> path = "<STR_LIT>" . format ( appointment_type_uuid if appointment_type_uuid else '<STR_LIT>' ) <EOL> return self . get ( path ) <EOL> def schedule_slots ( self , slots_request ) : <EOL> """<STR_LIT>""" <EOL> return self . post ( "<STR_LIT>" , data = slots_request ) <EOL> def appointments ( self , appointment_uuid = None , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> path = "<STR_LIT>" . format ( appointment_uuid if appointment_uuid else '<STR_LIT>' ) <EOL> return self . get ( path , ** kwargs ) <EOL> def book_appointment ( self , appointment_uuid , appointment_request ) : <EOL> """<STR_LIT>""" <EOL> path = "<STR_LIT>" . format ( appointment_uuid ) <EOL> return self . put ( path , data = appointment_request ) <EOL> update_appointment = book_appointment <EOL> def cancel_appointment ( self , appointment_uuid ) : <EOL> """<STR_LIT>""" <EOL> path = "<STR_LIT>" . format ( appointment_uuid ) <EOL> return self . delete ( path ) <EOL> def create_identity ( self , identity_request ) : <EOL> """<STR_LIT>""" <EOL> return self . post ( '<STR_LIT>' , data = identity_request ) <EOL> def update_identity ( self , identity_uuid , identity_request ) : <EOL> """<STR_LIT>""" <EOL> path = "<STR_LIT>" . format ( identity_uuid ) <EOL> return self . put ( path , data = identity_request ) <EOL> def identity ( self , identity_uuid = None , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> path = "<STR_LIT>" . format ( '<STR_LIT>' . format ( identity_uuid ) if identity_uuid else '<STR_LIT>' ) <EOL> return self . get ( path , ** kwargs ) <EOL> def identity_history ( self , identity_uuid , historical_version = None ) : <EOL> """<STR_LIT>""" <EOL> identity_url = "<STR_LIT>" . format ( self . url_base , str ( identity_uuid ) ) <EOL> if historical_version is not None : <EOL> identity_url = "<STR_LIT>" . format ( identity_url , historical_version ) <EOL> return self . api_client . get ( identity_url , headers = self . base_headers ) . json ( ) <EOL> def pharmacy_plans ( self , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> return self . get ( '<STR_LIT>' , ** kwargs ) <EOL> def pharmacy_formulary ( self , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> return self . get ( '<STR_LIT>' , ** kwargs ) <EOL> def pharmacy_drug_cost ( self , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> return self . get ( '<STR_LIT>' , ** kwargs ) <EOL> def pharmacy_network ( self , npi = None , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> path = "<STR_LIT>" . format ( npi ) if npi else '<STR_LIT>' <EOL> return self . get ( path , ** kwargs ) </s>
