Difference between revisions of "AtoZ-API"
Line 10: | Line 10: | ||
All API method calls follow the same generic process flow, as follows: |
All API method calls follow the same generic process flow, as follows: |
||
api.php simply instantiates a new API object ($api = new API) and then calls it's processApi() method |
|||
The API method extends the "REST" class, and API's constructor is simply REST's constructor. |
|||
ProcessAPI() checks to see if "method_exists" with the name of the API being called, and if so it executes this method. If no method exists it "responses" a 404 error. |
|||
Every API method function must end with a call to response($data, $status) as this closes out the API call. |
|||
Step 1 - Rest->constructor: |
|||
Step 1a - Instantiate and start a new "ExecutionTime" object. This sets and stores two variable (startTimeCPU and startTimeClock) |
|||
Step 1b - execute $this->inputs(). This takes the POST or GET data and returns them as a key/value array. It also sets $this->_token if one of the parameters was "tok" and sets the value of $this->_func to the name of the API function that was invoked |
|||
Step 1c - if the call is NOT to "getToken" then we instantiate an AccessRights object |
|||
Revision as of 11:12, 30 January 2016
Overview
This is the overview starting page for the API.JSON infrastructure for AtoZ
The core of the system comprises:
- /api-json/api.php
- /api-json/Rest.inc.php
- /api-json/dbConnect.inc.php
All calls to the system are calls to api.php, which handles presentation and uses the other two core files for the database interactions.
All API method calls follow the same generic process flow, as follows:
api.php simply instantiates a new API object ($api = new API) and then calls it's processApi() method The API method extends the "REST" class, and API's constructor is simply REST's constructor. ProcessAPI() checks to see if "method_exists" with the name of the API being called, and if so it executes this method. If no method exists it "responses" a 404 error. Every API method function must end with a call to response($data, $status) as this closes out the API call.
Step 1 - Rest->constructor: Step 1a - Instantiate and start a new "ExecutionTime" object. This sets and stores two variable (startTimeCPU and startTimeClock) Step 1b - execute $this->inputs(). This takes the POST or GET data and returns them as a key/value array. It also sets $this->_token if one of the parameters was "tok" and sets the value of $this->_func to the name of the API function that was invoked Step 1c - if the call is NOT to "getToken" then we instantiate an AccessRights object
Methods
Public methods are accessed as calls to https://www.atozofmedicines.com/app/api.json/ METHOD_NAME ? PARAMS
All public methods other than "getToken" need to be passed an access token as one of the input parameters. During the constructor to all other API methods the token is used to
- force a login if the specified token has expired
- check for permission to access the specific API in question (Checks for a record in AtoZ_API.t_User_API with permissible ValidFrom and ValidUntil range)
- Sets $this->_EDL_Set from AtoZ_API.t_User_API.EDL_SET. This private variable is used to limit the available drugs that a client can access.
The following public methods exist in api.php
getToken
The getToken method is used to authenticate based on a username and password and the returned token is required for all other API calls
Inputs
- "sys" (the system calling this - currently unused)
- "usr" (the username to use)
- "pwd" (the password to use)
Returns
Token : xxxxxxx
Example
http://atozofmeds.local/app/api.json/getToken?sys=web&usr=TESTING&pwd=API-TEST {"token":"222628849519EF07"}
searchTrade
The searchTrade method is used to search for a medicine in the system.
This API does NOT honour the $this->_EDL_Set in returning results!
Inputs
- tok (a valid authentication token, with permission to access this API)
- med (the name of the medicine to search for - code uses %med% wildcards in search)
Returns
ID, FullName
Example
http://atozofmeds.local/app/api.json/searchTrade?tok=222628849519EF07&med=panado [{"ID":"109594","FullName":"Panado \/ (CAP)"}, {"ID":"102512","FullName":"Panado 120 mg\/5 mL (SYR)"}, {"ID":"109591","FullName":"Panado 500 \/ (TAB)"}, {"ID":"107032","FullName":"Panado Childrens 125 mg\/ (MLT)"}]
Interactions
The method is used to search for interaction details for the medicines in the input list.
Inputs
- tok (a valid authentication token, with permission to access this API)
- lst (a pipe-delimited list of codes {nappi, NDC, etc} to include in the set
- limit (Optional : a "Y", "N" field indicating if the results should be limited to the "DDU" set or not: defaults to "Y")
Returns
Token : xxxxxxx
Example
http://www.atozofmedicines.com/app/api.json/Interactions?tok=58807DD58D548695&lst=%7C110332%7C103851%7C108395%7C118351%7C102858&limit=N {"DATA":[{"TradeA":"108395","MedicineA":"Cipla Warfarin","TradeB":"110332","MedicineB":"Zocor","severity":"unsafe.png", "Details":{ "Detail1":{"Category":"Warning","Description":"Caution advised.","ReferenceID":"24675"}, "Detail2":{"Category":"Advice","Description":"Individual response.","ReferenceID":"14706"}, "Detail3":{"Category":"Advice","Description":"Substitute statin: atorvastatin, pravastatin.","ReferenceID":"24680"} } }, {"TradeA":"102858","MedicineA":"Sandoz Omeprazole","TradeB":"108395","MedicineB":"Cipla Warfarin","severity":"unsafe.png", "Details":{ "Detail1":{"Category":"Warning","Description":"Caution advised.","ReferenceID":"20168"}, "Detail2":{"Category":"Monitor","Description":"INR\/PT levels closely if initiating, discontinuing or changing the dose of either drug.","ReferenceID":"20169"} } }], "MESSAGE":{"NoData":[["103851"],["118351"]]}}
Pregnancy
The method is used to
Inputs
Returns
Token : xxxxxxx
Example
http://atozofmeds.local/app/api.json/ {}
Lactation
The method is used to
Inputs
Returns
Token : xxxxxxx
Example
http://atozofmeds.local/app/api.json/ {}
Porphyria
The method is used to
Inputs
Returns
Token : xxxxxxx
Example
http://atozofmeds.local/app/api.json/ {}
PIL (under development)
The method is used to
Inputs
Returns
Token : xxxxxxx
Example
http://atozofmeds.local/app/api.json/ {}