Commit fd870b26 authored by R.W.Majeed's avatar R.W.Majeed

support input streams with file observation supplier, read test data from test resources directory

parent 3a9efe27
......@@ -22,11 +22,33 @@ package de.sekmi.histream.io;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import de.sekmi.histream.ObservationFactory;
import de.sekmi.histream.ObservationSupplier;
public interface FileObservationSupplierFactory {
ObservationSupplier forFile(File file, ObservationFactory factory)throws IOException;
/**
* Get an observation supplier for the given input stream.
* <p>
* The input stream will be wrapped and will be closed automatically
* by the {@link ObservationSupplier#close()} method.
* </p>
* <p>
* If this method fails via a checked exception, the input stream will
* be closed.
* </p>
* @param in input stream
* @param factory factory
* @return observation supplier
* @throws IOException error (will automatically close the input stream)
*/
ObservationSupplier forInputStream(InputStream in, ObservationFactory factory)throws IOException;
default ObservationSupplier forFile(File file, ObservationFactory factory) throws IOException {
return forInputStream(new FileInputStream(file), factory);
}
}
......@@ -20,10 +20,8 @@ package de.sekmi.histream.io;
* #L%
*/
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Map;
import de.sekmi.histream.ObservationFactory;
......@@ -40,10 +38,9 @@ public class FlatProviderFactory implements FileObservationSupplierFactory, Plug
// don't need to close anything
}
@SuppressWarnings("resource")
@Override
public ObservationSupplier forFile(File file, ObservationFactory factory) throws IOException {
return new FlatObservationSupplier(factory, new FileInputStream(file));
public ObservationSupplier forInputStream(InputStream in, ObservationFactory factory) throws IOException {
return new FlatObservationSupplier(factory, in);
}
}
......@@ -20,9 +20,6 @@ package de.sekmi.histream.io;
* #L%
*/
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Map;
......@@ -46,8 +43,7 @@ public class GroupedXMLProvider implements FileObservationSupplierFactory, Plugi
}
@Override
public ObservationSupplier forFile(File file, ObservationFactory factory) throws IOException {
InputStream in = new FileInputStream(file);
public ObservationSupplier forInputStream(InputStream in, ObservationFactory factory) throws IOException {
try {
return new GroupedXMLReader(factory, in);
} catch (JAXBException | XMLStreamException | FactoryConfigurationError e) {
......
......@@ -21,8 +21,6 @@ package de.sekmi.histream.io;
*/
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Map;
......@@ -46,8 +44,7 @@ public class XMLProviderFactory implements FileObservationSupplierFactory, Plugi
}
@Override
public ObservationSupplier forFile(File file, ObservationFactory factory) throws IOException {
InputStream in = new FileInputStream(file);
public ObservationSupplier forInputStream(InputStream in, ObservationFactory factory) throws IOException {
try {
return new XMLObservationSupplier(factory, in);
} catch (XMLStreamException | FactoryConfigurationError e) {
......
......@@ -196,7 +196,11 @@ public class FileObservationProviderTest {
return factory;
}
public ObservationSupplier getExampleSupplier() throws IOException{
return getExampleSupplier("examples/dwh-jaxb.xml");
try {
return new GroupedXMLReader(factory, getClass().getResourceAsStream("/dwh.xml"));
} catch (XMLStreamException | FactoryConfigurationError | JAXBException e) {
throw new IOException(e);
}
}
public ObservationSupplier getExampleSupplier(String path) throws IOException{
......
<!--
#%L
histream
%%
Copyright (C) 2013 - 2015 R.W.Majeed
%%
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
#L%
-->
<eav-data xmlns="http://sekmi.de/histream/ns/eav-data"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<!-- chronologisch impliziert, dass der zeitstempel eines nachfolgenden elementes
größer als alle vorangehenden elemente sein muss. Der Zeitstempel kann vor dem
Encounter-Start liegen -->
<meta>
<!-- Zeitpunkt, an dem der Export erstellt wurde bzw. Datenstand -->
<etl-strategy>replace-visit</etl-strategy>
<source timestamp="2015-04-21T06:58:00Z" id="test"/>
<!-- weitere metadaten nötig? wertebereich, datentypen, ontologie, ...? -->
</meta>
<patient id="XX12345">
<given-name>A B</given-name>
<surname>Dampf</surname>
<!-- Gender allows for female, male, indeterminate -->
<!-- Gender element can also be removed or left empty -->
<gender>female</gender>
<birthdate>2001-01-01</birthdate>
<deceased>2020</deceased>
<source timestamp="2015-09-28T09:41:10Z"/>
<encounter id="XXE12345">
<start>2014-01-01T10:30:00</start>
<end>2014-01-05T10:30:00</end>
<location>Zuhause</location>
<!-- TODO inpatient/outpatient
<provider>xxxa</provider>-->
<source timestamp="2015-09-28T08:41:10Z"/>
<facts>
<fact concept="T:date:secs" start="2014-09-07T10:40:03"/>
<fact concept="T:date:mins" start="2014-09-07T10:40"/>
<fact concept="T:date:hours" start="2014-09-07T10"/>
<fact concept="T:date:day" start="2014-09-07"/>
<fact concept="T:date:month" start="2014-09"/>
<fact concept="T:date:year" start="2014"/>
<!-- test parsing of data types -->
<fact concept="T:type:str"><value xsi:type="string">abc123</value></fact>
<fact concept="T:type:int"><value xsi:type="numeric">123</value></fact>
<!-- value attributes can be used in elements fact and value -->
<fact concept="T:type:dec"><value xsi:type="numeric" unit="mm">123.456</value></fact>
<fact concept="T:full" start="2010" end="2011" location="T:LOC"><value xsi:type="numeric" unit="mm">123.456</value></fact>
<!--
<fact concept="T:type:enum" type="xsi:integer">1</fact>
-->
<!-- test group items -->
<fact concept="T:group:1">
<value xsi:type="string">groupvalue</value>
<modifier code="T:mod:1"/>
<modifier code="T:mod:2"><value xsi:type="string">def456</value></modifier>
<modifier code="T:mod:3"><value xsi:type="numeric" unit="mm">78.9</value></modifier>
</fact>
<!-- group without value -->
<fact concept="T:group:2">
<modifier code="T:mod:1"/>
</fact>
</facts>
</encounter>
</patient>
</eav-data>
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