Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.


Panel


Panel
borderColororange
bgColoryellow
borderWidth1
borderStylesolid

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

Code Block
languagegroovy
static String validateJSON(String json)

Used to parse error responses.

formatDates

Code Block
languagegroovy
static String formatDates(String dateString)

Used to format dates for end user.

generateToken

Code Block
languagegroovy
static String generateToken(String secret, String payload)

Used to tokenize strings for sending to main VetView app.

extractTokenPayload

Code Block
languagegroovy
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.

Code Block
languagegroovy
ApiService (String baseUrl, String authToken)


If using application.yml to store the connection details, the GrailsApplication can be used.

Code Block
languagegroovy
ApiService (GrailsApplication grailsApplication)

Functions

createRequest

Code Block
languagegroovy
Map createRequest(String webServiceCall, String requestParams = '')

Checks for valid baseUrl and authToken.
Creates a map of the request details.

openConnection

Code Block
languagegroovy
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

Code Block
languagegroovy
Map mainAppStatusCheck()

Attempts to connect to VetView and returns the response.

Common Parameters

All remaining functions accept 2 parameters:

Code Block
languagegroovy
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

Code Block
languagegroovy
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
languagegroovy
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
languagegroovy
Map sendPut(String webServiceCall, String requestParams)

Used to send a PUT call to VetView.

sendDelete

Code Block
languagegroovy
Map sendDelete(String webServiceCall, String requestParams)

Used to send a DELETE command to VetView.

getFile

Code Block
languagegroovy
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
languagegroovy
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.



Insert excerpt
Setup & Admin Guides
Setup & Admin Guides
nopaneltrue

Info

To see commonly used terms in VetView Hospital, please visit our Hospital Glossary of Terms.


Panel
titleContents

Table of Contents