Commit 36664aeb authored by R.W.Majeed's avatar R.W.Majeed

introduced setObservationFactory for ObservationProvider

parent 693409a0
......@@ -5,5 +5,7 @@ import java.util.function.Consumer;
public interface ObservationProvider{
void setHandler(Consumer<Observation> consumer);
void setObservationFactory(ObservationFactory factory);
Class<?>[] getSupportedExtensions();
}
......@@ -15,7 +15,10 @@ public class AbstractObservationParser {
protected String sourceId;
protected String etlStrategy;
public AbstractObservationParser(ObservationFactory factory){
public AbstractObservationParser(){
}
public void setObservationFactory(ObservationFactory factory){
this.factory = factory;
}
......
package de.sekmi.histream.io;
public interface FileObservationProviderFactory {
import java.io.File;
import java.io.IOException;
import de.sekmi.histream.ObservationFactory;
public interface FileObservationProviderFactory {
FileObservationProvider forFile(File file, ObservationFactory factory)throws IOException;
}
......@@ -90,7 +90,7 @@ public class FlatObservationProvider extends AbstractObservationParser implement
}
public FlatObservationProvider(ObservationFactory factory, BufferedReader reader){
super(factory);
setObservationFactory(factory);
this.reader = reader;
this.fieldSeparator = Pattern.compile("\\t");
this.metaAssignment = Pattern.compile("^#@meta\\(([a-z\\.]+)\\)=(.*)$");
......
......@@ -49,8 +49,7 @@ public class SAXObservationProvider extends XMLObservationParser implements Cont
private ExtensionAccessor<Patient> patient;
*/
public SAXObservationProvider(ObservationFactory factory) {
super(factory);
public SAXObservationProvider() {
buffer = CharBuffer.allocate(1024);
}
......@@ -206,4 +205,9 @@ public class SAXObservationProvider extends XMLObservationParser implements Cont
private void provideObservation(Observation observation){
handler.accept(observation);
}
@Override
public void setObservationFactory(ObservationFactory factory) {
this.factory = factory;
}
}
......@@ -9,7 +9,6 @@ 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.Value;
import de.sekmi.histream.Value.Type;
import de.sekmi.histream.ext.Patient;
......@@ -61,8 +60,7 @@ class XMLObservationParser extends AbstractObservationParser{
protected Patient patient;
protected XMLObservationParser(ObservationFactory factory){
super(factory);
protected XMLObservationParser(){
visitData = new HashMap<>();
//factory.getExtensionAccessor(Patient.class);
// TODO: assert that the supportedExtensions are available from the factory
......
......@@ -3,7 +3,6 @@ package de.sekmi.histream.io;
import java.io.IOException;
import java.io.InputStream;
import java.io.UncheckedIOException;
import java.util.function.Supplier;
import javax.xml.stream.FactoryConfigurationError;
import javax.xml.stream.XMLInputFactory;
......@@ -27,7 +26,7 @@ public class XMLObservationProvider extends XMLObservationParser implements File
private AttributeAccessor atts;
public XMLObservationProvider(ObservationFactory factory, XMLStreamReader reader) {
super(factory);
setObservationFactory(factory);
this.reader = reader;
atts = new AttributeAccessor() {
@Override
......
package de.sekmi.histream.io;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Map;
import javax.xml.stream.FactoryConfigurationError;
import javax.xml.stream.XMLStreamException;
import de.sekmi.histream.ObservationFactory;
import de.sekmi.histream.Plugin;
public class XMLProviderFactory implements FileObservationProviderFactory, Plugin{
public void XMLObservationFactory(Map<String,String> props) {
// no configuration needed
}
@Override
public void close() throws IOException {
// don't need to close anything
}
@Override
public FileObservationProvider forFile(File file, ObservationFactory factory) throws IOException {
try {
return new XMLObservationProvider(factory, new FileInputStream(file));
} catch (XMLStreamException | FactoryConfigurationError e) {
throw new IOException(e);
}
}
}
......@@ -116,7 +116,8 @@ public class FileObservationProviderTest {
@Test
public void testSAXReader() throws Exception{
XMLReader reader = XMLReaderFactory.createXMLReader();
SAXObservationProvider provider = new SAXObservationProvider(factory);
SAXObservationProvider provider = new SAXObservationProvider();
provider.setObservationFactory(factory);
provider.setHandler(handler);
reader.setContentHandler(provider);
reader.parse(new InputSource(new FileReader("src/test/resources/dwh-eav.xml")));
......
......@@ -31,7 +31,8 @@ public class TestInsertXmlToI2b2 {
ObservationFactoryImpl factory = new ObservationFactoryImpl();
factory.registerExtension(patientStore.getStore());
factory.registerExtension(visitStore.getStore());
SAXObservationProvider provider = new SAXObservationProvider(factory);
SAXObservationProvider provider = new SAXObservationProvider();
provider.setObservationFactory(factory);
Map<String,String> props = new HashMap<>();
props.put("user", "i2b2demodata");
......
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