Ignore:
Timestamp:
Mar 21, 2011, 2:37:55 PM (11 years ago)
Author:
Nicklas Nordborg
Message:

Fixes #300: Allow non-standard personal numbers

This should now handle the 3 cases mentioned in comment 3.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • extensions/net.sf.basedb.reggie/trunk/resources/persinfo.jsp

    r1318 r1319  
    2828var currentStep = 1;
    2929var pnrIsValid = false;
     30var pnrIsAcceptable = false;
    3031var caseIsValid = false;
    3132var lateralityIsValid = false;
     
    4344{
    4445  return pnrIsValid && caseIsValid;
     46}
     47
     48function step1IsAcceptable()
     49{
     50  return pnrIsAcceptable && caseIsValid;
    4551}
    4652
     
    95101}
    96102
    97 function goNext()
    98 {
     103function goNext(manual)
     104{
     105  setInnerHTML('gonext.message', '');
    99106  if (currentStep == 1)
    100107  {
    101     if (step1IsValid()) gotoStep2();
     108    if (step1IsValid())
     109    {
     110      gotoStep2();
     111    }
     112    else if (step1IsAcceptable())
     113    {
     114      if (manual)
     115      {
     116        gotoStep2();
     117      }
     118      else
     119      {
     120        setInnerHTML('gonext.message', 'Personal number is non-standard. Click \'Next\' to continue registration.');
     121      }
     122    }
    102123  }
    103124  else if (currentStep == 2)
     
    125146  var pnr = frm.personalNumber.value;
    126147  pnrIsValid = false;
     148  pnrIsAcceptable = true;
    127149 
    128150  if (pnr.length < 12)
    129151  {
    130     setInputStatus('pnr', 'Too short', 'invalid');
     152    setInputStatus('pnr', 'Too short', 'warning');
    131153    return;
    132154  }
    133  
    134   if (!Dates.isDate(pnr.substring(0, 8), 'yyyyMMdd'))
    135   {
    136     setInputStatus('pnr', 'Not a valid date', 'invalid');
     155
     156  if (!pnr.match(/^\d+$/))
     157  {
     158    setInputStatus('pnr', 'Non-standard personal number', 'warning');
     159    return;
     160  }
     161 
     162  var isValidDate = Dates.isDate(pnr.substring(0, 8), 'yyyyMMdd');
     163  if (!isValidDate)
     164  {
     165    var dayInMonth = parseInt(pnr.substring(6, 8));
     166    if (dayInMonth > 60)
     167    {
     168      // 'Samordningsnummer' has day-in-month + 60; check this
     169      dayInMonth -= 60;
     170      var tmpPnr = pnr.substring(0, 6);
     171      if (dayInMonth < 10) tmpPnr += '0';
     172      tmpPnr += dayInMonth;
     173      isValidDate = Dates.isDate(tmpPnr, 'yyyyMMdd');
     174    }
     175  }
     176  if (!isValidDate)
     177  {
     178    setInputStatus('pnr', 'Not a valid date', 'warning');
    137179    return;
    138180  }
     
    140182  var sum = 0;
    141183  var factor = 2;
    142   var x = '';
     184  //var x = '';
    143185  for (var i = 2; i < 11; i++)
    144186  {
    145187    var digit = parseInt(pnr.substr(i, 1));
    146188    var tmp = factor * digit;
    147     x += '(' + factor + '*' + digit+')';
     189    //x += '(' + factor + '*' + digit+')';
    148190    sum += tmp >= 10 ? tmp - 9: tmp;
    149191    factor = factor == 2 ? 1 : 2;
    150192  }
     193  //alert(x + "; sum="+sum);
    151194 
    152195  var control = 10 - (sum % 10);
     
    154197  if (control != parseInt(pnr.substr(11, 1)))
    155198  {
    156     setInputStatus('pnr', 'Invalid control digit', 'invalid');
     199    setInputStatus('pnr', 'Invalid control digit', 'warning');
    157200    return;
    158201  }
     
    264307  var url = 'PersonalRegistration.servlet?ID=<%=ID%>&cmd=CheckPersonalNumberAndCaseName';
    265308  url += '&personalNumber=' + pnr;
     309  url += '&pnrIsValid=' + pnrIsValid;
    266310  url += '&caseName=' + caseName;
    267311  request.open("GET", url, false);
     
    287331    Main.show('newPatientSection');
    288332    frm.patientCode.value=patientInfo.name;
    289     setInnerHTML('new.dateOfBirth', patientInfo.dateOfBirth);
    290     setInnerHTML('new.gender', patientInfo.gender);
     333    setInnerHTML('new.dateOfBirth', patientInfo.dateOfBirth ? patientInfo.dateOfBirth : "---");
     334    setInnerHTML('new.gender', patientInfo.gender ? patientInfo.gender : "---");
    291335    frm.familyName.focus();
     336    if (!pnrIsValid)
     337    {
     338      setInputStatus('gender', 'Gender and DateOfBirth can\'t be automatically generated for non-standard Personal number', 'warning');
     339    }
    292340  }
    293341  else
     
    297345    setInnerHTML('existing.familyName', patientInfo.familyName);
    298346    setInnerHTML('existing.allFirstNames', patientInfo.allFirstNames);
    299     setInnerHTML('existing.dateOfBirth', patientInfo.dateOfBirth);
    300     setInnerHTML('existing.gender', patientInfo.gender);
     347    if (patientInfo.dateOfBirth) setInnerHTML('existing.dateOfBirth', patientInfo.dateOfBirth);
     348    if (patientInfo.gender) setInnerHTML('existing.gender', patientInfo.gender);
    301349    gotoStep3();
    302350  }
     
    605653}
    606654
    607 .stepfields .message
     655.stepfields .message, .navigation .message
    608656{
    609657  color: #cc0000;
     
    716764        <td class="prompt">Gender</td>
    717765        <td class="input" id="new.gender"></td>
    718         <td class="status"></td>
    719         <td class="help"></td>
     766        <td class="status" id="gender.status" rowspan="2"></td>
     767        <td class="help" rowspan="2"><span id="gender.message" class="message" style="display:none;"></span></td>
    720768      </tr>
    721769      <tr>
    722770        <td class="prompt">Date of birth</td>
    723771        <td class="input" id="new.dateOfBirth"></td>
    724         <td class="status"></td>
    725         <td class="help"></td>
    726772      </tr>
    727773      </table>
     
    831877  <div id="done" class="success" style="display: none; width: 800px; margin-left: 20px; margin-top: 20px;"></div>
    832878
    833   <table style="margin-left: 20px; margin-top: 10px;">
     879  <table style="margin-left: 20px; margin-top: 10px;" class="navigation">
    834880  <tr>
    835881    <td><base:button id="gocancel" title="Cancel" onclick="goRestart(false)" style="display: none;"/></td>
    836     <td><base:button id="gonext" title="Next" image="gonext.gif" onclick="goNext()"/></td>
     882    <td><base:button id="gonext" title="Next" image="gonext.gif" onclick="goNext(true)"/></td>
    837883    <td><base:button id="gocreate" title="Create" image="gonext.gif" onclick="goCreate()" style="display: none;"/></td>
    838884    <td><base:button id="gorestart" title="Restart" image="goback.gif" onclick="goRestart(true)" style="display: none;"/></td>
     885    <td id="gonext.message" class="message"></td>
    839886  </tr>
    840887  </table>
Note: See TracChangeset for help on using the changeset viewer.