Commit 918aa9fd authored by R.W.Majeed's avatar R.W.Majeed

table export will return summary

parent 87a10fe3
package de.sekmi.histream.export;
public class ExportSummary {
private int patientCount;
private int visitCount;
// TODO maybe add information for additional tables (e.g. table ids and maybe counts)
ExportSummary(int patientCount, int visitCount){
this.patientCount = patientCount;
this.visitCount = visitCount;
}
public int getPatientCount(){
return patientCount;
}
public int getVisitCount(){
return visitCount;
}
}
......@@ -113,8 +113,6 @@ class FragmentExporter extends VisitFragmentParser {
// remove visit from patient
currentPatient.removeChild(visit);
}
// TODO check for repeating concepts and write to separate parsers
// iterate through facts and
}
@Override
......@@ -150,4 +148,19 @@ class FragmentExporter extends VisitFragmentParser {
}
}
}
/**
* Retrieve number of processed patients
* @return patient count
*/
public int getPatientCount(){
return patientParser.getRowCount();
}
/**
* Retrieve number of processed visits
* @return visit count
*/
public int getVisitCount(){
return visitParser.getRowCount();
}
}
......@@ -33,6 +33,8 @@ public class TableExport {
private XPathFactory factory;
private NamespaceContext ns;
private ExportErrorHandler errorHandler;
private int patientCount;
private int visitCount;
public TableExport(ExportDescriptor desc){
this.desc = desc;
......@@ -119,11 +121,12 @@ public class TableExport {
* @throws ExportException export exception
* @throws IOException IO exception
*/
public void export(ObservationSupplier supplier, ExportWriter writer) throws ExportException, IOException{
public ExportSummary export(ObservationSupplier supplier, ExportWriter writer) throws ExportException, IOException{
requireDisjointConcepts();
try( FragmentExporter e = new FragmentExporter(createXPath(), desc, writer) ){
e.setErrorHandler(new ExportErrorHandler());
Streams.transfer(supplier, e);
return new ExportSummary(e.getPatientCount(), e.getVisitCount());
} catch (XMLStreamException | ParserConfigurationException e) {
throw new ExportException("Unable to create exporter", e);
} catch (UncheckedExportException e ){
......@@ -134,4 +137,11 @@ public class TableExport {
throw e.getCause();
}
}
public int getPatientCount(){
return patientCount;
}
public int getVisitCount(){
return visitCount;
}
}
......@@ -24,11 +24,14 @@ public class TableParser implements AutoCloseable{
private XPath xpath;
private XPathExpression[] xpaths;
private TableWriter writer;
/** Count data rows (excluding header) */
private int rowCount;
public TableParser(AbstractTable table, TableWriter writer, XPath xpath) throws ExportException, IOException{
this.table = table;
this.writer = writer;
this.xpath = xpath;
this.rowCount = 0;
Objects.requireNonNull(table);
Objects.requireNonNull(writer);
compileXPaths();
......@@ -58,6 +61,7 @@ public class TableParser implements AutoCloseable{
public void processNode(Node node) throws ExportException, IOException{
writer.row(valuesForFragment(node));
rowCount ++;
}
private String[] valuesForFragment(Node node) throws ExportException{
......@@ -77,4 +81,11 @@ public class TableParser implements AutoCloseable{
public void close() throws IOException {
writer.close();
}
/**
* Get the number of processed data rows (excluding header rows if applicable).
* @return row count
*/
public int getRowCount(){
return rowCount;
}
}
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