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

don't write empty operation outcome, add ok information if empty

parent f059485a
...@@ -65,6 +65,7 @@ public class SimplifiedOperationOutcome { ...@@ -65,6 +65,7 @@ public class SimplifiedOperationOutcome {
public static class Issue{ public static class Issue{
Severity severity; Severity severity;
String details; String details;
String diagnostics;
IssueType code; IssueType code;
public Issue(Severity severity, IssueType type, String details){ public Issue(Severity severity, IssueType type, String details){
this.severity = severity; this.severity = severity;
...@@ -86,6 +87,11 @@ public class SimplifiedOperationOutcome { ...@@ -86,6 +87,11 @@ public class SimplifiedOperationOutcome {
break; break;
} }
} }
public static Issue diagnosticInfo(String message){
Issue i = new Issue(Severity.information, IssueType.informational, null);
i.diagnostics = "all ok";
return i;
}
} }
private List<Issue> issues; private List<Issue> issues;
...@@ -109,7 +115,25 @@ public class SimplifiedOperationOutcome { ...@@ -109,7 +115,25 @@ public class SimplifiedOperationOutcome {
public void addIssue(Severity severity, IssueType type, String details){ public void addIssue(Severity severity, IssueType type, String details){
issues.add(new Issue(severity, details)); issues.add(new Issue(severity, details));
} }
private void writeIssue(XMLStreamWriter writer, Issue issue) throws XMLStreamException{
writer.writeStartElement("issue");
// severity
writer.writeStartElement("severity");
writer.writeAttribute("value", issue.severity.name());
writer.writeEndElement();
// code
writer.writeStartElement("code");
writer.writeAttribute("value", issue.code.value);
writer.writeEndElement();
if( issue.details != null ){
writer.writeStartElement("details");
writer.writeAttribute("value", issue.details);
writer.writeEndElement();
}
writer.writeEndElement();
}
/** /**
* Generate the XML representation of the response * Generate the XML representation of the response
* *
...@@ -128,22 +152,11 @@ public class SimplifiedOperationOutcome { ...@@ -128,22 +152,11 @@ public class SimplifiedOperationOutcome {
// writer.setDefaultNamespace(FHIR_NAMESPACE); // writer.setDefaultNamespace(FHIR_NAMESPACE);
// writer.writeDefaultNamespace(FHIR_NAMESPACE); // writer.writeDefaultNamespace(FHIR_NAMESPACE);
for( Issue issue : issues ){ for( Issue issue : issues ){
writer.writeStartElement("issue"); writeIssue(writer, issue);
// severity }
writer.writeStartElement("severity"); // prevent empty ObservationOutcome. Write success info for empty issues
writer.writeAttribute("value", issue.severity.name()); if( issues.isEmpty() ){
writer.writeEndElement(); writeIssue(writer, Issue.diagnosticInfo("all ok"));
// code
writer.writeStartElement("code");
writer.writeAttribute("value", issue.code.value);
writer.writeEndElement();
if( issue.details != null ){
writer.writeStartElement("details");
writer.writeAttribute("value", issue.details);
writer.writeEndElement();
}
writer.writeEndElement();
} }
writer.writeEndElement(); writer.writeEndElement();
writer.writeEndDocument(); writer.writeEndDocument();
......
Supports Markdown
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