Ignore:
Timestamp:
Oct 31, 2011, 11:37:15 AM (10 years ago)
Author:
Nicklas Nordborg
Message:

References #335: Use item subtypes - step 1

Installation wizard checks and create annotation type categories corresponding to some of the subtypes:

  • Patient
  • Case
  • Specimen
  • Lysate
Location:
extensions/net.sf.basedb.reggie/branches/2.0-dev
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • extensions/net.sf.basedb.reggie/branches/2.0-dev/resources/install.jsp

    r1427 r1429  
    5353  var numWarnings = 0;
    5454  var numErrors = 0;
     55  var numIncomplete = 0;
    5556  var checks = response.checks;
    5657  var html = '<table border="0" cellpadding="0" cellspacing="0" class="report">';
     
    6667      icon = 'error.gif';
    6768    }
     69    if (check.status == 'incomplete')
     70    {
     71      numIncomplete++;
     72      icon = 'warning.gif';
     73    }
    6874    if (check.status == 'error')
    6975    {
     
    122128    setWarningMessage(numWarnings+' warnings was detected. Reggie may still work. If not, you need to fix it manually.');
    123129  }
    124   Main.showHide('createMissingItems', numMissing > 0); 
    125  
     130  Main.showHide('createMissingItems', numMissing > 0);
     131  Main.showHide('fixIncompleteItems', numMissing == 0 && numIncomplete > 0);
    126132}
    127133
     
    147153.report #itemTypeCol
    148154{
    149   width: 150px;
     155  width: 180px;
    150156}
    151157
     
    200206  </div>
    201207
     208  <div id="fixIncompleteItems" style="display:none; margin-left: 20px; margin-top: 10px;">
     209    <table><tr><td>
     210    <base:button title="Fix items" image="fixit.png" onclick="createMissingItems()"/>
     211    </td></tr></table>
     212  </div>
     213
    202214  <div class="error" id="errorMessage" style="display: none; width: 800px; margin-left: 20px; margin-bottom: 0px;"></div>
    203215
  • extensions/net.sf.basedb.reggie/branches/2.0-dev/src/net/sf/basedb/reggie/Reggie.java

    r1427 r1429  
    88import net.sf.basedb.core.AnnotationSet;
    99import net.sf.basedb.core.AnnotationType;
     10import net.sf.basedb.core.AnnotationTypeCategory;
    1011import net.sf.basedb.core.DbControl;
    1112import net.sf.basedb.core.Group;
     
    259260  /**
    260261    List all annotation types with the given name.
     262    @since 2.0
     263  */
     264  public static List<AnnotationTypeCategory> listAnnotationTypeCategories(DbControl dc, String name)
     265  {
     266    ItemQuery<AnnotationTypeCategory> query = AnnotationTypeCategory.getQuery();
     267    query.restrict(Restrictions.eq(Hql.property("name"), Expressions.parameter("name", name, Type.STRING)));
     268    query.include(Include.ALL);
     269    return query.list(dc);
     270  }
     271 
     272  /**
     273    List all annotation types with the given name.
    261274  */
    262275  public static List<AnnotationType> listAnnotationTypes(DbControl dc, Item itemType, String name)
  • extensions/net.sf.basedb.reggie/branches/2.0-dev/src/net/sf/basedb/reggie/servlet/InstallServlet.java

    r1427 r1429  
    1717
    1818import net.sf.basedb.core.AnnotationType;
     19import net.sf.basedb.core.AnnotationTypeCategory;
    1920import net.sf.basedb.core.Application;
    2021import net.sf.basedb.core.DbControl;
     
    157158            null, effectiveOptions, createIfMissing));
    158159       
     160        // Annotation type categories
     161        jsonChecks.add(checkAnnotationTypeCategory(dc, Subtype.PATIENT, createIfMissing,
     162            Reggie.ANNOTATION_ALL_FIRST_NAMES, Reggie.ANNOTATION_DATE_OF_BIRTH,
     163            Reggie.ANNOTATION_FAMILY_NAME, Reggie.ANNOTATION_GENDER, Reggie.ANNOTATION_PERSONAL_NUMBER));
     164        jsonChecks.add(checkAnnotationTypeCategory(dc, Subtype.CASE, createIfMissing,
     165            Reggie.ANNOTATION_CONSENT, Reggie.ANNOTATION_LATERALITY,
     166            Reggie.ANNOTATION_PAD_CASE, Reggie.ANNOTATION_REASON_IF_NO_SPECIMEN));
     167        jsonChecks.add(checkAnnotationTypeCategory(dc, Subtype.SPECIMEN, createIfMissing,
     168            Reggie.ANNOTATION_ARRIVAL_DATE, Reggie.ANNOTATION_BIOPSY_TYPE,
     169            Reggie.ANNOTATION_LATERALITY, Reggie.ANNOTATION_NOF_DELIVERED_TUBES,
     170            Reggie.ANNOTATION_NOF_PIECES, Reggie.ANNOTATION_OPERATOR_DELIVERY_COMMENT,
     171            Reggie.ANNOTATION_OTHER_PARTITION_COMMENT, Reggie.ANNOTATION_OTHER_PATH_NOTE,
     172            Reggie.ANNOTATION_PAD, Reggie.ANNOTATION_RNALATER_DATETIME,
     173            Reggie.ANNOTATION_SAMPLING_DATETIME, Reggie.ANNOTATION_SPECIMEN_TYPE));
     174        jsonChecks.add(checkAnnotationTypeCategory(dc, Subtype.LYSATE, createIfMissing,
     175            Reggie.ANNOTATION_PARTITION_DATE));
    159176       
    160177        json.put("checks", jsonChecks);
    161178      }
     179     
    162180    }
    163181    catch (Throwable t)
     
    551569  }
    552570 
     571  /**
     572    Create an annotation type category with the given options. The category
     573    is created in a separate transaction.
     574    @since 2.0
     575  */
     576  public AnnotationTypeCategory createAnnotationTypeCategory(SessionControl sc, Subtype subtype, String... annotationTypes)
     577  {
     578    AnnotationTypeCategory cat = null;
     579    DbControl dc = sc.newDbControl();
     580    try
     581    {
     582      cat = AnnotationTypeCategory.getNew(dc);
     583      cat.setName(subtype.getName());
     584     
     585      if (annotationTypes != null)
     586      {
     587        for (String annotationType : annotationTypes)
     588        {
     589          AnnotationType at = Reggie.findAnnotationType(dc, subtype.getMainType(), annotationType, false);
     590          if (at != null)
     591          {
     592            at.addCategory(cat);
     593          }
     594        }
     595      }
     596     
     597      dc.saveItem(cat);
     598      dc.commit();
     599    }
     600    finally
     601    {
     602      if (dc != null) dc.close();
     603    }
     604    return cat;
     605  }
     606
     607  /**
     608    We need to do this in a separate transaction.
     609    @since 2.0
     610  */
     611  public void addAnnotionTypeToCategory(SessionControl sc, AnnotationType annotationType, AnnotationTypeCategory category)
     612  {
     613    DbControl dc = sc.newDbControl();
     614    try
     615    {
     616      annotationType = AnnotationType.getById(dc, annotationType.getId());
     617      category = AnnotationTypeCategory.getById(dc, category.getId());
     618      annotationType.addCategory(category);
     619      dc.commit();
     620    }
     621    finally
     622    {
     623      if (dc != null) dc.close();
     624    }
     625  }
     626 
     627  /**
     628    Check for an existing annotation type category.
     629    A JSONObject is returned with the result. The following
     630    keys are used:
     631    <ul>
     632    <li>itemType: ANNOTATIONTYPECATEGORY
     633    <li>name: The name of the subtype
     634    <li>id: The id of the subtype if it exists
     635    <li>mainType: The main item type that the subtype applies to
     636    <li>status: ok, error, or missing
     637    <li>message: A descriptive message in case of an error
     638    </ul>
     639    @since 2.0
     640  */
     641  @SuppressWarnings("unchecked")
     642  public JSONObject checkAnnotationTypeCategory(DbControl dc, Subtype subtype,
     643    boolean createIfMissing, String... annotationTypes)
     644  {
     645 
     646    JSONObject json = new JSONObject();
     647    JSONArray jsonMessages = new JSONArray();
     648    json.put("itemType", Item.ANNOTATIONTYPECATEGORY.name());
     649    json.put("name", subtype.getName());
     650     
     651    List<AnnotationTypeCategory> result = Reggie.listAnnotationTypeCategories(dc, subtype.getName());
     652    if (result.size() == 0)
     653    {
     654      if (createIfMissing)
     655      {
     656        AnnotationTypeCategory cat = createAnnotationTypeCategory(dc.getSessionControl(),
     657            subtype, annotationTypes);
     658        json.put("id", cat.getId());
     659        json.put("status", "ok");
     660        jsonMessages.add("Created");
     661      }
     662      else
     663      {
     664        json.put("status", "missing");
     665        jsonMessages.add("Not found");
     666      }
     667    }
     668    else if (result.size() > 1)
     669    {
     670      json.put("status", "error");
     671      jsonMessages.add("Found > 1 annotation type category");
     672    }
     673    else
     674    {
     675      AnnotationTypeCategory cat = result.get(0);
     676      json.put("id", cat.getId());
     677      json.put("status", "ok"); // For now -- more checks below
     678     
     679      if (annotationTypes != null)
     680      {
     681        for (String annotationType : annotationTypes)
     682        {
     683          AnnotationType at = Reggie.findAnnotationType(dc, subtype.getMainType(), annotationType, false);
     684          if (at != null && !at.isMember(cat))
     685          {
     686            if (createIfMissing)
     687            {
     688              addAnnotionTypeToCategory(dc.getSessionControl(), at, cat);
     689              if (jsonMessages.size() == 0) jsonMessages.add("Fixed");
     690            }
     691            else
     692            {
     693              json.put("status", "incomplete");
     694              jsonMessages.add("Not linked with: " + annotationType);
     695            }
     696          }
     697        }
     698      }
     699    }
     700    if (jsonMessages.size() == 0) jsonMessages.add("Ok");
     701    json.put("messages", jsonMessages);
     702    return json;
     703 
     704  }
     705
    553706
    554707  /**
Note: See TracChangeset for help on using the changeset viewer.