Changeset 1492


Ignore:
Timestamp:
Dec 2, 2011, 1:43:29 PM (10 years ago)
Author:
Nicklas Nordborg
Message:

Fixes #334: Use item subtypes - step 2

All queries now use subtype filters which should be more stable when finding items.

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

Legend:

Unmodified
Added
Removed
  • extensions/net.sf.basedb.reggie/trunk/src/net/sf/basedb/reggie/dao/Case.java

    r1463 r1492  
    4949    // Look for a case with the given name (primary case)
    5050    ItemQuery<Sample> caseQuery = Sample.getQuery();
     51    Subtype.CASE.addFilter(caseQuery);
    5152    caseQuery.restrict(Restrictions.eq(Hql.property("name"), Expressions.parameter("name", name, Type.STRING)));
    5253    List<Sample> cases = caseQuery.list(dc);
     
    6667      merged = true;
    6768      caseQuery = Sample.getQuery();
     69      Subtype.CASE.addFilter(caseQuery);
    6870      caseQuery.join(Hql.innerJoin("childCreationEvents", "cce"));
    6971      caseQuery.join(Hql.innerJoin("cce", "event", "evt"));
    70       caseQuery.join(Hql.innerJoin("evt", "bioMaterial", "bm")); // 'bm' should now refernce a specimen tube
    71       caseQuery.restrict(Restrictions.rlike(Hql.property("bm", "name"), Expressions.parameter("name", "^" + name + "\\.[0-9]+$", Type.STRING)));
     72      caseQuery.join(Hql.innerJoin("evt", "bioMaterial", "sp")); // 'sp' should now reference a specimen tube
     73      Subtype.SPECIMEN.addFilter(caseQuery, "sp");
     74      caseQuery.restrict(Restrictions.like(Hql.property("sp", "name"), Expressions.parameter("name", name + ".%", Type.STRING)));
    7275      caseQuery.setDistinct(true);
    7376     
     
    8588      if (cases.size() == 0)
    8689      {
    87         // Still not found... last chance is to find a ReasonIfNoSpecimen comment
     90        // Still not found... last chance is to find a (merged) case with ReasonIfNoSpecimen comment
    8891        // that has [caseName] as prefix...
    8992        AnnotationType reasonIfNoSpecimenType = Reggie.findAnnotationType(dc, Item.SAMPLE, Reggie.ANNOTATION_REASON_IF_NO_SPECIMEN, true);
    9093        caseQuery = Sample.getQuery();
     94        Subtype.CASE.addFilter(caseQuery);
    9195        caseQuery.restrict(Annotations.like(null, reasonIfNoSpecimenType, "[" + name + "]%", false));
    9296        cases = caseQuery.list(dc);
     
    122126  {
    123127    ItemQuery<Sample> caseQuery = patient.getBioSource().getSamples();
     128    Subtype.CASE.addFilter(caseQuery);
    124129    caseQuery.include(Include.ALL);
    125130    caseQuery.order(Orders.asc(Hql.property("name")));
  • extensions/net.sf.basedb.reggie/trunk/src/net/sf/basedb/reggie/dao/Patient.java

    r1463 r1492  
    3838    AnnotationType pnrType = Reggie.findAnnotationType(dc, Item.BIOSOURCE, Reggie.ANNOTATION_PERSONAL_NUMBER, true);
    3939    ItemQuery<BioSource> patientQuery = BioSource.getQuery();
     40    Subtype.PATIENT.addFilter(patientQuery);
    4041    patientQuery.restrict(Annotations.eq(null, pnrType, pnr, false));
    4142    List<BioSource> patients = patientQuery.list(dc);
  • extensions/net.sf.basedb.reggie/trunk/src/net/sf/basedb/reggie/dao/SpecimenTube.java

    r1488 r1492  
    99import net.sf.basedb.core.InvalidDataException;
    1010import net.sf.basedb.core.ItemQuery;
     11import net.sf.basedb.core.MeasuredBioMaterial;
    1112import net.sf.basedb.core.Sample;
    1213import net.sf.basedb.core.Type;
     
    3738  {
    3839    ItemQuery<Sample> specimenQuery = theCase.getSample().getChildSamples();
     40    Subtype.SPECIMEN.addFilter(specimenQuery);
    3941    if (limitToOriginal)
    4042    {
    41       specimenQuery.restrict(Restrictions.rlike(Hql.property("name"), Expressions.parameter("name", "^" + theCase.getOriginalName() + "\\.[0-9]+$", Type.STRING)));
     43      specimenQuery.restrict(Restrictions.like(Hql.property("name"), Expressions.parameter("name", theCase.getOriginalName() + ".%", Type.STRING)));
    4244    }
    4345    specimenQuery.order(Orders.asc(Hql.property("name")));
     
    6163  {
    6264    ItemQuery<Sample> specimenQuery = Sample.getQuery();
    63     specimenQuery.restrict(Restrictions.rlike(Hql.property("name"), Expressions.parameter("name", "^" + name + "\\.[0-9]+$", Type.STRING)));
     65    Subtype.SPECIMEN.addFilter(specimenQuery);
     66    specimenQuery.restrict(Restrictions.like(Hql.property("name"), Expressions.parameter("name", name + ".%", Type.STRING)));
    6467    specimenQuery.order(Orders.asc(Hql.property("name")));
    6568    specimenQuery.include(Include.ALL);
     
    7376  }
    7477 
    75  
     78  /**
     79    Find a specimen tube with the given name.
     80    @return A specimen tube, or null if not found
     81  */
    7682  public static SpecimenTube findByTubeName(DbControl dc, String tubeName)
    7783  {
     
    7985   
    8086    ItemQuery<Sample> tubeQuery = Sample.getQuery();
     87    Subtype.SPECIMEN.addFilter(tubeQuery);
    8188    tubeQuery.restrict(Restrictions.like(Hql.property("name"), Expressions.string(tubeName)));
    8289    tubeQuery.order(Orders.desc(Hql.property("name")));       
     
    98105 
    99106  /**
     107    Find unpartitioned specimen tubes. A specimen tube that has not been partitioned
     108    have a 'null' {@link MeasuredBioMaterial#getOriginalQuantity()}.
    100109    @since 1.6
    101    */
     110  */
    102111  public static List<SpecimenTube> findUnPartitionedTubes(DbControl dc)
    103112  {
     
    105114   
    106115    ItemQuery<Sample> tubeQuery = Sample.getQuery();
    107     tubeQuery.restrict(Restrictions.and(Restrictions.eq(Hql.property("originalQuantity"), null),
    108         Restrictions.rlike(Hql.property("name"), Expressions.parameter("name", "^.+\\.[0-9]+$", Type.STRING))));
     116    Subtype.SPECIMEN.addFilter(tubeQuery);
     117    tubeQuery.restrict(Restrictions.eq(Hql.property("originalQuantity"), null));
    109118    tubeQuery.order(Orders.desc(Hql.property("id")));
    110119    tubeQuery.include(Include.ALL);
  • extensions/net.sf.basedb.reggie/trunk/src/net/sf/basedb/reggie/dao/Subtype.java

    r1463 r1492  
    33import net.sf.basedb.core.DbControl;
    44import net.sf.basedb.core.Item;
     5import net.sf.basedb.core.ItemQuery;
    56import net.sf.basedb.core.ItemSubtype;
     7import net.sf.basedb.core.Subtypable;
     8import net.sf.basedb.core.query.Expressions;
     9import net.sf.basedb.core.query.Hql;
     10import net.sf.basedb.core.query.Restrictions;
    611import net.sf.basedb.reggie.Reggie;
    712
     
    98103  }
    99104 
     105  /**
     106    Add a filter restriction the given query so that it
     107    only return items of this subtype.
     108   
     109    @param query The query to filter
     110    @since 2.1
     111  */
     112  public void addFilter(ItemQuery<? extends Subtypable> query)
     113  {
     114    addFilter(query, null);
     115  }
     116
     117  /**
     118    Add a filter restriction to the given query based on the
     119    given subtype. If no alias is specified, the filter is
     120    applied to the root item, otherwise it is applied
     121    to the alias of a joined (eg. parent or child) item
     122   
     123    @param query The query to restrict
     124    @param alias Specify an alias if the filter should be
     125      placed on a joined (eg. child or parent) item instead
     126      of the root item
     127    @since 2.1
     128  */
     129  public void addFilter(ItemQuery<? extends Subtypable> query, String alias)
     130  {
     131    query.restrict(Restrictions.eq(Hql.property(alias, "itemSubtype"), Expressions.integer(id)));
     132  }
     133 
    100134}
  • extensions/net.sf.basedb.reggie/trunk/src/net/sf/basedb/reggie/servlet/PersonalRegistrationServlet.java

    r1463 r1492  
    193193          // No patient was found -- try to find the highest existing patient number
    194194          ItemQuery<BioSource> patientQuery = BioSource.getQuery();
     195          Subtype.PATIENT.addFilter(patientQuery);
    195196          patientQuery.restrict(Restrictions.like(Hql.property("name"), Expressions.string("PAT%")));
    196197          patientQuery.order(Orders.desc(Hql.property("name")));
  • extensions/net.sf.basedb.reggie/trunk/src/net/sf/basedb/reggie/servlet/SampleReportServlet.java

    r1491 r1492  
    2424import net.sf.basedb.core.query.Restrictions;
    2525import net.sf.basedb.reggie.converter.DateToStringConverter;
     26import net.sf.basedb.reggie.dao.Subtype;
    2627import net.sf.basedb.util.Values;
    2728import net.sf.basedb.util.error.ThrowableUtil;
     
    6465        String columnview = Values.getString(req.getParameter("columnview"), "MONTH");       
    6566        ItemQuery<Sample> sampleQuery = Sample.getQuery();
    66         sampleQuery.restrict(Restrictions.rlike(Hql.property("name"), Expressions.parameter("name", "^.+\\.[0-9]+$", Type.STRING)));
     67        Subtype.SPECIMEN.addFilter(sampleQuery);
    6768        sampleQuery.include(Include.ALL);
    6869        sampleQuery.setCacheResult(true);
Note: See TracChangeset for help on using the changeset viewer.