diff --git a/histream-export/.gitignore b/histream-export/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..8360da6d69893ae285a79a9d8ee7645b3951a524 --- /dev/null +++ b/histream-export/.gitignore @@ -0,0 +1,4 @@ +.settings/ +.classpath +.project +target/ diff --git a/histream-export/README.txt b/histream-export/README.txt new file mode 100644 index 0000000000000000000000000000000000000000..75501ed4bba7bde9ff3c7f29b7c6ed5892afe156 --- /dev/null +++ b/histream-export/README.txt @@ -0,0 +1,22 @@ +Algorithm +--------- + +1. Read all concept references. This can be actual concept codes + or wildcard concept codes. + +2. The facts will be processed grouped by encounter. E.g. as + a list of all concepts for the given encounter. + + If the patient or visit is different from the previous one + create new row in visit or encounter. Process all columns + which are NOT bound to any fact (not for fact tables which + are always bound to a fact). + +3. For each fact: +3.1 Find all matching columns. +3.2 + +or + +3. For each column: +3.1 Find all matching facts \ No newline at end of file diff --git a/histream-export/pom.xml b/histream-export/pom.xml new file mode 100644 index 0000000000000000000000000000000000000000..6d69b209770257f7143ebfa11682cf86ad005e47 --- /dev/null +++ b/histream-export/pom.xml @@ -0,0 +1,34 @@ + + 4.0.0 + HIStream : Export + + Export streams or collections of facts to table files + like CSV. + + + de.sekmi.histream + histream-export + 0.8-SNAPSHOT + + + de.sekmi.histream + histream + 0.8-SNAPSHOT + + + + + + + + + de.sekmi.histream + histream-core + 0.8-SNAPSHOT + + + junit + junit + + + \ No newline at end of file diff --git a/histream-export/src/main/java/de/sekmi/histream/export/TableExportFactory.java b/histream-export/src/main/java/de/sekmi/histream/export/TableExportFactory.java new file mode 100644 index 0000000000000000000000000000000000000000..a47e48c51a72071ad030a423088225e3d9877d06 --- /dev/null +++ b/histream-export/src/main/java/de/sekmi/histream/export/TableExportFactory.java @@ -0,0 +1,10 @@ +package de.sekmi.histream.export; + +import de.sekmi.histream.ObservationSupplier; + +public class TableExportFactory { + + public void export(ObservationSupplier supplier){ + + } +} diff --git a/histream-export/src/main/java/de/sekmi/histream/export/config/AbstractColumn.java b/histream-export/src/main/java/de/sekmi/histream/export/config/AbstractColumn.java new file mode 100644 index 0000000000000000000000000000000000000000..67dd94d210b6acd2de499fd6d550d2ba09542b78 --- /dev/null +++ b/histream-export/src/main/java/de/sekmi/histream/export/config/AbstractColumn.java @@ -0,0 +1,52 @@ +package de.sekmi.histream.export.config; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlAttribute; +import javax.xml.bind.annotation.XmlSeeAlso; +import javax.xml.bind.annotation.XmlTransient; + +@XmlTransient +@XmlAccessorType(XmlAccessType.NONE) +@XmlSeeAlso({SequenceColumn.class, IdColumn.class}) +public abstract class AbstractColumn { + + /** + * Column header name + */ + @XmlAttribute(required=true) + String header; + + + /** + * Column value to use to indicate NA. + * This will be used if null values are + * encountered by the column. If not specified, + * the empty string {@code ''} will be used. + */ + @XmlAttribute + String na; + + /** + * Prepare the column for the next row. This + * method is called once for every row. + *

The default implementation does nothing.

+ */ + protected void prepareRow(){ + + } + + /** + * Initializes the column. This method will be called + * only once and before any other method. + */ + protected void initialize(){ + + } + + /** + * Get the column value for the current row. + * @return String value or {@code null} for NA. + */ + public abstract Object getValueString(); +} diff --git a/histream-export/src/main/java/de/sekmi/histream/export/config/AbstractTable.java b/histream-export/src/main/java/de/sekmi/histream/export/config/AbstractTable.java new file mode 100644 index 0000000000000000000000000000000000000000..04e9d46120c88165382353df9cc19f73962d22f5 --- /dev/null +++ b/histream-export/src/main/java/de/sekmi/histream/export/config/AbstractTable.java @@ -0,0 +1,14 @@ +package de.sekmi.histream.export.config; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlTransient; + +@XmlTransient +@XmlAccessorType(XmlAccessType.NONE) +public abstract class AbstractTable { + + public abstract String[] getHeaders(); + public abstract AbstractColumn getColumn(int index); + public abstract AbstractColumn getColumnByHeader(String header); +} diff --git a/histream-export/src/main/java/de/sekmi/histream/export/config/ExportDescriptor.java b/histream-export/src/main/java/de/sekmi/histream/export/config/ExportDescriptor.java new file mode 100644 index 0000000000000000000000000000000000000000..b584e61354625dc1735c3497e5ccaa5924e0a88f --- /dev/null +++ b/histream-export/src/main/java/de/sekmi/histream/export/config/ExportDescriptor.java @@ -0,0 +1,17 @@ +package de.sekmi.histream.export.config; + +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; + +@XmlRootElement(name="export") +public class ExportDescriptor { + + @XmlElement + PatientTable patient; + + @XmlElement + VisitTable visit; + + @XmlElement(name="table") + FactTable[] tables; +} diff --git a/histream-export/src/main/java/de/sekmi/histream/export/config/FactTable.java b/histream-export/src/main/java/de/sekmi/histream/export/config/FactTable.java new file mode 100644 index 0000000000000000000000000000000000000000..0d25cd5a744b4287d1eb0aad5e25ec6327d61e84 --- /dev/null +++ b/histream-export/src/main/java/de/sekmi/histream/export/config/FactTable.java @@ -0,0 +1,5 @@ +package de.sekmi.histream.export.config; + +public class FactTable { + +} diff --git a/histream-export/src/main/java/de/sekmi/histream/export/config/IdColumn.java b/histream-export/src/main/java/de/sekmi/histream/export/config/IdColumn.java new file mode 100644 index 0000000000000000000000000000000000000000..d89f639a2613457f0620e7c0f0e40069421af179 --- /dev/null +++ b/histream-export/src/main/java/de/sekmi/histream/export/config/IdColumn.java @@ -0,0 +1,19 @@ +package de.sekmi.histream.export.config; + +/** + * Column which outputs intrinsic ID values. This + * column can only be used in {@link PatientTable} and + * {@link VisitTable}. + * + * @author R.W.Majeed + * + */ +public class IdColumn extends AbstractColumn{ + + @Override + public Object getValueString() { + // TODO Auto-generated method stub + return null; + } + +} diff --git a/histream-export/src/main/java/de/sekmi/histream/export/config/PatientTable.java b/histream-export/src/main/java/de/sekmi/histream/export/config/PatientTable.java new file mode 100644 index 0000000000000000000000000000000000000000..e8687840e2fd1e3966e5b71eef94b92980879be9 --- /dev/null +++ b/histream-export/src/main/java/de/sekmi/histream/export/config/PatientTable.java @@ -0,0 +1,9 @@ +package de.sekmi.histream.export.config; + +import javax.xml.bind.annotation.XmlElement; + +public class PatientTable { + + @XmlElement(name="column") + AbstractColumn[] columns; +} diff --git a/histream-export/src/main/java/de/sekmi/histream/export/config/SequenceColumn.java b/histream-export/src/main/java/de/sekmi/histream/export/config/SequenceColumn.java new file mode 100644 index 0000000000000000000000000000000000000000..6fe7171fb0eb5708dcbcfaf9e6308a21d425ec8c --- /dev/null +++ b/histream-export/src/main/java/de/sekmi/histream/export/config/SequenceColumn.java @@ -0,0 +1,35 @@ +package de.sekmi.histream.export.config; + +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; + +@XmlRootElement(name="sequence") +public class SequenceColumn extends AbstractColumn{ + @XmlElement(required=true) + String id; + + @XmlElement + Long start; + + long value; + + protected SequenceColumn(){ + } + public SequenceColumn(String id){ + this.id = id; + } + + @Override + protected void initialize(){ + if( start != null ){ + value = start; + }else{ + value = 1; + } + } + @Override + public Object getValueString() { + return value; + // TODO increment value somewhere else + } +} diff --git a/histream-export/src/main/java/de/sekmi/histream/export/config/VisitTable.java b/histream-export/src/main/java/de/sekmi/histream/export/config/VisitTable.java new file mode 100644 index 0000000000000000000000000000000000000000..3b39c0550c993f8af5e8587cf70289c73dcf303d --- /dev/null +++ b/histream-export/src/main/java/de/sekmi/histream/export/config/VisitTable.java @@ -0,0 +1,5 @@ +package de.sekmi.histream.export.config; + +public class VisitTable { + +} diff --git a/histream-export/src/main/java/de/sekmi/histream/export/config/package-info.java b/histream-export/src/main/java/de/sekmi/histream/export/config/package-info.java new file mode 100644 index 0000000000000000000000000000000000000000..bc4ba06c48dfe1d23f8278e475db7e3326028cb1 --- /dev/null +++ b/histream-export/src/main/java/de/sekmi/histream/export/config/package-info.java @@ -0,0 +1,8 @@ +/** + * Export configuration with JAXB annotations + * + */ +@javax.xml.bind.annotation.XmlSchema( + namespace="http://sekmi.de/ns/histream/export" +) +package de.sekmi.histream.export.config; \ No newline at end of file diff --git a/histream-export/src/test/java/de/sekmi/histream/export/config/TestMarshal.java b/histream-export/src/test/java/de/sekmi/histream/export/config/TestMarshal.java new file mode 100644 index 0000000000000000000000000000000000000000..1a1b13f7b9099c9fdfdacabf6471e1c2cb5b2721 --- /dev/null +++ b/histream-export/src/test/java/de/sekmi/histream/export/config/TestMarshal.java @@ -0,0 +1,27 @@ +package de.sekmi.histream.export.config; + +import javax.xml.bind.JAXBContext; +import javax.xml.bind.JAXBException; +import javax.xml.bind.Marshaller; + +import org.junit.Test; + +public class TestMarshal { + + @Test + public void verifyMarshal() throws JAXBException{ + ExportDescriptor e = new ExportDescriptor(); + e.patient = new PatientTable(); + e.patient.columns = new AbstractColumn[2]; + e.patient.columns[0] = new IdColumn(); + e.patient.columns[0].header = "pid"; + e.patient.columns[1] = new SequenceColumn("seq1"); + e.patient.columns[1].header = "seq"; + + JAXBContext j = JAXBContext.newInstance(ExportDescriptor.class); + Marshaller m = j.createMarshaller(); + m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); + m.marshal(e, System.out); + + } +} diff --git a/histream-export/src/test/resources/export1.xml b/histream-export/src/test/resources/export1.xml new file mode 100644 index 0000000000000000000000000000000000000000..6d2cac42fa430e1fea963234edadff8bb7a21ee0 --- /dev/null +++ b/histream-export/src/test/resources/export1.xml @@ -0,0 +1,69 @@ + + + + + + seq1 + + + + + + + + start + + + + + + + + fact.conceptId.substring(6) + + + + + + + + start + + + + PB + start + + + + + + + + + + + start + + + fuehrend + + ja + + + originalText + value + + + + + +
+
\ No newline at end of file diff --git a/pom.xml b/pom.xml index 55abb9265f9b1494f30f5caff1f35ad16fe68ac9..9dd5307ad856c45c99e7fde9828e9e343a5cc89c 100644 --- a/pom.xml +++ b/pom.xml @@ -57,6 +57,8 @@ histream-skos histream-import + histream-export + histream-js i2b2-integration-tests distribution