Commit 987f3ca5 authored by R.W.Majeed's avatar R.W.Majeed

test case for concept class annotator

parent 7d664d83
......@@ -2,14 +2,29 @@ package de.sekmi.histream.export;
import java.io.IOException;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* Keeps the table data in memory. Mainly useful for
* tests.
* <p>
* The patient and visit tables can be accessed with the
* constants {@link #PATIENT_TABLE} and {@link #VISIT_TABLE}.
* </p>
* @author R.W.Majeed
*
*/
public class MemoryExportWriter implements ExportWriter{
List<MemoryTable> tables;
public static final String PATIENT_TABLE = "patients";
public static final String VISIT_TABLE = "visits";
Map<String, MemoryTable> tables;
public MemoryExportWriter(){
tables = new LinkedList<>();
tables = new HashMap<>();
}
public static class MemoryTable implements TableWriter{
List<String[]> rows;
......@@ -52,32 +67,57 @@ public class MemoryExportWriter implements ExportWriter{
@Override
public TableWriter openPatientTable() {
MemoryTable t = new MemoryTable("patients");
tables.add(t);
MemoryTable t = new MemoryTable(PATIENT_TABLE);
tables.put(t.id, t);
return t;
}
@Override
public TableWriter openVisitTable() {
MemoryTable t = new MemoryTable("visits");
tables.add(t);
MemoryTable t = new MemoryTable(VISIT_TABLE);
tables.put(t.id, t);
return t;
}
@Override
public TableWriter openEAVTable(String id) {
if( tables.containsKey(id) ){
throw new IllegalArgumentException("Duplicate table id: "+id);
}
MemoryTable t = new MemoryTable(id);
tables.add(t);
tables.put(t.id, t);
return t;
}
public void dump(){
for( MemoryTable t : tables ){
for( MemoryTable t : tables.values() ){
t.dump();
System.out.println();
}
}
/**
* Access table data
* @param table table id
* @param column column name
* @param row row number
* @return data
* @throws IndexOutOfBoundsException if any of table, column, row does not exist
*/
public String get(String table, String column, int row) throws IndexOutOfBoundsException{
MemoryTable t = tables.get(table);
if( t == null ){
throw new IndexOutOfBoundsException("Non-existing table "+table);
}
int index = Arrays.asList(t.headers).indexOf(column);
if( index == -1 ){
throw new IndexOutOfBoundsException("Table "+table+" does not contain column "+column);
}
if( row < 0 || row >= t.rows.size() ){
throw new IndexOutOfBoundsException("Unable to access row "+row+" in table "+table+" (has only "+t.rows.size()+" rows)");
}
return t.rows.get(row)[index];
}
@Override
public void close(){
}
......
......@@ -34,6 +34,8 @@ public class TestExport {
try( ObservationSupplier s = t.getExampleSupplier() ){
export.export(s, m);
}
// verify class lookup
Assert.assertEquals("T:date:year", m.get(MemoryExportWriter.VISIT_TABLE, "byclass", 0));
m.dump();
// TODO something wrong with namespaces in xpath/dom
}
......
......@@ -2,8 +2,8 @@
<export xmlns="http://sekmi.de/ns/histream/export-v1"
xmlns:eav="http://sekmi.de/histream/ns/eav-data">
<concepts>
<group class="diag">
<concept wildcard-notation="ICD10:*"/>
<group class="testclass">
<concept wildcard-notation="T:date:yea*"/>
</group>
<concept notation="T:full"/>
<concept wildcard-notation="CEDIS:*"/>
......@@ -18,6 +18,7 @@
<column header="pid" xpath="../@id"/>
<column header="vid" xpath="@id"/>
<column header="start" xpath="eav:start"/>
<column header="byclass" xpath="eav:fact[@class='testclass']/@concept"/>
<column header="f_start" xpath="eav:fact[@concept='T:full']/@start"/>
<column header="f_end" xpath="eav:fact[@concept='T:full']/@end"/>
<column header="f_loc" xpath="eav:fact[@concept='T:full']/@location"/>
......
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