Changeset 1524


Ignore:
Timestamp:
Jan 25, 2012, 11:02:05 AM (11 years ago)
Author:
Nicklas Nordborg
Message:

References #349: Copy consent information to multiple cases

The blood registration now checks if there is a case with consent information and allows copying of that information to the blood sample.

Location:
extensions/net.sf.basedb.reggie/trunk
Files:
1 added
5 edited

Legend:

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

    r1522 r1524  
    4040var patientInfo = null;
    4141var bloodInfo = null;
     42var caseInfo = null;
    4243
    4344function init()
     
    325326  // Get biosource information from the AJAX response
    326327  bloodInfo = response.bloodInfo;
    327  
    328   if (bloodInfo && bloodInfo.patient)
    329   {
    330     frm.personalNumber.value = bloodInfo.patient.personalNumber;
     328  patientInfo = response.patientInfo;
     329  caseInfo = response.caseInfo;
     330 
     331  if (patientInfo)
     332  {
     333    frm.personalNumber.value = patientInfo.personalNumber;
    331334    gotoStep2();
    332335  }
     
    342345  currentStep = 2;
    343346 
    344   var pnr = frm.personalNumber.value;
    345   var request = Ajax.getXmlHttpRequest();
    346   var url = 'PersonalRegistration.servlet?ID=<%=ID%>&cmd=GetPatientInfo';
    347   url += '&personalNumber=' + pnr;
    348   url += '&pnrIsValid=' + pnrIsValid;
    349   request.open("GET", url, false);
    350   request.send(null);
    351  
    352   if (debug) Main.debug(request.responseText);
    353  
    354   var response = JSON.parse(request.responseText);
    355   if (response.status != 'ok')
    356   {
    357     setFatalError(response.message);
    358     return false;
    359   }
    360  
    361   // Get patient information from the AJAX response
    362   patientInfo = response.patientInfo;
     347  if (!patientInfo)
     348  {
     349    var pnr = frm.personalNumber.value;
     350    var request = Ajax.getXmlHttpRequest();
     351    var url = 'PersonalRegistration.servlet?ID=<%=ID%>&cmd=GetPatientInfo';
     352    url += '&personalNumber=' + pnr;
     353    url += '&pnrIsValid=' + pnrIsValid;
     354    request.open("GET", url, false);
     355    request.send(null);
     356   
     357    if (debug) Main.debug(request.responseText);
     358   
     359    var response = JSON.parse(request.responseText);
     360    if (response.status != 'ok')
     361    {
     362      setFatalError(response.message);
     363      return false;
     364    }
     365   
     366    // Get patient information from the AJAX response
     367    patientInfo = response.patientInfo;
     368  }
    363369
    364370  Main.show('gocancel');
     
    403409  currentStep = 3;
    404410 
    405   var updateMode = bloodInfo.id && bloodInfo.patient;
     411  var updateMode = bloodInfo.id;
    406412  Main.show('bloodSection');
    407413 
     
    423429    frm.serum.checked = bloodInfo.serum == 'Yes';
    424430  }
     431  else
     432  {
     433    if (caseInfo && caseInfo.consent)
     434    {
     435      frm.copyConsent.value = caseInfo.id;
     436      var html = "From case '" + caseInfo.name + "' (" + caseInfo.consent;
     437      if (caseInfo.consentDate) html += '; ' + caseInfo.consentDate;
     438      html += ')';
     439      setInnerHTML('copyConsent.text', html);
     440      Main.show("copyConsentSection");
     441    }
     442  }
    425443 
    426444  Main.hide('gonext');
     
    449467  bloodInfo.freezerDate = Main.trimString(frm.freezerDate.value + ' ' + frm.freezerTime.value);
    450468  bloodInfo.serum = frm.serum.checked ? "Yes" : "No";
     469  if (frm.copyConsent.checked && frm.copyConsent.value)
     470  {
     471    bloodInfo.copyConsent = parseInt(frm.copyConsent.value);
     472  }
    451473
    452474  frm.samplingDate.disabled = true;
     
    455477  frm.freezerTime.disabled = true;
    456478
    457   var updateMode = bloodInfo.id && bloodInfo.patient;
     479  var updateMode = bloodInfo.id;
    458480  var submitInfo = new Object();
    459481  submitInfo.patientInfo = patientInfo;
     
    675697        <td class="help">Mark the check box if serum/plasma is available.</td>
    676698      </tr>
     699      <tr id="copyConsentSection" style="display: none;">
     700        <td class="prompt">Copy consent?</td>
     701        <td class="input">
     702          <input type="checkbox" name="copyConsent" id="copyConsent" value="" checked>
     703          <label for="copyConsent"><span id="copyConsent.text"></span></label>
     704        </td>
     705        <td class="status" id="copyConsent.status"></td>
     706        <td class="help"></td>
     707      </tr>
    677708      </table>
    678709    </td>
  • extensions/net.sf.basedb.reggie/trunk/src/net/sf/basedb/reggie/Reggie.java

    r1515 r1524  
    11package net.sf.basedb.reggie;
    22
     3import java.text.SimpleDateFormat;
    34import java.util.ArrayList;
    45import java.util.Collections;
     
    2122import net.sf.basedb.core.query.Hql;
    2223import net.sf.basedb.core.query.Restrictions;
     24import net.sf.basedb.reggie.converter.DateToStringConverter;
     25import net.sf.basedb.reggie.converter.StringToDateConverter;
    2326import net.sf.basedb.reggie.dao.Subtype;
    2427
     
    203206  public static final String ANNOTATION_BLOOD_SERUM = "BloodSerum";
    204207
    205    
     208  /**
     209    Default converter for date values to string values: yyyyMMdd
     210    @since 2.2
     211  */
     212  public static final DateToStringConverter CONVERTER_DATE_TO_STRING = new DateToStringConverter(new SimpleDateFormat("yyyyMMdd"));
     213 
     214  /**
     215    Default converter for string values to date values: yyyyMMdd
     216    @since 2.2
     217  */
     218  public static final StringToDateConverter CONVERTER_STRING_TO_DATE = new StringToDateConverter(new SimpleDateFormat("yyyyMMdd"));
     219 
     220  /**
     221    Default converter for date+time values to string values: yyyyMMdd HHmm
     222    @since 2.2
     223  */
     224  public static final DateToStringConverter CONVERTER_DATETIME_TO_STRING = new DateToStringConverter(new SimpleDateFormat("yyyyMMdd HHmm"));
     225 
     226  /**
     227    Default converter for string values to date+time values: yyyyMMdd HHmm
     228    @since 2.2
     229  */
     230  public static final StringToDateConverter CONVERTER_STRING_TO_DATETIME = new StringToDateConverter(new SimpleDateFormat("yyyyMMdd HHmm"));
     231 
     232 
    206233  /**
    207234    List all subtypes for the given item type that has the given name.
  • extensions/net.sf.basedb.reggie/trunk/src/net/sf/basedb/reggie/servlet/BloodRegistrationServlet.java

    r1522 r1524  
    1919import net.sf.basedb.core.BioSource;
    2020import net.sf.basedb.core.DbControl;
     21import net.sf.basedb.core.InvalidDataException;
    2122import net.sf.basedb.core.Item;
    2223import net.sf.basedb.core.Sample;
    2324import net.sf.basedb.core.SessionControl;
    2425import net.sf.basedb.reggie.Reggie;
    25 import net.sf.basedb.reggie.converter.DateToStringConverter;
    26 import net.sf.basedb.reggie.converter.StringToDateConverter;
    2726import net.sf.basedb.reggie.dao.Blood;
    2827import net.sf.basedb.reggie.dao.Case;
     28import net.sf.basedb.reggie.dao.Consent;
    2929import net.sf.basedb.reggie.dao.Patient;
    3030import net.sf.basedb.reggie.dao.Subtype;
     
    6868        dc = sc.newDbControl();
    6969       
    70         // Find blood by case name (blood name = case name + '.b' suffix)
     70        // Find blood + case by case name (blood name = case name + '.b' suffix)
    7171        String caseName = req.getParameter("caseName");
    7272        Blood blood = Blood.findByCaseName(dc, caseName);
     73        Case theCase = Case.findByName(dc, caseName);
    7374        Patient patient = null;
    7475        JSONObject jsonBlood = null;
     
    8081         
    8182          // ... blood annotations
    82           DateToStringConverter dateConverter = new DateToStringConverter(new SimpleDateFormat("yyyyMMdd HHmm"));
    83           blood.loadAnnotations(dc, "samplingDate", Reggie.ANNOTATION_BLOOD_SAMPLING_DATETIME, dateConverter);
    84           blood.loadAnnotations(dc, "freezerDate", Reggie.ANNOTATION_BLOOD_FREEZER_DATETIME, dateConverter);
     83          blood.loadAnnotations(dc, "samplingDate", Reggie.ANNOTATION_BLOOD_SAMPLING_DATETIME, Reggie.CONVERTER_DATETIME_TO_STRING);
     84          blood.loadAnnotations(dc, "freezerDate", Reggie.ANNOTATION_BLOOD_FREEZER_DATETIME, Reggie.CONVERTER_DATETIME_TO_STRING);
    8585          blood.loadAnnotations(dc, "serum", Reggie.ANNOTATION_BLOOD_SERUM, null);
    8686
     
    9393        else
    9494        {
    95           // Could not find blood -- see if we can find a regular case so that we can get patient info
     95          // Could not find blood
    9696          jsonBlood = new JSONObject();
    9797          jsonBlood.put("name", caseName + ".b");
    98           Case theCase = Case.findByName(dc, caseName);
    99           if (theCase != null)
     98         
     99        }
     100        json.put("bloodInfo", jsonBlood);
     101       
     102        if (theCase != null)
     103        {
     104          // Check that the registration is not prohibited
     105          theCase.verifyConsent(dc, null);
     106          Consent.loadConsentAnnotations(dc, theCase);
     107          JSONObject jsonCase = theCase.asJSONObject();
     108
     109          Patient casePatient = Patient.findByCase(dc, theCase);
     110          if (casePatient != null)
    100111          {
    101             // Check that the registration is not prohibited
    102             theCase.verifyConsent(dc, null);
    103             patient = Patient.findByCase(dc, theCase);
     112            // Verify that both samples have the same patient
     113            if (patient != null && !casePatient.equals(patient))
     114            {
     115              throw new InvalidDataException("Found case '" + theCase.getName() + "' and blood '" + blood.getName() +
     116                "' but they have not the same patient. This wizard can't continue until that is corrected.");
     117            }
     118            patient = casePatient;
    104119          }
     120          json.put("caseInfo", jsonCase);
    105121        }
    106122       
     
    109125        {
    110126          patient.loadDefaultAnnotations(dc);
    111           jsonBlood.put("patient", patient.asJSONObject());
    112         }
    113        
    114         // This is what we send back to the browser
    115         json.put("bloodInfo", jsonBlood);
     127          json.put("patientInfo", patient.asJSONObject());
     128        }
     129       
    116130      }
    117131    }
     
    160174        dc = sc.newDbControl();
    161175        BioSource patient = getOrCreatePatient(dc, jsonPat, jsonMessages);
    162        
    163         // If we already have a case with id it is probably due to an already registered consent=yes
    164         Number preCaseId = (Number)jsonBlood.get("id");
    165              
    166         // Load/create case
     176                 
     177        // Load/create blood
    167178        String bloodName = (String)jsonBlood.get("name");
    168         Sample blood = null;
    169 
    170         if (preCaseId != null)
    171         {
    172           // Load existing case
    173           blood = Sample.getById(dc, preCaseId.intValue());
    174         }
    175         else
    176         {
    177           // Register a new case
    178           blood = Sample.getNew(dc);
    179           dc.saveItem(blood);
    180         }
     179        Sample blood = Sample.getNew(dc);
    181180        blood.setItemSubtype(Subtype.BLOOD.load(dc));
    182181        blood.setName(bloodName);
    183182        blood.getCreationEvent().setSource(patient);
     183        dc.saveItem(blood);
    184184
    185185        // Annotations
     
    187187        AnnotationType freezerType = Reggie.findAnnotationType(dc, Item.SAMPLE, Reggie.ANNOTATION_BLOOD_FREEZER_DATETIME, true);
    188188        AnnotationType serumType = Reggie.findAnnotationType(dc, Item.SAMPLE, Reggie.ANNOTATION_BLOOD_SERUM, true);
    189         StringToDateConverter dateConverter = new StringToDateConverter(new SimpleDateFormat("yyyyMMdd HHmm"));
    190         Date samplingDate = dateConverter.convert((String)jsonBlood.get("samplingDate"));
    191         Date freezerDate = dateConverter.convert((String)jsonBlood.get("freezerDate"));
     189        Date samplingDate = Reggie.CONVERTER_STRING_TO_DATETIME.convert((String)jsonBlood.get("samplingDate"));
     190        Date freezerDate = Reggie.CONVERTER_STRING_TO_DATETIME.convert((String)jsonBlood.get("freezerDate"));
    192191        if (samplingDate != null) Reggie.setAnnotationValue(blood, samplingDateType, samplingDate);
    193192        if (freezerDate != null) Reggie.setAnnotationValue(blood, freezerType, freezerDate);
    194193        Reggie.setAnnotationValue(blood, serumType, jsonBlood.get("serum"));
    195194
     195        Number copyConsentId = (Number)jsonBlood.get("copyConsent");
     196        if (copyConsentId != null)
     197        {
     198          Sample consentCase = Sample.getById(dc, copyConsentId.intValue());
     199          Consent.copyConsentAnnotations(dc, consentCase, blood);
     200        }
     201
     202       
    196203        jsonMessages.add("Blood '" + bloodName + "' created successfully.");
    197204       
     
    215222        AnnotationType freezerType = Reggie.findAnnotationType(dc, Item.SAMPLE, Reggie.ANNOTATION_BLOOD_FREEZER_DATETIME, true);
    216223        AnnotationType serumType = Reggie.findAnnotationType(dc, Item.SAMPLE, Reggie.ANNOTATION_BLOOD_SERUM, true);
    217         StringToDateConverter dateConverter = new StringToDateConverter(new SimpleDateFormat("yyyyMMdd HHmm"));
    218         Date samplingDate = dateConverter.convert((String)jsonBlood.get("samplingDate"));
    219         Date freezerDate = dateConverter.convert((String)jsonBlood.get("freezerDate"));
     224        Date samplingDate = Reggie.CONVERTER_STRING_TO_DATETIME.convert((String)jsonBlood.get("samplingDate"));
     225        Date freezerDate = Reggie.CONVERTER_STRING_TO_DATETIME.convert((String)jsonBlood.get("freezerDate"));
    220226        if (samplingDate != null) Reggie.setAnnotationValue(blood, samplingDateType, samplingDate);
    221227        if (freezerDate != null) Reggie.setAnnotationValue(blood, freezerType, freezerDate);
  • extensions/net.sf.basedb.reggie/trunk/src/net/sf/basedb/reggie/servlet/ConsentFormServlet.java

    r1521 r1524  
    22
    33import java.io.IOException;
    4 import java.text.SimpleDateFormat;
    54import java.util.Date;
    65import java.util.List;
     
    2423import net.sf.basedb.core.SessionControl;
    2524import net.sf.basedb.reggie.Reggie;
    26 import net.sf.basedb.reggie.converter.DateToStringConverter;
    27 import net.sf.basedb.reggie.converter.StringToDateConverter;
    2825import net.sf.basedb.reggie.dao.Blood;
    2926import net.sf.basedb.reggie.dao.Case;
     27import net.sf.basedb.reggie.dao.Consent;
    3028import net.sf.basedb.reggie.dao.Patient;
    31 import net.sf.basedb.reggie.dao.ReggieItem;
    3229import net.sf.basedb.reggie.dao.SpecimenTube;
    3330import net.sf.basedb.reggie.dao.Subtype;
     
    4239  private static final long serialVersionUID = 28308664025515890L;
    4340
    44   private final DateToStringConverter date2StringConverter;
    45   private final StringToDateConverter string2DateConverter;
    46 
    4741  public ConsentFormServlet()
    48   {
    49     date2StringConverter = new DateToStringConverter(new SimpleDateFormat("yyyyMMdd"));
    50     string2DateConverter = new StringToDateConverter(new SimpleDateFormat("yyyyMMdd"));
    51   }
     42  {}
    5243
    5344  @SuppressWarnings("unchecked")
     
    122113          for (Case c : allCases)
    123114          {
    124             loadConsentAnnotation(dc, c);
     115            Consent.loadConsentAnnotations(dc, c);
    125116            c.loadAnnotations(dc, "laterality", Reggie.ANNOTATION_LATERALITY, null);
    126117            jsonAll.add(c.asJSONObject());
     
    133124          for (Blood b : allBlood)
    134125          {
    135             loadConsentAnnotation(dc, b);
     126            Consent.loadConsentAnnotations(dc, b);
    136127            jsonAll.add(b.asJSONObject());
    137128          }
     
    143134        {
    144135          // This is case 3 as described above.
    145           loadConsentAnnotation(dc, theCase);
     136          Consent.loadConsentAnnotations(dc, theCase);
    146137          json.put("caseInfo", theCase.asJSONObject());
    147138        }
     
    210201        String caseName = (String)jsonConsent.get("caseName");
    211202        String consent = Values.getStringOrNull((String)jsonConsent.get("consent"));
    212         Date consentDate = string2DateConverter.convert((String)jsonConsent.get("consentDate"));
     203        Date consentDate = Reggie.CONVERTER_STRING_TO_DATE.convert((String)jsonConsent.get("consentDate"));
    213204        // ID of samples can be both case and blood samples
    214205        List<Number> selectedSamples = (List<Number>)jsonConsent.get("selectedSamples");
     
    283274   
    284275  }
     276
    285277 
    286   /**
    287     Load consent-related annotations for the given item
    288   */
    289   private void loadConsentAnnotation(DbControl dc, ReggieItem item)
    290   {
    291     item.loadAnnotations(dc, "consent", Reggie.ANNOTATION_CONSENT, null);
    292     item.loadAnnotations(dc, "consentDate", Reggie.ANNOTATION_CONSENT_DATE, date2StringConverter);
    293   }
    294  
     278
    295279}
  • extensions/net.sf.basedb.reggie/trunk/src/net/sf/basedb/reggie/servlet/PersonalRegistrationServlet.java

    r1523 r1524  
    2424import net.sf.basedb.core.SessionControl;
    2525import net.sf.basedb.reggie.Reggie;
    26 import net.sf.basedb.reggie.converter.DateToStringConverter;
    27 import net.sf.basedb.reggie.converter.StringToDateConverter;
    2826import net.sf.basedb.reggie.dao.Blood;
    2927import net.sf.basedb.reggie.dao.Case;
     28import net.sf.basedb.reggie.dao.Consent;
    3029import net.sf.basedb.reggie.dao.Patient;
    3130import net.sf.basedb.reggie.dao.SpecimenTube;
     
    4140
    4241  private static final long serialVersionUID = 8770173686061080429L;
    43   private final DateToStringConverter dateTimeConverter;
    44   private final DateToStringConverter dateConverter;
    4542 
    4643  public PersonalRegistrationServlet()
    47   {
    48     dateTimeConverter = new DateToStringConverter(new SimpleDateFormat("yyyyMMdd HHmm"));
    49     dateConverter = new DateToStringConverter(new SimpleDateFormat("yyyyMMdd"));
    50   }
     44  {}
    5145
    5246  @SuppressWarnings("unchecked")
     
    132126          blood.verifyConsent(dc, null);
    133127          blood.loadAnnotations(dc, "consent", Reggie.ANNOTATION_CONSENT, null);
    134           blood.loadAnnotations(dc, "consentDate", Reggie.ANNOTATION_CONSENT_DATE, dateConverter);
     128          blood.loadAnnotations(dc, "consentDate", Reggie.ANNOTATION_CONSENT_DATE, Reggie.CONVERTER_DATE_TO_STRING);
    135129         
    136130          // Wrap what we have so far up into JSON objects
     
    158152            tube.loadAnnotations("pad", padType, null);
    159153            tube.loadAnnotations("laterality", lateralityType, null);
    160             tube.loadAnnotations("samplingDate", samplingDateType, dateTimeConverter);
    161             tube.loadAnnotations("rnaLaterDate", rnaLaterDateType, dateTimeConverter);
     154            tube.loadAnnotations("samplingDate", samplingDateType, Reggie.CONVERTER_DATETIME_TO_STRING);
     155            tube.loadAnnotations("rnaLaterDate", rnaLaterDateType, Reggie.CONVERTER_DATETIME_TO_STRING);
    162156            jsonTubes.add(tube.asJSONObject());
    163157          }
     
    205199            {
    206200              c.loadAnnotations("laterality", lateralityType, null);
    207               c.loadAnnotations(dc, "consent", Reggie.ANNOTATION_CONSENT, null);
    208               c.loadAnnotations(dc, "consentDate", Reggie.ANNOTATION_CONSENT_DATE, dateConverter);
     201              Consent.loadConsentAnnotations(dc, c);
    209202              jsonCases.add(c.asJSONObject());
    210203            }
     
    302295            // Remove the pre-registered case but copy consent information first
    303296            Sample preCase = Sample.getById(dc, preCaseId.intValue());
    304             copyConsentAnnotations(dc, preCase, theCase);
     297            Consent.copyConsentAnnotations(dc, preCase, theCase);
    305298            dc.deleteItem(preCase);
    306299          }
     
    333326          {
    334327            Sample consentCase = Sample.getById(dc, copyConsentId.intValue());
    335             copyConsentAnnotations(dc, consentCase, theCase);
     328            Consent.copyConsentAnnotations(dc, consentCase, theCase);
    336329          }
    337330         
     
    351344          AnnotationType rnaLaterType = Reggie.findAnnotationType(dc, Item.SAMPLE, Reggie.ANNOTATION_RNALATER_DATETIME, true);
    352345         
    353           StringToDateConverter dateConverter = new StringToDateConverter(new SimpleDateFormat("yyyyMMdd HHmm"));
    354           Date samplingDate = dateConverter.convert((String)jsonCase.get("samplingDate"));
    355           Date rnaLaterDate = dateConverter.convert((String)jsonCase.get("rnaLaterDate"));
     346          Date samplingDate = Reggie.CONVERTER_STRING_TO_DATETIME.convert((String)jsonCase.get("samplingDate"));
     347          Date rnaLaterDate = Reggie.CONVERTER_STRING_TO_DATETIME.convert((String)jsonCase.get("rnaLaterDate"));
    356348
    357349          for (int i = 0; i < jsonSpecimen.size(); ++i)
     
    421413          AnnotationType rnaLaterType = Reggie.findAnnotationType(dc, Item.SAMPLE, Reggie.ANNOTATION_RNALATER_DATETIME, true);
    422414         
    423           StringToDateConverter dateConverter = new StringToDateConverter(new SimpleDateFormat("yyyyMMdd HHmm"));
    424           Date samplingDate = dateConverter.convert((String)jsonCase.get("samplingDate"));
    425           Date rnaLaterDate = dateConverter.convert((String)jsonCase.get("rnaLaterDate"));
     415          Date samplingDate = Reggie.CONVERTER_STRING_TO_DATETIME.convert((String)jsonCase.get("samplingDate"));
     416          Date rnaLaterDate = Reggie.CONVERTER_STRING_TO_DATETIME.convert((String)jsonCase.get("rnaLaterDate"));
    426417         
    427418          for (int i = 0; i < jsonSpecimen.size(); ++i)
     
    530521  }
    531522 
    532   private void copyConsentAnnotations(DbControl dc, Sample from, Sample to)
    533   {
    534     AnnotationType consentType = Reggie.findAnnotationType(dc, Item.SAMPLE, Reggie.ANNOTATION_CONSENT, true);
    535     AnnotationType consentDateType = Reggie.findAnnotationType(dc, Item.SAMPLE, Reggie.ANNOTATION_CONSENT_DATE, true);
    536    
    537     Reggie.copyAnnotationValues(from, to, consentType, false);
    538     Reggie.copyAnnotationValues(from, to, consentDateType, false);
    539   }
    540523}
Note: See TracChangeset for help on using the changeset viewer.