Commit 8ed00085 authored by rwm's avatar rwm
Browse files

base type for Column

parent 3d658d95
...@@ -31,7 +31,7 @@ public class ColumnMap{ ...@@ -31,7 +31,7 @@ public class ColumnMap{
* @throws ParseException if the column cannot be found in the headers * @throws ParseException if the column cannot be found in the headers
* @throws NullPointerException if column is null * @throws NullPointerException if column is null
*/ */
public void registerColumn(Column column)throws ParseException{ public void registerColumn(Column<?> column)throws ParseException{
Objects.requireNonNull(column); Objects.requireNonNull(column);
column.validate(); // TODO: maybe call after unmarshal of column column.validate(); // TODO: maybe call after unmarshal of column
...@@ -54,7 +54,7 @@ public class ColumnMap{ ...@@ -54,7 +54,7 @@ public class ColumnMap{
} }
throw new ParseException("Column name '"+column.getName()+"' not found in header"); throw new ParseException("Column name '"+column.getName()+"' not found in header");
} }
public Integer indexOf(Column column){ public Integer indexOf(Column<?> column){
return map.get(column.getName()); return map.get(column.getName());
} }
} }
\ No newline at end of file
package de.sekmi.histream.etl.config; package de.sekmi.histream.etl.config;
import java.text.DecimalFormat;
import java.util.Objects; import java.util.Objects;
import javax.xml.bind.annotation.XmlAttribute; import javax.xml.bind.annotation.XmlAttribute;
...@@ -20,7 +19,7 @@ import de.sekmi.histream.etl.ParseException; ...@@ -20,7 +19,7 @@ import de.sekmi.histream.etl.ParseException;
*/ */
@XmlTransient @XmlTransient
@XmlSeeAlso({StringColumn.class}) @XmlSeeAlso({StringColumn.class})
public abstract class Column { public abstract class Column<T> {
protected Column(){ protected Column(){
} }
public Column(String name){ public Column(String name){
...@@ -75,6 +74,8 @@ public abstract class Column { ...@@ -75,6 +74,8 @@ public abstract class Column {
public String getName(){return name;} public String getName(){return name;}
public abstract T valueOf(Object input) throws ParseException;
/** /**
* Convert a string input value to the output data type. The resulting type depends * Convert a string input value to the output data type. The resulting type depends
* on the type attribute and can be one of Long, BigDecimal, String, DateTime * on the type attribute and can be one of Long, BigDecimal, String, DateTime
...@@ -85,7 +86,7 @@ public abstract class Column { ...@@ -85,7 +86,7 @@ public abstract class Column {
* @param value input value. e.g. from text table column * @param value input value. e.g. from text table column
* @return output type representing the input value * @return output type representing the input value
*/ */
public Object valueOf(Object value)throws ParseException{ public Object preprocessValue(Object value)throws ParseException{
if( constantValue != null ){ if( constantValue != null ){
value = constantValue; value = constantValue;
} }
...@@ -105,7 +106,7 @@ public abstract class Column { ...@@ -105,7 +106,7 @@ public abstract class Column {
return value; return value;
} }
public Object valueOf(ColumnMap map, Object[] row) throws ParseException{ public T valueOf(ColumnMap map, Object[] row) throws ParseException{
if( name.isEmpty() ){ if( name.isEmpty() ){
// use constant value if available // use constant value if available
return valueOf(null); return valueOf(null);
...@@ -122,18 +123,6 @@ public abstract class Column { ...@@ -122,18 +123,6 @@ public abstract class Column {
return input; return input;
} }
public static class DecimalColumn extends Column{
@XmlTransient
DecimalFormat decimalFormat;
/**
* Decimal format string for parsing via {@link DecimalFormat}
* @see DecimalFormat#DecimalFormat(String)
*/
@XmlAttribute
String format;
}
public void validate()throws ParseException{ public void validate()throws ParseException{
if( name.isEmpty() && constantValue == null ){ if( name.isEmpty() && constantValue == null ){
throw new ParseException("Empty column name only allowed if constant-value is specified"); throw new ParseException("Empty column name only allowed if constant-value is specified");
......
...@@ -25,7 +25,7 @@ public class Concept{ ...@@ -25,7 +25,7 @@ public class Concept{
@XmlAttribute(required=true) @XmlAttribute(required=true)
String id; String id;
// TODO: value should contain also type (string,decimal,integer,...) // TODO: value should contain also type (string,decimal,integer,...)
Column value; Column<?> value;
StringColumn unit; StringColumn unit;
@XmlElement(required=true) @XmlElement(required=true)
DateTimeColumn start; DateTimeColumn start;
...@@ -39,7 +39,7 @@ public class Concept{ ...@@ -39,7 +39,7 @@ public class Concept{
@XmlAttribute(required=true) @XmlAttribute(required=true)
String id; String id;
// TODO: value with type // TODO: value with type
Column value; Column<?> value;
StringColumn unit; StringColumn unit;
private Modifier(){ private Modifier(){
...@@ -60,7 +60,7 @@ public class Concept{ ...@@ -60,7 +60,7 @@ public class Concept{
} }
protected Observation createObservation(String patid, String visit, ObservationFactory factory, ColumnMap map, Object[] row) throws ParseException{ protected Observation createObservation(String patid, String visit, ObservationFactory factory, ColumnMap map, Object[] row) throws ParseException{
DateTimeAccuracy start = (DateTimeAccuracy)this.start.valueOf(map,row); DateTimeAccuracy start = this.start.valueOf(map,row);
Observation o = factory.createObservation(patid, this.id, start); Observation o = factory.createObservation(patid, this.id, start);
if( visit != null ){ if( visit != null ){
o.setEncounterId(visit); o.setEncounterId(visit);
...@@ -68,8 +68,9 @@ public class Concept{ ...@@ -68,8 +68,9 @@ public class Concept{
Object value = this.value.valueOf(map, row); Object value = this.value.valueOf(map, row);
String unit = null; String unit = null;
if( this.unit != null ){ if( this.unit != null ){
unit = (String)this.unit.valueOf(map, row); unit = this.unit.valueOf(map, row);
} }
// TODO: use type of column this.value to infer value type
if( value == null ){ if( value == null ){
// no value // no value
o.setValue(null); o.setValue(null);
......
...@@ -16,7 +16,7 @@ import de.sekmi.histream.etl.ParseException; ...@@ -16,7 +16,7 @@ import de.sekmi.histream.etl.ParseException;
* @author Raphael * @author Raphael
* *
*/ */
public class DateTimeColumn extends Column{ public class DateTimeColumn extends Column<DateTimeAccuracy>{
@XmlTransient @XmlTransient
DateTimeFormatter formatter; DateTimeFormatter formatter;
/** /**
...@@ -37,8 +37,8 @@ public class DateTimeColumn extends Column{ ...@@ -37,8 +37,8 @@ public class DateTimeColumn extends Column{
} }
@Override @Override
public Object valueOf(Object value) throws ParseException{ public DateTimeAccuracy valueOf(Object value) throws ParseException{
value = super.valueOf(value); value = super.preprocessValue(value);
if( value instanceof String ){ if( value instanceof String ){
// parse date according to format // parse date according to format
if( formatter == null && format != null ){ if( formatter == null && format != null ){
......
...@@ -6,7 +6,6 @@ import javax.xml.bind.annotation.XmlAccessorType; ...@@ -6,7 +6,6 @@ import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementWrapper; import javax.xml.bind.annotation.XmlElementWrapper;
import de.sekmi.histream.DateTimeAccuracy;
import de.sekmi.histream.ObservationFactory; import de.sekmi.histream.ObservationFactory;
import de.sekmi.histream.etl.ColumnMap; import de.sekmi.histream.etl.ColumnMap;
import de.sekmi.histream.etl.ParseException; import de.sekmi.histream.etl.ParseException;
...@@ -33,7 +32,7 @@ public class PatientTable extends Table<PatientRow> implements WideInterface{ ...@@ -33,7 +32,7 @@ public class PatientTable extends Table<PatientRow> implements WideInterface{
DateTimeColumn birthdate; DateTimeColumn birthdate;
DateTimeColumn deathdate; DateTimeColumn deathdate;
StringColumn gender; StringColumn gender;
Column[] ignore; Column<?>[] ignore;
} }
@Override @Override
...@@ -54,10 +53,10 @@ public class PatientTable extends Table<PatientRow> implements WideInterface{ ...@@ -54,10 +53,10 @@ public class PatientTable extends Table<PatientRow> implements WideInterface{
@Override @Override
public PatientRow fillRecord(ColumnMap map, Object[] row, ObservationFactory factory) throws ParseException { public PatientRow fillRecord(ColumnMap map, Object[] row, ObservationFactory factory) throws ParseException {
PatientRow patient = new PatientRow(); PatientRow patient = new PatientRow();
patient.setId(idat.patientId.valueOf(map, row).toString()); patient.setId(idat.patientId.valueOf(map, row));
patient.setNames((String)idat.firstname.valueOf(map, row), (String)idat.surname.valueOf(map, row)); patient.setNames(idat.firstname.valueOf(map, row), idat.surname.valueOf(map, row));
patient.setBirthDate((DateTimeAccuracy)idat.birthdate.valueOf(map, row)); patient.setBirthDate(idat.birthdate.valueOf(map, row));
patient.setDeathDate((DateTimeAccuracy)idat.deathdate.valueOf(map, row)); patient.setDeathDate(idat.deathdate.valueOf(map, row));
// TODO concepts // TODO concepts
return patient; return patient;
} }
......
package de.sekmi.histream.etl.config; package de.sekmi.histream.etl.config;
public class StringColumn extends Column{ import de.sekmi.histream.etl.ParseException;
public class StringColumn extends Column<String>{
public StringColumn(String name) { public StringColumn(String name) {
super(name); super(name);
...@@ -8,5 +10,11 @@ public class StringColumn extends Column{ ...@@ -8,5 +10,11 @@ public class StringColumn extends Column{
protected StringColumn(){ protected StringColumn(){
super(); super();
} }
@Override
public String valueOf(Object input) throws ParseException {
Object value = preprocessValue(input);
if( value != null )return value.toString();
else return null;
}
} }
\ No newline at end of file
...@@ -6,7 +6,6 @@ import javax.xml.bind.annotation.XmlElement; ...@@ -6,7 +6,6 @@ import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementWrapper; import javax.xml.bind.annotation.XmlElementWrapper;
import javax.xml.bind.annotation.XmlType; import javax.xml.bind.annotation.XmlType;
import de.sekmi.histream.DateTimeAccuracy;
import de.sekmi.histream.ObservationFactory; import de.sekmi.histream.ObservationFactory;
import de.sekmi.histream.etl.ColumnMap; import de.sekmi.histream.etl.ColumnMap;
import de.sekmi.histream.etl.ParseException; import de.sekmi.histream.etl.ParseException;
...@@ -28,7 +27,7 @@ public class VisitTable extends Table<VisitRow> implements WideInterface{ ...@@ -28,7 +27,7 @@ public class VisitTable extends Table<VisitRow> implements WideInterface{
DateTimeColumn start; DateTimeColumn start;
DateTimeColumn end; DateTimeColumn end;
// TODO inpatient/outpatient state // TODO inpatient/outpatient state
Column[] ignore; Column<?>[] ignore;
} }
@Override @Override
public ColumnMap getColumnMap(String[] headers) throws ParseException { public ColumnMap getColumnMap(String[] headers) throws ParseException {
...@@ -48,10 +47,10 @@ public class VisitTable extends Table<VisitRow> implements WideInterface{ ...@@ -48,10 +47,10 @@ public class VisitTable extends Table<VisitRow> implements WideInterface{
@Override @Override
public VisitRow fillRecord(ColumnMap map, Object[] row, ObservationFactory factory) throws ParseException { public VisitRow fillRecord(ColumnMap map, Object[] row, ObservationFactory factory) throws ParseException {
VisitRow visit = new VisitRow(); VisitRow visit = new VisitRow();
visit.setId(idat.visitId.valueOf(map, row).toString()); visit.setId(idat.visitId.valueOf(map, row));
visit.setPatientId(idat.patientId.valueOf(map, row).toString()); visit.setPatientId(idat.patientId.valueOf(map, row));
visit.setStartTime((DateTimeAccuracy)idat.start.valueOf(map, row)); visit.setStartTime(idat.start.valueOf(map, row));
visit.setEndTime((DateTimeAccuracy)idat.end.valueOf(map, row)); visit.setEndTime(idat.end.valueOf(map, row));
// TODO other // TODO other
// TODO concepts // TODO concepts
return visit; return visit;
......
...@@ -31,8 +31,8 @@ public class WideTable extends Table<WideRow> { ...@@ -31,8 +31,8 @@ public class WideTable extends Table<WideRow> {
@Override @Override
public WideRow fillRecord(ColumnMap map, Object[] row, ObservationFactory factory) throws ParseException { public WideRow fillRecord(ColumnMap map, Object[] row, ObservationFactory factory) throws ParseException {
String patid = (String)idat.patientId.valueOf(map, row); String patid = idat.patientId.valueOf(map, row);
String visit = (String)idat.visitId.valueOf(map, row); String visit = idat.visitId.valueOf(map, row);
WideRow rec = new WideRow(patid,visit); WideRow rec = new WideRow(patid,visit);
for( Concept c : concepts ){ for( Concept c : concepts ){
Observation o = c.createObservation(patid, visit, factory, map, row); Observation o = c.createObservation(patid, visit, factory, map, row);
......
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