예제 #1
0
  public void fillData(Set<TestResult> testResults) {
    Transaction tra = RegaDBMain.getApp().createTransaction();

    for (int i = 0; i < testItems.size(); i++) {
      TestItem ti = testItems.get(i);
      Test test = getTest(tra, ti);
      if (test == null) continue;

      TestResult theTr = null;
      for (TestResult tr : testResults) {
        if (tr.getTest().getDescription().equals(test.getDescription())) {
          theTr = tr;
          break;
        }
      }

      FormField f = testFormFields.get(i);
      if (theTr != null) {
        if (f instanceof ComboBox) {
          ((ComboBox) f).selectItem(theTr.getTestNominalValue().getValue());
        } else {
          if (theTr.getValue() != null) f.setText(theTr.getValue());
          else f.setText(new String(theTr.getData()));
        }
      }
    }
  }
예제 #2
0
  public void init(InteractionState interactionState, IForm form, FormTable table) {
    Transaction tr = RegaDBMain.getApp().createTransaction();

    for (UITestItem ti : testItems) {
      Test t = getTest(tr, ti);
      if (t != null) {
        Label l = new Label(TestComboBox.getLabel(t));
        FormField testResultField;
        if (ValueTypes.getValueType(t.getTestType().getValueType()) == ValueTypes.NOMINAL_VALUE) {
          testResultField = new ComboBox(interactionState, form);
          for (TestNominalValue tnv : t.getTestType().getTestNominalValues()) {
            ((ComboBox) testResultField)
                .addItem(new DataComboMessage<TestNominalValue>(tnv, tnv.getValue()));
          }
          ((ComboBox) testResultField).sort();

          if (ti.noValueSelected) ((ComboBox) testResultField).addNoSelectionItem();

          ((ComboBox) testResultField).selectIndex(0);

          if (ti.defaultValue != null && interactionState.isEditable())
            ((ComboBox) testResultField).selectItem(ti.defaultValue);
        } else {
          testResultField =
              FormField.getTextField(
                  ValueTypes.getValueType(t.getTestType().getValueType()), interactionState, form);
        }

        table.addLineToTable(l, testResultField);
        testFormFields.add(testResultField);
      } else {
        System.err.println("ViralIsolateForm: test does not exist: '" + ti.description + '\'');
      }
    }
  }
예제 #3
0
  public void saveData(Set<TestResult> testResults) {
    Transaction tra = RegaDBMain.getApp().createTransaction();

    for (int i = 0; i < testItems.size(); i++) {
      TestResult tr = null;
      for (TestResult vi_tr : testResults) {
        if (vi_tr.getTest().getDescription().equals(testItems.get(i).description)) {
          tr = vi_tr;
          break;
        }
      }
      FormField f = testFormFields.get(i);
      if (f instanceof ComboBox) {
        DataComboMessage<TestNominalValue> dcm =
            (DataComboMessage<TestNominalValue>) ((ComboBox) f).currentItem();
        if (dcm != null && dcm.getValue() != null) {
          TestItem ti = testItems.get(i);
          if (tr == null) tr = createTestResult(getTest(tra, ti));
          tr.setTestNominalValue(
              ((DataComboMessage<TestNominalValue>) ((ComboBox) f).currentItem()).getDataValue());
        } else if (tr != null) {
          removeTestResult(tr);
        }
      } else {
        if (f.text() != null && !f.text().trim().equals("")) {
          TestItem ti = testItems.get(i);
          if (tr == null) tr = createTestResult(getTest(tra, ti));
          tr.setValue(f.text());
        } else if (tr != null) {
          removeTestResult(tr);
        }
      }
    }
  }
예제 #4
0
  @SuppressWarnings("rawtypes")
  @Override
  public File run() throws Exception {
    File result = File.createTempFile("nadir_", ".csv", getResultDir());
    PrintStream out = new PrintStream(new FileOutputStream(result));

    TestType tt = pTestType.getTestTypeComboBox().currentValue();
    ValueTypes vt = ValueTypes.getValueType(tt.getValueType());
    String hql =
        "select tr.patient.patientId, tr.test.description, tr.testDate, tr.value from TestResult tr join tr.patient.patientDatasets patient_dataset"
            + " where patient_dataset.id.dataset.datasetIi = :var_dataset"
            + " and tr.testDate <= :var_date"
            + " and tr.test.testIi in (select testIi from Test t where t.testType.testTypeIi = :var_testtype)"
            + " order by tr.patient.patientId, ";

    if (vt == ValueTypes.LIMITED_NUMBER)
      hql += "cast(substring(tr.value, 2, length(tr.value)) as double)";
    else hql += "cast(tr.value as double)";

    Transaction t = RegaDBMain.getApp().createTransaction();
    Query q = t.createQuery(hql);
    q.setParameter("var_dataset", pDataset.getDataset().getDatasetIi());
    q.setParameter("var_date", pDate.getDate());
    q.setParameter("var_testtype", tt.getTestTypeIi());

    out.println("patient_id,test,test_date,value");

    List r = q.list();
    String prevPatientId = null;
    for (Object o : r) {
      Object[] oo = (Object[]) o;
      String patientId = (String) oo[0];
      String test = (String) oo[1];
      Date testDate = (Date) oo[2];
      String value = (String) oo[3];

      if (!patientId.equals(prevPatientId)) {
        out.println(
            '"'
                + patientId
                + "\",\""
                + test
                + "\",\""
                + DateUtils.format(testDate)
                + "\",\""
                + value
                + '"');
        prevPatientId = patientId;
      }
    }

    t.commit();
    out.close();

    return result;
  }
