Widget:PillIdentifier: Difference between revisions

Jump to navigation Jump to search
No edit summary
No edit summary
 
(34 intermediate revisions by the same user not shown)
Line 20: Line 20:
})();
})();
$("#firstHeading").remove();
$("#firstHeading").remove();
$("#searchbox").remove();
$('#submit').click(runQuery);
$('#submit').click(runQuery);
$('.navTool').click(nav);
$('.navTool').click(nav);
$('.pillResult').hover(function(){
        $("#reset").click(resetForm);
$(this).children("a:first").children("img:first").css("border-radius","0%");
 
}, function(){
$(".pillShapeOption").click(function(){
$(this).children("a:first").children("img:first").css("border-radius","50%");
$(".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({
Line 72: Line 85:
$('.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 126: Line 158:
function runQuery() {
function runQuery() {
$('#resultsTable-body').html('');
$('#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                //////
/////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////
//////                  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
//If the .getJSON() function is able to successfully receive information
//have provided.  The data that is returned is in JSON format, meaning  
//from the WikiDoc API, it will begin to execute the unnamed function we
//that we will have lots of objects within objects.  Our function says  
//have provided.  The data that is returned is in JSON format, meaning  
//that for EACH property of data.query.results (that is, each returned  
//that we will have lots of objects within objects.  Our function says  
//result from the query) we should perform the following operations.
//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  
//We will first store all the results as local variables. Some of these
//you see some string() methods. After storing our variables,we
//results will need to be converted to a string, so don't be alarmed if  
//construct a hyperlink and image URL.  Lastly, we add a row to the  
//you see some string() methods. After storing our variables,we
//our results table.
//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
//The EACH loop will run through all of the described steps before
//of our results, row by row.
//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];
drugNameFull = val.fulltext;
pillImprint = val.printouts["Pill Imprint"];
drugNameShort = drugNameFull.split("#")[0];
pillDosage = val.printouts["Pill Dosage"];
pillImprint = val.printouts["Pill Imprint"];
pillIngred = val.printouts["Pill Ingred"];
pillDosage = val.printouts["Pill Dosage"];
pillColor = val.printouts["Pill Color"];
pillIngred = val.printouts["Pill Ingred"];
pillShape = val.printouts["Pill Shape"];
pillColor = val.printouts["Pill Color"];
pillSize = val.printouts["Pill Size (mm)"];
pillShape = val.printouts["Pill Shape"];
pillScoring = val.printouts["Pill Scoring"];
pillSize = val.printouts["Pill Size (mm)"];
ndc = val.printouts["NDC"];
pillScoring = val.printouts["Pill Scoring"];
pillName = String(val.printouts["Pill Name"][0]).split(' ').join('_');
ndc = val.printouts["NDC"];
/////////////////////////////////////////////////////////////////////////
pillName = String(val.printouts["Pill Name"][0]).split(' ').join('_');
//////                  Generate the URL to the image.            //////
/////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////
//////                  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
//When a picture is uploaded, the server will place the file in a   
//file named "Example.jpg" will have an MD5 hashed name of:
//directory. This directory is based upon the MD5 hashed name of file. A
// "a91fe217e45a700fc2dab0cc476f01c7."   
//file named "Example.jpg" will have an MD5 hashed name of:
//The file would then be located at the following URl:
// "a91fe217e45a700fc2dab0cc476f01c7."   
// "http://static.wikidoc.org/a/a9/Example.jpg"
//The file would then be located at the following URl:
//To generate the URL, we use the MD5 method provided in the CryptoJS lib
// "http://static.wikidoc.org/a/a9/Example.jpg"
//This means http://www.wikidoc.org/includes/raty/md5.js must be loaded
//To generate the URL, we use the MD5 method provided in the CryptoJS lib
//First we create the MD5 hash of the pill name
//This means http://www.wikidoc.org/includes/raty/md5.js must be loaded
md5 = String(CryptoJS.MD5(pillName));
//First we create the MD5 hash of the pill name
//Next we build the directory name using the first two characters  
md5 = String(CryptoJS.MD5(pillName));
imageDirect = 'http://static.wikidoc.org/' + md5.charAt(0) + '/' + md5.substring(0,2) + '/' + 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              //////
/////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////
//////                Create the Drug Name Hyperlink              //////
//Turn the spaces into underscores
/////////////////////////////////////////////////////////////////////////
linkName = String(drugNameShort).split(' ').join('_')
//Turn the spaces into underscores
//String together appropiate text to create the link
linkName = String(drugNameShort).split(' ').join('_');
drugNameLink = 'http://www.wikidoc.org/index.php/'+linkName
//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  //////
/////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////
//////  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
//Adding the results parameters works in the following way.
//  the variable "table"
//  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.   
//  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+'">' +
var pillContainer ='<div class="pillResult">' +
'<img src="'+imageDirect+'" alt"'+drugNameShort+'">' +
'<a href="'+drugNameLink+'">' +
'</a>' +
'<img src="'+imageDirect+'" alt"'+drugNameShort+'">' +
' <div class="pillResult-text">' +
'</a>' +
'<h1><a href="'+drugNameLink+'">'+drugNameShort+'</a></h1>' +
' <div class="pillResult-text">' +
'<h2>'+pillDosage+'</h2>' +
'<h1><a href="'+drugNameLink+'">'+drugNameShort+'</a></h1>' +
'<p>'+pillShape+', '+pillColor+', '+pillSize+' mm, NDC'+ndc+'</p>'+
'<h2>'+pillDosage+' (' + pillImprint + ')</h2>' +
'<p>'+pillIngred+'</p>' +
'<p>'+pillShape+', '+pillColor+', '+pillSize+' mm, Scored ' + pillScoring +', NDC: '+ndc+'</p>'+
'</div>' +
'<p>'+pillIngred+'</p>' +
'</div>';
'</div>' +
'</div>';
//Add Values to the cells:
$("#resultsTable-container").append(pillContainer);
//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 277: Line 314:
$("#"+selectedProperty).val(selectedValue);
$("#"+selectedProperty).val(selectedValue);
}
}
function nav(){
function nav(){
Line 325: Line 361:
}
}
};
};
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 385: Line 433:
width: 100px;
width: 100px;
margin: 50px;
margin: 50px;
cursor:pointer;
}
}
.pillColorOption {
.pillColorOption {
Line 391: Line 440:
width: 100px;
width: 100px;
margin: 50px;
margin: 50px;
cursor:pointer;
}
}
.pillScoreOption {
.pillScoreOption {
Line 397: Line 447:
width: 100px;
width: 100px;
margin: 50px;
margin: 50px;
cursor:pointer;
}
}
Line 468: Line 519:
#pillIDNav div{
#pillIDNav div{
display:inline-block;
display:inline-block;
cursor:pointer;
}
}


#formConatiner div{
#formConatiner div{
display:inline-block;
display:inline-block;
padding:5px;
}
}
#formContainer{
#formContainer{
background:#6e6e6e;
background:#6e6e6e;
border:50%;
    width: 60%;
