Changeset 1520


Ignore:
Timestamp:
Jan 23, 2012, 4:03:26 PM (11 years ago)
Author:
Nicklas Nordborg
Message:

References #348: Copy consent information to multiple cases

The consent registration wizard can now find other cases and blood samples registered for a patient and display a list of checkboxes which enable/disable consent registration for that case/blood. The drawback is that if not all cases/blood are selected, it is not possible to register a consent later for those with the wizard.

This need to be fixed, but before that I think the code need to be cleaned up a bit. I has become messy and we have similar code in the other wizards for finding case/patient/blood/consent information that I think should collected into a single place.

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

Legend:

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

    r1519 r1520  
    2929<script language="JavaScript">
    3030
    31 var debug = false;
     31var debug = true;
    3232var currentStep = 1;
    3333var caseIsValid = false;
     
    3838var caseInfo = null;
    3939var bloodInfo = null;
     40var patientInfo = null;
    4041
    4142function init()
     
    117118  caseInfo = response.caseInfo;
    118119  bloodInfo = response.bloodInfo;
     120  patientInfo = response.patientInfo;
    119121 
    120122  if (caseInfo.consentDate)
     
    127129  }
    128130  frm.consentDate.focus();
     131 
     132  if (patientInfo)
     133  {
     134    var html = '';
     135    if (patientInfo.allCases)
     136    {
     137      for (var i = 0; i < patientInfo.allCases.length; i++)
     138      {
     139        var c = patientInfo.allCases[i];
     140        html += '<input type="checkbox" name="case.'+c.id+'" id="case.'+c.id+'" checked><label for="'+c.id+'">Case: ' + c.name + '</label><br>';
     141      }
     142    }
    129143   
     144    if (patientInfo.allBlood)
     145    {
     146      for (var i = 0; i < patientInfo.allBlood.length; i++)
     147      {
     148        var c = patientInfo.allBlood[i];
     149        html += '<input type="checkbox" name="blood.'+ c.id + '" id="case.'+c.id+'" checked><label for="'+c.id+'">Blood: ' + c.name + '</label><br>';
     150      }
     151    }
     152   
     153    document.getElementById('moreCases').innerHTML = html;
     154    Main.show('moreCasesSection');
     155  }
     156 
    130157  if (caseInfo.consent || bloodInfo.consent)
    131158  {
     
    213240  }
    214241 
     242  if (patientInfo)
     243  {
     244    if (patientInfo.allCases)
     245    {
     246      var selectedCases = new Array();
     247      for (var i = 0; i < patientInfo.allCases.length; i++)
     248      {
     249        var c = patientInfo.allCases[i];
     250        if (frm['case.'+c.id].checked) selectedCases[selectedCases.length] = c.id;
     251      }
     252      caseInfo.selectedCases = selectedCases;
     253    }
     254   
     255    if (patientInfo.allBlood)
     256    {
     257      var selectedBlood = new Array();
     258      for (var i = 0; i < patientInfo.allBlood.length; i++)
     259      {
     260        var c = patientInfo.allBlood[i];
     261        if (frm['blood.'+c.id].checked) selectedBlood[selectedBlood.length] = c.id;
     262      }
     263      bloodInfo.selectedBlood = selectedBlood;
     264    }
     265  }
     266
    215267  var submitInfo = new Object();
    216268  submitInfo.caseInfo = caseInfo;
    217269  submitInfo.bloodInfo = bloodInfo;
    218 
     270 
    219271  if (debug) Main.debug(JSON.stringify(submitInfo));
    220272  var request = Ajax.getXmlHttpRequest();
     
    380432          <input id="consent.yes" type="radio" name="consent" value="Yes" disabled onchange="consentOnChange()">
    381433            <label id="consent.yes.label" for="consent.yes" class="disabled">Yes</label><br>
     434          <div id="moreCasesSection" style="display: none;">
     435            <table border="0" cellpadding="0" cellspacing="0">
     436            <tr valign="baseline">
     437              <td><img src="../../images/joust/joinbottom.gif"></td>
     438              <td id="moreCases"></td>
     439            </tr>
     440            </table>
     441          </div>
    382442          <input id="consent.notAsked" type="radio" name="consent" value="Not asked" disabled onchange="consentOnChange()">
    383443            <label id="consent.notAsked.label" for="consent.notAsked" class="disabled">Not asked</label>
  • extensions/net.sf.basedb.reggie/trunk/src/net/sf/basedb/reggie/servlet/ConsentFormServlet.java

    r1519 r1520  
    7575        Case theCase = Case.findByName(dc, caseName);
    7676        Blood blood = Blood.findByCaseName(dc, caseName);
     77        Patient patient = null;
    7778       
    7879        List<SpecimenTube> specimenTubes = null;
     
    8889          DateToStringConverter dateConverter = new DateToStringConverter(new SimpleDateFormat("yyyyMMdd"));
    8990          theCase.loadAnnotations(dc, "consentDate", Reggie.ANNOTATION_CONSENT_DATE, dateConverter);
    90          
     91
     92          // Get patient
     93          patient = Patient.findByCase(dc, theCase);
     94
    9195          // Wrap it up into JSON objects
    9296          jsonCase = theCase.asJSONObject();
     
    117121          DateToStringConverter dateConverter = new DateToStringConverter(new SimpleDateFormat("yyyyMMdd"));
    118122          blood.loadAnnotations(dc, "consentDate", Reggie.ANNOTATION_CONSENT_DATE, dateConverter);
    119          
     123
     124          // Get patient
     125          if (patient == null) patient = Patient.findByBlood(dc, blood);
     126
    120127          // Wrap it up into JSON objects
    121128          jsonBlood = blood.asJSONObject();
    122129        }
     130        else
     131        {
     132          jsonBlood = new JSONObject();
     133          jsonBlood.put("name", caseName+".b");
     134        }
    123135       
    124136        json.put("bloodInfo", jsonBlood);
     137       
     138        if (patient != null)
     139        {
     140          JSONObject jsonPatient = patient.asJSONObject();
     141         
     142          // Load all cases for the patient
     143          List<Case> allCases = Case.findByPatient(dc, patient);
     144          JSONArray jsonAll = new JSONArray();
     145          if (allCases.size() > 0)
     146          {
     147            for (Case c : allCases)
     148            {
     149              jsonAll.add(c.asJSONObject());
     150            }
     151          }
     152          jsonPatient.put("allCases", jsonAll);
     153         
     154          // Load all blood for the patient
     155          List<Blood> allBlood = Blood.findByPatient(dc, patient);
     156          jsonAll = new JSONArray();
     157          if (allBlood.size() > 0)
     158          {
     159            for (Blood b : allBlood)
     160            {
     161              jsonAll.add(b.asJSONObject());
     162            }
     163          }
     164          jsonPatient.put("allBlood", jsonAll);
     165          json.put("patientInfo", jsonPatient);
     166        }
    125167
    126168      }
     
    198240            jsonMessages.add("Patient '" + vPat.getName() + "' created.");
    199241          }
     242          Reggie.setAnnotationValue(theCase, consentType, consent);
     243          if (consentDate != null) Reggie.setAnnotationValue(theCase, consentDateType, consentDate);
    200244         
    201245          dc.saveItem(theCase);
     
    204248        else
    205249        {
    206           // Load existing case
    207           theCase = Sample.getById(dc, caseId.intValue());
    208           jsonMessages.add("Consent for case '" + theCase.getName() + "' set to: " + consent);
    209         }
    210         Reggie.setAnnotationValue(theCase, consentType, consent);
    211         if (consentDate != null) Reggie.setAnnotationValue(theCase, consentDateType, consentDate);
     250          List<Number> selectedCases = (List<Number>)jsonCase.get("selectedCases");
     251          if (selectedCases != null)
     252          {
     253            for (Number n : selectedCases)
     254            {
     255              theCase = Sample.getById(dc, n.intValue());
     256              Reggie.setAnnotationValue(theCase, consentType, consent);
     257              if (consentDate != null) Reggie.setAnnotationValue(theCase, consentDateType, consentDate);
     258              jsonMessages.add("Consent for case '" + theCase.getName() + "' set to: " + consent);
     259            }
     260          }
     261          else
     262          {
     263            // Load existing case
     264            theCase = Sample.getById(dc, caseId.intValue());
     265            Reggie.setAnnotationValue(theCase, consentType, consent);
     266            if (consentDate != null) Reggie.setAnnotationValue(theCase, consentDateType, consentDate);
     267            jsonMessages.add("Consent for case '" + theCase.getName() + "' set to: " + consent);
     268          }
     269        }
    212270       
    213271        // Blood if available
    214         if (bloodId != null)
     272        List<Number> selectedBlood = (List<Number>)jsonBlood.get("selectedBlood");
     273        if (selectedBlood != null)
     274        {
     275          for (Number n : selectedBlood)
     276          {
     277            Sample blood = Sample.getById(dc, n.intValue());
     278            jsonMessages.add("Consent for blood '" + blood.getName() + "' set to: " + consent);
     279            Reggie.setAnnotationValue(blood, consentType, consent);
     280            if (consentDate != null) Reggie.setAnnotationValue(blood, consentDateType, consentDate);
     281          }
     282         
     283        }
     284        else if (bloodId != null)
    215285        {
    216286          Sample blood = Sample.getById(dc, bloodId.intValue());
Note: See TracChangeset for help on using the changeset viewer.