Widget:PillIdentifier: Difference between revisions

Jump to navigation Jump to search
No edit summary
No edit summary
 
(19 intermediate revisions by the same user not shown)
Line 24: Line 24:
$('.navTool').click(nav);
$('.navTool').click(nav);
         $("#reset").click(resetForm);
         $("#reset").click(resetForm);
$(".pillShapeOption").click(function(){
$(".pillShapeOption").click(function(){
$(".pillShapeOption").children("img").css("border","");
$(".pillShapeOption").children("img").css("border","");
Line 161: Line 162:
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) {
console.log(data.query.results);
if(countProperties(data.query.results) > 0){
$.each(data.query.results, function(ind, val) {
$.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
//If the .getJSON() function is able to successfully receive information
//from the WikiDoc API, it will begin to execute the unnamed function we
//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  
//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 we will have lots of objects within objects.  Our function says  
//that for EACH property of data.query.results (that is, each returned  
//that for EACH property of data.query.results (that is, each returned  
//result from the query) we should perform the following operations.
//result from the query) we should perform the following operations.
//
//
//We will first store all the results as local variables. Some of these
//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  
//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
//you see some string() methods. After storing our variables,we
//construct a hyperlink and image URL.  Lastly, we add a row to the  
//construct a hyperlink and image URL.  Lastly, we add a row to the  
//our results table.
//our results table.
//
//
//The EACH loop will run through all of the described steps before
//The EACH loop will run through all of the described steps before
//starting with the next returned result.  Doing this will build a table
//starting with the next returned result.  Doing this will build a table
//of our results, row by row.
//of our results, row by row.
drugNameFull = val.fulltext;
drugNameFull = val.fulltext;
drugNameShort = drugNameFull.split("#")[0];
drugNameShort = drugNameFull.split("#")[0];
pillImprint = val.printouts["Pill Imprint"];
pillImprint = val.printouts["Pill Imprint"];
pillDosage = val.printouts["Pill Dosage"];
pillDosage = val.printouts["Pill Dosage"];
pillIngred = val.printouts["Pill Ingred"];
pillIngred = val.printouts["Pill Ingred"];
pillColor = val.printouts["Pill Color"];
pillColor = val.printouts["Pill Color"];
pillShape = val.printouts["Pill Shape"];
pillShape = val.printouts["Pill Shape"];
pillSize = val.printouts["Pill Size (mm)"];
pillSize = val.printouts["Pill Size (mm)"];
pillScoring = val.printouts["Pill Scoring"];
pillScoring = val.printouts["Pill Scoring"];
ndc = val.printouts["NDC"];
ndc = val.printouts["NDC"];
pillName = String(val.printouts["Pill Name"][0]).split(' ').join('_');
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   
//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
//directory. This directory is based upon the MD5 hashed name of file. A
//file named "Example.jpg" will have an MD5 hashed name of:
//file named "Example.jpg" will have an MD5 hashed name of:
// "a91fe217e45a700fc2dab0cc476f01c7."   
// "a91fe217e45a700fc2dab0cc476f01c7."   
//The file would then be located at the following URl:
//The file would then be located at the following URl:
// "http://static.wikidoc.org/a/a9/Example.jpg"
// "http://static.wikidoc.org/a/a9/Example.jpg"
//To generate the URL, we use the MD5 method provided in the CryptoJS lib
//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
//This means http://www.wikidoc.org/includes/raty/md5.js must be loaded
//First we create the MD5 hash of the pill name
//First we create the MD5 hash of the pill name
md5 = String(CryptoJS.MD5(pillName));
md5 = String(CryptoJS.MD5(pillName));
//Next we build the directory name using the first two characters  
//Next we build the directory name using the first two characters  
imageDirect = 'http://static.wikidoc.org/' + md5.charAt(0) + '/' + md5.substring(0,2) + '/' + pillName
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
//Turn the spaces into underscores
linkName = String(drugNameShort).split(' ').join('_')
linkName = String(drugNameShort).split(' ').join('_');
//String together appropiate text to create the link
//String together appropiate text to create the link
drugNameLink = 'http://www.wikidoc.org/index.php/'+linkName
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.
//Adding the results parameters works in the following way.
//  The location of a specific table within the document is assigned to
//  The location of a specific table within the document is assigned to
//  the variable "table"
//  the variable "table"
//  
//  
//  A row is added the to table at the index location (ind being the
//  A row is added the to table at the index location (ind being the
//  index of the .each() loop.   
//  index of the .each() loop.   
//
//
var pillContainer ='<div class="pillResult">' +
var pillContainer ='<div class="pillResult">' +
            '<a href="'+drugNameLink+'">' +
'<a href="'+drugNameLink+'">' +
'<img src="'+imageDirect+'" alt"'+drugNameShort+'">' +
'<img src="'+imageDirect+'" alt"'+drugNameShort+'">' +
'</a>' +
'</a>' +
' <div class="pillResult-text">' +
' <div class="pillResult-text">' +
'<h1><a href="'+drugNameLink+'">'+drugNameShort+'</a></h1>' +
'<h1><a href="'+drugNameLink+'">'+drugNameShort+'</a></h1>' +
'<h2>'+pillDosage+' (' + pillImprint + ')</h2>' +
'<h2>'+pillDosage+' (' + pillImprint + ')</h2>' +
'<p>'+pillShape+', '+pillColor+', '+pillSize+' mm, Scored ' + pillScoring +', NDC: '+ndc+'</p>'+
'<p>'+pillShape+', '+pillColor+', '+pillSize+' mm, Scored ' + pillScoring +', NDC: '+ndc+'</p>'+
'<p>'+pillIngred+'</p>' +
'<p>'+pillIngred+'</p>' +
'</div>' +
'</div>' +
'</div>';
'</div>';
//Add Values to the cells:
//Add Values to the cells:
$("#resultsTable-container").append(pillContainer);
$("#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 309: Line 314:
$("#"+selectedProperty).val(selectedValue);
$("#"+selectedProperty).val(selectedValue);
}
}
function nav(){
function nav(){
Line 357: 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 417: Line 433:
width: 100px;
width: 100px;
margin: 50px;
margin: 50px;
cursor:pointer;
}
}
.pillColorOption {
.pillColorOption {
Line 423: Line 440:
width: 100px;
width: 100px;
margin: 50px;
margin: 50px;
cursor:pointer;
}
}
.pillScoreOption {
.pillScoreOption {
Line 429: Line 447:
width: 100px;
width: 100px;
margin: 50px;
margin: 50px;
cursor:pointer;
}
}
Line 501: Line 520:
#pillIDNav div{
#pillIDNav div{
display:inline-block;
display:inline-block;
cursor:pointer;
}
}



Latest revision as of 02:37, 3 August 2015