如何为 Hapi Fhir 服务器实现 Observation Resource Provider 的搜索操作?

How to implement Search operation for an Observation Resource Provider for Hapi Fhir server?

我想了解 Hapi Fhir 中的 RESTful 服务器是如何工作的,我想为 Observation 资源实现一些 @Search 方法。

目前,我有这个@Read 操作,它在尝试从浏览器访问资源(如:http://localhost:8080/NewFHIRServer/fhir)时成功运行:

@Read()
public Observation readObservationById(@IdParam IdDt theId) {
    for (Entry<Long, Deque<Observation>> entry : myPatientIdToObservations.entrySet())
    {
        for (Observation obs : entry.getValue()) {
            if (obs.getId().equals(theId)) {
                return obs;
            }
        }
    }

    throw new ResourceNotFoundException(theId);
}    

但是,当我尝试对@Search 操作执行类似操作时,出现错误。我希望能够通过 运行 这样的(或类似的)搜索得到回复:

Bundle response = client
        .search()
        .forResource(Observation.class)
        .where(Observation.SUBJECT.hasId("Patient/1"))
        .execute();   

我的@Read 方法需要哪些参数才能实现这一点?我现在得到的错误如下:

The FHIR endpoint on this server does not know how to handle GET operation[Observation] with parameters [[subject]]

很明显为什么它不起作用,因为我的 header 看起来像这样:

public Observation searchObservationById(@IdParam IdDt theId)     

我一直在查看示例以尝试解决这个问题,但我不太明白此参数中的语法含义:

public List<Patient> getPatient(@RequiredParam(name = Patient.SP_FAMILY) StringParam theFamilyName)...

为了使用最后一个示例,您将如何进行查询?

谢谢

要实现搜索方法,您需要在方法上使用 @Search 而不是 @Read。然后,您使用零个或多个用 @OptionalParam@RequiredParam.

注释的参数

为了使您的特定示例工作,您需要一个实现 _id 搜索参数的搜索方法,例如

@Search public List<Patient> getPatient(@RequiredParam(name = Patient.SP_RES_ID) StringParam theId) { }