初步学习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文件中加入
5.7.2
ca.uhn.hapi.fhir hapi-fhir-base${hapifhir.version} ca.uhn.hapi.fhir hapi-fhir-structures-r4${hapifhir.version} ca.uhn.hapi.fhir hapi-fhir-validation-resources-r4${hapifhir.version}
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 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 search() {
List list = new ArrayList();
list.addAll(myPatients.values());
return list;
}
@Search
public List search(@RequiredParam(name = Patient.SP_FAMILY) StringParam theParam) {
List list = new ArrayList();
// 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格式的验证
首次写博客请大家多多指教



