@Override
public String generateHtml(FormEntryContext context) {
StringBuilder sb = new StringBuilder();
if (context.getMode().equals(Mode.VIEW) && existingObs != null) {
Obs complexObs = Context.getObsService().getComplexObs(existingObs.getId(), "");
AnnotatedImage ai = (AnnotatedImage) existingObs.getComplexData().getData();
String encodedImage = null;
try {
encodedImage = DrawingUtil.imageToBase64(ai.getImage());
}
catch (IOException e) {
log.error("unable to encode image to Base64 format", e);
}
sb.append("<link rel='stylesheet' media='screen' type='text/css' href='/" + WebConstants.WEBAPP_NAME
+ "/moduleResources/drawing/drawingHtmlForm.css' />");
sb.append("<script type='text/javascript'>var ancount"
+ id
+ "=0; var redDot ='/openmrstru/moduleResources/drawing/red-dot.png';var close = '/openmrstru/moduleResources/drawing/close.gif';function createMarker"
+ id
+ "(identification, x, y, text, stat) {var annotationId = \"marker"
+ id
+ "\" + ancount"
+ id
+ ";ancount"
+ id
+ "++;var annDivData = \"<img src='\" + close + \"' style='float:right' onClick='$j(this).parent().parent().fadeOut(500)'/><span style='background-color:white'>\" + text + \"</span></br>\";var v = '<div class=\"container\"><div style=\"position:absolute;z-index:5;display:none\"><div id=\"' + annotationId + '_data\" class=\"divContainerDown\">' + annDivData + '</div><div class=\"calloutDown\"><div class=\"calloutDown2\"></div></div></div>';$j('#canvasDiv"
+ id
+ "').append(v + '<img id=\"' + annotationId + '\" src=\"' + redDot + '\" style=\"top:' + y + 'px;left:' + x + 'px;position:absolute;z-index:4\"/></div>');$j('#' + annotationId).click(function(event) {$j('#' + annotationId + '_data').parent().css('top', event.pageY-$j('#canvasDiv"
+ id
+ "').offset().top - $j('#' + annotationId + '_data').parent().height());$j('#' + annotationId + '_data').parent().css('left', event.pageX-$j('#canvasDiv"
+ id
+ "').offset().left - $j('#' + annotationId + '_data').parent().width() / 8 - 5);$j('#' + annotationId + '_data').parent().show();});}");
sb.append("$j(document).ready(function(){");
for (ImageAnnotation annotation : ai.getAnnotations())
sb.append("createMarker" + id + "(" + annotation.getId() + "," + annotation.getLocation().getX() + ","
+ annotation.getLocation().getY() + ",'" + annotation.getText() + "','" + annotation.getStatus()
+ "');");
sb.append("})</script>");
sb.append("<h4>" + complexObs.getConcept().getName(Context.getLocale()).getName() + "</h4>");
sb.append("<div id='canvasDiv" + id + "' style='position:relative'><img src='" + encodedImage + "'></div>");
//sb.append(complexData.getData());
} else if (context.getMode() == Mode.EDIT || context.getMode() == Mode.ENTER) {
sb.append("<link rel='stylesheet' type='text/css' href='/" + WebConstants.WEBAPP_NAME