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

base type for Column

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