"Key" images series for Stone Viewer ?

Some users that I work with are interested in having the ability to create “Key” images for studies. This is probably somewhat related to the To Do List item referencing saving annotations for the Stone Viewer.

I started playing around with that a bit on a development system and came up with something that might work, but still a work in progress. I host the front-end (Applications/StoneWebViewer/WebApplication/index.html from the source) and simply added this around line 667 in the source:

Make Key Image

and then added this around line 301 in app.js:

SaveKeyImage: function(studyInstanceUid)
var canvas = document.getElementById(app.GetActiveCanvas());
let image = canvas.toDataURL(‘image/png’);
axios.post(app.globalConfiguration.OrthancApiRoot + ‘/make_key_image’, {“StudyInstanceUID”:studyInstanceUid,“data_url”:image,“ImageComments”:“ImageComments”})
.then(function(response) {
response = response.data;

I am using a proxy, but that sends a request to a Python Plug-in that then adds the jpeg / png image from the active canvas to a new or existing series that contains all of the key images.

def MakeKeyImage(output, uri, **request):

pass in StudyInstanceUID, data_url, ImageComment

if request[‘method’] != ‘POST’:
response = dict();
query = json.loads(request[‘body’])
study = json.loads(orthanc.RestApiPost(‘/tools/lookup’, query[‘StudyInstanceUID’]))[0] # assume a unique StudyInstancUID on server
series = json.loads(orthanc.RestApiGet(‘/studies/’ + study[“ID”] + ‘/series’))
keyimagesID = False
for seriesitem in series:
if seriesitem[‘MainDicomTags’][‘SeriesDescription’] == ‘KEY_IMAGES’:
keyimagesID = seriesitem[‘ID’]
dicomdata = dict()

if keyimagesID:
parent = keyimagesID
dicomdata[‘Tags’] = {“ImageComments”:query[‘ImageComments’]}
parent = study[“ID”]
dicomdata[‘Tags’] = {“Modality”:“OT”,“SeriesDescription”: “KEY_IMAGES”,“SequenceName” : “KEY_IMAGES”,“ImageComments”:query[‘ImageComments’],“SeriesNumber”:“0”}
dicomdata[‘Parent’] = parent
dicomdata[‘Content’] = query[‘data_url’]
dicom = json.loads(orthanc.RestApiPost(‘/tools/create-dicom’, json.dumps(dicomdata)))
response[‘keyimagesID’] = keyimagesID
response[‘status’] = study
response[‘create-dicom’] = dicom
output.AnswerBuffer(json.dumps(response), ‘application/json’)

orthanc.RegisterRestCallback(‘/make_key_image’, MakeKeyImage)

Needs to be developed a bit more, but seems like a nice feature to have.