Try   HackMD

FHIR REST Operation

1. Read

Read Operation (인스턴스)란 리소스 ID를 입력값으로 요청하여 리턴값으로 리
소스를 받아 오는 기능을 제공하는 API이다.

  • @Read 애노테이션에서 명시되어 있다.
  • 최소한 하나의 @IdParam 파라미터값을 입력값으로 받아 처리한다.
  • 임의의 Patient ID를 받아 테스트 데이터로 생성한 Patient를 리턴값으로 돌려 주는 예제 코드를 만들어보자.
    아래의 getResourceById 메소드는 RestfulPatientResourceProvider 클래스 내부 에 (또는 어디든지 필요한 Provider 내부에) 구현할 수 있다.

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

  • 아래와 같이 테스트 URL을 실행하여 결과를 확인합니다.
http://localhost:8080/hapi-fhirstarters-simple-server/Patient/123
  • 실행 결과는 아래와 같가

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

2. Create

Read Operation (인스턴스)란 리소스 ID를 입력값으로 요청하여 리턴값으로 리
소스를 받아 오는 기능을 제공하는 API이다.

  • @Read 애노테이션에서 명시되어 있다.
  • 최소한 하나의 @IdParam 파라미터값을 입력값으로 받아 처리한다.
  • 임의의 Patient ID를 받아 테스트 데이터로 생성한 Patient를 리턴값으로 돌려 주는 예제 코드를 만들어보자.
    아래의 getResourceById 메소드는 RestfulPatientResourceProvider 클래스 내부 에 (또는 어디든지 필요한 Provider 내부에) 구현할 수 있다.

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

  • 요청 URL을 아래와 같이 설정합니다.
METHOD : POST

URL: http://localhost:8080/hapi-fhirstarters-simple-server/Patient
{
  "resourceType": "Patient",
  "id": "123",
  "meta": {},
  "versionId": "1",
  "identifier": [
    {
      "system": "urn:mrns",
      "value": "12345"
    }
  ],
  "name": [
    {
      "family": "Smith",
      "given": [
        "Tester",
        "Q"
      ]
    }
  ],
  "gender": "male",
  "birthDate": "1974-12-25",
  "deceasedBoolean": false,
  "address": [
    {
      "city": "Pleasantville",
      "district": "Rainbow",
      "state": "Vic",
      "postalCode": "3999"
    }
  ],
  "period": {
    "start": "1974-12-25"
  },
  "managingOrganization": {
    "reference": "Organization/1"
  }
}

3. Update

  • Update 오퍼레이션은 특정 리소스 인스턴스의 내용을 변경하기 위해 필요한 API이다.
    7 리소스 ID와 Version ID를 입력 파라미터로 받는다. (여러 버전간의 충돌을 피 하기 위해 필요)
  • Update 메소드는 @Update annotation으로 명시되어야 하며 @ResourceParam
    annotation으로 명시된 파라미터를 가져야 한다.
    이 파라미터는 생성을 요청한 리소스의 ID가 된다.
  • 추가적으로 이 메소드는 @IdParam annotation의 파라미터를 가질 수 있다.
  • Update 메소드는 MethodOutcome 객체를 리턴값으로 돌려줌 MethodOutcome 객체에는 변경된 컨텐츠 내용이 포함되어 있다.
  • 예제 코드
    Image Not Showing Possible Reasons
    • The image was uploaded to a note which you don't have access to
    • The note which the image was originally uploaded to has been deleted
    Learn More →
METHOD : PUT

URL: http://localhost:8080/hapi-fhirstarters-simple-server/Patient/123

4. Delete

  • Delete 오퍼레이션은 특정 ID로 지정된 리소스를 서버 저장소에서 제거하는 기능이다.
    리소스 ID는 @IdParam 애노테이션에서 명시된다.

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

METHOD : DELETE

URL: http://localhost:8080/hapi-fhirstarters-simple-server/Patient/1
  • Search 오퍼레이션은 서버에 저장된 리소스를 특정 조건을 기준으로 검색하여 부합하는 결과만을 가져오는 것이다.

  • FHIR 리소스에는 많은 엘리멘트들이 각각의 데이터 타입으로 정의되어 있으며, 검색 조건은 여러 개일수 있으므로 Search는 아주 단순한 조건부터 매우 복잡 한 조건까지 표현할 수 있어여 한다.

  • Search 조건은 URL의 파라미터로 표시된다. FHIR에서는 기본적으로 아래의 8 가지의 검색 파라미터를 제공한다.

    • Number
    • Date/DateTime
    • String
    • Token
    • Reference
    • Composite
    • Quantity
    • URI
  • 검색 API의 아노테이션은 @Search()이다. 아래와 같이 구현부를 PatientResource Provider.java 안에 추가하자.

@Search()
public List<Patient> searchByFamily(StringParam theFamily) {
    searchByLastName(@RequiredParam(name = Patient.SP_FAMILY))
    String valueToMatch = theFamily.getValue();
    if (theFamily.isExact()) {
        // Do an exact match search
    } else {
        // Do a fuzzy search if possible
        // ...populate...
        Patient patient = new Patient();
        patient.addIdentifier().setSystem("urn:mrns").setValue("12345");
        patient.addName().setFamily("Smith").addGiven("Tester").addGiven("Q");
        //...etc...
        // Every returned resource must have its logical ID set. If the server supports versioning, that should be set too
        String logicalId = "4325";
        String versionId = "2"; // optional
        patient.setId(new IdType("Patient", logicalId, versionId));

        // You could return as many resources as you wanted, and they should actually match the given search criteria.
        List<Patient> retVal = new ArrayList<>();
        retVal.add(patient);
        return retVal;
    }
}

  • 컴파일 후 서버를 가동하면 잊지 말고 Capability Statement를 출력하여 새 API 가 기능명세서에 추가되었는지 확인하자.
  • Search API가 올바르게 구현되었는지 아래의 테스트 URL을 브라우저에서 실행 하여 결과를 확인하자.
http://localhost:8080/hapi-fhirstarters-simple-server/Patient?family=smith