Changeset 2144


Ignore:
Timestamp:
Nov 19, 2013, 10:13:28 AM (10 years ago)
Author:
olle
Message:

Refs #534. Case summary updated to use an input personal number instead of a case name, provided the user has sufficient permissions to do so:

  1. Java servlet CaseSummaryServlet.java in reggie/src/net/sf/basedb/reggie/servlet/ updates:
    a. Protected method void doGet(HttpServletRequest req, HttpServletResponse resp) should be updated for command "GetCaseInfo" to call new private method boolean caseNameIsValid(String caseName, boolean allowSuffix) to check if the input string is a valid case name, and if not, perform a search for a patient record with the input string used as a potential personal number. If a patient record is found, a new search is performed to find a case for the patient. If more than one case are found, the first found case is used. If a case name is found from an input personal number, case and patient data that has already been found, should not be obtained again from the case name, in order to speed up the database search.
    b. New private method boolean caseNameIsValid(String caseName, boolean allowSuffix) added. It checks if the input string is a 7-digit value + optional 'C' suffix.

  2. JSP script case_summary.jsp in reggie/resources/reports/ updates:
    a. Variable caseName is made a global variable, in order for its value to be accessible for the print dialog header line, in case a personal number is used as input.
    b. Function init() should be updated to used the case name returned from the servlet request, as the former may have been found from an input personal number. Header texts for main web page and pop-up window should be updated to use the potentially changed case name.
    c. Function goPrint() should update the header text in the print dialog to use the potentially changed case name.

  3. Java data access object Case.java in reggie/src/net/sf/basedb/reggie/dao/ updated in JavaDoc comment for public static method List<Case> findByPatient(DbControl dc, Patient patient) to note that the returned list is sorted in ascending order after case name.


Location:
extensions/net.sf.basedb.reggie/trunk
Files:
3 edited

