BBahmni 한국어 매뉴얼검색
한국어 번역 완료
한국어English

CRUD API(*Resource.java) 추가

이 문서는 OpenMRS 모듈에 새 리소스를 추가하는 방법을 자세히 설명합니다.

편의를 위해 수술실의 Surgical Block 리소스를 예로 사용하겠습니다. 리소스는 여기에서 확인할 수 있습니다.관련 문서: here

Web API는 일반적으로 모듈 코드의 omod 폴더에 추가합니다. 새 리소스를 추가하려면 다음 위치로 이동합니다.

openmrs-module-operationtheater/omod/src/main/java/org/openmrs/module/operationtheater/web/resource

폴더입니다.

  • DataDelegatingCrudResource를 확장하는 새 파일 SurgicalBlockResource를 생성합니다 => <도메인 객체 이름>Resource.java JVM이 리소스로 식별하도록 @Resource 애너테이션을 지정합니다. 이름, 지원 클래스(API 호출로 불러올 모델/객체), OpenMRS 런타임 버전도 지정해야 합니다. 예: java]]>
@Resource(name = "/surgicalBlock1", supportedClass = SurgicalBlock.class, supportedOpenmrsVersions = {"2.0.*", "2.1.*"}) 
public class SurgicalOperationResource extends DataDelegatingCrudResource<SurgicalBlock>
  1. getByUniqueId(String uuid): UUID로 GET 요청 delete(Surgical block, String uuid, RequestContext, requestContext) save(SurgicalBlock surgicalBlock): 객체 생성 update(String uuid, SimpleObject propertiesToUpdate, RequestContext context): 객체 갱신 getRepresentationDescription(Representation representation): 표현 유형을 입력받아 DelegatingResourceDescription 객체를 반환합니다. 표현 입력에 따라 응답 구조를 다르게 만들 수 있습니다. 표현은 Ref, Default, Full 세 가지입니다.
if ((representation instanceof DefaultRepresentation) || (representation instanceof RefRepresentation)) {
  DelegatingResourceDescription description = new DelegatingResourceDescription();
  description.addProperty("id");
  description.addProperty("uuid");
  description.addProperty("provider", Representation.DEFAULT);
}

통합 테스트 작성 방법

통합 테스트는 엔드투엔드로 테스트하며 메모리 내 데이터베이스를 생성합니다. 필요한 모든 hbm 파일을 <module>/omod/src/test/resources/test-hibernate.cfg.xml에 추가해야 합니다.

아래와 같이 hibernate-configuration 영역에 추가합니다.

<mapping resource="BedPatientAssignment.hbm.xml"/>
<mapping resource="Bed.hbm.xml"/>

런타임에는 <module>/omod/src/test/resources/TestingApplicationContext.xml에서 Hibernate 구성을 불러옵니다.

<property name="configLocations">
  <list>
      <value>classpath:test-hibernate.cfg.xml</value>
  </list>
</property>

........ 작성 중...

원문 정보

Bahmni Wiki · CC BY-SA 4.0

원문 보기 ↗