Commit 2221723e authored by rwm's avatar rwm
Browse files

column types for integer and decimal

parent 8ed00085
...@@ -18,7 +18,7 @@ import de.sekmi.histream.etl.ParseException; ...@@ -18,7 +18,7 @@ import de.sekmi.histream.etl.ParseException;
* *
*/ */
@XmlTransient @XmlTransient
@XmlSeeAlso({StringColumn.class}) @XmlSeeAlso({StringColumn.class,IntegerColumn.class,DateTimeColumn.class,DecimalColumn.class})
public abstract class Column<T> { public abstract class Column<T> {
protected Column(){ protected Column(){
} }
......
package de.sekmi.histream.etl.config;
import java.math.BigDecimal;
import javax.xml.bind.annotation.XmlType;
import de.sekmi.histream.etl.ParseException;
@XmlType(name="decimal")
public class DecimalColumn extends Column<BigDecimal>{
@Override
public BigDecimal valueOf(Object input) throws ParseException {
Object value = preprocessValue(input);
if( value == null ){
return null;
}else if( value instanceof String ){
// TODO: use decimalformat for parsing
return new BigDecimal((String)value);
}else if( value instanceof BigDecimal ){
return (BigDecimal)value;
}else{
throw new ParseException("Invalid type for decimal column: "+value.getClass().getName());
}
}
}
package de.sekmi.histream.etl.config;
import javax.xml.bind.annotation.XmlType;
import de.sekmi.histream.etl.ParseException;
@XmlType(name="integer")
public class IntegerColumn extends Column<Long> {
@Override
public Long valueOf(Object input) throws ParseException {
input = preprocessValue(input);
if( input == null ){
return null;
}else if( input instanceof String ){
// TODO: use integerformat for parsing
return Long.parseLong((String)input);
}else if( input instanceof Integer ){
return new Long((Integer)input);
}else if( input instanceof Long ){
return (Long)input;
}else{
throw new ParseException("Unsupported input type "+input.getClass().getName());
}
}
}
package de.sekmi.histream.etl.config; package de.sekmi.histream.etl.config;
import javax.xml.bind.annotation.XmlType;
import de.sekmi.histream.etl.ParseException; import de.sekmi.histream.etl.ParseException;
@XmlType(name="string")
public class StringColumn extends Column<String>{ public class StringColumn extends Column<String>{
public StringColumn(String name) { public StringColumn(String name) {
......
...@@ -2,6 +2,7 @@ package de.sekmi.histream.etl.config; ...@@ -2,6 +2,7 @@ package de.sekmi.histream.etl.config;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.math.BigDecimal;
import java.time.temporal.ChronoField; import java.time.temporal.ChronoField;
import javax.xml.bind.JAXB; import javax.xml.bind.JAXB;
...@@ -59,8 +60,8 @@ public class TestReadTables { ...@@ -59,8 +60,8 @@ public class TestReadTables {
Assert.assertTrue(r.getFacts().size() > 0); Assert.assertTrue(r.getFacts().size() > 0);
Observation o = r.getFacts().get(0); Observation o = r.getFacts().get(0);
Assert.assertEquals("natrium", o.getConceptId()); Assert.assertEquals("natrium", o.getConceptId());
Assert.assertEquals(Value.Type.Text, o.getValue().getType()); Assert.assertEquals(Value.Type.Numeric, o.getValue().getType());
Assert.assertEquals("124", o.getValue().getStringValue()); Assert.assertEquals(BigDecimal.valueOf(124), o.getValue().getNumericValue());
} }
} }
} }
...@@ -33,8 +33,8 @@ ...@@ -33,8 +33,8 @@
<birthdate format="d.M.u">geburtsdatum</birthdate> <birthdate format="d.M.u">geburtsdatum</birthdate>
<deathdate format="d.M.u">verstorben</deathdate> <deathdate format="d.M.u">verstorben</deathdate>
<gender>geschlecht</gender> <gender>geschlecht</gender>
<ignore xsi:type="stringColumn">ignoriert1</ignore> <ignore xsi:type="string">ignoriert1</ignore>
<ignore xsi:type="stringColumn">patfakt1</ignore> <ignore xsi:type="string">patfakt1</ignore>
</idat> </idat>
</patient-table> </patient-table>
<!-- optional --> <!-- optional -->
...@@ -53,7 +53,7 @@ ...@@ -53,7 +53,7 @@
<mdat> <mdat>
<!-- in/out code --> <!-- in/out code -->
<concept id="weight"> <concept id="weight">
<value xsi:type="stringColumn">gewicht</value> <value xsi:type="string">gewicht</value>
<start>start</start> <start>start</start>
</concept> </concept>
</mdat> </mdat>
...@@ -71,11 +71,11 @@ ...@@ -71,11 +71,11 @@
<mdat> <mdat>
<concept id="natrium"> <concept id="natrium">
<!-- TODO implement numeric columns --> <!-- TODO implement numeric columns -->
<value xsi:type="stringColumn">na</value> <value xsi:type="decimal">na</value>
<start format="d.M.u[ H[:m[:s]]]">zeitpunkt</start> <start format="d.M.u[ H[:m[:s]]]">zeitpunkt</start>
<unit constant-value="mmol/l" /> <unit constant-value="mmol/l" />
<modifier id="other"> <modifier id="other">
<value xsi:type="stringColumn" constant-value=""/> <value xsi:type="string" constant-value=""/>
</modifier> </modifier>
</concept> </concept>
</mdat> </mdat>
......
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