Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
AKTIN
dwh-import
Commits
d519ef92
Commit
d519ef92
authored
Apr 17, 2019
by
R.W.Majeed
Browse files
implemented outcome message filtering.
support more levels for debug logging.
parent
70833b70
Changes
2
Hide whitespace changes
Inline
Side-by-side
cda-server/src/main/java/org/aktin/cda/etl/fhir/Binary.java
View file @
d519ef92
...
...
@@ -49,6 +49,7 @@ import org.aktin.cda.Validator;
import
org.aktin.cda.etl.fhir.SimplifiedOperationOutcome.IssueType
;
import
org.aktin.cda.etl.fhir.SimplifiedOperationOutcome.Severity
;
import
org.aktin.dwh.ImportSummary
;
import
org.aktin.dwh.PreferenceKey
;
import
org.w3c.dom.Document
;
@Path
(
"Binary"
)
...
...
@@ -128,6 +129,33 @@ public class Binary implements ExternalInterface{
private
DataSource
serverErrorOutcome
(
Throwable
e
)
throws
XMLStreamException
{
return
outcomeToXML
(
SimplifiedOperationOutcome
.
error
(
e
));
}
/**
* Filter the operation outcome messages according to the configuration.
* E.g. remove entries with level below a certain treshold
* @param outcome outcome to filter
*/
private
void
filterOutcome
(
SimplifiedOperationOutcome
outcome
)
{
String
filter
=
prefs
.
get
(
PreferenceKey
.
importCdaFhirOutcomeLevel
);
if
(
filter
==
null
||
filter
.
length
()
==
0
||
filter
.
equals
(
"all"
)
)
{
return
;
// nothing to do
}
switch
(
filter
)
{
case
"info"
:
outcome
.
removeIssuesBelowSeverity
(
Severity
.
information
);
break
;
case
"warning"
:
outcome
.
removeIssuesBelowSeverity
(
Severity
.
warning
);
break
;
case
"error"
:
outcome
.
removeIssuesBelowSeverity
(
Severity
.
error
);
break
;
case
"none"
:
outcome
.
removeAllIssues
();
break
;
}
}
@POST
public
Response
create
(
Source
doc
){
SimplifiedOperationOutcome
outcome
=
new
SimplifiedOperationOutcome
();
...
...
@@ -226,14 +254,37 @@ public class Binary implements ExternalInterface{
}
private
void
tryDebugProcessing
(
Document
cda
,
SimplifiedOperationOutcome
outcome
){
String
debugDir
=
prefs
.
get
(
"import.cda.d
ebug
.d
ir
"
);
String
debugDir
=
prefs
.
get
(
PreferenceKey
.
importCdaD
ebug
D
ir
);
if
(
debugDir
==
null
||
debugDir
.
length
()
==
0
){
return
;
// nothing to do
}
String
debugLevel
=
prefs
.
get
(
"import.cda.debug.level"
);
if
(
debugLevel
!=
null
&&
debugLevel
.
equals
(
"error"
)
&&
outcome
.
getIssueCount
()
==
0
){
// dump only documents with errors
return
;
// nothing to do
String
debugLevel
=
prefs
.
get
(
PreferenceKey
.
importCdaDebugLevel
);
if
(
debugLevel
==
null
)
{
// unset debug level defaults to all documents
debugLevel
=
"all"
;
}
if
(
debugLevel
.
equals
(
"none"
)
)
{
// logging disables
return
;
}
int
[]
counts
=
outcome
.
getDetailedCounts
();
// add more severe messages to lesser ones
counts
[
1
]
+=
counts
[
0
];
// warning logging also includes error logging
counts
[
2
]
+=
counts
[
1
];
// info logging also includes error and warning logging
if
(
debugLevel
.
equals
(
"all"
)
)
{
// continue to store all documents
}
else
if
(
debugLevel
.
equals
(
"error"
)
&&
counts
[
0
]
==
0
)
{
// level is error but no errors occurred,
// skip this document
return
;
}
else
if
(
debugLevel
.
equals
(
"warning"
)
&&
counts
[
1
]
==
0
)
{
// level is warning, but no warnings (or errors) occurred,
// skip document
return
;
}
else
if
(
debugLevel
.
equals
(
"info"
)
&&
counts
[
2
]
==
0
)
{
// level is info, but no info message (or warnings/errors) occurred
// skip document
return
;
}
// XXX maybe extract patient id extension for name?
...
...
@@ -264,7 +315,7 @@ public class Binary implements ExternalInterface{
log
.
warning
(
"Failed to configure indent for XML debug documents: "
+
e
.
getMessage
());
}
copy
.
transform
(
src
,
new
StreamResult
(
out
));
// write
error
s in XML comment after content
// write
message
s in XML comment after content
out
.
write
(
"\n\n<!-- OperationOutcome\n"
);
out
.
write
(
outcome
.
toString
().
replaceAll
(
"<"
,
"<"
));
out
.
write
(
"\n-->\n"
);
...
...
cda-server/src/main/java/org/aktin/cda/etl/fhir/SimplifiedOperationOutcome.java
View file @
d519ef92
...
...
@@ -3,7 +3,10 @@ package org.aktin.cda.etl.fhir;
import
java.io.PrintWriter
;
import
java.io.StringWriter
;
import
java.util.ArrayList
;
import
java.util.HashSet
;
import
java.util.Iterator
;
import
java.util.List
;
import
java.util.Set
;
import
javax.activation.DataSource
;
import
javax.xml.XMLConstants
;
...
...
@@ -103,6 +106,29 @@ public class SimplifiedOperationOutcome {
public
int
getIssueCount
(){
return
issues
.
size
();
}
/**
* Retrieve detailed counts for debugging levels in the following order: errors, warnings, informational
* @return array containing detailed counts for the outcome resource
*/
public
int
[]
getDetailedCounts
()
{
int
[]
counts
=
new
int
[
3
];
for
(
Issue
issue
:
issues
)
{
switch
(
issue
.
severity
){
case
error:
case
fatal:
counts
[
0
]++;
break
;
case
warning:
counts
[
1
]++;
break
;
case
information:
counts
[
2
]++;
break
;
default
:
}
}
return
counts
;
}
/**
* Add an issue to the response
* @param severity issue severity
...
...
@@ -134,6 +160,39 @@ public class SimplifiedOperationOutcome {
}
writer
.
writeEndElement
();
}
/**
* Remove issues below a certain severity.
* E.g. if the limit is {@code error} then warning and information messages are removed.
* Limit of {@code information} has no effect, since no messages are below.}
* To remove all issues, use {@link #removeAllIssues()}
* @param severity. {@code null}
*/
public
void
removeIssuesBelowSeverity
(
Severity
limit
)
{
Iterator
<
Issue
>
i
=
issues
.
iterator
();
Set
<
Severity
>
forRemoval
=
new
HashSet
<>();
switch
(
limit
)
{
case
fatal:
case
error:
forRemoval
.
add
(
Severity
.
warning
);
case
warning:
forRemoval
.
add
(
Severity
.
information
);
case
information:
default
:
}
while
(
i
.
hasNext
()
)
{
Issue
e
=
i
.
next
();
if
(
forRemoval
.
contains
(
e
.
severity
)
)
{
i
.
remove
();
}
}
}
/**
* Remove all reported issues from the list.
*/
public
void
removeAllIssues
()
{
issues
.
clear
();
}
/**
* Generate the XML representation of the response
*
...
...
Write
Preview
Supports
Markdown
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