Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
H
histream
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
Operations
Operations
Incidents
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Raphael
histream
Commits
67e399fd
Commit
67e399fd
authored
Aug 22, 2017
by
R.W.Majeed
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
allow time zone specification for XML output of timestamps
parent
b8a123f9
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
4 deletions
+32
-4
histream-core/src/main/java/de/sekmi/histream/io/GroupedXMLWriter.java
.../src/main/java/de/sekmi/histream/io/GroupedXMLWriter.java
+19
-4
histream-core/src/test/java/de/sekmi/histream/io/TestXMLWriter.java
...ore/src/test/java/de/sekmi/histream/io/TestXMLWriter.java
+13
-0
No files found.
histream-core/src/main/java/de/sekmi/histream/io/GroupedXMLWriter.java
View file @
67e399fd
package
de.sekmi.histream.io
;
package
de.sekmi.histream.io
;
import
java.io.OutputStream
;
import
java.io.OutputStream
;
import
java.time.ZoneId
;
import
javax.xml.XMLConstants
;
import
javax.xml.XMLConstants
;
import
javax.xml.bind.JAXBContext
;
import
javax.xml.bind.JAXBContext
;
...
@@ -21,6 +22,7 @@ import de.sekmi.histream.impl.ExternalSourceImpl;
...
@@ -21,6 +22,7 @@ import de.sekmi.histream.impl.ExternalSourceImpl;
import
de.sekmi.histream.impl.GroupedObservationHandler
;
import
de.sekmi.histream.impl.GroupedObservationHandler
;
import
de.sekmi.histream.impl.Meta
;
import
de.sekmi.histream.impl.Meta
;
import
de.sekmi.histream.impl.ObservationImpl
;
import
de.sekmi.histream.impl.ObservationImpl
;
import
de.sekmi.histream.xml.DateTimeAccuracyAdapter
;
/**
/**
* Writes observations to a single XML file. Observations must be grouped by patient and encounter.
* Writes observations to a single XML file. Observations must be grouped by patient and encounter.
...
@@ -36,6 +38,7 @@ public class GroupedXMLWriter extends GroupedObservationHandler{
...
@@ -36,6 +38,7 @@ public class GroupedXMLWriter extends GroupedObservationHandler{
private
int
formattingDepth
;
private
int
formattingDepth
;
private
Meta
meta
;
private
Meta
meta
;
private
int
observationCount
;
private
int
observationCount
;
private
ZoneId
zoneId
;
/**
/**
* Used to output XML
* Used to output XML
...
@@ -101,6 +104,18 @@ public class GroupedXMLWriter extends GroupedObservationHandler{
...
@@ -101,6 +104,18 @@ public class GroupedXMLWriter extends GroupedObservationHandler{
}
catch
(
PropertyException
e
)
{
}
catch
(
PropertyException
e
)
{
}
}
}
}
/**
* Set the timezone id for output of timestamp values.
* @param timeZone zone id or {@code null} to omit zone offset information
*/
public
void
setZoneId
(
ZoneId
timeZone
){
this
.
zoneId
=
timeZone
;
// modify marshaller to use the timezone for timestamps
DateTimeAccuracyAdapter
a
=
new
DateTimeAccuracyAdapter
();
a
.
setZoneId
(
zoneId
);
marshaller
.
setAdapter
(
DateTimeAccuracyAdapter
.
class
,
a
);
}
@Override
@Override
protected
void
beginStream
()
throws
ObservationException
{
protected
void
beginStream
()
throws
ObservationException
{
...
@@ -162,14 +177,14 @@ public class GroupedXMLWriter extends GroupedObservationHandler{
...
@@ -162,14 +177,14 @@ public class GroupedXMLWriter extends GroupedObservationHandler{
if
(
visit
.
getStartTime
()
!=
null
){
if
(
visit
.
getStartTime
()
!=
null
){
formatIndent
();
formatIndent
();
writer
.
writeStartElement
(
XMLConstants
.
DEFAULT_NS_PREFIX
,
"start"
,
NAMESPACE
);
writer
.
writeStartElement
(
XMLConstants
.
DEFAULT_NS_PREFIX
,
"start"
,
NAMESPACE
);
writer
.
writeCharacters
(
visit
.
getStartTime
().
toPartialIso8601
());
writer
.
writeCharacters
(
visit
.
getStartTime
().
toPartialIso8601
(
zoneId
));
writer
.
writeEndElement
();
writer
.
writeEndElement
();
formatNewline
();
formatNewline
();
}
}
if
(
visit
.
getEndTime
()
!=
null
){
if
(
visit
.
getEndTime
()
!=
null
){
formatIndent
();
formatIndent
();
writer
.
writeStartElement
(
XMLConstants
.
DEFAULT_NS_PREFIX
,
"end"
,
NAMESPACE
);
writer
.
writeStartElement
(
XMLConstants
.
DEFAULT_NS_PREFIX
,
"end"
,
NAMESPACE
);
writer
.
writeCharacters
(
visit
.
getEndTime
().
toPartialIso8601
());
writer
.
writeCharacters
(
visit
.
getEndTime
().
toPartialIso8601
(
zoneId
));
writer
.
writeEndElement
();
writer
.
writeEndElement
();
formatNewline
();
formatNewline
();
}
}
...
@@ -270,7 +285,7 @@ public class GroupedXMLWriter extends GroupedObservationHandler{
...
@@ -270,7 +285,7 @@ public class GroupedXMLWriter extends GroupedObservationHandler{
if
(
patient
.
getBirthDate
()
!=
null
){
if
(
patient
.
getBirthDate
()
!=
null
){
formatIndent
();
formatIndent
();
writer
.
writeStartElement
(
XMLConstants
.
DEFAULT_NS_PREFIX
,
"birthdate"
,
NAMESPACE
);
writer
.
writeStartElement
(
XMLConstants
.
DEFAULT_NS_PREFIX
,
"birthdate"
,
NAMESPACE
);
writer
.
writeCharacters
(
patient
.
getBirthDate
().
toPartialIso8601
());
writer
.
writeCharacters
(
patient
.
getBirthDate
().
toPartialIso8601
(
zoneId
));
writer
.
writeEndElement
();
writer
.
writeEndElement
();
formatNewline
();
formatNewline
();
}
}
...
@@ -280,7 +295,7 @@ public class GroupedXMLWriter extends GroupedObservationHandler{
...
@@ -280,7 +295,7 @@ public class GroupedXMLWriter extends GroupedObservationHandler{
formatIndent
();
formatIndent
();
writer
.
writeStartElement
(
XMLConstants
.
DEFAULT_NS_PREFIX
,
"deceased"
,
NAMESPACE
);
writer
.
writeStartElement
(
XMLConstants
.
DEFAULT_NS_PREFIX
,
"deceased"
,
NAMESPACE
);
if
(
patient
.
getDeathDate
()
!=
null
){
if
(
patient
.
getDeathDate
()
!=
null
){
writer
.
writeCharacters
(
patient
.
getDeathDate
().
toPartialIso8601
());
writer
.
writeCharacters
(
patient
.
getDeathDate
().
toPartialIso8601
(
zoneId
));
}
}
writer
.
writeEndElement
();
writer
.
writeEndElement
();
formatNewline
();
formatNewline
();
...
...
histream-core/src/test/java/de/sekmi/histream/io/TestXMLWriter.java
View file @
67e399fd
...
@@ -8,6 +8,7 @@ import java.io.OutputStream;
...
@@ -8,6 +8,7 @@ import java.io.OutputStream;
import
java.nio.file.Files
;
import
java.nio.file.Files
;
import
java.nio.file.Path
;
import
java.nio.file.Path
;
import
java.time.Instant
;
import
java.time.Instant
;
import
java.time.ZoneId
;
import
javax.xml.XMLConstants
;
import
javax.xml.XMLConstants
;
import
javax.xml.bind.JAXB
;
import
javax.xml.bind.JAXB
;
...
@@ -189,6 +190,18 @@ public class TestXMLWriter {
...
@@ -189,6 +190,18 @@ public class TestXMLWriter {
w
.
close
();
w
.
close
();
s
.
close
();
s
.
close
();
}
}
@Test
public
void
testTimestampsWithZoneOffset
()
throws
Exception
{
FileObservationProviderTest
t
=
new
FileObservationProviderTest
();
t
.
initializeObservationFactory
();
ObservationSupplier
s
=
t
.
getExampleSupplier
();
GroupedXMLWriter
w
=
new
GroupedXMLWriter
(
debugLog
);
w
.
setZoneId
(
ZoneId
.
of
(
"Asia/Shanghai"
));
Meta
.
transfer
(
s
,
w
);
Streams
.
transfer
(
s
,
w
);
w
.
close
();
s
.
close
();
}
@Test
@Test
public
void
testWriteMeta
(){
public
void
testWriteMeta
(){
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment