英文:
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());
}
}
英文:
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
得分: 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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论