Widget:PillIdentifier: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
(51 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
<includeonly> | <includeonly> | ||
<script content-type= "application/javascript" src="http://www.wikidoc.org/ | <script content-type= "application/javascript" src="http://www.wikidoc.org/extensions/raty/md5.js"></script> | ||
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> | <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> | ||
<link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/themes/smoothness/jquery-ui.css"> | <link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/themes/smoothness/jquery-ui.css"> | ||
Line 19: | Line 19: | ||
} | } | ||
})(); | })(); | ||
$("#firstHeading").remove(); | |||
$("#searchbox").remove(); | |||
$('#submit').click(runQuery); | $('#submit').click(runQuery); | ||
$('.navTool').click(nav); | $('.navTool').click(nav); | ||
$("#reset").click(resetForm); | |||
$(".pillShapeOption").click(function(){ | |||
$(".pillShapeOption").children("img").css("border",""); | |||
$(this).children("img:first").css("border","thin solid black"); | |||
$(this).children("img:first").css("border-radius","10%"); | |||
}); | |||
$(".pillColorOption").click(function(){ | |||
$(".pillColorOption").children("img").css("border",""); | |||
$(this).children("img:first").css("border","thin solid black"); | |||
$(this).children("img:first").css("border-radius","10%"); | |||
}); | |||
$(".pillScoreOption").click(function(){ | |||
$(".pillScoreOption").children("img").css("border",""); | |||
$(this).children("img:first").css("border","thin solid black"); | |||
$(this).children("img:first").css("border-radius","10%"); | |||
}); | |||
$("#slider").slider({ | $("#slider").slider({ | ||
min: 0, | min: 0, | ||
Line 63: | Line 82: | ||
$('.pillColorOption').click(updateFormClick); | $('.pillColorOption').click(updateFormClick); | ||
$('.pillScoreOption').click(updateFormClick); | $('.pillScoreOption').click(updateFormClick); | ||
$('.pillMiscContainer').change(updateFormText); | $('.pillMiscContainer').change(updateFormText); | ||
}; | }; | ||
function resetForm(){ | |||
$('.pillShapeOption').children("img").css("border",""); | |||
$('.pillColorOption').children("img").css("border",""); | |||
$('.pillScoreOption').children("img").css("border",""); | |||
$("#selectedShape").val(""); | |||
$("#selectedColor").val(""); | |||
$("#selectedScoring").val(""); | |||
$("#selectedImprint").val(""); | |||
$("#selectedNDC").val(""); | |||
$("#selectedIngred").val(""); | |||
$(".propertyContainerActive").attr("class", "propertyContainerInactive"); | |||
$("#queryContainer_Shape").attr("class", "propertyContainerActive"); | |||
$("#back").css("visibility","hidden"); | |||
$('#resultsTable-container').html(''); | |||
}; | |||
function buildQueryParameters(){ | function buildQueryParameters(){ | ||
var queryShape = ""; | var queryShape = ""; | ||
Line 118: | Line 155: | ||
return queryShape+queryColor+queryScoring+queryImprint+queryMinSize+queryMaxSize+queryNDC+queryIngred; | return queryShape+queryColor+queryScoring+queryImprint+queryMinSize+queryMaxSize+queryNDC+queryIngred; | ||
}; | }; | ||
function runQuery() { | function runQuery() { | ||
$('#resultsTable- | $('#resultsTable-container').html(''); | ||
var queryParameters = buildQueryParameters(); | var queryParameters = buildQueryParameters(); | ||
var printoutRequests = "|?Pill%20Imprint|?Pill%20Dosage|?Pill%20Ingred|?Pill%20Color|?Pill%20Shape|?Pill%20Size%20(mm)|?Pill%20Scoring|?NDC|?Pill%20Name"; | var printoutRequests = "|?Pill%20Imprint|?Pill%20Dosage|?Pill%20Ingred|?Pill%20Color|?Pill%20Shape|?Pill%20Size%20(mm)|?Pill%20Scoring|?NDC|?Pill%20Name"; | ||
var jsonURL = "http://www.wikidoc.org/api.php?action=ask&query="+queryParameters+printoutRequests+"&format=json"; | var jsonURL = "http://www.wikidoc.org/api.php?action=ask&query="+queryParameters+printoutRequests+"&format=json"; | ||
$.getJSON(jsonURL, function (data) { | $.getJSON(jsonURL, function (data) { | ||
$.each(data.query.results, function(ind, val) { | if(countProperties(data.query.results) > 0){ | ||
$.each(data.query.results, function(ind, val) { | |||
///////////////////////////////////////////////////////////////////////// | |||
////// Store each returned result ////// | |||
///////////////////////////////////////////////////////////////////////// | |||
// | |||
//If the .getJSON() function is able to successfully receive information | |||
//from the WikiDoc API, it will begin to execute the unnamed function we | |||
//have provided. The data that is returned is in JSON format, meaning | |||
//that we will have lots of objects within objects. Our function says | |||
//that for EACH property of data.query.results (that is, each returned | |||
//result from the query) we should perform the following operations. | |||
// | |||
//We will first store all the results as local variables. Some of these | |||
//results will need to be converted to a string, so don't be alarmed if | |||
//you see some string() methods. After storing our variables,we | |||
//construct a hyperlink and image URL. Lastly, we add a row to the | |||
//our results table. | |||
// | |||
//The EACH loop will run through all of the described steps before | |||
//starting with the next returned result. Doing this will build a table | |||
//of our results, row by row. | |||
drugNameFull = val.fulltext; | |||
drugNameShort = drugNameFull.split("#")[0]; | |||
pillImprint = val.printouts["Pill Imprint"]; | |||
pillDosage = val.printouts["Pill Dosage"]; | |||
pillIngred = val.printouts["Pill Ingred"]; | |||
pillColor = val.printouts["Pill Color"]; | |||
pillShape = val.printouts["Pill Shape"]; | |||
pillSize = val.printouts["Pill Size (mm)"]; | |||
pillScoring = val.printouts["Pill Scoring"]; | |||
ndc = val.printouts["NDC"]; | |||
pillName = String(val.printouts["Pill Name"][0]).split(' ').join('_'); | |||
///////////////////////////////////////////////////////////////////////// | |||
////// Generate the URL to the image. ////// | |||
///////////////////////////////////////////////////////////////////////// | |||
// | |||
//When a picture is uploaded, the server will place the file in a | |||
//directory. This directory is based upon the MD5 hashed name of file. A | |||
//file named "Example.jpg" will have an MD5 hashed name of: | |||
// "a91fe217e45a700fc2dab0cc476f01c7." | |||
//The file would then be located at the following URl: | |||
// "http://static.wikidoc.org/a/a9/Example.jpg" | |||
//To generate the URL, we use the MD5 method provided in the CryptoJS lib | |||
//This means http://www.wikidoc.org/includes/raty/md5.js must be loaded | |||
//First we create the MD5 hash of the pill name | |||
md5 = String(CryptoJS.MD5(pillName)); | |||
//Next we build the directory name using the first two characters | |||
imageDirect = 'http://static.wikidoc.org/' + md5.charAt(0) + '/' + md5.substring(0,2) + '/' + pillName; | |||
///////////////////////////////////////////////////////////////////////// | |||
////// Create the Drug Name Hyperlink ////// | |||
///////////////////////////////////////////////////////////////////////// | |||
//Turn the spaces into underscores | |||
linkName = String(drugNameShort).split(' ').join('_'); | |||
//String together appropiate text to create the link | |||
drugNameLink = 'http://www.wikidoc.org/index.php/'+linkName; | |||
///////////////////////////////////////////////////////////////////////// | |||
////// Add each iteration of query results to the Results Table ////// | |||
///////////////////////////////////////////////////////////////////////// | |||
// | |||
//Adding the results parameters works in the following way. | |||
// The location of a specific table within the document is assigned to | |||
// the variable "table" | |||
// | |||
// A row is added the to table at the index location (ind being the | |||
// index of the .each() loop. | |||
// | |||
var pillContainer ='<div class="pillResult">' + | |||
'<a href="'+drugNameLink+'">' + | |||
'<img src="'+imageDirect+'" alt"'+drugNameShort+'">' + | |||
'</a>' + | |||
' <div class="pillResult-text">' + | |||
'<h1><a href="'+drugNameLink+'">'+drugNameShort+'</a></h1>' + | |||
'<h2>'+pillDosage+' (' + pillImprint + ')</h2>' + | |||
'<p>'+pillShape+', '+pillColor+', '+pillSize+' mm, Scored ' + pillScoring +', NDC: '+ndc+'</p>'+ | |||
'<p>'+pillIngred+'</p>' + | |||
'</div>' + | |||
'</div>'; | |||
//Add Values to the cells: | |||
$("#resultsTable-container").append(pillContainer); | |||
}); | |||
} else { | |||
$("#resultsTable-container").append('<div style="margin:auto"><span style="font-size:36px;">No Results Found. Please Check Back Later.</span></div>'); | |||
} | |||
} | |||
}); | }); | ||
$('#resultsTable-container').css("visibility", "visible"); | $('#resultsTable-container').css("visibility", "visible"); | ||
} | |||
} | |||
function updatePillSizeImages() { | function updatePillSizeImages() { | ||
Line 292: | Line 314: | ||
$("#"+selectedProperty).val(selectedValue); | $("#"+selectedProperty).val(selectedValue); | ||
} | } | ||
function nav(){ | function nav(){ | ||
Line 303: | Line 324: | ||
["#queryContainer_Shape", "#queryContainer_Scoring"], | ["#queryContainer_Shape", "#queryContainer_Scoring"], | ||
["#queryContainer_Color", "#queryContainer_Size"], | ["#queryContainer_Color", "#queryContainer_Size"], | ||
["#queryContainer_Scoring","#misc"] | ["#queryContainer_Scoring","#misc"], | ||
["#queryContainer_Size", ""] | ["#queryContainer_Size", ""] | ||
]; | ]; | ||
Line 319: | Line 340: | ||
var newActiveDiv = positionArr[position][dirIndex]; | var newActiveDiv = positionArr[position][dirIndex]; | ||
$(".propertyContainerActive").attr("class", "propertyContainerInactive"); | $(".propertyContainerActive").attr("class", "propertyContainerInactive"); | ||
$(newActiveDiv).attr("class", "propertyContainerActive"); | $(newActiveDiv).attr("class", "propertyContainerActive"); | ||
var nextPosition = $(newActiveDiv).data()["order"]; | var nextPosition = $(newActiveDiv).data()["order"]; | ||
if (positionArr[nextPosition][0] | if (positionArr[nextPosition][0] == ""){ | ||
$("#back").css("visibility"," | $("#back").css("visibility","hidden"); | ||
} | } | ||
else | else | ||
{ | { | ||
$("#back").css("visibility"," | $("#back").css("visibility","visible"); | ||
} | } | ||
if (positionArr[nextPosition][1] | if (positionArr[nextPosition][1] == ""){ | ||
$("#next").css("visibility"," | $("#next").css("visibility","hidden"); | ||
} | } | ||
else | else | ||
{ | { | ||
$("#next").css("visibility"," | $("#next").css("visibility","visible"); | ||
} | } | ||
}; | }; | ||
function countProperties (obj) { | |||
var count = 0; | |||
for (var property in obj) { | |||
if (Object.prototype.hasOwnProperty.call(obj, property)) { | |||
count++; | |||
} | |||
} | |||
return count; | |||
} | |||
</script> | </script> | ||
<style type="text/css"> | <style type="text/css"> | ||
Line 402: | Line 433: | ||
width: 100px; | width: 100px; | ||
margin: 50px; | margin: 50px; | ||
cursor:pointer; | |||
} | } | ||
.pillColorOption { | .pillColorOption { | ||
Line 408: | Line 440: | ||
width: 100px; | width: 100px; | ||
margin: 50px; | margin: 50px; | ||
cursor:pointer; | |||
} | } | ||
.pillScoreOption { | .pillScoreOption { | ||
Line 414: | Line 447: | ||
width: 100px; | width: 100px; | ||
margin: 50px; | margin: 50px; | ||
cursor:pointer; | |||
} | } | ||
Line 484: | Line 518: | ||
} | } | ||
. | #pillIDNav div{ | ||
display:inline-block; | |||
cursor:pointer; | |||
} | |||
#formConatiner div{ | |||
display:inline-block; | |||
padding:5px; | |||
} | |||
#formContainer{ | |||
background:#6e6e6e; | |||
width: 60%; | |||
margin: auto; | |||
margin-top: 15px; | |||
padding: 15px; | |||
border-radius: 20px; | |||
color:white; | |||
} | |||
#formContainer h2{ | |||
margin-top: 0; | |||
color: white; | |||
text-shadow: 1px 1px 1px #000; | |||
} | |||
.pillResult{ | |||
display:table-row; | |||
} | |||
.pillResult img{ | |||
width:150px; | |||
height:auto; | |||
display:table-cell; | |||
vertical-align: middle; | |||
border-radius:50%; | |||
margin:10px; | |||
} | |||
.pillResult-text{ | |||
display:table-cell; | |||
vertical-align:top; | |||
padding-left:5px; | |||
} | |||
.pillResult-text h1{ | |||
margin:0px; | |||
font-size:24px; | |||
} | |||
.pillResult-text h2{ | |||
margin:0px; | |||
font-size:18px; | |||
} | |||
.pillResult-text p{ | |||
margin:0px; | |||
font-size:16px; | |||
} | } | ||
</style> | </style> | ||
Line 493: | Line 584: | ||
<div id="pillIdentiferTitle"> | <div id="pillIdentiferTitle"> | ||
<span>Pill Identifier</span> | <span>Pill Identifier</span> | ||
</div> | |||
<div id="formContainer"> | |||
<h2>Selected Properties</h2> | |||
<form id="selectedProperties" action="" method="get"> | |||
<div id="selectedShape-container" class="ui-button"> | |||
<span>Shape:</span><input readonly type="text" name="selectedShape" id="selectedShape" size="10" value=""> | |||
</div> | |||
<div id="selectedColor-container" class="ui-button"> | |||
<span>Color:</span><input readonly type="text" name="selectedColor" id="selectedColor" size="10" value=""> | |||
</div> | |||
<div id="selectedScoring-container" class="ui-button"> | |||
<span>Scoring:</span><input readonly type="text" name="selectedScoring" id="selectedScoring" size="5" value=""> | |||
</div> | |||
<div class="ui-button" id="selectedMinSize-container"> | |||
<span>Size:</span><input readonly type="text" name="selectedMinSize" size="3" id="selectedMinSize" value="5"><span> to </span><input readonly type="text" name="selectedMaxSize" size="3" id="selectedMaxSize" value="20"> | |||
</div><br> | |||
<div class="ui-button" id="selectedImprint-container"> | |||
<span>Imprint:</span><input readonly type="text" name="selectedImprint" id="selectedImprint" value=""> | |||
</div> | |||
<div class="ui-button" id="selectedNDC-container"> | |||
<span>NDC:</span><input readonly type="text" name="selectedNDC" id="selectedNDC" value=""> | |||
</div> | |||
<div class="ui-button" id="selectedIngred-container"> | |||
<span>Ingredients:</span><input readonly type="text" name="selectedIngred" id="selectedIngred" value=""> | |||
</div> | |||
</form> | |||
</div> | |||
<div id="queryContainer"> | <div id="queryContainer"> | ||
<div id="queryContainer_Shape" class="propertyContainerActive" data-order="1"> | <div id="queryContainer_Shape" class="propertyContainerActive" data-order="1"> | ||
Line 606: | Line 723: | ||
</div> | </div> | ||
</div> | </div> | ||
<div id="pillIDNav"> | <div id="pillIDNav"> | ||
<div id="reset"> | |||
<img src="http://static.wikidoc.org/a/a9/Pid_resetbutton.png" alt="reset"> | |||
</div> | |||
<div id="back" class="navTool" data-direction="back" style="visibility:hidden"> | <div id="back" class="navTool" data-direction="back" style="visibility:hidden"> | ||
<img src="http://static.wikidoc.org/8/83/Pid_backbutton.png" alt="back"> | <img src="http://static.wikidoc.org/8/83/Pid_backbutton.png" alt="back"> | ||
Line 631: | Line 740: | ||
</div> | </div> | ||
<div id="resultsTable-container" style="visibility:collapse;"> | <div id="resultsTable-container" style="visibility:collapse;"> | ||
</div> | </div> | ||
</includeonly> | </includeonly> |