예제 #5
0
  public TestListWidget(InteractionState is, List<UITestItem> testItems, Set<TestResult> results) {
    this.testItems = new ArrayList<UITestItem>(testItems);

    Transaction tr = RegaDBMain.getApp().createTransaction();
    Iterator<UITestItem> i = this.testItems.iterator();
    while (i.hasNext()) {
      UITestItem ti = i.next();
      Test t = getTest(tr, ti);
      if (!showTest(is, t, results)) i.remove();
    }
  }
  public void loadTable(
      Collection<String> drugClasses,
      boolean showMutations,
      boolean showAllAlgorithms,
      Set<TestResult> testResults,
      TestType gssTestType) {
    clear();

    if (gssTestType == null) {
      return;
    }

    Transaction t = RegaDBMain.getApp().createTransaction();
    List<DrugClass> sortedDrugClasses_ = t.getDrugClassesSortedOnResistanceRanking();

    // drug names - column position
    HashMap<String, Integer> algoColumn = new HashMap<String, Integer>();
    int col = 0;
    getElementAt(0, col).addWidget(new WText(""));
    col = getColumnCount();
    getElementAt(0, col).addWidget(new WText(""));
    int maxWidth = 0;
    for (Test test : getAlgorithms(t, gssTestType, showAllAlgorithms)) {
      col = getColumnCount();
      getElementAt(0, col).addWidget(new TableHeader(test.getDescription()));
      getElementAt(0, col).setStyleClass("column-title");

      algoColumn.put(test.getDescription(), col);
      maxWidth += test.getDescription().length();
    }

    // drug names - row position
    HashMap<String, Integer> drugColumn = new HashMap<String, Integer>();

    List<DrugGeneric> genericDrugs;
    int row;
    boolean firstGenericDrugInThisClass;
    for (DrugClass dc : sortedDrugClasses_) {
      if (!drugClasses.contains(dc.getClassId())) continue;

      genericDrugs = t.getDrugGenericSortedOnResistanceRanking(dc);
      firstGenericDrugInThisClass = true;
      for (DrugGeneric dg : genericDrugs) {
        row = getRowCount();
        if (firstGenericDrugInThisClass) {
          getElementAt(row, 0).addWidget(new TableHeader(dc.getClassId() + ":"));
          firstGenericDrugInThisClass = false;
          getElementAt(row, 0).setStyleClass("form-label-area");
        }
        getElementAt(row, 1).addWidget(new TableHeader(dg.getGenericId()));
        drugColumn.put(dg.getGenericId(), row);
        getElementAt(row, 1).setStyleClass("form-label-area");
      }
    }

    ViralIsolateFormConfig config =
        RegaDBSettings.getInstance().getInstituteConfig().getViralIsolateFormConfig();

    // clear table
    for (int i = 1; i < getRowCount(); i++) {
      for (int j = 2; j < getColumnCount(); j++) {
        ViralIsolateFormUtils.putResistanceTableResult(
            null, getElementAt(i, j), config, false, showMutations);
      }
    }

    Integer colN;
    Integer rowN;
    for (TestResult tr : testResults) {
      if (tr.getTest().getAnalysis() != null
          && Equals.isSameTestType(gssTestType, tr.getTest().getTestType())) {
        if (!drugClasses.contains(tr.getDrugGeneric().getDrugClass().getClassId())) continue;

        colN = algoColumn.get(tr.getTest().getDescription());
        rowN = drugColumn.get(ViralIsolateFormUtils.getFixedGenericId(tr));
        if (colN != null && rowN != null) {
          ViralIsolateFormUtils.putResistanceTableResult(
              tr, getElementAt(rowN, colN), config, false, showMutations);
        }
      }
    }
  }