HAPI FHIR @Create Operation not returning MethodOutcome Response

738 views Asked by At

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());

}
}
1

There are 1 answers

0
Wilson.F On

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.