Commit 0b294db1 authored by R.W.Majeed's avatar R.W.Majeed

ObservationParser to process InputStream

parent a9b02fa7
......@@ -6,7 +6,7 @@ import de.sekmi.histream.ext.ExternalSourceType;
/**
* Observation of a single event or a single fact assigned to a single patient.
* TODO include java.util.stream API
*
* @author Raphael
*
*/
......
package de.sekmi.histream;
import java.io.IOException;
import java.io.InputStream;
public interface ObservationParser extends ObservationProvider {
public void parse(InputStream input) throws IOException;
}
package de.sekmi.histream.impl;
import java.io.IOException;
import java.io.InputStream;
import java.math.BigDecimal;
import java.nio.BufferOverflowException;
import java.nio.CharBuffer;
......@@ -11,14 +13,18 @@ import java.util.logging.Logger;
import org.xml.sax.Attributes;
import org.xml.sax.ContentHandler;
import org.xml.sax.InputSource;
import org.xml.sax.Locator;
import org.xml.sax.SAXException;
import org.xml.sax.XMLReader;
import org.xml.sax.helpers.XMLReaderFactory;
import de.sekmi.histream.AbnormalFlag;
import de.sekmi.histream.DateTimeAccuracy;
import de.sekmi.histream.Modifier;
import de.sekmi.histream.Observation;
import de.sekmi.histream.ObservationFactory;
import de.sekmi.histream.ObservationParser;
import de.sekmi.histream.Value;
import de.sekmi.histream.Value.Type;
import de.sekmi.histream.ext.Patient;
......@@ -35,7 +41,7 @@ import de.sekmi.histream.ext.Visit;
* @author Raphael
*
*/
public class SAXObservationProvider extends AbstractObservationProvider implements ContentHandler{
public class SAXObservationProvider extends AbstractObservationProvider implements ContentHandler, ObservationParser{
private static final Logger log = Logger.getLogger(SAXObservationProvider.class.getName());
static private Class<?>[] supportedExtensions = new Class<?>[]{Patient.class,Visit.class};
......@@ -366,4 +372,15 @@ public class SAXObservationProvider extends AbstractObservationProvider implemen
public void beforeFacts(Consumer<Visit> handler){
this.beforeFacts = handler;
}
@Override
public void parse(InputStream input) throws IOException{
try {
XMLReader reader = XMLReaderFactory.createXMLReader();
reader.setContentHandler(this);
reader.parse(new InputSource(input));
} catch (SAXException e) {
throw new IOException(e);
}
}
}
package de.sekmi.histream.impl;
import java.io.FileReader;
import java.io.FileInputStream;
import java.sql.SQLException;
import org.xml.sax.InputSource;
import org.xml.sax.XMLReader;
import org.xml.sax.helpers.XMLReaderFactory;
import de.sekmi.histream.i2b2.I2b2Inserter;
import de.sekmi.histream.i2b2.I2b2Visit;
......@@ -29,7 +26,6 @@ public class TestInsertXmlToI2b2 {
ObservationFactoryImpl factory = new ObservationFactoryImpl();
factory.registerExtension(patientStore.getStore());
factory.registerExtension(visitStore.getStore());
XMLReader reader = XMLReaderFactory.createXMLReader();
SAXObservationProvider provider = new SAXObservationProvider(factory);
I2b2Inserter inserter = new I2b2Inserter();
inserter.open();
......@@ -49,8 +45,7 @@ public class TestInsertXmlToI2b2 {
visitStore.getStore().loadMaxInstanceNums();
provider.setHandler(inserter);
reader.setContentHandler(provider);
reader.parse(new InputSource(new FileReader("src/test/resources/dwh-eav.xml")));
provider.parse(new FileInputStream("src/test/resources/dwh-eav.xml"));
inserter.close();
visitStore.close();
patientStore.close();
......
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