Changeset 1958


Ignore:
Timestamp:
May 3, 2013, 2:03:46 PM (9 years ago)
Author:
olle
Message:

Refs #487. Second version of the INCA export. Class/file ExportServlet.java in reggie/src/net/sf/basedb/reggie/servlet/ has been updated to include all samples of type Specimen and NoSpecimen for each laterality, up to one for each biopsy type and date, and include the sample biopsy type in the exported data:

  1. Since the export format for the monthly operation list and the INCA export now differ considerably, a new inner class PersonalIncaExportData is introduced for the INCA export, while PersonalOpDate will be used for the monthly operation list export. Class PersonalIncaExportData contains the same private final attributes as PersonalOpDate plus a new String biopsyType. The public methods boolean equals(Object obj) and int compareTo(PersonalIncaExportData o) are extended to check the subtype and biopsyType values, in that order, if all other checked values are equal.
  2. Private method HashMap<String, Sample> updatePatientNumberSampleHashMap(...) is simplified by storing a new sample if no sample has been stored for a patient, and replace a stored blood sample with a new sample of other subtype, or a new blood sample with earlier sampling date than the stored one.
  3. When assembling samples for the INCA export in the second step of the procedure, only blood samples will be checked against the hash maps.
  4. Sample biopsy type will be included in the export, in a column directly after the the sample subtype column.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • extensions/net.sf.basedb.reggie/trunk/src/net/sf/basedb/reggie/servlet/ExportServlet.java

    r1957 r1958  
    135135        SnapshotManager manager = new SnapshotManager();       
    136136        DateFormatter dateFormat = new DateFormatter("yyyy-MM-dd");
     137        // Set of objects with comparison for operation list export
    137138        Set<PersonalOpDate> opDates = new TreeSet<PersonalOpDate>();
     139        // Set of objects with comparison for INCA export
     140        Set<PersonalIncaExportData> incaExportData = new TreeSet<PersonalIncaExportData>();
    138141        Pattern caseNamePattern = Pattern.compile("\\..*"); // Pattern to strip suffix from case name (eg. everything after first '.')
    139142        if ("ExportMonthlyOpList".equals(cmd))
     
    243246          for (Sample s : samples)
    244247          {
    245             // Check if sample stored for patient number
    246             if (!patientNumberSampleLeftHashMap.containsValue(s) && !patientNumberSampleRightHashMap.containsValue(s))
    247             {
    248               continue;
    249             }
    250248            // Find patient id
    251249            BioMaterial theCase = null;
     
    304302                String patientId = exportPatientId ? patient.getName() : null;
    305303                String caseName = caseNamePattern.matcher(s.getName()).replaceFirst("");
    306                 if (subtype.equals("Blood"))
     304                if (subtype != null && subtype.equals("Blood"))
    307305                {
    308306                  subtype = "BloodOnly";
    309307                }
    310                 opDates.add(new PersonalOpDate(pnr, opDate, site, laterality, subtype, caseName, consent, patientId));
     308                String biopsyType = (String)Annotationtype.BIOPSY_TYPE.getAnnotationValue(dc, manager, s);
     309                // If biopsy type should be included, exchange null values for explanatory text
     310                if (biopsyType == null)
     311                {
     312                  if (subtype != null)
     313                  {
     314                    // Note: subtype here is sample.getItemSubtype().getName()
     315                    if (subtype.equals("Specimen") || subtype.equals("NoSpecimen"))
     316                    {
     317                      biopsyType = "default";
     318                    }
     319                    else if (subtype.equals("Blood") || subtype.equals("BloodOnly"))
     320                    {
     321                      biopsyType = "not_available";
     322                    }
     323                  }
     324                }
     325                incaExportData.add(new PersonalIncaExportData(pnr, opDate, site, laterality, subtype, caseName, consent, patientId, biopsyType));
    311326              }
    312327            }
     
    337352        os.write(tableHeaderStart);
    338353        if (exportSubtype) os.write("\tSample");
     354        if (exportSubtype) os.write("\tBiopsyType");
    339355        if (exportPatientId) os.write("\tPatientId");
    340356        os.write("\tConsent\n");
    341357
    342         for (PersonalOpDate pop : opDates)
    343         {
    344           os.write(pop.toString());
    345           os.write("\n");
     358        if ("ExportMonthlyOpList".equals(cmd))
     359        {
     360          for (PersonalOpDate pop : opDates)
     361          {
     362            os.write(pop.toString());
     363            os.write("\n");
     364          }
     365        }
     366        else if ("ExportINCA".equals(cmd))
     367        {
     368          for (PersonalIncaExportData pie : incaExportData)
     369          {
     370            os.write(pie.toString());
     371            os.write("\n");
     372          }
    346373        }
    347374       
     
    362389  }
    363390
     391
     392  /**
     393   * Updates a hash map of patient numbers/samples with a new sample.
     394   * The sample is stored for the patient, if no previous sample
     395   * has been stored for the latter. If a sample has been stored,
     396   * a new specimen or no specimen will replace a blood sample,
     397   * and a blood sample with earlier sampling date will replace
     398   * a blood sample with a later one.
     399   * Used to find patients that only have blood samples, and
     400   * then find the earliest blood sample for the patient.
     401   *
     402   * @param dc DbControl The DcControl to use for database access
     403   * @param manager SnapshotManager Snapshot manager for annotations
     404   * @param patientNumberSampleHashMap HashMap<String, Sample> Hash map to update
     405   * @param patientNumber String Patient number of update sample
     406   * @param s Sample Update sample
     407   * @param laterality String Laterality string of update sample
     408   * @return HashMap<String, Sample> The (optionally) updated hash map
     409   */
    364410  private HashMap<String, Sample> updatePatientNumberSampleHashMap(
    365411      DbControl dc, SnapshotManager manager,
     
    374420    Sample storedSample = null;
    375421    ItemSubtype storedSampleSubtype = null;
    376     String storedSampleLaterality = null;
    377422    if (patientNumberSampleHashMap.containsKey(patientNumber))
    378423    {
    379424      storedSample = (Sample) patientNumberSampleHashMap.get(patientNumber);
    380425      storedSampleSubtype = storedSample.getItemSubtype();
    381       if (storedSampleSubtype.equals(subtypeSpecimen) || storedSampleSubtype.equals(subtypeNoSpecimen))
    382       {
    383         // The parent is the 'Case' for specimens and no specimens
    384         BioMaterial curCase = (MeasuredBioMaterial) storedSample.getParent();
    385         if (curCase != null && curCase instanceof Sample)
    386         {
    387           storedSampleLaterality = (String)Annotationtype.LATERALITY.getAnnotationValue(dc, manager, curCase);
    388         }
    389       }
    390426    }
    391427    // Update section
     
    394430      // Patient number not in hash map, store sample
    395431      patientNumberSampleHashMap.put(patientNumber, s);
    396     }
    397     else if (storedSampleSubtype.equals(subtypeSpecimen))
    398     {
    399       if (s.getItemSubtype().equals(subtypeSpecimen))
    400       {
    401         // Replace stored entry if sample has laterality and stored sample does not
    402         // If laterality equal, store sample if specimen with earlier date
    403         if ((storedSampleLaterality == null || storedSampleLaterality.equals(""))
    404             && (laterality != null && !laterality.equals("")))
    405         {
    406           patientNumberSampleHashMap.put(patientNumber, s);
    407         }
    408         else if (s.getCreationEvent().getEventDate().before(storedSample.getCreationEvent().getEventDate()))
    409         {
    410           patientNumberSampleHashMap.put(patientNumber, s);
    411         }
    412       }
    413     }
    414     else if (storedSampleSubtype.equals(subtypeNoSpecimen))
    415     {
    416       // Replace stored entry if sample equals specimen
    417       if (s.getItemSubtype().equals(subtypeSpecimen))
    418       {
    419         patientNumberSampleHashMap.put(patientNumber, s);
    420       }
    421       else if (s.getItemSubtype().equals(subtypeNoSpecimen))
    422       {
    423         // Replace stored entry if sample has laterality and stored sample does not
    424         // If laterality equal, store sample if specimen with earlier date
    425         if ((storedSampleLaterality == null || storedSampleLaterality.equals(""))
    426             && (laterality != null && !laterality.equals("")))
    427         {
    428           patientNumberSampleHashMap.put(patientNumber, s);
    429         }
    430         else if (s.getCreationEvent().getEventDate().before(storedSample.getCreationEvent().getEventDate()))
    431         {
    432           patientNumberSampleHashMap.put(patientNumber, s);
    433         }
    434       }
    435432    }
    436433    else if (storedSampleSubtype.equals(subtypeBlood))
     
    525522   
    526523  }
     524
     525
     526  class PersonalIncaExportData
     527    implements Comparable<PersonalIncaExportData>
     528  {
     529    private final String pnr;
     530    private final String opDate;
     531    private final Site site;
     532    private final String laterality;
     533    private final String subtype;
     534    private final String caseName;
     535    private final String consent;
     536    private final String patientId;
     537    private final String biopsyType;
     538   
     539    PersonalIncaExportData(String pnr, String opDate, Site site, String laterality, String subtype, String caseName, String consent, String patientId, String biopsyType)
     540    {
     541      this.pnr = pnr;
     542      this.opDate = opDate;
     543      this.site = site;
     544      this.laterality = laterality;
     545      this.subtype = subtype;
     546      this.caseName = caseName;
     547      this.consent = consent;
     548      this.patientId = patientId;
     549      this.biopsyType = biopsyType;
     550    }
     551   
     552    @Override
     553    public String toString()
     554    {
     555      return pnr + "\t" + caseName + "\t" + opDate +
     556          "\t" + (laterality == null ? "" : laterality) +
     557          "\t" + site.getName() +
     558          (subtype==null ? "" : "\t" + subtype) +
     559          (biopsyType==null ? "" : "\t" + biopsyType) +
     560          (patientId==null ? "" : "\t"+patientId)+
     561          "\t" + (consent == null ? "MISSING" : consent.toUpperCase());
     562    }
     563
     564    @Override
     565    public int hashCode()
     566    {
     567      return pnr.hashCode() + opDate.hashCode();
     568    }
     569
     570    @Override
     571    public boolean equals(Object obj)
     572    {
     573      if (obj == null) return false;
     574      if (this == obj) return true;
     575     
     576      if (obj.getClass() != this.getClass()) return false;
     577      PersonalIncaExportData o = (PersonalIncaExportData)obj;
     578      return EqualsHelper.equals(this.pnr, o.pnr) &&
     579          EqualsHelper.equals(this.opDate, o.opDate) &&
     580          EqualsHelper.equals(this.laterality, o.laterality) &&
     581          EqualsHelper.equals(this.subtype, o.subtype) &&
     582          EqualsHelper.equals(this.biopsyType, o.biopsyType);
     583    }
     584
     585    @Override
     586    public int compareTo(PersonalIncaExportData o)
     587    {
     588      int result = Reggie.nullSafeCompare(this.opDate, o.opDate);
     589      if (result == 0)
     590      {
     591        result =  Reggie.nullSafeCompare(this.pnr, o.pnr);
     592        if (result == 0)
     593        {
     594          result = Reggie.nullSafeCompare(this.laterality, o.laterality);
     595          if (result == 0)
     596          {
     597            result = Reggie.nullSafeCompare(this.subtype, o.subtype);
     598            if (result == 0)
     599            {
     600              result = Reggie.nullSafeCompare(this.biopsyType, o.biopsyType);
     601            }
     602          }
     603        }
     604      }
     605      return result;
     606    }
     607   
     608  }
    527609 
    528610}
Note: See TracChangeset for help on using the changeset viewer.