Commit eb28122d authored by R.W.Majeed's avatar R.W.Majeed
Browse files

read/write source id+timestamp with JAXB

parent 56150288
......@@ -45,9 +45,9 @@
<xs:complexType name="factType">
<xs:sequence>
<xs:element name="source" type="sourceType" minOccurs="0" maxOccurs="1"/>
<xs:element name="value" type="valueType" minOccurs="0" maxOccurs="1"/>
<xs:element name="modifier" type="modifierType" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="source" type="sourceType" minOccurs="0" maxOccurs="1"/>
</xs:sequence>
<xs:attribute type="xs:string" name="patient" />
<xs:attribute type="xs:string" name="encounter" />
......
......@@ -5,4 +5,5 @@
patient="12345" encounter="23456" concept="T:testconcept1" start="2015-01-09T22:30" end="2015-01" location="L:ocation" provider="provider">
<value xsi:type="numeric" unit="mm" flag="A" operator="E">123</value>
<modifier code="M:test"><value xsi:type="string">123</value></modifier>
<source id="system1" timestamp="2015-08-24T21:11:15.332Z"/>
</fact>
\ No newline at end of file
package de.sekmi.histream.impl;
/*
* #%L
* histream
......@@ -33,6 +34,8 @@ import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlSeeAlso;
import javax.xml.bind.annotation.XmlTransient;
import javax.xml.bind.annotation.XmlType;
import javax.xml.bind.annotation.adapters.XmlAdapter;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
import de.sekmi.histream.DateTimeAccuracy;
import de.sekmi.histream.Modifier;
......@@ -49,7 +52,7 @@ import de.sekmi.histream.ext.ExternalSourceType;
*/
@XmlRootElement(name="fact")
@XmlAccessorType(XmlAccessType.NONE)
@XmlType(propOrder={"abstractValue","modifierList"})
@XmlType(propOrder={"abstractValue","modifierList","source"})
@XmlSeeAlso({StringValue.class,NumericValue.class})
public class ObservationImpl implements Observation{
public static final String XML_NAMESPACE="http://sekmi.de/histream/ns/eav-data";
......@@ -273,7 +276,25 @@ public class ObservationImpl implements Observation{
}
private static class SourceAdapter extends XmlAdapter<ExternalSourceImpl, ExternalSourceType>{
@Override
public ExternalSourceType unmarshal(ExternalSourceImpl v) throws Exception {
return v;
}
@Override
public ExternalSourceImpl marshal(ExternalSourceType v) throws Exception {
if( v == null )return null;
else if( v instanceof ExternalSourceImpl )return (ExternalSourceImpl)v;
else return new ExternalSourceImpl(v.getSourceId(), v.getSourceTimestamp());
}
}
@Override
@XmlElement
@XmlJavaTypeAdapter(SourceAdapter.class)
public ExternalSourceType getSource() {
return source;
}
......
......@@ -5,6 +5,7 @@ import java.io.IOException;
import java.io.StringReader;
import java.io.StringWriter;
import java.math.BigDecimal;
import java.time.Instant;
import javax.xml.XMLConstants;
import javax.xml.bind.JAXB;
......@@ -33,6 +34,7 @@ import de.sekmi.histream.DateTimeAccuracy;
import de.sekmi.histream.Modifier;
import de.sekmi.histream.Observation;
import de.sekmi.histream.Value;
import de.sekmi.histream.ext.ExternalSourceType;
public class ObservationImplJAXBTest {
public static final File EXAMPLE_FACT_XSD = new File("examples/fact.xsd");
......@@ -61,6 +63,7 @@ public class ObservationImplJAXBTest {
case 0:
// string value
o.setValue(new StringValue("strval"));
o.setSource(new ExternalSourceImpl("source1",Instant.now()));
break;
case 1:
// numeric value without modifiers
......@@ -141,11 +144,16 @@ public class ObservationImplJAXBTest {
Assert.assertEquals(Value.Type.Numeric, o.getValue().getType());
Assert.assertEquals(new BigDecimal(123), o.getValue().getNumericValue());
Assert.assertTrue(o.hasModifiers());
Modifier m = o.getModifier("M:test");
Assert.assertNotNull(m);
Assert.assertNotNull(m.getValue());
Assert.assertEquals(Value.Type.Text, m.getValue().getType());
Assert.assertEquals("123", m.getValue().getStringValue());
ExternalSourceType s = o.getSource();
Assert.assertNotNull(m);
Assert.assertEquals("system1", s.getSourceId());
}
}
......
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