VetView API Library
- Cathy Allison
- Abraham Westfall
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.
ApiUtils
validateJSON
static String validateJSON(String json)
Used to parse error responses.
formatDates
static String formatDates(String dateString)
Used to format dates for end user.
generateToken
static String generateToken(String secret, String payload)
Used to tokenize strings for sending to main VetView app.
extractTokenPayload
static Map extractTokenPayload(String token, String secret)
Extracts tokenized string.
ApiService
ApiService can be instantiated two ways, depending on your application.
A base URL and auth token can be passed directly.
ApiService (String baseUrl, String authToken)
If using application.yml to store the connection details, the GrailsApplication can be used.
ApiService (GrailsApplication grailsApplication)
Functions
createRequest
Map createRequest(String webServiceCall, String requestParams = '')
Checks for valid baseUrl and authToken.
Creates a map of the request details.
openConnection
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 Response
All 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
Map mainAppStatusCheck()
Attempts to connect to VetView and returns the response.
Common Parameters
All remaining functions accept 2 parameters:
String webServiceCall, String requestParams
webServiceCall is the path to the desired function.
It is appended to the baseUrl setting.
requestParams is a URL-safe string of parameters.
getResponse
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
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
Map sendPut(String webServiceCall, String requestParams)
Used to send a PUT call to VetView.
sendDelete
Map sendDelete(String webServiceCall, String requestParams)
Used to send a DELETE command to VetView.
getFile
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
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.
VetView Wiki Most recent releases of VetView: Version 5.0.2 and 4.2.8 Hotfix (Released 12/20/2024)
To see commonly used terms in VetView Hospital, please visit our Hospital Glossary of Terms.