Commit 6b09d5fa authored by rwm's avatar rwm

allow tables to ignore records

parent 681c4479
......@@ -40,28 +40,32 @@ public class RecordSupplier<R extends FactRow> implements Supplier<R>, AutoClose
@Override
public R get() {
Object[] row = rows.get();
if( row == null ){
// no more rows
return null;
}
R p;
try {
p = table.fillRecord(map, row, factory);
} catch (ParseException e) {
if( e.getLocation() == null ){
// add location information
e.setLocation(rows.getLocation());
do{
Object[] row = rows.get();
if( row == null ){
// no more rows
return null;
}
throw new UncheckedParseException(e);
}
try {
p = table.fillRecord(map, row, factory);
} catch (ParseException e) {
if( e.getLocation() == null ){
// add location information
e.setLocation(rows.getLocation());
}
throw new UncheckedParseException(e);
}
// repeat if fillRecord decides to skip the record
}while( p == null );
// fill source information
for( Observation o : p.getFacts() ){
o.setSource(source);
}
return p;
}
}
......@@ -89,6 +89,20 @@ public abstract class Table<T extends FactRow> {
}
}
/**
* Creates and fills a record from a table row.
* <p>
* The method can decide to ignore a row (and issue a warning)
* e.g if certain criteria are not met or the configuration
* requires some rows to be ignored. In this case, {@code null} is
* returned.
*
* @param map column map
* @param row row data
* @param factory observation factory
* @return complete record or {@code null} if the row should be ignored
* @throws ParseException for parse errors
*/
public abstract T fillRecord(ColumnMap map, Object[] row, ObservationFactory factory) throws ParseException;
public RecordSupplier<T> open(ObservationFactory factory, Meta meta) throws IOException, ParseException{
......
......@@ -73,12 +73,15 @@ public class VisitTable extends Table<VisitRow> implements ConceptTable{
visit.setId(idat.visitId.valueOf(map, row));
visit.setPatientId(idat.patientId.valueOf(map, row));
DateTimeAccuracy start = idat.start.valueOf(map, row);
if( start == null ){
if( start != null ){
visit.setStartTime(start);
}else{
// no start time specified for visit row
// any other way to retrieve a timestamp??
throw new ParseException("No start timestamp found for visit row, but needed for observation");
// ignore row
// TODO issue warning
return null;
}
visit.setStartTime(start);
if( idat.end != null ){
visit.setEndTime(idat.end.valueOf(map, row));
}
......@@ -92,7 +95,11 @@ public class VisitTable extends Table<VisitRow> implements ConceptTable{
if( concepts != null ){
for( Concept c : concepts ){
Observation o = c.createObservation(visit.getPatientId(), visit.getId(), factory, map, row);
visit.getFacts().add(o);
if( o == null ){
// observation ignored
}else{
visit.getFacts().add(o);
}
}
}
return visit;
......
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