From ce329c2fa0c28548aea3fd36ab9fab3d4bf165c7 Mon Sep 17 00:00:00 2001 From: Volker Schmidt Date: Sat, 10 Nov 2018 23:36:39 +0100 Subject: [PATCH] Added tests and documentation for REST interfaces. --- README.md | 4 +- .../org/dhis2/fhir/adapter/AppConfig.java | 51 +++------- app/src/main/resources/application.yml | 7 +- app/src/main/resources/templates/setup.html | 4 + .../ZonedDateTimeToDateConverter.java | 57 +++++++++++ .../fhir/adapter/jackson/JacksonConfig.java | 78 +++++++++++++++ .../ZonedDateTimeToDateConverterTest.java | 60 ++++++++++++ .../fhir/adapter/dhis/config/DhisConfig.java | 5 + fhir/pom.xml | 15 +++ .../adapter/fhir/data/DataBasePackage.java | 38 +++++++ .../model/ProcessedRemoteFhirResource.java | 10 +- .../data/model/QueuedRemoteFhirResource.java | 8 +- .../QueuedRemoteSubscriptionRequest.java | 8 +- ...ProcessedRemoteFhirResourceRepository.java | 4 +- ...essedRemoteFhirResourceRepositoryImpl.java | 4 +- ...ueuedRemoteFhirResourceRepositoryImpl.java | 4 +- ...moteSubscriptionRequestRepositoryImpl.java | 4 +- .../fhir/metadata/MetadataBasePackage.java | 38 +++++++ .../fhir/metadata/model/AbstractRule.java | 2 +- .../adapter/fhir/metadata/model/Code.java | 2 +- .../fhir/metadata/model/CodeCategory.java | 2 +- .../adapter/fhir/metadata/model/CodeSet.java | 2 +- .../adapter/fhir/metadata/model/Constant.java | 2 +- .../metadata/model/MappedTrackerProgram.java | 2 +- .../model/MappedTrackerProgramStage.java | 2 +- .../metadata/model/RemoteSubscription.java | 2 +- .../model/RemoteSubscriptionResource.java | 2 +- .../RemoteSubscriptionResourceUpdate.java | 8 +- .../adapter/fhir/metadata/model/Script.java | 2 +- .../fhir/metadata/model/ScriptArg.java | 2 +- .../fhir/metadata/model/ScriptSource.java | 2 +- .../adapter/fhir/metadata/model/System.java | 2 +- .../metadata/model/VersionedBaseMetadata.java | 18 ++-- .../repository/CodeCategoryRepository.java | 2 +- ...eSubscriptionResourceUpdateRepository.java | 6 +- ...ustomRemoteSubscriptionRepositoryImpl.java | 4 +- ...scriptionResourceUpdateRepositoryImpl.java | 8 +- ...moteSubscriptionResourceEventListener.java | 4 +- ...ctSubscriptionResourceBundleRetriever.java | 20 ++-- .../impl/RemoteRestHookProcessorImpl.java | 19 ++-- .../remote/impl/SubscriptionResourceInfo.java | 12 +-- .../fhir/repository/RemoteFhirResource.java | 10 +- .../fhir/security/AdapterAuthorities.java | 2 +- .../fhir/security/AdapterSecurityConfig.java | 2 +- .../production/V1.0.0.0_0_1__Initial.sql | 76 +++++++------- .../fhir/AbstractJpaRepositoryTest.java | 83 ++++++++++++++++ .../dhis2/fhir/adapter/fhir/TestConfig.java | 98 +++++++++++++++++++ .../adapter/fhir/TestWebSecurityConfig.java | 73 ++++++++++++++ .../CodeCategoryRepositoryTest.java | 64 ++++++++++++ fhir/src/test/resources/logback-test.xml | 33 +++++++ .../repository/createCodeCategory.json | 5 + fhir/src/test/resources/test.properties | 36 +++++++ pom.xml | 14 +++ 53 files changed, 848 insertions(+), 174 deletions(-) create mode 100644 common/src/main/java/org/dhis2/fhir/adapter/converter/ZonedDateTimeToDateConverter.java create mode 100644 common/src/main/java/org/dhis2/fhir/adapter/jackson/JacksonConfig.java create mode 100644 common/src/test/java/org/dhis2/fhir/adapter/converter/ZonedDateTimeToDateConverterTest.java create mode 100644 fhir/src/main/java/org/dhis2/fhir/adapter/fhir/data/DataBasePackage.java create mode 100644 fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/MetadataBasePackage.java create mode 100644 fhir/src/test/java/org/dhis2/fhir/adapter/fhir/AbstractJpaRepositoryTest.java create mode 100644 fhir/src/test/java/org/dhis2/fhir/adapter/fhir/TestConfig.java create mode 100644 fhir/src/test/java/org/dhis2/fhir/adapter/fhir/TestWebSecurityConfig.java create mode 100644 fhir/src/test/java/org/dhis2/fhir/adapter/fhir/metadata/repository/CodeCategoryRepositoryTest.java create mode 100644 fhir/src/test/resources/logback-test.xml create mode 100644 fhir/src/test/resources/org/dhis2/fhir/adapter/fhir/metadata/repository/createCodeCategory.json create mode 100644 fhir/src/test/resources/test.properties diff --git a/README.md b/README.md index 058caa60..41d6779f 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,9 @@ # DHIS2 FHIR Adapter ## Overview This repository contains the source code of the DHIS2 FHIR Adapter. The current scope of the Adapter is to import data into DHIS2 Tracker by using FHIR Subscriptions. Event if the adapter may support more FHIR Resource types at the moment, the initial - official support is for FHIR Patient resources that are transformed to DHIS2 Tracked Entity instances. + official support is for FHIR Patient resources that are transformed to DHIS2 Tracked Entity instances. + +The import works on the basis of a domain specific business rule engine that decides about transformations of medical data to questionnaire-like structures (DHIS2 Tracker Programs and their Program Stages). ![DHIS2 FHIR Adapter High Level Architecture](docs/images/DHIS2_FHIR_Adapter_High_Level_Architecture.png "DHIS2 FHIR Adapter High Level Architecture") diff --git a/app/src/main/java/org/dhis2/fhir/adapter/AppConfig.java b/app/src/main/java/org/dhis2/fhir/adapter/AppConfig.java index 3d09025e..df9680e0 100644 --- a/app/src/main/java/org/dhis2/fhir/adapter/AppConfig.java +++ b/app/src/main/java/org/dhis2/fhir/adapter/AppConfig.java @@ -28,62 +28,31 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -import com.fasterxml.jackson.databind.ser.impl.SimpleBeanPropertyFilter; -import com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider; -import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateDeserializer; -import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateSerializer; -import org.dhis2.fhir.adapter.jackson.SecuredPropertyFilter; -import org.dhis2.fhir.adapter.jackson.ToManyPropertyFilter; -import org.dhis2.fhir.adapter.jackson.ToOnePropertyFilter; -import org.dhis2.fhir.adapter.jackson.ZonedDateTimeDeserializer; -import org.dhis2.fhir.adapter.jackson.ZonedDateTimeSerializer; -import org.springframework.boot.autoconfigure.jackson.Jackson2ObjectMapperBuilderCustomizer; +import org.dhis2.fhir.adapter.converter.ZonedDateTimeToDateConverter; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import org.springframework.core.annotation.Order; +import org.springframework.format.FormatterRegistry; import org.springframework.http.HttpMethod; import org.springframework.validation.annotation.Validated; import org.springframework.web.servlet.config.annotation.CorsRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; import javax.annotation.Nonnull; -import java.time.ZoneId; -import java.time.format.DateTimeFormatter; +import java.time.ZonedDateTime; +import java.util.Date; /** + * Common application configuration. + * * @author volsch */ @Configuration @Validated public class AppConfig { - @Bean - @Order( 1 ) - public Jackson2ObjectMapperBuilderCustomizer jackson2ObjectMapperBuilderCustomizer() - { - return jacksonObjectMapperBuilder -> { - final ZoneId zoneId = ZoneId.systemDefault(); - jacksonObjectMapperBuilder - .serializers( - new ZonedDateTimeSerializer(), - new LocalDateSerializer( DateTimeFormatter.ISO_LOCAL_DATE ) ) - .deserializers( - new ZonedDateTimeDeserializer(), - new LocalDateDeserializer( DateTimeFormatter.ISO_LOCAL_DATE ) ); - jacksonObjectMapperBuilder.filters( new SimpleFilterProvider() - .addFilter( SecuredPropertyFilter.FILTER_NAME, new SecuredPropertyFilter() ) - .addFilter( ToManyPropertyFilter.FILTER_NAME, new SimpleBeanPropertyFilter() - { - } ) - .addFilter( ToOnePropertyFilter.FILTER_NAME, new SimpleBeanPropertyFilter() - { - } ) ); - }; - } - @Bean @Nonnull - public WebMvcConfigurer corsConfigurer() + public WebMvcConfigurer mvcConfigurer() { return new WebMvcConfigurer() { @@ -95,6 +64,12 @@ public void addCorsMappings( @Nonnull CorsRegistry registry ) .allowedMethods( HttpMethod.GET.name(), HttpMethod.POST.name(), HttpMethod.PUT.name(), HttpMethod.PATCH.name(), HttpMethod.DELETE.name(), HttpMethod.HEAD.name(), HttpMethod.OPTIONS.name() ) .allowCredentials( true ); } + + @Override + public void addFormatters( @Nonnull FormatterRegistry registry ) + { + registry.addConverter( ZonedDateTime.class, Date.class, new ZonedDateTimeToDateConverter() ); + } }; } } diff --git a/app/src/main/resources/application.yml b/app/src/main/resources/application.yml index 1ee843c6..85961ac1 100644 --- a/app/src/main/resources/application.yml +++ b/app/src/main/resources/application.yml @@ -27,9 +27,6 @@ # spring: - jackson: - serialization: - write-dates-as-timestamps: false data: rest: basePath: /api @@ -39,6 +36,10 @@ spring: hibernate: ddl-auto: none open-in-view: false + properties: + hibernate: + jdbc: + time_zone: UTC application: name: DHIS2 FHIR Adapter diff --git a/app/src/main/resources/templates/setup.html b/app/src/main/resources/templates/setup.html index f47c9f79..ee6ee763 100644 --- a/app/src/main/resources/templates/setup.html +++ b/app/src/main/resources/templates/setup.html @@ -32,6 +32,10 @@ DHIS2 FHIR Adapter - Initial Setup