Commit 2a33652c authored by R.W.Majeed's avatar R.W.Majeed

XPath expressions for visits can now access the patient via .. (e.g. ../@id)

parent 5c477f43
......@@ -6,7 +6,7 @@ import javax.xml.parsers.ParserConfigurationException;
import javax.xml.stream.XMLStreamException;
import javax.xml.xpath.XPath;
import org.w3c.dom.Node;
import org.w3c.dom.Element;
import de.sekmi.histream.ObservationException;
import de.sekmi.histream.export.config.ExportDescriptor;
......@@ -26,6 +26,7 @@ class FragmentExporter extends VisitFragmentParser {
TableParser patientParser;
TableParser visitParser;
private Element currentPatient;
protected FragmentExporter(XPath xpath, ExportDescriptor desc, ExportWriter writer) throws ExportException, XMLStreamException, ParserConfigurationException {
super();
......@@ -39,7 +40,8 @@ class FragmentExporter extends VisitFragmentParser {
}
@Override
protected void patientFragment(Node patient) throws ObservationException {
protected void patientFragment(Element patient) throws ObservationException {
currentPatient = patient;
try {
patientParser.writeRow(patient);
} catch (ExportException | IOException e) {
......@@ -48,11 +50,18 @@ class FragmentExporter extends VisitFragmentParser {
}
@Override
protected void visitFragment(Node visit) throws ObservationException {
protected void visitFragment(Element visit) throws ObservationException {
// move visit to patient
// this allows XPath expressions to access the patient via
// the parent element. E.g. '../@id' to get the patient id
currentPatient.appendChild(visit);
try {
visitParser.writeRow(visit);
} catch (ExportException | IOException e) {
throw new ObservationException(e);
} finally {
// remove visit from patient
currentPatient.removeChild(visit);
}
// TODO check for repeating concepts and write to separate parsers
}
......
......@@ -12,6 +12,7 @@ import javax.xml.transform.dom.DOMResult;
import org.w3c.dom.Document;
import org.w3c.dom.DocumentFragment;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import de.sekmi.histream.ObservationException;
......@@ -74,7 +75,7 @@ abstract class VisitFragmentParser extends GroupedXMLWriter {
}else{
// No visit for patient.
// process patient fragment anyway
patientFragment(currentPatient.getFirstChild());
patientFragment((Element)currentPatient.getFirstChild());
}
}
......@@ -96,7 +97,7 @@ abstract class VisitFragmentParser extends GroupedXMLWriter {
if( firstVisit == false ){
// patient fragment was parsed
fixNamespaces(currentPatient);
patientFragment(currentPatient.getFirstChild());
patientFragment((Element)currentPatient.getFirstChild());
firstVisit = true;
}
......@@ -120,7 +121,7 @@ abstract class VisitFragmentParser extends GroupedXMLWriter {
fixNamespaces(currentVisit);
Node node = currentVisit.getFirstChild();
Objects.requireNonNull(node);
visitFragment(currentVisit.getFirstChild());
visitFragment((Element)currentVisit.getFirstChild());
}
/**
* Called after each patient fragment was parsed.
......@@ -129,7 +130,7 @@ abstract class VisitFragmentParser extends GroupedXMLWriter {
* @param patient patient node
* @throws ObservationException error
*/
protected void patientFragment(Node patient)throws ObservationException{
protected void patientFragment(Element patient)throws ObservationException{
}
/**
......@@ -139,5 +140,5 @@ abstract class VisitFragmentParser extends GroupedXMLWriter {
* @param visit visit node
* @throws ObservationException error
*/
protected abstract void visitFragment(Node visit) throws ObservationException;
protected abstract void visitFragment(Element visit) throws ObservationException;
}
......@@ -5,6 +5,7 @@ import java.util.function.Supplier;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.stream.XMLStreamException;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import de.sekmi.histream.Observation;
......@@ -21,7 +22,7 @@ public class VisitFragmentSupplier implements Supplier<Node> {
this.supplier = supplier;
this.parser = new VisitFragmentParser() {
@Override
protected void visitFragment(Node visit) {
protected void visitFragment(Element visit) {
VisitFragmentSupplier.this.visit = visit;
}
};
......
......@@ -15,6 +15,7 @@
<column header="modified" xpath="eav:source/@timestamp"/>
</patient-table>
<visit-table>
<column header="pid" xpath="../@id"/>
<column header="vid" xpath="@id"/>
<column header="start" xpath="eav:start"/>
<column header="f_start" xpath="eav:fact[@concept='T:full']/@start"/>
......
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