margin:auto;
    margin: auto;
    margin-top: 15px;
    padding: 15px;
    border-radius: 20px;
    color:white;
}
}
.pillResult{
 
display:table-row;
    #formContainer h2{
    margin-top: 0;
    color: white;
    text-shadow: 1px 1px 1px #000;
    }
 
.pillResult{
display:table-row;
}
}
.pillResult img{
.pillResult img{
width:150px;
width:150px;
Line 489: Line 554:
vertical-align: middle;
vertical-align: middle;
border-radius:50%;
border-radius:50%;
margin:10px;
}
}
.pillResult-text{
.pillResult-text{
Line 510: Line 576:
font-size:16px;
font-size:16px;
}
}


</style>
</style>
Line 518: Line 586:
</div>
</div>
         <div id="formContainer">
         <div id="formContainer">
            <h2>Selected Properties</h2>
             <form id="selectedProperties" action="" method="get">
             <form id="selectedProperties" action="" method="get">
             <div id="selectedShape-container" class="ui-button">
             <div id="selectedShape-container" class="ui-button">
                 <span>Shape:</span><input readonly type="text" name="selectedShape" id="selectedShape" value="">
                 <span>Shape:</span><input readonly type="text" name="selectedShape" id="selectedShape" size="10" value="">
             </div>
             </div>
             <div id="selectedColor-container" class="ui-button">
             <div id="selectedColor-container" class="ui-button">
                 <span>Color:</span><input readonly type="text" name="selectedColor" id="selectedColor" value="">
                 <span>Color:</span><input readonly type="text" name="selectedColor" id="selectedColor" size="10" value="">
             </div>
             </div>
             <div id="selectedScoring-container" class="ui-button">
             <div id="selectedScoring-container" class="ui-button">
                 <span>Scoring:</span><input readonly type="text" name="selectedScoring" id="selectedScoring" value="">
                 <span>Scoring:</span><input readonly type="text" name="selectedScoring" id="selectedScoring" size="5" value="">
             </div>           
             </div>           
             <div class="ui-button" id="selectedMinSize-container">
             <div class="ui-button" id="selectedMinSize-container">
Line 656: Line 725:


     <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">

Latest revision as of 02:37, 3 August 2015