Downloads Documentation Community Contribute Demo






Show Sidebar
Login | Register
Show
Ignore:
Timestamp:
05/21/08 16:28:30 (8 months ago)
Author:
catullus
Message:

Phase 1 of patient validator code (making identifier validation pluggable). See ticekt #296. PatientIdentifierType can now specify an IdentifierValidator that is used to validate identifiers of that type. The old openmrs default check digit validator has been implemented using this methodology as the LuhnIdentifierValidator.

Some functionality has been lost with this commit, namely, auto jumping to patients in patient search no longer works. Additionally, the isValidCheckDigit calculated column will always use LuhnIdentifierValidator as opposed to correctly determining the validator to use.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • openmrs/trunk/web/scripts/dojo/src/widget/openmrs/PatientSearch.js.withjstl

    r4095 r4301  
    5656                        if (patients.length < 1) { 
    5757                                if (this.text && this.text.match(/\d/)) { 
    58                                         if (this.isValidCheckDigit(this.text) == false) { 
    59                                                 //the user didn't input an identifier with a valid check digit 
    60                                                 this.hideHeaderRow(); 
    61                                                 var img = this.getProblemImage(); 
    62                                                 var tmp = " <img src='" + img.src + "' title='" + img.title + "' /> " + this.invalidCheckDigitText + this.text; 
    63                                                 patients.push(tmp); 
    64                                                 patients.push(this.noPatientsFoundText); 
    65                                                 patients.push(this.searchOnPatientNameText); 
    66                                         } 
    67                                         else { 
    68                                                 //the user did input a valid identifier, but we don't have it 
    69                                                 patients.push(this.noPatientsFoundText); 
    70                                                 patients.push(this.searchOnPatientNameText); 
    71                                                 if (this.showAddPatientLink) 
    72                                                         patients.push(this.addPatientLink); 
    73                                         } 
     58                                        patients.push(this.noPatientsFoundText); 
     59                                        patients.push(this.searchOnPatientNameText); 
     60                                        if (this.showAddPatientLink) 
     61                                                patients.push(this.addPatientLink); 
    7462                                } 
    7563                                else { 
     
    8169                        } 
    8270                        // if hits 
    83                         else if (patients.length > 1 || this.isValidCheckDigit(this.text) == false)
     71                        else
    8472                                if (this.showAddPatientLink) 
    8573                                        patients.push(this.addPatientLink);     //setup links for appending to the end 
     
    8775                }, 
    8876                 
    89                 invalidCheckDigitText: "<spring:message javaScriptEscape="true" code="error.checkdigit"/>: ", 
    9077                searchOnPatientNameText: "<spring:message javaScriptEscape="true" code="PatientSearch.searchOnName"/>", 
    9178                noPatientsFoundText: "<spring:message javaScriptEscape="true" code="PatientSearch.noneFound"/> <br/> ", 
     
    10895                                obj.appendChild(document.createTextNode(p.identifier + " ")); 
    10996                                td.appendChild(obj); 
    110                                 if (p.identifierCheckDigit) { 
    111                                         if (this.isValidCheckDigit(p.identifier) == false) { 
    112                                                 td.appendChild(this.getProblemImage()); 
    113                                         } 
    114                                 } 
    11597                                if (p.voided) { 
    11698                                        td.className += " retired"; 
     
    162144                }, 
    163145                 
    164                 getProblemImage: function() { 
    165                         var img = document.createElement("img"); 
    166                         img.src = openmrsContextPath + "/images/problem.gif"; 
    167                         img.title="<spring:message javaScriptEscape="true" code="error.checkdigits.verbose"/>"; 
    168                         return img; 
    169                 }, 
    170                  
    171146                getRowHeight: function() { 
    172147                        return 23; 
     
    205180                        } 
    206181                }, 
    207                  
    208                 isValidCheckDigit: function(value) { 
    209                         if (value == null) return false; 
    210                          
    211                         if (value.length < 3 || value.indexOf('-') != value.length - 2) 
    212                                 return false; 
    213                          
    214                         var checkDigit = value.charAt(value.length - 1).valueOf(); 
    215                          
    216                         var valueWithoutCheckDigit = value.substr(0, value.length - 2); 
    217                          
    218                         return (checkDigit == this.getCheckDigit(valueWithoutCheckDigit)); 
    219                 }, 
    220                  
    221                 getCheckDigit: function(value) { 
    222                  
    223                         // allowable characters within identifier 
    224                         var validChars = "0123456789ABCDEFGHIJKLMNOPQRSTUVYWXZ_"; 
    225                          
    226                         if (this.stripCharsInBag(value, validChars) != "") { 
    227                                 //Invalid character in string 
    228                         } 
    229                          
    230                         // remove whitespace 
    231                         value = value.replace([         ], ""); 
    232                         // convert to uppercase 
    233                         value = value.toUpperCase(); 
    234                          
    235                         // running total 
    236                         var sum = 0; 
    237                          
    238                         //alert("sum: " + sum + " ch: " + ch + " digit: " + digit + " weight: " + weight); 
    239                          
    240                         // loop through digits from right to left 
    241                         for (var i = 0; i < value.length; i++) { 
    242                                 //set ch to "current" character to be processed 
    243                                 var ch = value.charCodeAt(value.length - i - 1); 
    244                                 var digit = ch - 48; 
    245                                 var weight; 
    246                                 if (i % 2 == 0) { 
    247                                         // for alternating digits starting with the rightmost, we use our formula 
    248                                         // this is the same as multiplying x 2 and adding digits together for values 
    249                                         // 0 to 9.  Using the following formula allows us to gracefully calculate a 
    250                                         // weight for non-numeric "digits" as well (from their ASCII value - 48). 
    251                                         weight = (2 * digit) - Math.floor(digit / 5) * 9; 
    252                                 } 
    253                                 else { 
    254                                         // even-positioned digits just contribute their ascii value minus 48 
    255                                         weight = digit; 
    256                                 } 
    257                                 // keep a running total of weights 
    258                                 sum = sum + weight; 
    259                         }        
    260                         // avoid sum less than 10 (if characters below "0" allowed, this could happen) 
    261                         sum = Math.abs(sum) + 10; 
    262                         // check digit is amount needed to reach next number divisible by ten  
    263                         return (10 - (sum % 10)) % 10; 
    264                          
    265                 }, 
    266                  
     182                                 
    267183                stripCharsInBag: function(s, bag){ 
    268184                        var i; 
     
    285201                        //      only allow the first item to be automatically selected if: 
    286202                        //              the entered text is a string or the entered text is a valid identifier 
    287                         return (this.text && (this.text.match(/\d/) == false || this.isValidCheckDigit(this.text))); 
     203                        return (this.text && (this.text.match(/\d/) == false)); 
    288204                } 
    289205