FHIR、FAPI 初体验

初步学习FHIR的话还是要先去官方文档中学习一些基础的概念,首选要知道FHIR是干什么用的。

Resourcelist - FHIR v4.3.0)这个官网的地址。

FHIR 是由 HL7® 发布的医疗保健数据交换标准。

看完介绍。我们可以根据我们的需求来看看有哪些资源类型, 比如我们要看一下Patient(患者)的一个规范。

这里有资源的内容和格式,可以通过查看json格式来了解Patient的数据格式和规范。

 在这里对患者就有了个规范有了初步了解,那我们怎么把他结合java代码呢。就用到HAPI了Profiles and Extensions - HAPI FHIR DocumentationResource Providers and Plain Providers - HAPI FHIR DocumentationProfiles and Extensions - HAPI FHIR Documentation

在这里我结合springboot简单的说一下

首先 在pom文件中加入

<hapifhir.version>5.7.2</hapifhir.version>
<!-- This dependency includes the core HAPI-FHIR classes -->
<dependency>
    <groupId>ca.uhn.hapi.fhir</groupId>
    <artifactId>hapi-fhir-base</artifactId>
    <version>${hapifhir.version}</version>
</dependency>

<!-- At least one "structures" JAR must also be included -->
<dependency>
    <groupId>ca.uhn.hapi.fhir</groupId>
    <artifactId>hapi-fhir-structures-r4</artifactId>
    <version>${hapifhir.version}</version>
</dependency>
<dependency>
    <groupId>ca.uhn.hapi.fhir</groupId>
    <artifactId>hapi-fhir-validation-resources-r4</artifactId>
    <version>${hapifhir.version}</version>
</dependency>

package com.ha.fhir.provide.controller;

import ca.uhn.fhir.rest.annotation.*;
import ca.uhn.fhir.rest.param.StringParam;
import ca.uhn.fhir.rest.server.IResourceProvider;
import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException;
import com.ha.fhir.BaseProvider;
import org.hl7.fhir.instance.model.api.IBaseResource;
import org.hl7.fhir.r4.model.Enumerations;
import org.hl7.fhir.r4.model.IdType;
import org.hl7.fhir.r4.model.Patient;

import java.util.*;

public class RestfulPatientResourceProvider extends BaseProvider implements IResourceProvider {
    private Map<String, Patient> myPatients = new HashMap();

    @Override
    public Class<? extends IBaseResource> getResourceType() {
        return Patient.class;
    }

    public RestfulPatientResourceProvider(){
        Patient patient = new Patient();
        patient.setId("1");
        patient.addIdentifier();
        patient.getIdentifier().get(0).setSystem("urn:hapitest:mrns");
        patient.getIdentifier().get(0).setValue("00002");
        patient.addName().setFamily("Curry");
        patient.getName().get(0).addGiven("PatientOne");
        patient.setGender(Enumerations.AdministrativeGender.FEMALE);
        patient.addGeneralPractitioner().setReference("sss");
        myPatients.put(patient.getId(),patient);
    }

    @Read()
    public Patient getResourceById(@IdParam IdType theId) {
        Patient patient = myPatients.get(theId.getIdPart());
        if (patient == null) {
            throw new ResourceNotFoundException(theId);
        }
        return patient;
    }

    @Search()
    public List<Patient> search() {
        List<Patient> list = new ArrayList<Patient>();
        list.addAll(myPatients.values());
        return list;
    }

    @Search
    public List<Patient> search(@RequiredParam(name = Patient.SP_FAMILY) StringParam theParam) {
        List<Patient> list = new ArrayList<Patient>();
        // Loop through the patients looking for matches
        for (Patient patient : myPatients.values()) {
            String familyName = patient.getNameFirstRep().getFamily().toLowerCase();
            if (familyName.contains(theParam.getValue().toLowerCase()) == false) {
                continue;
            }
            list.add(patient);
        }
        return list;
    }

}

 

 这里的@Read()类似spring boot中的@Get。HAPI中有自己的restful接口定义。

这里再介绍一下 model-mapper ModelMapper - Getting Started.

我们在获取其他地方的患者数据时可能是不满足FHIR规范,所以需要mapping成我们FHIR标准的一个实体类。再转成我们的FHIR标准进行一个输出。

HAPI还提供了校验FHIR格式的方法。

这是多json格式的验证

 这是对xml格式的验证

 

首次写博客请大家多多指教

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值