Legend:

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

    r2134 r2144  
    7474var debug = false;
    7575var ID = '<%=ID%>';
     76var caseName= '';
    7677
    7778var TRUNCATE_SIZE = [-1, 30, 20, 15];
     
    296297  if (frm.caseName) frm.caseName.focus();
    297298 
    298   var caseName = '<%=HTML.javaScriptEncode(caseName)%>';
     299  caseName = '<%=HTML.javaScriptEncode(caseName)%>';
    299300  var isAdmin = <%=isAdmin ? "true" : "false"%>;
    300301  var isPatientCurator = <%=isPatientCurator ? "true" : "false"%>;
     
    303304  url += '&caseName=<%=HTML.urlEncode(caseName)%>';
    304305  var request = Ajax.getXmlHttpRequest();
    305   request.open("GET", url, false); 
     306  request.open("GET", url, false);
    306307  request.send(null);
    307308 
     
    324325  if (caseInfo)
    325326  {
     327    // Use returned case name, as it may have been found from personal number
     328    caseName = caseInfo.name;
     329    // Update header text to use the potentially changed case name
     330    if (document.getElementById('path-case-summary') != null)
     331    {
     332      document.getElementById('path-case-summary').innerHTML = 'Case summary - ' + escape(caseName);
     333    }
     334    if (document.getElementById('path-case-summary-popup') != null)
     335    {
     336      document.getElementById('path-case-summary-popup').innerHTML = 'Case summary - ' + escape(caseName);
     337    }
    326338    consentOk = !caseInfo.consent || caseInfo.consent == 'Yes';
    327339    addColumn('case.name', makeLink('SAMPLE', caseInfo));
     
    802814  var printNote = '<b>Note!</b> For better printing set page orientation to <i>portrait</i>.<br>';
    803815  printNote += ' You may have to <i>scale down</i> to fit everything on the width of the page.';
    804   openPrintWindow('<%=ID%>', 'all-content', 'Case summary - <%=HTML.encodeTags(caseName)%>', 'portrait', printNote, '../', 'case_summary.css');
     816  openPrintWindow('<%=ID%>', 'all-content', 'Case summary - ' + escape(caseName), 'portrait', printNote, '../', 'case_summary.css');
    805817}
    806818
     
    873885  {
    874886    %>
    875     <h1>Case summary - <%= HTML.encodeTags(caseName)%></h1>
     887    <h1  id="path-case-summary-popup">Case summary - <%= HTML.encodeTags(caseName)%></h1>
    876888    <%
    877889  }
  • extensions/net.sf.basedb.reggie/trunk/src/net/sf/basedb/reggie/dao/Case.java

    r1907 r2144  
    102102  /**
    103103    Find all cases linked with a patient. A patient can have 0, 1 or 2
    104     cases. If more than two are found an exception is thrown.
     104    cases. If more than two are found an exception is thrown.
     105    The cases are sorted in ascending order after case name.
    105106  */
    106107  public static List<Case> findByPatient(DbControl dc, Patient patient)
  • extensions/net.sf.basedb.reggie/trunk/src/net/sf/basedb/reggie/servlet/CaseSummaryServlet.java

    r2134 r2144  
    55import java.util.List;
    66import java.util.Set;
     7import java.util.regex.Matcher;
     8import java.util.regex.Pattern;
    79
    810import javax.servlet.ServletException;
     
    2628import net.sf.basedb.core.MeasuredBioMaterial;
    2729import net.sf.basedb.core.Permission;
     30import net.sf.basedb.core.PermissionDeniedException;
    2831import net.sf.basedb.core.Sample;
    2932import net.sf.basedb.core.SessionControl;
     
    9093       
    9194        String caseName = req.getParameter("caseName");
     95        // Check if input 'caseName' is valid, or is personal number
     96        boolean validCaseName = caseNameIsValid(caseName, true);
     97        Patient patient = null;
     98        Case theCase = null;
     99        List<Case> caseList = null;
     100        if (!validCaseName)
     101        {
     102          // Input 'caseName' may be personal number
     103          String potentialPnr = caseName;
     104          // Find cases by personal number if user has permission to do so
     105          try
     106          {
     107            patient = Patient.findByPersonalNumber(dc, potentialPnr);
     108          }
     109          catch (PermissionDeniedException e)
     110          {}
     111          if (patient != null)
     112          {
     113            caseList = Case.findByPatient(dc, patient);
     114            if (caseList != null && caseList.size() > 0)
     115            {
     116              // Use lowest case name (a patient can have at most 2 cases)
     117              theCase = (Case) caseList.get(0);
     118            }
     119            if (theCase != null)
     120            {
     121              // Use case name found from personal number
     122              caseName = theCase.getName();
     123            }
     124          }
     125        }
     126       
    92127        JSONArray jsonSections = new JSONArray();
    93128        json.put("sections", jsonSections);
     
    101136       
    102137        // Load case (null if not found) and patient
    103         Case theCase = Case.findByName(dc, caseName);
    104         Patient patient = null;
     138        if (theCase == null)
     139        {
     140          theCase = Case.findByName(dc, caseName);
     141        }
    105142        if (theCase != null)
    106143        {
     
    108145          jsonSections.add(loadSectionInfo(sc, "case"));
    109146          json.put("caseInfo", theCase.asJSONObject());
    110           patient = Patient.findByCase(dc, theCase);
     147          if (patient == null)
     148          {
     149            patient = Patient.findByCase(dc, theCase);
     150          }
    111151        }
    112152
     
    346386      json.writeJSONString(resp.getWriter());
    347387    }
     388  }
     389
     390  /*
     391    Verify that the 'case' name is a 7-digit value + optional 'C' suffix.
     392   
     393    @param caseName String Input case name to check.
     394    @param allowSuffix boolean Flag indicating if optional 'C' suffix is allowed.
     395    @return boolean True if potential case name (not necessarily in database), false otherwise.
     396   */
     397  private boolean caseNameIsValid(String caseName, boolean allowSuffix)
     398  {
     399    boolean isValid = false;
     400    if (caseName != null)
     401    {
     402      String regex = allowSuffix ? "^\\d{7}C?$" : "^\\d{7}$";
     403      Pattern pattern = Pattern.compile(regex);
     404      Matcher matcher = pattern.matcher(caseName);
     405      isValid = matcher.matches();
     406    }
     407    return isValid;
    348408  }
    349409
Note: See TracChangeset for help on using the changeset viewer.