0

I was basing my program off of the samples on hapishir's website and the operation works in that I receive the JSON body and I'm updating the database. The issue I have though is that there is no response being returned. I build the MethodOutcome object, and "return" it, but nothing appears in postman. I've written @read and @Search operations also and those both return the resource in the response on Postmat, but this @Create doesn't return any response.

ObservationResourceProvider.java

public class ObservationResourceProvider implements IResourceProvider {

public ObservationResourceProvider() {    }

@Override
public Class<? extends IBaseResource> getResourceType() {
    return Observation.class;
}

@Create()
public MethodOutcome createObservation(@ResourceParam Observation observation){
    
    OpenERMDatabase db = new OpenERMDatabase();
    String newObservationId = db.addNewObservation(observation);

    //return the new Id if success else return an error message
    MethodOutcome retVal = new MethodOutcome();
    if (newObservationId != null) {
        retVal.setId(new IdType("Observation", newObservationId, "1.0"));
        retVal.setCreated(true);
    }else {
        OperationOutcome outcome = new OperationOutcome();
        outcome.addIssue().setDiagnostics("An Error Occurred");
        retVal.setOperationOutcome(outcome);
        retVal.setCreated(false);
    }

    
    return retVal;
}

}

SimpleRestfulServer.java

@WebServlet("/*")
public class SimpleRestfulServer extends RestfulServer{

//Initialize
@Override
protected void initialize()throws ServletException{
    //create a context for the appropriate version
    setFhirContext(FhirContext.forDstu3());

    //Register Resource Providers
    registerProvider(new PatientResourceProvider());
    registerProvider(new ObservationResourceProvider());

}
}
Travis Frazier
  • 441
  • 3
  • 13
  • It'd be wise to detail what you are seeing in postman. You don't see "nothing". You see response headers, response status, etc. etc. The only time you truly see nothing is if the request fails to execute in it's entirety, usually because you have the wrong URL. – Gimby Oct 12 '20 at 13:24
  • That's a good point. The body has nothing in it, there is header data though which includes a "location" field that has "http://localhost:15437/Observation//_history/1.0" in it which could be used to get the ID value of the newly created , but there is never any diagnostic information for the fail scenario in the body or header. Where could I find that? – Travis Frazier Oct 12 '20 at 14:05
  • That sounds like expected behavior to me. FHIR is based on a pure REST implementation and a pure REST implementation dictates that in a response you can figure out the location of a created entity. You have that information in the response header apparently. Is it documented somewhere that you are supposed to get a JSON response body? – Gimby Oct 13 '20 at 15:18
  • I don't really care if it's in the header or the body, but I still don't see any information for Diagnostics. If its not returned in the body, and I don't see anything in the header for it in the fail tests I run, then how do I find this info? – Travis Frazier Oct 13 '20 at 18:19
  • ... by requesting the location URL that you get? – Gimby Oct 15 '20 at 11:40
  • When I tried it days ago it just returned errors saying "Invalid request Invalid request: The FHIR endpoint on this server does not know how to handle GET operation[Observation/1/_history/1.0] with parameters [[]]". If there is something I need to set up for that url to work to get diagnostic information then could you link it? – Travis Frazier Oct 15 '20 at 14:25

1 Answers1

1

I've built an environment and debugged the server side code. I'm sure you will get some hint from this. There are three modes defined in PreferReturnEnum, when you specify an extra header in the HEADERS with key as "Prefer" and value as " return=OperationOutcome", the value defined in operationOutcome will be retured.

Wilson.F
  • 49
  • 3