Commit ba809851 authored by R.W.Majeed's avatar R.W.Majeed
Browse files

Observations without value now return getValue() null

parent 502f8ee6
......@@ -78,6 +78,7 @@ public class I2b2Inserter extends AbstractObservationHandler implements Observat
private String nullLocationCd;
private String nullModifierCd;
private String nullValueFlagCd;
private String nullValueTypeCd;
private Preprocessor etlPreprocessor;
private int insertCount;
......@@ -87,6 +88,7 @@ public class I2b2Inserter extends AbstractObservationHandler implements Observat
this.nullValueFlagCd = "@";// technically, null is allowed, but the demodata uses both '@' and ''
// TODO nullBlob (technically null allowed, but '' is used in demodata)
this.nullModifierCd = "@"; // null not allowed, @ is used in demodata
this.nullValueTypeCd = "@"; // TODO check database
insertCount = 0;
open(config);
}
......@@ -310,34 +312,9 @@ public class I2b2Inserter extends AbstractObservationHandler implements Observat
insertFact.setInt(7, instanceNum);
Value v = (m==null)?o.getValue():m.getValue();
switch( v.getType() ){
case Numeric:
if( v == null ){
// valtype_cd
insertFact.setString(8, "N");
// tval_char
insertFact.setString(9, getI2b2Operator(v));
// nval_num
insertFact.setBigDecimal(10, v.getNumericValue());
// value_flag_cd
insertFact.setString(11, getI2b2ValueFlagCd(v));
// units_cd
insertFact.setString(12, replaceNull(v.getUnits(),nullUnitCd));
break;
case Text:
// valtype_cd
insertFact.setString(8, "T");
// tval_char
insertFact.setString(9, v.getValue());
// nval_num
insertFact.setBigDecimal(10, null);
// value_flag_cd
insertFact.setString(11, getI2b2ValueFlagCd(v));
// units_cd
insertFact.setString(12, replaceNull(v.getUnits(),nullUnitCd));
break;
case None:
// valtype_cd
insertFact.setString(8, "@");
insertFact.setString(8, nullValueTypeCd);
// tval_char
insertFact.setString(9, null);
// nval_num
......@@ -346,9 +323,35 @@ public class I2b2Inserter extends AbstractObservationHandler implements Observat
insertFact.setString(11, nullValueFlagCd);
// units_cd
insertFact.setString(12, nullUnitCd);
break;
default:
throw new UnsupportedOperationException("Incomplete refactoring, unsupported value type "+v.getType());
}else{
switch( v.getType() ){
case Numeric:
// valtype_cd
insertFact.setString(8, "N");
// tval_char
insertFact.setString(9, getI2b2Operator(v));
// nval_num
insertFact.setBigDecimal(10, v.getNumericValue());
// value_flag_cd
insertFact.setString(11, getI2b2ValueFlagCd(v));
// units_cd
insertFact.setString(12, replaceNull(v.getUnits(),nullUnitCd));
break;
case Text:
// valtype_cd
insertFact.setString(8, "T");
// tval_char
insertFact.setString(9, v.getValue());
// nval_num
insertFact.setBigDecimal(10, null);
// value_flag_cd
insertFact.setString(11, getI2b2ValueFlagCd(v));
// units_cd
insertFact.setString(12, replaceNull(v.getUnits(),nullUnitCd));
break;
default:
throw new UnsupportedOperationException("Incomplete refactoring, unsupported value type "+v.getType());
}
}
// end_date
if( o.getEndTime() == null ){
......
package de.sekmi.histream;
import de.sekmi.histream.impl.AbstractValue;
/*
* #%L
* histream
......@@ -37,9 +35,8 @@ public interface ConceptValuePair {
public String getConceptId();
/**
* Get the value. This method shall not return {@code null}.
* If a non-existing value is needed, use {@link AbstractValue#NONE}
* @return value value
* Get the value. Returns {@code null} if there is no value.
* @return value value or {@code null}
*/
public Value getValue();
}
......@@ -66,10 +66,6 @@ public interface Value {
*
*/
public enum Type{
/**
* No value (getValue will return null)
*/
None,
/**
* Text value
*/
......
......@@ -20,9 +20,6 @@ package de.sekmi.histream.impl;
* #L%
*/
import java.math.BigDecimal;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlTransient;
......@@ -33,21 +30,20 @@ import de.sekmi.histream.Value;
public abstract class AbstractValue implements Value{
@XmlAttribute(name="flag")
protected AbnormalFlag flag;
@XmlAttribute(name="unit")
protected String units;
public static AbstractValue NONE = new NilValue();
@Override
public AbnormalFlag getAbnormalFlag() {return flag;}
public void setAbnormalFlag(AbnormalFlag flag){
this.flag = flag;
}
@Override
public String getUnits() {return units;}
/**
* Compare whether the abstract properties defined in this class match
* @param o other abstract value to compare
......@@ -58,26 +54,4 @@ public abstract class AbstractValue implements Value{
if( !(o.flag == null && this.flag == null) && !(this.flag != null && this.flag.equals(o.flag)) )return false;
return true;
}
private static class NilValue extends AbstractValue{
@Override
public String getValue() {return null;}
@Override
public BigDecimal getNumericValue() {return null;}
@Override
public Type getType() {return Type.None;}
@Override
public Operator getOperator() {return null;}
@Override
public BigDecimal getReferenceLow() {return null;}
@Override
public BigDecimal getReferenceHigh() {return null;}
}
}
......@@ -43,7 +43,6 @@ import de.sekmi.histream.Value;
import de.sekmi.histream.ext.Patient;
import de.sekmi.histream.ext.Patient.Sex;
import de.sekmi.histream.ext.Visit;
import de.sekmi.histream.impl.AbstractValue;
import de.sekmi.histream.impl.NumericValue;
import de.sekmi.histream.impl.StringValue;
......@@ -289,7 +288,7 @@ public class FlatObservationSupplier extends AbstractObservationParser implement
}
private Value parseValue(Record record){
if( record.getType() == null )return AbstractValue.NONE;
if( record.getType() == null )return null;
Value value;
switch( record.getType() ){
case "dat": // date
......@@ -303,7 +302,7 @@ public class FlatObservationSupplier extends AbstractObservationParser implement
default:
// throw error
case "nil":
value = AbstractValue.NONE;
value = null;
}
return value;
......
......@@ -88,7 +88,7 @@ class XMLObservationParser extends AbstractObservationParser{
protected void parseValueType(String type){
if( type == null ){
factType = Type.None;
factType = null;
}else switch( type ){
case "xsi:string":
factType = Type.Text;
......@@ -225,22 +225,23 @@ class XMLObservationParser extends AbstractObservationParser{
*/
protected Value parseValue(String valueText){
AbstractValue val;
switch( factType ){
case None:
if( factType == null ){
if( valueText != null && valueText.length() != 0 )
log.warning("Value type None, but content not empty");
val = AbstractValue.NONE;
break;
case Text:
val = new StringValue(valueText);
break;
case Numeric:
val = new NumericValue(new BigDecimal(valueText), valueUnit, valueOp);
break;
default:
throw new IllegalArgumentException("Unsupported fact type "+factType);
val = null;
}else{
switch( factType ){
case Text:
val = new StringValue(valueText);
break;
case Numeric:
val = new NumericValue(new BigDecimal(valueText), valueUnit, valueOp);
break;
default:
throw new IllegalArgumentException("Unsupported fact type "+factType);
}
val.setAbnormalFlag(valueFlag);
}
val.setAbnormalFlag(valueFlag);
// TOOD: set operator
return val;
}
......
......@@ -128,7 +128,7 @@ public class FileObservationProviderTest {
Modifier m = o.getModifier("T:mod:1");
Assert.assertNotNull(m);
Assert.assertEquals("T:mod:1", m.getConceptId());
Assert.assertEquals(Value.Type.None, m.getValue().getType());
Assert.assertNull(m.getValue());
Assert.assertTrue(e.hasNext());
m = o.getModifier("T:mod:2");
Assert.assertNotNull(m);
......@@ -143,11 +143,11 @@ public class FileObservationProviderTest {
},
(Observation o) -> {
Assert.assertEquals("T:group:2", o.getConceptId());
Assert.assertEquals(Value.Type.None, o.getValue().getType());
Assert.assertNull(o.getValue());
Modifier m = o.getModifier("T:mod:1");
Assert.assertNotNull(m);
Assert.assertEquals("T:mod:1", m.getConceptId());
Assert.assertEquals(Value.Type.None, m.getValue().getType());
Assert.assertNull(m.getValue());
},
});
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment