Using JSON in Android for DICOM Communication

We have received several requests regarding PACS and DICOM Communication within our Android imaging SDK. One way of accomplishing this is by using JSON to communicate with the RESTful web services included with the HTML5 Zero Footprint DICOM Viewer.

The snippet below shows a portion of the asynchronous code that calls the RESTful Medical Viewer Service and then parses the JSON response to get the SOP Instance UID. After that, the SOP Instance UID is used to get the image data and put it into an InputStream.


protected Bitmap doInBackground(String... urls) {
   String seriesID = //...
   // ************* Get Selected Series Presentation Info ***************
   // ------ Get the presentation info for the first series -----
   httpget = getHttpGet(String.format("http://demo.leadtools.com/MedicalViewerService/ObjectRetrieveService.svc/GetPresentationInfo?auth=%s&series=%s", authenticationToken, seriesID));             
   // Send the request and read the response
   httpResponse = httpclient.execute(httpget);

   resEntity = httpResponse.getEntity();

   String info = EntityUtils.toString(resEntity);
   // ###********** Get Selected Series Info ************###

   JSONArray infoArray = new JSONArray(info);
   if(studiesArray.length() < 1)
      return null;

   JSONObject sopInfoObj = infoArray.getJSONObject(0);
   String sopInstanceUID = sopInfoObj.getString("SOPInstanceUID");

   // ************* Get the images (First Frame) ***************             
   int frameNumber = 1;
   InputStream in = new URL(String.format("http://demo.leadtools.com/MedicalViewerService/ObjectRetrieveService.svc/GetImage?auth=%s&instance=%s&frame=%d&cx=%d&cy=%d", authenticationToken, sopInstanceUID, frameNumber, 1024, 1024)).openStream();          
   // ###********** Get the images url (First Frame) ************###
   return BitmapFactory.decodeStream(in);
}

protected void onPostExecute(Bitmap bm) {
   mDialog.dismiss();
   if(bm == null) {
      displayAlert("Ann Error Occured");
   } else {
      ImageView imgView = (ImageView) findViewById(R.id.imageview1);
      imgView.setImageBitmap(bm);
   }
}

Calling Medical Web Viewer on Android

Typically, the workflow for something like this would be to authenticate the service calls, start at the patient or study level with a broad or narrow search, parse the JSON, and display the matching results. Then the user can drill down to the series and image or images to be displayed with increasingly narrow service requests and JSON responses. Attached is an Android Java project that does just that and more. If you have any more questions or would like to see more examples like this, please leave a comment below or contact support@leadtools.com

This entry was posted in Medical Imaging and tagged , , , , , , , , , , , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *