HAPI FHIR的@Create操作未返回MethodOutcome响应。

huangapple go评论84阅读模式
英文:

HAPI FHIR @Create Operation not returning MethodOutcome 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());
    }
}

Link to hapishir's website

英文:

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&lt;? extends IBaseResource&gt; 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(&quot;Observation&quot;, newObservationId, &quot;1.0&quot;));
        retVal.setCreated(true);
    }else {
        OperationOutcome outcome = new OperationOutcome();
        outcome.addIssue().setDiagnostics(&quot;An Error Occurred&quot;);
        retVal.setOperationOutcome(outcome);
        retVal.setCreated(false);
    }

    
    return retVal;
}

}

SimpleRestfulServer.java

@WebServlet(&quot;/*&quot;)
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

得分: 1

我已经构建了一个环境并调试了服务器端的代码。
我确定你会从这里得到一些提示。在PreferReturnEnum中定义了三种模式,在HEADERS中使用键为“Prefer”、值为“return=OperationOutcome”的额外标头时,将返回在operationOutcome中定义的值。

英文:

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.

huangapple
  • 本文由 发表于 2020年10月9日 00:33:31
  • 转载请务必保留本文链接:https://go.coder-hub.com/64266873.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定