FHIR Chat · JAVA, OperationOutcome.issue.code · implementers

Stream: implementers

Topic: JAVA, OperationOutcome.issue.code


view this post on Zulip Zak Guler (Aug 17 2018 at 19:42):

first timer, I am new to HAPI/FHIR and to this forum. hope some one will be kind to answer a simple How-To question:
I am trying to generate the following Java Rest response:

http://hapi.fhir.org/baseDstu3/MAMA?given=Ruth&_pretty=true

***Unknown resource type MAMA
        {
          "resourceType": "OperationOutcome",
          "text": {
            "status": "generated",
            "div": "<div xmlns=\"http://www.w3.org/1999/xhtml\"><h1>Operation Outcome</h1><table border=\"0\"><tr><td style=\"font-weight: bold;\">ERROR</td><td>[]</td><td><pre>Unknown resource type 'MAMA' - Server knows how to handle: [Appointment, Account,...]</pre></td>\n\t\t\t\t\t\n\t\t\t\t\n\t\t\t</tr>\n\t\t</table>\n\t</div>"
          },
          "issue": [
            {
              "severity": "error",
              "code": "processing",
              "diagnostics": "Unknown resource type 'MAMA' - Server knows how to handle: [Appointment, Account, ..."
            }
          ]
        }

*** I was unable to generate 'OperationOutcome.issue.code'.

the following is the sample code I used:
OperationOutcome outcome = new OperationOutcome();

        outcome.getText().setStatusAsString("generated");
        outcome.getText().setDivAsString("<div>Unknown resource type 'MAMA' - Server knows how to handle: [Appointment, Account,...]</div>");

        outcome.addIssue()
                .setSeverity(OperationOutcome.IssueSeverity.ERROR)
                .setDiagnostics("Unknown resource type 'MAMA' - Server knows how to handle: [Appointment, Account, ...]");

        FhirContext ctx = config.getCtx();          
        String outFhirString = ""; 
        outFhirString = ctx.newJsonParser().setPrettyPrint(true).encodeResourceToString(outcome);   
        return outFhirString;

I couldn't find a way to do the following 'outcome.addIssue().setCode("xyz..");'

this may be a basic question but I couldn't find a way to implement it. any help would be appreciated.
thanx
Zak zguler@utah.gov

view this post on Zulip Lloyd McKenzie (Aug 17 2018 at 19:48):

@James Agnew ?

view this post on Zulip Zak Guler (Aug 17 2018 at 19:48):

(deleted)

view this post on Zulip Grahame Grieve (Aug 17 2018 at 20:26):

you are better to use the enumeration

view this post on Zulip Grahame Grieve (Aug 17 2018 at 20:26):

.addIssue().setCode(IssueType.xxx)

view this post on Zulip Grahame Grieve (Aug 17 2018 at 20:27):

if you really want to use a string:
.addIssue().getCodeAsElement().setValueAsString("....")- but you still must use one of the valid enumeration strings

view this post on Zulip Zak Guler (Aug 20 2018 at 15:32):

but, there is no .addIssue().addCode() in the api that I am using. that is why I was unable to set the code. I wonder if I need to use different jars?

the jar files I am using is for STU3:
<dependency>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-fhir-base</artifactId>
<version>3.3.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/ca.uhn.hapi.fhir/hapi-fhir-structures-dstu3 -->
<dependency>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-fhir-structures-dstu3</artifactId>
<version>3.3.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/ca.uhn.hapi.fhir/hapi-fhir-client -->
<dependency>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-fhir-client</artifactId>
<version>3.3.0</version>
</dependency>

view this post on Zulip Grahame Grieve (Aug 20 2018 at 15:53):

@James Agnew

view this post on Zulip James Agnew (Aug 20 2018 at 17:58):

Up until HAPI FHIR 3.4.0, the response error for trying to access an unknown resource was pretty much hardcoded into HAPI.

By coincidence, this just changed a few weeks ago. If you are ok with using the current pre-release version (3.5.0-SNAPSHOT) you can override throwUnknownResourceTypeException(String) on RestfulServer. In your method, you throw ResourceNotFoundException, and you can pass in an OperationOutcome if you want.

view this post on Zulip Zak Guler (Aug 20 2018 at 18:34):

in my case, I am not using a RestfulServer. I am getting the Patient data from our server and use "ctx = FhirContext.forDstu3()" to build a client response. the challenge now is the api I am using OperationOutcome does not have a method called .addCode() in it. so how can I add the Code to the Issue element like:
operationOutcome .addIssue().addCode(IssueType.xxx); ???
Am I using the wrong jar file? or am I using the wrong version 3.0.0??? this is the kind of help that I need. where can I find method "addIssue().addCode()"???
thank you for your help.

view this post on Zulip Zak Guler (Aug 20 2018 at 18:35):

Or getIssue().SetCode()!!!

view this post on Zulip Zak Guler (Aug 20 2018 at 20:03):

ooh, so Sorry, silly me.
I was looking for addCode() and when I looked more closely to Grahame Grieve's response it was setCode() and not addCode() like the others.

view this post on Zulip James Agnew (Aug 20 2018 at 21:34):

Yup, it's setCode. If you're curious, the reason for that is that we use addFoo for repeating things, but not for 1..1 things.

view this post on Zulip Zak Guler (Aug 20 2018 at 22:18):

thank you for clarifying some things for me. I am new to FHIR and I am trying to learn it as soon as I can. so much to explore but it is getting easier as I go.


Last updated: Apr 12 2022 at 19:14 UTC