首页 > 解决方案 > Hapi Fhir 查询与 AND / OR 与地图

问题描述

使用 Hapi Fhir,我尝试编写一个查询以使用地图传递 where 条件,如下所示:

Map<String, List<IQueryParameterType>> hmParameter = criteria.getMapForWhere();

Bundle bundle = fhirClientR4Configuration.clientFhihrR4().search().forResource(ServiceRequest.class)
            .where(hmParameter).returnBundle(Bundle.class).execute();

我的条件对象有一个方法getMapForWhere(),我用包装器前端对象中的信息填充此映射,如下所示:

public Map<String, List<IQueryParameterType>> getMapForWhere() {
    Map<String, List<IQueryParameterType>> hmOut = new HashMap<String, List<IQueryParameterType>>();
    // Adding STATUS
    if (this.status != null && !this.status.equals("")) {
        StringParam sp = new StringParam();
        sp.setValue(this.status);
        List<IQueryParameterType> lst = new ArrayList<IQueryParameterType>();
        lst.add(sp);
        hmOut.put(ServiceRequest.SP_STATUS, lst);
    }

    // Adding INTENT
    if (this.intent != null && !this.intent.equals("")) {
        StringParam sp = new StringParam();
        sp.setValue(this.intent);
        List<IQueryParameterType> lst = new ArrayList<IQueryParameterType>();
        lst.add(sp);
        hmOut.put(ServiceRequest.SP_INTENT, lst);
    }

    return hmOut;
}

当我想用所有 AND 编写查询时,此代码工作正常。

但是如果我想添加另一个条件如下:

    List<IQueryParameterOr> lstOr = new ArrayList<IQueryParameterOr>();
    
    StringOrListParam lstServices = new StringOrListParam();
    
    StringParam sp = new StringParam();
    StringParam sg = new StringParam();
    
    sp.setValue(MEDICAL_SERVICE_PAI);
    sg.setValue(SOCIAL_SERVICE_PAI);
    lstServices.addOr(sp);
    lstServices.addOr(sg);
    lstOr.add(lstServices);
    
    hmOut.put(ServiceRequest.SP_CATEGORY, lstOr);

显然 hmOut 出错了,因为该映射的定义不同。但我不知道如何转换IParameterOrIParameterType.

标签: hapi-fhirhl7-fhir

解决方案


推荐阅读