Panel |
---|
borderColor | orange |
---|
bgColor | yellow |
---|
borderWidth | 1 |
---|
borderStyle | solid |
---|
| VetView API Library |
Reusable JAR library that has the main functions for connection to and communication with VetView. The API Library contains a service class and a utilities class, named ApiService and ApiUtils, respectively. ApiService contains methods for connecting to and communicating with VetView. ApiUtils contains helper functions to be used when interfacing with VetView. ApiUtilsvalidateJSON Code Block |
---|
| static String validateJSON(String json) |
Used to parse error responses. Code Block |
---|
| static String formatDates(String dateString) |
Used to format dates for end user. generateToken Code Block |
---|
| static String generateToken(String secret, String payload) |
Used to tokenize strings for sending to main VetView app. Code Block |
---|
| static Map extractTokenPayload(String token, String secret) |
Extracts tokenized string. ApiServiceApiService can be instantiated two ways, depending on your application. A base URL and auth token can be passed directly. Code Block |
---|
| ApiService (String baseUrl, String authToken) |
If using application.yml to store the connection details, the GrailsApplication can be used.
Code Block |
---|
| ApiService (GrailsApplication grailsApplication) |
FunctionscreateRequest Code Block |
---|
| Map createRequest(String webServiceCall, String requestParams = '') |
Checks for valid baseUrl and authToken. Creates a map of the request details. openConnection Code Block |
---|
| HttpURLConnection openConnection(Map requestMap) |
Utilizes the Map from createRequest, opens a connection to VetView, and returns the connection object. createRequest and openConnection are the building blocks of all API calls and are used in all remaining functions. Map ResponseAll remaining functions return a Map representing the response. Return Maps are Map versions of the JSON results as shown on the API Swagger Documentation Page. mainAppStatusCheck Code Block |
---|
| Map mainAppStatusCheck() |
Attempts to connect to VetView and returns the response. Common ParametersAll remaining functions accept 2 parameters: Code Block |
---|
| String webServiceCall, String requestParams |
webServiceCall is the path to the desired function. Is appended to the baseUrl setting. requestParams is a URL-safe string of parameters. getResponse Code Block |
---|
| Map getResponse(String webServiceCall, String requestParams)
//Example
def result = apiService.getResponse('common/getConnectionStatus', "") |
Used to send a GET call to VetView and return results. callPost Code Block |
---|
| Map callPost(String webServiceCall, String requestParams, Map postData = null)
//Example
DateFormat apiDateFormat = new SimpleDateFormat("MM/dd/yyyy hh:mm:ss a")
Map newSpecimen = [:]
newSpecimen.put('accessionID', 577144)
newSpecimen.put('specimenCodeID', 35)
newSpecimen.put('specimenQty', 1)
newSpecimen.put('specimenLocationID', params?.id)
newSpecimen.put('testTubeNo', 'Thirteen')
newSpecimen.put('sampledDate', apiDateFormat.format(new Date()))
Map result = apiService.callPost("labs/specimens/createSpecimen", "", newSpecimen) |
Used to send POST commands to VetView and return results. callPost accepts a third parameter: a Map of the object being sent. Anytime an object is sent it will be a POST call, whether that's to create an entry or to update one. sendPut Code Block |
---|
| Map sendPut(String webServiceCall, String requestParams) |
Used to send a PUT call to VetView. sendDelete Code Block |
---|
| Map sendDelete(String webServiceCall, String requestParams) |
Used to send a DELETE command to VetView. getFile Code Block |
---|
| Map getFile(String webServiceCall, String requestParams)
//Example
Map result = apiService.getFile("labs/specimens/printLabel", "id=${params?.id}")
//Output to browser
response.setContentType("application/octet-stream")
response.setHeader("Content-disposition", "attachment;filename=" + result.filename)
response.outputStream << result.stream |
Used to retrieve a file from VetView. sendFile Code Block |
---|
| Map sendFile(String webServiceCall, String requestParams, File file, String displayName = '', String description = '')
//Example
File newFile = new File("path/to/file/filename.pdf")
Map result = apiService.sendFile("labRequests/uploadAttachment", "id=${params.id}", newFile) |
Used to send a file to VetView. sendFile accepts a third parameter: the File object being sent. |