From 3b10c926705de0ba9924573a7fc3727820c7c5e8 Mon Sep 17 00:00:00 2001 From: Volker Schmidt Date: Mon, 10 Dec 2018 16:15:53 +0100 Subject: [PATCH] Added support for detecting endless synchronizations for DHIS2. --- app/src/main/resources/logback-spring.xml | 4 +- ...edEntityInstanceTransformationAppTest.java | 2 +- ...edEntityInstanceTransformationAppTest.java | 2 +- .../fhir/adapter/dhis/model/DhisResource.java | 17 ++ .../adapter/dhis/queue/DhisQueueConfig.java | 21 ++ .../dhis/queue/JmsJsonTypeIdMapping.java | 44 +++ .../fhir/adapter/dhis/queue/QueueConfig.java | 9 +- .../dhis/sync/DhisResourceQueueItem.java | 13 - .../dhis/sync/DhisResourceRepository.java | 52 ++++ .../sync/impl/DhisResourceRepositoryImpl.java | 178 ++++++++++++ .../dhis/tracker/program/Enrollment.java | 22 ++ .../adapter/dhis/tracker/program/Event.java | 15 +- .../trackedentity/TrackedEntityInstance.java | 23 ++ .../trackedentity/TrackedEntityService.java | 2 +- .../impl/TrackedEntityServiceImpl.java | 2 +- ...archicallyFhirResourceRepositoryImpl.java} | 12 +- ...stu3RemoteFhirResourceRepositoryImpl.java} | 8 +- ...stu3AddressFhirToDhisTransformerUtils.java | 6 +- .../Dstu3CodeFhirToDhisTransformerUtils.java | 4 +- ...ontactPointFhirToDhisTransformerUtils.java | 6 +- ...tu3DateTimeFhirToDhisTransformerUtils.java | 4 +- ...3FhirClientFhirToDhisTransformerUtils.java | 4 +- .../Dstu3GeoFhirToDhisTransformerUtils.java | 4 +- ...u3HumanNameFhirToDhisTransformerUtils.java | 6 +- ...3IdentifierFhirToDhisTransformerUtils.java | 6 +- ...mmunizationFhirToDhisTransformerUtils.java | 4 +- ...ObservationFhirToDhisTransformerUtils.java | 4 +- ...rganizationFhirToDhisTransformerUtils.java | 14 +- ...stu3PatientFhirToDhisTransformerUtils.java | 4 +- ...u3VitalSignFhirToDhisTransformerUtils.java | 4 +- ...ferenceFhirToDhisTransformerUtilsTest.java | 30 +- ...AddressFhirToDhisTransformerUtilsTest.java | 2 +- ...tu3CodeFhirToDhisTransformerUtilsTest.java | 8 +- ...ctPointFhirToDhisTransformerUtilsTest.java | 2 +- ...ateTimeFhirToDhisTransformerUtilsTest.java | 2 +- ...stu3GeoFhirToDhisTransformerUtilsTest.java | 2 +- ...manNameFhirToDhisTransformerUtilsTest.java | 2 +- ...ntifierFhirToDhisTransformerUtilsTest.java | 10 +- ...izationFhirToDhisTransformerUtilsTest.java | 23 +- ...PatientFhirToDhisTransformerUtilsTest.java | 2 +- .../adapter/fhir/queue/FhirQueueConfig.java | 22 ++ .../fhir/repository/DhisRepository.java | 44 +++ ...java => RemoteFhirResourceRepository.java} | 6 +- ...HierarchicallyFhirResourceRepository.java} | 4 +- ...ractRemoteFhirResourceRepositoryImpl.java} | 18 +- ...archicallyFhirResourceRepositoryImpl.java} | 18 +- .../repository/impl/DhisRepositoryImpl.java | 261 ++++++++++++++++++ .../repository/impl/FhirRepositoryImpl.java | 154 +++-------- .../dhis/DhisToFhirTransformOutcome.java | 86 ++++++ .../dhis/DhisToFhirTransformerContext.java | 68 +++++ .../dhis/DhisToFhirTransformerRequest.java | 52 ++++ .../dhis/DhisToFhirTransformerService.java | 50 ++++ .../transform/dhis/model/DhisRequest.java | 54 ++++ .../dhis/model/ImmutableDhisRequest.java | 69 +++++ .../dhis/model/WritableDhisRequest.java | 72 +++++ .../FhirToDhisTransformOutcome.java | 32 ++- .../FhirToDhisTransformerContext.java | 14 +- .../fhir/FhirToDhisTransformerRequest.java | 52 ++++ .../FhirToDhisTransformerService.java | 15 +- ...rackedEntityInstanceNotFoundException.java | 2 +- .../impl/AbstractFhirToDhisTransformer.java | 12 +- .../impl/FhirToDhisTransformer.java | 13 +- .../FhirToDhisTransformerContextImpl.java | 8 +- .../FhirToDhisTransformerRequestImpl.java | 114 ++++++++ .../FhirToDhisTransformerServiceImpl.java | 99 ++++--- .../{ => fhir}/impl/TransformationConfig.java | 2 +- .../impl/TransformerScriptException.java | 2 +- .../impl/program/EventComparator.java | 2 +- .../{ => fhir}/impl/program/EventInfo.java | 4 +- .../program/FhirToDhisOptionSetUtils.java | 4 +- .../FhirToProgramStageTransformer.java | 16 +- .../program/ImmutableScriptedEnrollment.java | 10 +- .../impl/program/ImmutableScriptedEvent.java | 10 +- .../FhirToTrackedEntityTransformer.java | 15 +- ...ractAddressFhirToDhisTransformerUtils.java | 2 +- ...bstractCodeFhirToDhisTransformerUtils.java | 8 +- ...ontactPointFhirToDhisTransformerUtils.java | 2 +- ...actDateTimeFhirToDhisTransformerUtils.java | 4 +- ...tFhirClientFhirToDhisTransformerUtils.java | 6 +- .../AbstractFhirToDhisTransformerUtils.java | 4 +- ...AbstractGeoFhirToDhisTransformerUtils.java | 2 +- ...ctHumanNameFhirToDhisTransformerUtils.java | 2 +- ...tIdentifierFhirToDhisTransformerUtils.java | 8 +- ...mmunizationFhirToDhisTransformerUtils.java | 2 +- ...ObservationFhirToDhisTransformerUtils.java | 2 +- ...rganizationFhirToDhisTransformerUtils.java | 26 +- ...ractPatientFhirToDhisTransformerUtils.java | 2 +- ...ctVitalSignFhirToDhisTransformerUtils.java | 2 +- .../impl/util/BeanTransformerUtils.java | 2 +- .../impl/util/FhirToDhisTransformerUtils.java | 2 +- .../ReferenceFhirToDhisTransformerUtils.java | 20 +- .../impl/util/ScriptedDateTimeUtils.java | 2 +- .../impl/util/TransformerComparatorUtils.java | 2 +- .../{ => fhir}/model/FhirRequest.java | 8 +- .../{ => fhir}/model/FhirRequestMethod.java | 2 +- .../model/ImmutableFhirRequest.java | 8 +- .../{ => fhir}/model/ResourceSystem.java | 2 +- .../{ => fhir}/model/WritableFhirRequest.java | 8 +- .../ScriptedDhisResource.java | 19 +- .../ScriptedEnrollment.java | 14 +- .../program => scripted}/ScriptedEvent.java | 14 +- .../ScriptedTrackedEntityInstance.java | 14 +- .../WritableScriptedEnrollment.java | 18 +- .../WritableScriptedEvent.java | 23 +- ...WritableScriptedTrackedEntityInstance.java | 14 +- .../FhirToDhisTransformerContextImplTest.java | 6 +- 106 files changed, 1803 insertions(+), 430 deletions(-) rename app/src/test/java/org/dhis2/fhir/adapter/fhir/transform/{ => fhir}/impl/trackedentity/AbstractTrackedEntityInstanceTransformationAppTest.java (98%) rename app/src/test/java/org/dhis2/fhir/adapter/fhir/transform/{ => fhir}/impl/trackedentity/PatientToTrackedEntityInstanceTransformationAppTest.java (99%) create mode 100644 dhis/src/main/java/org/dhis2/fhir/adapter/dhis/queue/JmsJsonTypeIdMapping.java create mode 100644 dhis/src/main/java/org/dhis2/fhir/adapter/dhis/sync/DhisResourceRepository.java create mode 100644 dhis/src/main/java/org/dhis2/fhir/adapter/dhis/sync/impl/DhisResourceRepositoryImpl.java rename fhir-dstu3/src/main/java/org/dhis2/fhir/adapter/fhir/remote/impl/dstu3/{Dstu3RemoteHierarchicallyFhirRepositoryImpl.java => Dstu3RemoteHierarchicallyFhirResourceRepositoryImpl.java} (82%) rename fhir-dstu3/src/main/java/org/dhis2/fhir/adapter/fhir/repository/impl/dstu3/{Dstu3RemoteFhirRepositoryImpl.java => Dstu3RemoteFhirResourceRepositoryImpl.java} (90%) rename fhir-dstu3/src/main/java/org/dhis2/fhir/adapter/fhir/transform/{ => fhir}/impl/util/dstu3/Dstu3AddressFhirToDhisTransformerUtils.java (96%) rename fhir-dstu3/src/main/java/org/dhis2/fhir/adapter/fhir/transform/{ => fhir}/impl/util/dstu3/Dstu3CodeFhirToDhisTransformerUtils.java (97%) rename fhir-dstu3/src/main/java/org/dhis2/fhir/adapter/fhir/transform/{ => fhir}/impl/util/dstu3/Dstu3ContactPointFhirToDhisTransformerUtils.java (94%) rename fhir-dstu3/src/main/java/org/dhis2/fhir/adapter/fhir/transform/{ => fhir}/impl/util/dstu3/Dstu3DateTimeFhirToDhisTransformerUtils.java (95%) rename fhir-dstu3/src/main/java/org/dhis2/fhir/adapter/fhir/transform/{ => fhir}/impl/util/dstu3/Dstu3FhirClientFhirToDhisTransformerUtils.java (96%) rename fhir-dstu3/src/main/java/org/dhis2/fhir/adapter/fhir/transform/{ => fhir}/impl/util/dstu3/Dstu3GeoFhirToDhisTransformerUtils.java (96%) rename fhir-dstu3/src/main/java/org/dhis2/fhir/adapter/fhir/transform/{ => fhir}/impl/util/dstu3/Dstu3HumanNameFhirToDhisTransformerUtils.java (95%) rename fhir-dstu3/src/main/java/org/dhis2/fhir/adapter/fhir/transform/{ => fhir}/impl/util/dstu3/Dstu3IdentifierFhirToDhisTransformerUtils.java (92%) rename fhir-dstu3/src/main/java/org/dhis2/fhir/adapter/fhir/transform/{ => fhir}/impl/util/dstu3/Dstu3ImmunizationFhirToDhisTransformerUtils.java (94%) rename fhir-dstu3/src/main/java/org/dhis2/fhir/adapter/fhir/transform/{ => fhir}/impl/util/dstu3/Dstu3ObservationFhirToDhisTransformerUtils.java (96%) rename fhir-dstu3/src/main/java/org/dhis2/fhir/adapter/fhir/transform/{ => fhir}/impl/util/dstu3/Dstu3OrganizationFhirToDhisTransformerUtils.java (87%) rename fhir-dstu3/src/main/java/org/dhis2/fhir/adapter/fhir/transform/{ => fhir}/impl/util/dstu3/Dstu3PatientFhirToDhisTransformerUtils.java (95%) rename fhir-dstu3/src/main/java/org/dhis2/fhir/adapter/fhir/transform/{ => fhir}/impl/util/dstu3/Dstu3VitalSignFhirToDhisTransformerUtils.java (96%) rename fhir-dstu3/src/test/java/org/dhis2/fhir/adapter/fhir/transform/{ => fhir}/impl/util/ReferenceFhirToDhisTransformerUtilsTest.java (91%) rename fhir-dstu3/src/test/java/org/dhis2/fhir/adapter/fhir/transform/{ => fhir}/impl/util/dstu3/Dstu3AddressFhirToDhisTransformerUtilsTest.java (99%) rename fhir-dstu3/src/test/java/org/dhis2/fhir/adapter/fhir/transform/{ => fhir}/impl/util/dstu3/Dstu3CodeFhirToDhisTransformerUtilsTest.java (98%) rename fhir-dstu3/src/test/java/org/dhis2/fhir/adapter/fhir/transform/{ => fhir}/impl/util/dstu3/Dstu3ContactPointFhirToDhisTransformerUtilsTest.java (99%) rename fhir-dstu3/src/test/java/org/dhis2/fhir/adapter/fhir/transform/{ => fhir}/impl/util/dstu3/Dstu3DateTimeFhirToDhisTransformerUtilsTest.java (99%) rename fhir-dstu3/src/test/java/org/dhis2/fhir/adapter/fhir/transform/{ => fhir}/impl/util/dstu3/Dstu3GeoFhirToDhisTransformerUtilsTest.java (97%) rename fhir-dstu3/src/test/java/org/dhis2/fhir/adapter/fhir/transform/{ => fhir}/impl/util/dstu3/Dstu3HumanNameFhirToDhisTransformerUtilsTest.java (98%) rename fhir-dstu3/src/test/java/org/dhis2/fhir/adapter/fhir/transform/{ => fhir}/impl/util/dstu3/Dstu3IdentifierFhirToDhisTransformerUtilsTest.java (94%) rename fhir-dstu3/src/test/java/org/dhis2/fhir/adapter/fhir/transform/{ => fhir}/impl/util/dstu3/Dstu3OrganizationFhirToDhisTransformerUtilsTest.java (92%) rename fhir-dstu3/src/test/java/org/dhis2/fhir/adapter/fhir/transform/{ => fhir}/impl/util/dstu3/Dstu3PatientFhirToDhisTransformerUtilsTest.java (97%) create mode 100644 fhir/src/main/java/org/dhis2/fhir/adapter/fhir/repository/DhisRepository.java rename fhir/src/main/java/org/dhis2/fhir/adapter/fhir/repository/{RemoteFhirRepository.java => RemoteFhirResourceRepository.java} (91%) rename fhir/src/main/java/org/dhis2/fhir/adapter/fhir/repository/{RemoteHierarchicallyFhirRepository.java => RemoteHierarchicallyFhirResourceRepository.java} (94%) rename fhir/src/main/java/org/dhis2/fhir/adapter/fhir/repository/impl/{AbstractRemoteFhirRepositoryImpl.java => AbstractRemoteFhirResourceRepositoryImpl.java} (89%) rename fhir/src/main/java/org/dhis2/fhir/adapter/fhir/repository/impl/{AbstractRemoteHierarchicallyFhirRepositoryImpl.java => AbstractRemoteHierarchicallyFhirResourceRepositoryImpl.java} (85%) create mode 100644 fhir/src/main/java/org/dhis2/fhir/adapter/fhir/repository/impl/DhisRepositoryImpl.java create mode 100644 fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/dhis/DhisToFhirTransformOutcome.java create mode 100644 fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/dhis/DhisToFhirTransformerContext.java create mode 100644 fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/dhis/DhisToFhirTransformerRequest.java create mode 100644 fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/dhis/DhisToFhirTransformerService.java create mode 100644 fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/dhis/model/DhisRequest.java create mode 100644 fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/dhis/model/ImmutableDhisRequest.java create mode 100644 fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/dhis/model/WritableDhisRequest.java rename fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/{ => fhir}/FhirToDhisTransformOutcome.java (74%) rename fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/{ => fhir}/FhirToDhisTransformerContext.java (89%) create mode 100644 fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/FhirToDhisTransformerRequest.java rename fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/{ => fhir}/FhirToDhisTransformerService.java (77%) rename fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/{ => fhir}/TrackedEntityInstanceNotFoundException.java (97%) rename fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/{ => fhir}/impl/AbstractFhirToDhisTransformer.java (97%) rename fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/{ => fhir}/impl/FhirToDhisTransformer.java (85%) rename fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/{ => fhir}/impl/FhirToDhisTransformerContextImpl.java (92%) create mode 100644 fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/FhirToDhisTransformerRequestImpl.java rename fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/{ => fhir}/impl/FhirToDhisTransformerServiceImpl.java (63%) rename fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/{ => fhir}/impl/TransformationConfig.java (98%) rename fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/{ => fhir}/impl/TransformerScriptException.java (97%) rename fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/{ => fhir}/impl/program/EventComparator.java (97%) rename fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/{ => fhir}/impl/program/EventInfo.java (95%) rename fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/{ => fhir}/impl/program/FhirToDhisOptionSetUtils.java (97%) rename fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/{ => fhir}/impl/program/FhirToProgramStageTransformer.java (98%) rename fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/{ => fhir}/impl/program/ImmutableScriptedEnrollment.java (91%) rename fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/{ => fhir}/impl/program/ImmutableScriptedEvent.java (92%) rename fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/{ => fhir}/impl/trackedentity/FhirToTrackedEntityTransformer.java (96%) rename fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/{ => fhir}/impl/util/AbstractAddressFhirToDhisTransformerUtils.java (98%) rename fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/{ => fhir}/impl/util/AbstractCodeFhirToDhisTransformerUtils.java (97%) rename fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/{ => fhir}/impl/util/AbstractContactPointFhirToDhisTransformerUtils.java (98%) rename fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/{ => fhir}/impl/util/AbstractDateTimeFhirToDhisTransformerUtils.java (98%) rename fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/{ => fhir}/impl/util/AbstractFhirClientFhirToDhisTransformerUtils.java (97%) rename fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/{ => fhir}/impl/util/AbstractFhirToDhisTransformerUtils.java (95%) rename fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/{ => fhir}/impl/util/AbstractGeoFhirToDhisTransformerUtils.java (98%) rename fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/{ => fhir}/impl/util/AbstractHumanNameFhirToDhisTransformerUtils.java (98%) rename fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/{ => fhir}/impl/util/AbstractIdentifierFhirToDhisTransformerUtils.java (97%) rename fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/{ => fhir}/impl/util/AbstractImmunizationFhirToDhisTransformerUtils.java (97%) rename fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/{ => fhir}/impl/util/AbstractObservationFhirToDhisTransformerUtils.java (98%) rename fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/{ => fhir}/impl/util/AbstractOrganizationFhirToDhisTransformerUtils.java (90%) rename fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/{ => fhir}/impl/util/AbstractPatientFhirToDhisTransformerUtils.java (98%) rename fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/{ => fhir}/impl/util/AbstractVitalSignFhirToDhisTransformerUtils.java (97%) rename fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/{ => fhir}/impl/util/BeanTransformerUtils.java (97%) rename fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/{ => fhir}/impl/util/FhirToDhisTransformerUtils.java (96%) rename fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/{ => fhir}/impl/util/ReferenceFhirToDhisTransformerUtils.java (91%) rename fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/{ => fhir}/impl/util/ScriptedDateTimeUtils.java (97%) rename fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/{ => fhir}/impl/util/TransformerComparatorUtils.java (97%) rename fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/{ => fhir}/model/FhirRequest.java (94%) rename fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/{ => fhir}/model/FhirRequestMethod.java (97%) rename fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/{ => fhir}/model/ImmutableFhirRequest.java (94%) rename fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/{ => fhir}/model/ResourceSystem.java (98%) rename fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/{ => fhir}/model/WritableFhirRequest.java (96%) rename fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/{impl => scripted}/ScriptedDhisResource.java (83%) rename fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/{impl/program => scripted}/ScriptedEnrollment.java (89%) rename fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/{impl/program => scripted}/ScriptedEvent.java (90%) rename fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/{impl/trackedentity => scripted}/ScriptedTrackedEntityInstance.java (90%) rename fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/{impl/program => scripted}/WritableScriptedEnrollment.java (90%) rename fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/{impl/program => scripted}/WritableScriptedEvent.java (93%) rename fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/{impl/trackedentity => scripted}/WritableScriptedTrackedEntityInstance.java (97%) rename fhir/src/test/java/org/dhis2/fhir/adapter/fhir/transform/{ => fhir}/impl/FhirToDhisTransformerContextImplTest.java (94%) diff --git a/app/src/main/resources/logback-spring.xml b/app/src/main/resources/logback-spring.xml index 011572aa..6c9c919b 100644 --- a/app/src/main/resources/logback-spring.xml +++ b/app/src/main/resources/logback-spring.xml @@ -29,9 +29,9 @@ + value="${CONSOLE_LOG_PATTERN:-%clr(%d{${LOG_DATEFORMAT_PATTERN:-yyyy-MM-dd HH:mm:ss.SSS}}){faint} %clr(${LOG_LEVEL_PATTERN:-%5p}) %clr(${PID:- }){magenta} %clr(---){faint} %clr([%15.15t]){faint} %clr(%-40.40logger{39}){cyan} %clr(:){faint} %X{fhirId}%X{dhisId} - %m%n${LOG_EXCEPTION_CONVERSION_WORD:-%wEx}}" /> + value="${FILE_LOG_PATTERN:-%d{${LOG_DATEFORMAT_PATTERN:-yyyy-MM-dd HH:mm:ss.SSS}} ${LOG_LEVEL_PATTERN:-%5p} ${PID:- } --- [%t] %-40.40logger{39} : %X{fhirId}%X{dhisId} - %m%n${LOG_EXCEPTION_CONVERSION_WORD:-%wEx}}" /> diff --git a/app/src/test/java/org/dhis2/fhir/adapter/fhir/transform/impl/trackedentity/AbstractTrackedEntityInstanceTransformationAppTest.java b/app/src/test/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/trackedentity/AbstractTrackedEntityInstanceTransformationAppTest.java similarity index 98% rename from app/src/test/java/org/dhis2/fhir/adapter/fhir/transform/impl/trackedentity/AbstractTrackedEntityInstanceTransformationAppTest.java rename to app/src/test/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/trackedentity/AbstractTrackedEntityInstanceTransformationAppTest.java index f32e6b80..5d4c68c2 100644 --- a/app/src/test/java/org/dhis2/fhir/adapter/fhir/transform/impl/trackedentity/AbstractTrackedEntityInstanceTransformationAppTest.java +++ b/app/src/test/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/trackedentity/AbstractTrackedEntityInstanceTransformationAppTest.java @@ -1,4 +1,4 @@ -package org.dhis2.fhir.adapter.fhir.transform.impl.trackedentity; +package org.dhis2.fhir.adapter.fhir.transform.fhir.impl.trackedentity; /* * Copyright (c) 2004-2018, University of Oslo diff --git a/app/src/test/java/org/dhis2/fhir/adapter/fhir/transform/impl/trackedentity/PatientToTrackedEntityInstanceTransformationAppTest.java b/app/src/test/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/trackedentity/PatientToTrackedEntityInstanceTransformationAppTest.java similarity index 99% rename from app/src/test/java/org/dhis2/fhir/adapter/fhir/transform/impl/trackedentity/PatientToTrackedEntityInstanceTransformationAppTest.java rename to app/src/test/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/trackedentity/PatientToTrackedEntityInstanceTransformationAppTest.java index c3ef7566..e5c9ab81 100644 --- a/app/src/test/java/org/dhis2/fhir/adapter/fhir/transform/impl/trackedentity/PatientToTrackedEntityInstanceTransformationAppTest.java +++ b/app/src/test/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/trackedentity/PatientToTrackedEntityInstanceTransformationAppTest.java @@ -1,4 +1,4 @@ -package org.dhis2.fhir.adapter.fhir.transform.impl.trackedentity; +package org.dhis2.fhir.adapter.fhir.transform.fhir.impl.trackedentity; /* * Copyright (c) 2004-2018, University of Oslo diff --git a/dhis/src/main/java/org/dhis2/fhir/adapter/dhis/model/DhisResource.java b/dhis/src/main/java/org/dhis2/fhir/adapter/dhis/model/DhisResource.java index c3c444f5..d41e8b00 100644 --- a/dhis/src/main/java/org/dhis2/fhir/adapter/dhis/model/DhisResource.java +++ b/dhis/src/main/java/org/dhis2/fhir/adapter/dhis/model/DhisResource.java @@ -31,6 +31,7 @@ import org.dhis2.fhir.adapter.model.Identifiable; import javax.annotation.Nonnull; +import java.time.ZonedDateTime; /** * Base interface of DHIS2 Resources. @@ -39,6 +40,22 @@ */ public interface DhisResource extends Identifiable { + /** + * @return the unique ID of the DHIS 2 organization unit to which this resource belongs, + * or null if this resource does not belong to any DHIS 2 organization unit. + */ + String getOrgUnitId(); + + /** + * @return the unique ID of the resource (including the type of the resource). + */ + DhisResourceId getResourceId(); + + /** + * @return the timestamp when the resource has been updated the last time. + */ + ZonedDateTime getLastUpdated(); + /** * @return the concrete resource type of the resource. */ diff --git a/dhis/src/main/java/org/dhis2/fhir/adapter/dhis/queue/DhisQueueConfig.java b/dhis/src/main/java/org/dhis2/fhir/adapter/dhis/queue/DhisQueueConfig.java index 91bc131e..94c3c23a 100644 --- a/dhis/src/main/java/org/dhis2/fhir/adapter/dhis/queue/DhisQueueConfig.java +++ b/dhis/src/main/java/org/dhis2/fhir/adapter/dhis/queue/DhisQueueConfig.java @@ -28,9 +28,12 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +import com.google.common.collect.ImmutableMap; import org.apache.activemq.artemis.jms.server.config.JMSQueueConfiguration; import org.apache.activemq.artemis.jms.server.config.impl.JMSQueueConfigurationImpl; +import org.dhis2.fhir.adapter.dhis.sync.DhisResourceQueueItem; import org.dhis2.fhir.adapter.dhis.sync.impl.DhisSyncConfig; +import org.dhis2.fhir.adapter.dhis.sync.impl.DhisSyncRequestQueueItem; import org.springframework.boot.autoconfigure.jms.artemis.ArtemisConfigurationCustomizer; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -40,6 +43,7 @@ import javax.annotation.Nonnull; import javax.jms.ConnectionFactory; +import java.util.Map; /** * Configuration of queues that are used by the adapter. @@ -117,4 +121,21 @@ protected JmsTemplate dhisResourceQueueJmsTemplate( @Nonnull ConnectionFactory c jmsTemplate.setMessageConverter( jmsMessageConverter ); return jmsTemplate; } + + @Bean + @Nonnull + protected JmsJsonTypeIdMapping dhisJmsJsonTypeIdMapping() + { + return new JmsJsonTypeIdMapping() + { + @Nonnull + @Override + public Map> getTypeIdMappings() + { + return ImmutableMap.of( + "dhisSyncRequest", DhisSyncRequestQueueItem.class, + "dhisResource", DhisResourceQueueItem.class ); + } + }; + } } diff --git a/dhis/src/main/java/org/dhis2/fhir/adapter/dhis/queue/JmsJsonTypeIdMapping.java b/dhis/src/main/java/org/dhis2/fhir/adapter/dhis/queue/JmsJsonTypeIdMapping.java new file mode 100644 index 00000000..ea2ad555 --- /dev/null +++ b/dhis/src/main/java/org/dhis2/fhir/adapter/dhis/queue/JmsJsonTypeIdMapping.java @@ -0,0 +1,44 @@ +package org.dhis2.fhir.adapter.dhis.queue; + +/* + * Copyright (c) 2004-2018, University of Oslo + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * Neither the name of the HISP project nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +import javax.annotation.Nonnull; +import java.util.Map; + +/** + * Returns mappings from a class to a type ID that will be stored in a JMS message + * instead of the full qualified class name. + * + * @author volsch + */ +public interface JmsJsonTypeIdMapping +{ + @Nonnull + Map> getTypeIdMappings(); +} diff --git a/dhis/src/main/java/org/dhis2/fhir/adapter/dhis/queue/QueueConfig.java b/dhis/src/main/java/org/dhis2/fhir/adapter/dhis/queue/QueueConfig.java index 5ce60beb..64066650 100644 --- a/dhis/src/main/java/org/dhis2/fhir/adapter/dhis/queue/QueueConfig.java +++ b/dhis/src/main/java/org/dhis2/fhir/adapter/dhis/queue/QueueConfig.java @@ -43,6 +43,9 @@ import javax.annotation.Nonnull; import javax.jms.ConnectionFactory; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; /** * General configuration of queues that are used by the adapter. @@ -56,12 +59,16 @@ public class QueueConfig @Primary @Bean @Nonnull - protected MessageConverter jacksonJmsMessageConverter( @Nonnull ObjectMapper objectMapper ) + protected MessageConverter jacksonJmsMessageConverter( @Nonnull ObjectMapper objectMapper, @Nonnull Collection typeIdMappings ) { + final Map> resultingMappings = new HashMap<>(); + typeIdMappings.forEach( tim -> resultingMappings.putAll( tim.getTypeIdMappings() ) ); + final MappingJackson2MessageConverter converter = new MappingJackson2MessageConverter(); converter.setObjectMapper( objectMapper ); converter.setTargetType( MessageType.TEXT ); converter.setTypeIdPropertyName( "_type" ); + converter.setTypeIdMappings( resultingMappings ); return converter; } diff --git a/dhis/src/main/java/org/dhis2/fhir/adapter/dhis/sync/DhisResourceQueueItem.java b/dhis/src/main/java/org/dhis2/fhir/adapter/dhis/sync/DhisResourceQueueItem.java index f615b8cd..71a8d3e0 100644 --- a/dhis/src/main/java/org/dhis2/fhir/adapter/dhis/sync/DhisResourceQueueItem.java +++ b/dhis/src/main/java/org/dhis2/fhir/adapter/dhis/sync/DhisResourceQueueItem.java @@ -29,14 +29,12 @@ */ import com.fasterxml.jackson.annotation.JsonIgnore; -import com.fasterxml.jackson.annotation.JsonProperty; import org.dhis2.fhir.adapter.data.model.ProcessedItemInfo; import org.dhis2.fhir.adapter.data.model.UuidDataGroupId; import org.dhis2.fhir.adapter.data.processor.DataItemQueueItem; import javax.annotation.Nonnull; import java.io.Serializable; -import java.util.UUID; /** * Processing request for a DHIS2 resource synchronization that is enqueued and dequeued. @@ -70,15 +68,4 @@ public void setDataGroupId( UuidDataGroupId dataGroupId ) { super.setDataGroupId( dataGroupId ); } - - @JsonProperty - public UUID getRemoteSubscriptionResourceId() - { - return (getDataGroupId() == null) ? null : getDataGroupId().getId(); - } - - public void setRemoteSubscriptionResourceId( UUID remoteSubscriptionResourceId ) - { - super.setDataGroupId( (remoteSubscriptionResourceId == null) ? null : new UuidDataGroupId( remoteSubscriptionResourceId ) ); - } } diff --git a/dhis/src/main/java/org/dhis2/fhir/adapter/dhis/sync/DhisResourceRepository.java b/dhis/src/main/java/org/dhis2/fhir/adapter/dhis/sync/DhisResourceRepository.java new file mode 100644 index 00000000..3b334d3b --- /dev/null +++ b/dhis/src/main/java/org/dhis2/fhir/adapter/dhis/sync/DhisResourceRepository.java @@ -0,0 +1,52 @@ +package org.dhis2.fhir.adapter.dhis.sync; + +/* + * Copyright (c) 2004-2018, University of Oslo + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * Neither the name of the HISP project nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +import org.dhis2.fhir.adapter.dhis.model.DhisResource; +import org.dhis2.fhir.adapter.dhis.model.DhisResourceId; + +import javax.annotation.Nonnull; +import java.util.Optional; + +/** + * Utility methods to access DHIS resources. + * + * @author volsch + */ +public interface DhisResourceRepository +{ + @Nonnull + Optional findRefreshed( @Nonnull DhisResourceId dhisResourceId ); + + @Nonnull + Optional find( @Nonnull DhisResourceId dhisResourceId ); + + @Nonnull + DhisResource save( @Nonnull DhisResource resource ); +} diff --git a/dhis/src/main/java/org/dhis2/fhir/adapter/dhis/sync/impl/DhisResourceRepositoryImpl.java b/dhis/src/main/java/org/dhis2/fhir/adapter/dhis/sync/impl/DhisResourceRepositoryImpl.java new file mode 100644 index 00000000..18389970 --- /dev/null +++ b/dhis/src/main/java/org/dhis2/fhir/adapter/dhis/sync/impl/DhisResourceRepositoryImpl.java @@ -0,0 +1,178 @@ +package org.dhis2.fhir.adapter.dhis.sync.impl; + +/* + * Copyright (c) 2004-2018, University of Oslo + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * Neither the name of the HISP project nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +import org.dhis2.fhir.adapter.dhis.model.DhisResource; +import org.dhis2.fhir.adapter.dhis.model.DhisResourceId; +import org.dhis2.fhir.adapter.dhis.sync.DhisResourceRepository; +import org.dhis2.fhir.adapter.dhis.tracker.program.EnrollmentService; +import org.dhis2.fhir.adapter.dhis.tracker.program.Event; +import org.dhis2.fhir.adapter.dhis.tracker.program.EventService; +import org.dhis2.fhir.adapter.dhis.tracker.trackedentity.TrackedEntityInstance; +import org.dhis2.fhir.adapter.dhis.tracker.trackedentity.TrackedEntityService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Component; + +import javax.annotation.Nonnull; +import java.util.Collections; +import java.util.List; +import java.util.Optional; + +/** + * Implementation of {@link DhisResourceRepository}. + * + * @author volsch + */ +@Component +public class DhisResourceRepositoryImpl implements DhisResourceRepository +{ + private final Logger logger = LoggerFactory.getLogger( getClass() ); + + private final TrackedEntityService trackedEntityService; + + private final EnrollmentService enrollmentService; + + private final EventService eventService; + + public DhisResourceRepositoryImpl( + @Nonnull TrackedEntityService trackedEntityService, + @Nonnull EnrollmentService enrollmentService, + @Nonnull EventService eventService ) + { + this.trackedEntityService = trackedEntityService; + this.enrollmentService = enrollmentService; + this.eventService = eventService; + } + + @Nonnull + @Override + public Optional findRefreshed( @Nonnull DhisResourceId dhisResourceId ) + { + switch ( dhisResourceId.getType() ) + { + case TRACKED_ENTITY: + return trackedEntityService.findById( dhisResourceId.getId() ); + case ENROLLMENT: + case PROGRAM_STAGE_EVENT: + throw new UnsupportedOperationException( "Finding DHIS enrollment and event resources is nut supported currently." ); + default: + throw new AssertionError( "Unhandled DHIS resource type: " + dhisResourceId.getType() ); + } + } + + @Nonnull + @Override + public Optional find( @Nonnull DhisResourceId dhisResourceId ) + { + // caching is not supported currently + return findRefreshed( dhisResourceId ); + } + + @Override + @Nonnull + public DhisResource save( @Nonnull DhisResource resource ) + { + switch ( resource.getResourceType() ) + { + case TRACKED_ENTITY: + saveTrackedEntityInstance( (TrackedEntityInstance) resource ); + break; + case ENROLLMENT: + throw new UnsupportedOperationException( "Saving DHIS enrollment resources is nut supported currently." ); + case PROGRAM_STAGE_EVENT: + saveEvent( (Event) resource ); + break; + default: + throw new AssertionError( "Unhandled DHIS resource type: " + resource.getResourceType() ); + } + return resource; + } + + private boolean saveTrackedEntityInstance( @Nonnull TrackedEntityInstance trackedEntityInstance ) + { + if ( trackedEntityInstance.isNewResource() || trackedEntityInstance.isModified() ) + { + logger.debug( "Persisting tracked entity instance." ); + final DhisResource dhisResource = trackedEntityService.createOrUpdate( trackedEntityInstance ); + logger.info( "Persisted tracked entity instance {}.", dhisResource.getId() ); + return true; + } + + logger.info( "Tracked entity instance {} has not been modified.", trackedEntityInstance.getId() ); + return false; + } + + private boolean saveEvent( @Nonnull Event event ) + { + boolean updated = false; + + if ( (event.getTrackedEntityInstance() != null) && event.getTrackedEntityInstance().isModified() ) + { + logger.debug( "Persisting tracked entity instance." ); + trackedEntityService.createOrUpdate( event.getTrackedEntityInstance() ); + logger.info( "Persisted tracked entity instance {}.", event.getTrackedEntityInstance().getId() ); + updated = true; + } + + if ( event.getEnrollment().isNewResource() ) + { + logger.info( "Creating new enrollment." ); + event.getEnrollment().setEvents( Collections.singletonList( event ) ); + enrollmentService.create( event.getEnrollment() ); + logger.info( "Created new enrollment {} with new event.", event.getEnrollment().getId(), event.getId() ); + updated = true; + } + else + { + final List events = event.getEnrollment().getEvents(); + if ( event.getEnrollment().isModified() ) + { + logger.info( "Updating existing enrollment." ); + event.setEnrollment( enrollmentService.update( event.getEnrollment() ) ); + logger.info( "Updated existing enrollment {}.", event.getEnrollment().getId() ); + updated = true; + } + + for ( final Event e : events ) + { + if ( e.isModified() || e.isAnyDataValueModified() ) + { + logger.debug( "Persisting event." ); + final DhisResource dhisResource = eventService.createOrMinimalUpdate( event ); + logger.info( "Persisted event {}.", dhisResource.getId() ); + updated = true; + } + } + } + + return updated; + } + +} diff --git a/dhis/src/main/java/org/dhis2/fhir/adapter/dhis/tracker/program/Enrollment.java b/dhis/src/main/java/org/dhis2/fhir/adapter/dhis/tracker/program/Enrollment.java index fb92d123..8dab58ea 100644 --- a/dhis/src/main/java/org/dhis2/fhir/adapter/dhis/tracker/program/Enrollment.java +++ b/dhis/src/main/java/org/dhis2/fhir/adapter/dhis/tracker/program/Enrollment.java @@ -32,6 +32,7 @@ import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; import org.dhis2.fhir.adapter.dhis.model.DhisResource; +import org.dhis2.fhir.adapter.dhis.model.DhisResourceId; import org.dhis2.fhir.adapter.dhis.model.DhisResourceType; import org.dhis2.fhir.adapter.dhis.tracker.trackedentity.TrackedEntityInstance; import org.dhis2.fhir.adapter.geo.Location; @@ -61,6 +62,9 @@ public class Enrollment implements DhisResource, Serializable @JsonInclude( JsonInclude.Include.NON_NULL ) private String id; + @JsonProperty( access = JsonProperty.Access.READ_ONLY ) + private ZonedDateTime lastUpdated; + @JsonProperty( "orgUnit" ) private String orgUnitId; @@ -96,6 +100,13 @@ public Enrollment( boolean newResource ) this.events = new ArrayList<>(); } + @JsonIgnore + @Override + public DhisResourceId getResourceId() + { + return (getId() == null) ? null : new DhisResourceId( DhisResourceType.ENROLLMENT, getId() ); + } + @Override public boolean isNewResource() { @@ -110,6 +121,17 @@ public DhisResourceType getResourceType() return DhisResourceType.ENROLLMENT; } + @Override + public ZonedDateTime getLastUpdated() + { + return lastUpdated; + } + + public void setLastUpdated( ZonedDateTime lastUpdated ) + { + this.lastUpdated = lastUpdated; + } + public String getId() { return id; diff --git a/dhis/src/main/java/org/dhis2/fhir/adapter/dhis/tracker/program/Event.java b/dhis/src/main/java/org/dhis2/fhir/adapter/dhis/tracker/program/Event.java index 6875dbce..1b30068f 100644 --- a/dhis/src/main/java/org/dhis2/fhir/adapter/dhis/tracker/program/Event.java +++ b/dhis/src/main/java/org/dhis2/fhir/adapter/dhis/tracker/program/Event.java @@ -33,6 +33,7 @@ import com.fasterxml.jackson.annotation.JsonProperty; import org.dhis2.fhir.adapter.dhis.model.DataValue; import org.dhis2.fhir.adapter.dhis.model.DhisResource; +import org.dhis2.fhir.adapter.dhis.model.DhisResourceId; import org.dhis2.fhir.adapter.dhis.model.DhisResourceType; import org.dhis2.fhir.adapter.dhis.model.WritableDataValue; import org.dhis2.fhir.adapter.dhis.tracker.trackedentity.TrackedEntityInstance; @@ -59,6 +60,9 @@ public class Event implements DhisResource, Serializable, Comparable @JsonInclude( JsonInclude.Include.NON_NULL ) private String id; + @JsonProperty( access = JsonProperty.Access.READ_ONLY ) + private ZonedDateTime lastUpdated; + @JsonProperty( "orgUnit" ) private String orgUnitId; @@ -91,9 +95,6 @@ public class Event implements DhisResource, Serializable, Comparable private Location coordinate; - @JsonInclude( JsonInclude.Include.NON_NULL ) - private ZonedDateTime lastUpdated; - private List dataValues; @JsonIgnore @@ -111,6 +112,13 @@ public Event( boolean newResource ) this.dataValues = new ArrayList<>(); } + @JsonIgnore + @Override + public DhisResourceId getResourceId() + { + return (getId() == null) ? null : new DhisResourceId( DhisResourceType.PROGRAM_STAGE_EVENT, getId() ); + } + @JsonIgnore @Nonnull @Override @@ -247,6 +255,7 @@ public void setCoordinate( Location coordinate ) this.coordinate = coordinate; } + @Override public ZonedDateTime getLastUpdated() { return lastUpdated; diff --git a/dhis/src/main/java/org/dhis2/fhir/adapter/dhis/tracker/trackedentity/TrackedEntityInstance.java b/dhis/src/main/java/org/dhis2/fhir/adapter/dhis/tracker/trackedentity/TrackedEntityInstance.java index 1d4cdb45..41833737 100644 --- a/dhis/src/main/java/org/dhis2/fhir/adapter/dhis/tracker/trackedentity/TrackedEntityInstance.java +++ b/dhis/src/main/java/org/dhis2/fhir/adapter/dhis/tracker/trackedentity/TrackedEntityInstance.java @@ -32,11 +32,13 @@ import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; import org.dhis2.fhir.adapter.dhis.model.DhisResource; +import org.dhis2.fhir.adapter.dhis.model.DhisResourceId; import org.dhis2.fhir.adapter.dhis.model.DhisResourceType; import javax.annotation.Nonnull; import javax.annotation.Nullable; import java.io.Serializable; +import java.time.ZonedDateTime; import java.util.ArrayList; import java.util.Collection; import java.util.Objects; @@ -52,6 +54,9 @@ public class TrackedEntityInstance implements DhisResource, Serializable @JsonInclude( JsonInclude.Include.NON_NULL ) private String id; + @JsonProperty( access = JsonProperty.Access.READ_ONLY ) + private ZonedDateTime lastUpdated; + @JsonIgnore private String identifier; @@ -90,6 +95,13 @@ public TrackedEntityInstance( @Nonnull TrackedEntityType type, @Nullable String } } + @JsonIgnore + @Override + public DhisResourceId getResourceId() + { + return (getId() == null) ? null : new DhisResourceId( DhisResourceType.TRACKED_ENTITY, getId() ); + } + @JsonIgnore @Nonnull @Override @@ -98,6 +110,17 @@ public DhisResourceType getResourceType() return DhisResourceType.TRACKED_ENTITY; } + @Override + public ZonedDateTime getLastUpdated() + { + return lastUpdated; + } + + public void setLastUpdated( ZonedDateTime lastUpdated ) + { + this.lastUpdated = lastUpdated; + } + @Override public boolean isNewResource() { diff --git a/dhis/src/main/java/org/dhis2/fhir/adapter/dhis/tracker/trackedentity/TrackedEntityService.java b/dhis/src/main/java/org/dhis2/fhir/adapter/dhis/tracker/trackedentity/TrackedEntityService.java index 9df838c5..40d68a3f 100644 --- a/dhis/src/main/java/org/dhis2/fhir/adapter/dhis/tracker/trackedentity/TrackedEntityService.java +++ b/dhis/src/main/java/org/dhis2/fhir/adapter/dhis/tracker/trackedentity/TrackedEntityService.java @@ -50,7 +50,7 @@ void updateGeneratedValues( @Nonnull TrackedEntityInstance trackedEntityInstance @Nonnull Map requiredValues ); @Nonnull - Optional getById( @Nonnull String id ); + Optional findById( @Nonnull String id ); @Nonnull Collection findByAttrValueRefreshed( @Nonnull String typeId, diff --git a/dhis/src/main/java/org/dhis2/fhir/adapter/dhis/tracker/trackedentity/impl/TrackedEntityServiceImpl.java b/dhis/src/main/java/org/dhis2/fhir/adapter/dhis/tracker/trackedentity/impl/TrackedEntityServiceImpl.java index da354a1e..41bda301 100644 --- a/dhis/src/main/java/org/dhis2/fhir/adapter/dhis/tracker/trackedentity/impl/TrackedEntityServiceImpl.java +++ b/dhis/src/main/java/org/dhis2/fhir/adapter/dhis/tracker/trackedentity/impl/TrackedEntityServiceImpl.java @@ -156,7 +156,7 @@ public void updateGeneratedValues( @Nonnull TrackedEntityInstance trackedEntityI @HystrixCommand @Nonnull @Override - public Optional getById( @Nonnull String id ) + public Optional findById( @Nonnull String id ) { TrackedEntityInstance instance; try diff --git a/fhir-dstu3/src/main/java/org/dhis2/fhir/adapter/fhir/remote/impl/dstu3/Dstu3RemoteHierarchicallyFhirRepositoryImpl.java b/fhir-dstu3/src/main/java/org/dhis2/fhir/adapter/fhir/remote/impl/dstu3/Dstu3RemoteHierarchicallyFhirResourceRepositoryImpl.java similarity index 82% rename from fhir-dstu3/src/main/java/org/dhis2/fhir/adapter/fhir/remote/impl/dstu3/Dstu3RemoteHierarchicallyFhirRepositoryImpl.java rename to fhir-dstu3/src/main/java/org/dhis2/fhir/adapter/fhir/remote/impl/dstu3/Dstu3RemoteHierarchicallyFhirResourceRepositoryImpl.java index d6601e8e..c7dc466b 100644 --- a/fhir-dstu3/src/main/java/org/dhis2/fhir/adapter/fhir/remote/impl/dstu3/Dstu3RemoteHierarchicallyFhirRepositoryImpl.java +++ b/fhir-dstu3/src/main/java/org/dhis2/fhir/adapter/fhir/remote/impl/dstu3/Dstu3RemoteHierarchicallyFhirResourceRepositoryImpl.java @@ -28,8 +28,8 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -import org.dhis2.fhir.adapter.fhir.repository.RemoteFhirRepository; -import org.dhis2.fhir.adapter.fhir.repository.impl.AbstractRemoteHierarchicallyFhirRepositoryImpl; +import org.dhis2.fhir.adapter.fhir.repository.RemoteFhirResourceRepository; +import org.dhis2.fhir.adapter.fhir.repository.impl.AbstractRemoteHierarchicallyFhirResourceRepositoryImpl; import org.hl7.fhir.dstu3.model.Bundle; import org.hl7.fhir.dstu3.model.Resource; import org.hl7.fhir.instance.model.api.IBaseBundle; @@ -40,16 +40,16 @@ import java.util.List; /** - * Implementation of {@link AbstractRemoteHierarchicallyFhirRepositoryImpl} for DSTU3. + * Implementation of {@link AbstractRemoteHierarchicallyFhirResourceRepositoryImpl} for DSTU3. * * @author volsch */ @Component -public class Dstu3RemoteHierarchicallyFhirRepositoryImpl extends AbstractRemoteHierarchicallyFhirRepositoryImpl +public class Dstu3RemoteHierarchicallyFhirResourceRepositoryImpl extends AbstractRemoteHierarchicallyFhirResourceRepositoryImpl { - public Dstu3RemoteHierarchicallyFhirRepositoryImpl( @Nonnull RemoteFhirRepository remoteFhirRepository ) + public Dstu3RemoteHierarchicallyFhirResourceRepositoryImpl( @Nonnull RemoteFhirResourceRepository remoteFhirResourceRepository ) { - super( remoteFhirRepository ); + super( remoteFhirResourceRepository ); } @Nonnull diff --git a/fhir-dstu3/src/main/java/org/dhis2/fhir/adapter/fhir/repository/impl/dstu3/Dstu3RemoteFhirRepositoryImpl.java b/fhir-dstu3/src/main/java/org/dhis2/fhir/adapter/fhir/repository/impl/dstu3/Dstu3RemoteFhirResourceRepositoryImpl.java similarity index 90% rename from fhir-dstu3/src/main/java/org/dhis2/fhir/adapter/fhir/repository/impl/dstu3/Dstu3RemoteFhirRepositoryImpl.java rename to fhir-dstu3/src/main/java/org/dhis2/fhir/adapter/fhir/repository/impl/dstu3/Dstu3RemoteFhirResourceRepositoryImpl.java index ae9db2ba..dcd259d0 100644 --- a/fhir-dstu3/src/main/java/org/dhis2/fhir/adapter/fhir/repository/impl/dstu3/Dstu3RemoteFhirRepositoryImpl.java +++ b/fhir-dstu3/src/main/java/org/dhis2/fhir/adapter/fhir/repository/impl/dstu3/Dstu3RemoteFhirResourceRepositoryImpl.java @@ -32,7 +32,7 @@ import org.dhis2.fhir.adapter.fhir.metadata.model.RemoteSubscriptionResource; import org.dhis2.fhir.adapter.fhir.metadata.model.SubscriptionType; import org.dhis2.fhir.adapter.fhir.metadata.repository.RemoteSubscriptionRepository; -import org.dhis2.fhir.adapter.fhir.repository.impl.AbstractRemoteFhirRepositoryImpl; +import org.dhis2.fhir.adapter.fhir.repository.impl.AbstractRemoteFhirResourceRepositoryImpl; import org.hl7.fhir.dstu3.model.Subscription; import org.hl7.fhir.instance.model.api.IAnyResource; import org.springframework.beans.factory.ObjectProvider; @@ -42,14 +42,14 @@ import java.util.List; /** - * Implementation of {@link AbstractRemoteFhirRepositoryImpl} for DSTU3. + * Implementation of {@link AbstractRemoteFhirResourceRepositoryImpl} for DSTU3. * * @author volsch */ @Component -public class Dstu3RemoteFhirRepositoryImpl extends AbstractRemoteFhirRepositoryImpl +public class Dstu3RemoteFhirResourceRepositoryImpl extends AbstractRemoteFhirResourceRepositoryImpl { - public Dstu3RemoteFhirRepositoryImpl( @Nonnull RemoteSubscriptionRepository repository, @Nonnull ObjectProvider> fhirContexts ) + public Dstu3RemoteFhirResourceRepositoryImpl( @Nonnull RemoteSubscriptionRepository repository, @Nonnull ObjectProvider> fhirContexts ) { super( repository, fhirContexts ); } diff --git a/fhir-dstu3/src/main/java/org/dhis2/fhir/adapter/fhir/transform/impl/util/dstu3/Dstu3AddressFhirToDhisTransformerUtils.java b/fhir-dstu3/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/dstu3/Dstu3AddressFhirToDhisTransformerUtils.java similarity index 96% rename from fhir-dstu3/src/main/java/org/dhis2/fhir/adapter/fhir/transform/impl/util/dstu3/Dstu3AddressFhirToDhisTransformerUtils.java rename to fhir-dstu3/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/dstu3/Dstu3AddressFhirToDhisTransformerUtils.java index 13190c98..1452097c 100644 --- a/fhir-dstu3/src/main/java/org/dhis2/fhir/adapter/fhir/transform/impl/util/dstu3/Dstu3AddressFhirToDhisTransformerUtils.java +++ b/fhir-dstu3/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/dstu3/Dstu3AddressFhirToDhisTransformerUtils.java @@ -1,4 +1,4 @@ -package org.dhis2.fhir.adapter.fhir.transform.impl.util.dstu3; +package org.dhis2.fhir.adapter.fhir.transform.fhir.impl.util.dstu3; /* * Copyright (c) 2004-2018, University of Oslo @@ -31,8 +31,8 @@ import org.apache.commons.lang3.StringUtils; import org.dhis2.fhir.adapter.fhir.model.FhirVersion; import org.dhis2.fhir.adapter.fhir.script.ScriptExecutionContext; -import org.dhis2.fhir.adapter.fhir.transform.impl.util.AbstractAddressFhirToDhisTransformerUtils; -import org.dhis2.fhir.adapter.fhir.transform.impl.util.TransformerComparatorUtils; +import org.dhis2.fhir.adapter.fhir.transform.fhir.impl.util.AbstractAddressFhirToDhisTransformerUtils; +import org.dhis2.fhir.adapter.fhir.transform.fhir.impl.util.TransformerComparatorUtils; import org.dhis2.fhir.adapter.scriptable.Scriptable; import org.hl7.fhir.dstu3.model.Address; import org.hl7.fhir.dstu3.model.PrimitiveType; diff --git a/fhir-dstu3/src/main/java/org/dhis2/fhir/adapter/fhir/transform/impl/util/dstu3/Dstu3CodeFhirToDhisTransformerUtils.java b/fhir-dstu3/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/dstu3/Dstu3CodeFhirToDhisTransformerUtils.java similarity index 97% rename from fhir-dstu3/src/main/java/org/dhis2/fhir/adapter/fhir/transform/impl/util/dstu3/Dstu3CodeFhirToDhisTransformerUtils.java rename to fhir-dstu3/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/dstu3/Dstu3CodeFhirToDhisTransformerUtils.java index 850f3e26..173172f9 100644 --- a/fhir-dstu3/src/main/java/org/dhis2/fhir/adapter/fhir/transform/impl/util/dstu3/Dstu3CodeFhirToDhisTransformerUtils.java +++ b/fhir-dstu3/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/dstu3/Dstu3CodeFhirToDhisTransformerUtils.java @@ -1,4 +1,4 @@ -package org.dhis2.fhir.adapter.fhir.transform.impl.util.dstu3; +package org.dhis2.fhir.adapter.fhir.transform.fhir.impl.util.dstu3; /* * Copyright (c) 2004-2018, University of Oslo @@ -36,7 +36,7 @@ import org.dhis2.fhir.adapter.fhir.model.SystemCodeValue; import org.dhis2.fhir.adapter.fhir.script.ScriptArgUtils; import org.dhis2.fhir.adapter.fhir.script.ScriptExecutionContext; -import org.dhis2.fhir.adapter.fhir.transform.impl.util.AbstractCodeFhirToDhisTransformerUtils; +import org.dhis2.fhir.adapter.fhir.transform.fhir.impl.util.AbstractCodeFhirToDhisTransformerUtils; import org.dhis2.fhir.adapter.scriptable.Scriptable; import org.hl7.fhir.dstu3.model.CodeableConcept; import org.hl7.fhir.dstu3.model.Coding; diff --git a/fhir-dstu3/src/main/java/org/dhis2/fhir/adapter/fhir/transform/impl/util/dstu3/Dstu3ContactPointFhirToDhisTransformerUtils.java b/fhir-dstu3/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/dstu3/Dstu3ContactPointFhirToDhisTransformerUtils.java similarity index 94% rename from fhir-dstu3/src/main/java/org/dhis2/fhir/adapter/fhir/transform/impl/util/dstu3/Dstu3ContactPointFhirToDhisTransformerUtils.java rename to fhir-dstu3/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/dstu3/Dstu3ContactPointFhirToDhisTransformerUtils.java index 6b7f24c4..64051dcb 100644 --- a/fhir-dstu3/src/main/java/org/dhis2/fhir/adapter/fhir/transform/impl/util/dstu3/Dstu3ContactPointFhirToDhisTransformerUtils.java +++ b/fhir-dstu3/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/dstu3/Dstu3ContactPointFhirToDhisTransformerUtils.java @@ -1,4 +1,4 @@ -package org.dhis2.fhir.adapter.fhir.transform.impl.util.dstu3; +package org.dhis2.fhir.adapter.fhir.transform.fhir.impl.util.dstu3; /* * Copyright (c) 2004-2018, University of Oslo @@ -30,8 +30,8 @@ import org.dhis2.fhir.adapter.fhir.model.FhirVersion; import org.dhis2.fhir.adapter.fhir.script.ScriptExecutionContext; -import org.dhis2.fhir.adapter.fhir.transform.impl.util.AbstractContactPointFhirToDhisTransformerUtils; -import org.dhis2.fhir.adapter.fhir.transform.impl.util.TransformerComparatorUtils; +import org.dhis2.fhir.adapter.fhir.transform.fhir.impl.util.AbstractContactPointFhirToDhisTransformerUtils; +import org.dhis2.fhir.adapter.fhir.transform.fhir.impl.util.TransformerComparatorUtils; import org.dhis2.fhir.adapter.scriptable.Scriptable; import org.hl7.fhir.dstu3.model.ContactPoint; import org.hl7.fhir.instance.model.api.ICompositeType; diff --git a/fhir-dstu3/src/main/java/org/dhis2/fhir/adapter/fhir/transform/impl/util/dstu3/Dstu3DateTimeFhirToDhisTransformerUtils.java b/fhir-dstu3/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/dstu3/Dstu3DateTimeFhirToDhisTransformerUtils.java similarity index 95% rename from fhir-dstu3/src/main/java/org/dhis2/fhir/adapter/fhir/transform/impl/util/dstu3/Dstu3DateTimeFhirToDhisTransformerUtils.java rename to fhir-dstu3/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/dstu3/Dstu3DateTimeFhirToDhisTransformerUtils.java index 40b53e38..d1805375 100644 --- a/fhir-dstu3/src/main/java/org/dhis2/fhir/adapter/fhir/transform/impl/util/dstu3/Dstu3DateTimeFhirToDhisTransformerUtils.java +++ b/fhir-dstu3/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/dstu3/Dstu3DateTimeFhirToDhisTransformerUtils.java @@ -1,4 +1,4 @@ -package org.dhis2.fhir.adapter.fhir.transform.impl.util.dstu3; +package org.dhis2.fhir.adapter.fhir.transform.fhir.impl.util.dstu3; /* * Copyright (c) 2004-2018, University of Oslo @@ -31,7 +31,7 @@ import ca.uhn.fhir.model.api.TemporalPrecisionEnum; import org.dhis2.fhir.adapter.fhir.model.FhirVersion; import org.dhis2.fhir.adapter.fhir.script.ScriptExecutionContext; -import org.dhis2.fhir.adapter.fhir.transform.impl.util.AbstractDateTimeFhirToDhisTransformerUtils; +import org.dhis2.fhir.adapter.fhir.transform.fhir.impl.util.AbstractDateTimeFhirToDhisTransformerUtils; import org.dhis2.fhir.adapter.scriptable.Scriptable; import org.dhis2.fhir.adapter.util.CastUtils; import org.hl7.fhir.dstu3.model.BaseDateTimeType; diff --git a/fhir-dstu3/src/main/java/org/dhis2/fhir/adapter/fhir/transform/impl/util/dstu3/Dstu3FhirClientFhirToDhisTransformerUtils.java b/fhir-dstu3/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/dstu3/Dstu3FhirClientFhirToDhisTransformerUtils.java similarity index 96% rename from fhir-dstu3/src/main/java/org/dhis2/fhir/adapter/fhir/transform/impl/util/dstu3/Dstu3FhirClientFhirToDhisTransformerUtils.java rename to fhir-dstu3/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/dstu3/Dstu3FhirClientFhirToDhisTransformerUtils.java index fb0c9b32..afd54b2d 100644 --- a/fhir-dstu3/src/main/java/org/dhis2/fhir/adapter/fhir/transform/impl/util/dstu3/Dstu3FhirClientFhirToDhisTransformerUtils.java +++ b/fhir-dstu3/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/dstu3/Dstu3FhirClientFhirToDhisTransformerUtils.java @@ -1,4 +1,4 @@ -package org.dhis2.fhir.adapter.fhir.transform.impl.util.dstu3; +package org.dhis2.fhir.adapter.fhir.transform.fhir.impl.util.dstu3; /* * Copyright (c) 2004-2018, University of Oslo @@ -33,7 +33,7 @@ import org.dhis2.fhir.adapter.fhir.metadata.repository.SystemCodeRepository; import org.dhis2.fhir.adapter.fhir.model.FhirVersion; import org.dhis2.fhir.adapter.fhir.script.ScriptExecutionContext; -import org.dhis2.fhir.adapter.fhir.transform.impl.util.AbstractFhirClientFhirToDhisTransformerUtils; +import org.dhis2.fhir.adapter.fhir.transform.fhir.impl.util.AbstractFhirClientFhirToDhisTransformerUtils; import org.dhis2.fhir.adapter.scriptable.Scriptable; import org.hl7.fhir.dstu3.model.Bundle; import org.hl7.fhir.dstu3.model.Bundle.BundleEntryComponent; diff --git a/fhir-dstu3/src/main/java/org/dhis2/fhir/adapter/fhir/transform/impl/util/dstu3/Dstu3GeoFhirToDhisTransformerUtils.java b/fhir-dstu3/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/dstu3/Dstu3GeoFhirToDhisTransformerUtils.java similarity index 96% rename from fhir-dstu3/src/main/java/org/dhis2/fhir/adapter/fhir/transform/impl/util/dstu3/Dstu3GeoFhirToDhisTransformerUtils.java rename to fhir-dstu3/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/dstu3/Dstu3GeoFhirToDhisTransformerUtils.java index e212e679..61a7d12c 100644 --- a/fhir-dstu3/src/main/java/org/dhis2/fhir/adapter/fhir/transform/impl/util/dstu3/Dstu3GeoFhirToDhisTransformerUtils.java +++ b/fhir-dstu3/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/dstu3/Dstu3GeoFhirToDhisTransformerUtils.java @@ -1,4 +1,4 @@ -package org.dhis2.fhir.adapter.fhir.transform.impl.util.dstu3; +package org.dhis2.fhir.adapter.fhir.transform.fhir.impl.util.dstu3; /* * Copyright (c) 2004-2018, University of Oslo @@ -33,7 +33,7 @@ import org.dhis2.fhir.adapter.fhir.script.ScriptExecutionContext; import org.dhis2.fhir.adapter.fhir.transform.TransformerException; import org.dhis2.fhir.adapter.fhir.transform.TransformerMappingException; -import org.dhis2.fhir.adapter.fhir.transform.impl.util.AbstractGeoFhirToDhisTransformerUtils; +import org.dhis2.fhir.adapter.fhir.transform.fhir.impl.util.AbstractGeoFhirToDhisTransformerUtils; import org.dhis2.fhir.adapter.geo.Location; import org.dhis2.fhir.adapter.scriptable.Scriptable; import org.hl7.fhir.dstu3.model.DecimalType; diff --git a/fhir-dstu3/src/main/java/org/dhis2/fhir/adapter/fhir/transform/impl/util/dstu3/Dstu3HumanNameFhirToDhisTransformerUtils.java b/fhir-dstu3/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/dstu3/Dstu3HumanNameFhirToDhisTransformerUtils.java similarity index 95% rename from fhir-dstu3/src/main/java/org/dhis2/fhir/adapter/fhir/transform/impl/util/dstu3/Dstu3HumanNameFhirToDhisTransformerUtils.java rename to fhir-dstu3/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/dstu3/Dstu3HumanNameFhirToDhisTransformerUtils.java index 504a8722..7f1daed0 100644 --- a/fhir-dstu3/src/main/java/org/dhis2/fhir/adapter/fhir/transform/impl/util/dstu3/Dstu3HumanNameFhirToDhisTransformerUtils.java +++ b/fhir-dstu3/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/dstu3/Dstu3HumanNameFhirToDhisTransformerUtils.java @@ -1,4 +1,4 @@ -package org.dhis2.fhir.adapter.fhir.transform.impl.util.dstu3; +package org.dhis2.fhir.adapter.fhir.transform.fhir.impl.util.dstu3; /* * Copyright (c) 2004-2018, University of Oslo @@ -30,8 +30,8 @@ import org.dhis2.fhir.adapter.fhir.model.FhirVersion; import org.dhis2.fhir.adapter.fhir.script.ScriptExecutionContext; -import org.dhis2.fhir.adapter.fhir.transform.impl.util.AbstractHumanNameFhirToDhisTransformerUtils; -import org.dhis2.fhir.adapter.fhir.transform.impl.util.TransformerComparatorUtils; +import org.dhis2.fhir.adapter.fhir.transform.fhir.impl.util.AbstractHumanNameFhirToDhisTransformerUtils; +import org.dhis2.fhir.adapter.fhir.transform.fhir.impl.util.TransformerComparatorUtils; import org.dhis2.fhir.adapter.scriptable.Scriptable; import org.hl7.fhir.dstu3.model.HumanName; import org.hl7.fhir.dstu3.model.PrimitiveType; diff --git a/fhir-dstu3/src/main/java/org/dhis2/fhir/adapter/fhir/transform/impl/util/dstu3/Dstu3IdentifierFhirToDhisTransformerUtils.java b/fhir-dstu3/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/dstu3/Dstu3IdentifierFhirToDhisTransformerUtils.java similarity index 92% rename from fhir-dstu3/src/main/java/org/dhis2/fhir/adapter/fhir/transform/impl/util/dstu3/Dstu3IdentifierFhirToDhisTransformerUtils.java rename to fhir-dstu3/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/dstu3/Dstu3IdentifierFhirToDhisTransformerUtils.java index 9606c80c..cd2dcad6 100644 --- a/fhir-dstu3/src/main/java/org/dhis2/fhir/adapter/fhir/transform/impl/util/dstu3/Dstu3IdentifierFhirToDhisTransformerUtils.java +++ b/fhir-dstu3/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/dstu3/Dstu3IdentifierFhirToDhisTransformerUtils.java @@ -1,4 +1,4 @@ -package org.dhis2.fhir.adapter.fhir.transform.impl.util.dstu3; +package org.dhis2.fhir.adapter.fhir.transform.fhir.impl.util.dstu3; /* * Copyright (c) 2004-2018, University of Oslo @@ -30,8 +30,8 @@ import org.dhis2.fhir.adapter.fhir.model.FhirVersion; import org.dhis2.fhir.adapter.fhir.script.ScriptExecutionContext; -import org.dhis2.fhir.adapter.fhir.transform.impl.util.AbstractIdentifierFhirToDhisTransformerUtils; -import org.dhis2.fhir.adapter.fhir.transform.impl.util.ReferenceFhirToDhisTransformerUtils; +import org.dhis2.fhir.adapter.fhir.transform.fhir.impl.util.AbstractIdentifierFhirToDhisTransformerUtils; +import org.dhis2.fhir.adapter.fhir.transform.fhir.impl.util.ReferenceFhirToDhisTransformerUtils; import org.dhis2.fhir.adapter.scriptable.Scriptable; import org.hl7.fhir.dstu3.model.Identifier; import org.hl7.fhir.instance.model.api.IDomainResource; diff --git a/fhir-dstu3/src/main/java/org/dhis2/fhir/adapter/fhir/transform/impl/util/dstu3/Dstu3ImmunizationFhirToDhisTransformerUtils.java b/fhir-dstu3/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/dstu3/Dstu3ImmunizationFhirToDhisTransformerUtils.java similarity index 94% rename from fhir-dstu3/src/main/java/org/dhis2/fhir/adapter/fhir/transform/impl/util/dstu3/Dstu3ImmunizationFhirToDhisTransformerUtils.java rename to fhir-dstu3/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/dstu3/Dstu3ImmunizationFhirToDhisTransformerUtils.java index 4cb570e7..88b0166f 100644 --- a/fhir-dstu3/src/main/java/org/dhis2/fhir/adapter/fhir/transform/impl/util/dstu3/Dstu3ImmunizationFhirToDhisTransformerUtils.java +++ b/fhir-dstu3/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/dstu3/Dstu3ImmunizationFhirToDhisTransformerUtils.java @@ -1,4 +1,4 @@ -package org.dhis2.fhir.adapter.fhir.transform.impl.util.dstu3; +package org.dhis2.fhir.adapter.fhir.transform.fhir.impl.util.dstu3; /* * Copyright (c) 2004-2018, University of Oslo @@ -31,7 +31,7 @@ import org.dhis2.fhir.adapter.fhir.model.FhirVersion; import org.dhis2.fhir.adapter.fhir.script.ScriptExecutionContext; import org.dhis2.fhir.adapter.fhir.transform.TransformerException; -import org.dhis2.fhir.adapter.fhir.transform.impl.util.AbstractImmunizationFhirToDhisTransformerUtils; +import org.dhis2.fhir.adapter.fhir.transform.fhir.impl.util.AbstractImmunizationFhirToDhisTransformerUtils; import org.dhis2.fhir.adapter.scriptable.Scriptable; import org.hl7.fhir.dstu3.model.Immunization; import org.hl7.fhir.instance.model.api.IDomainResource; diff --git a/fhir-dstu3/src/main/java/org/dhis2/fhir/adapter/fhir/transform/impl/util/dstu3/Dstu3ObservationFhirToDhisTransformerUtils.java b/fhir-dstu3/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/dstu3/Dstu3ObservationFhirToDhisTransformerUtils.java similarity index 96% rename from fhir-dstu3/src/main/java/org/dhis2/fhir/adapter/fhir/transform/impl/util/dstu3/Dstu3ObservationFhirToDhisTransformerUtils.java rename to fhir-dstu3/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/dstu3/Dstu3ObservationFhirToDhisTransformerUtils.java index 7cd1c3d8..931c4349 100644 --- a/fhir-dstu3/src/main/java/org/dhis2/fhir/adapter/fhir/transform/impl/util/dstu3/Dstu3ObservationFhirToDhisTransformerUtils.java +++ b/fhir-dstu3/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/dstu3/Dstu3ObservationFhirToDhisTransformerUtils.java @@ -1,4 +1,4 @@ -package org.dhis2.fhir.adapter.fhir.transform.impl.util.dstu3; +package org.dhis2.fhir.adapter.fhir.transform.fhir.impl.util.dstu3; /* * Copyright (c) 2004-2018, University of Oslo @@ -30,7 +30,7 @@ import org.dhis2.fhir.adapter.fhir.model.FhirVersion; import org.dhis2.fhir.adapter.fhir.script.ScriptExecutionContext; -import org.dhis2.fhir.adapter.fhir.transform.impl.util.AbstractObservationFhirToDhisTransformerUtils; +import org.dhis2.fhir.adapter.fhir.transform.fhir.impl.util.AbstractObservationFhirToDhisTransformerUtils; import org.dhis2.fhir.adapter.scriptable.Scriptable; import org.hl7.fhir.dstu3.model.Observation; import org.hl7.fhir.dstu3.model.Observation.ObservationComponentComponent; diff --git a/fhir-dstu3/src/main/java/org/dhis2/fhir/adapter/fhir/transform/impl/util/dstu3/Dstu3OrganizationFhirToDhisTransformerUtils.java b/fhir-dstu3/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/dstu3/Dstu3OrganizationFhirToDhisTransformerUtils.java similarity index 87% rename from fhir-dstu3/src/main/java/org/dhis2/fhir/adapter/fhir/transform/impl/util/dstu3/Dstu3OrganizationFhirToDhisTransformerUtils.java rename to fhir-dstu3/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/dstu3/Dstu3OrganizationFhirToDhisTransformerUtils.java index 31251f35..77fd75bb 100644 --- a/fhir-dstu3/src/main/java/org/dhis2/fhir/adapter/fhir/transform/impl/util/dstu3/Dstu3OrganizationFhirToDhisTransformerUtils.java +++ b/fhir-dstu3/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/dstu3/Dstu3OrganizationFhirToDhisTransformerUtils.java @@ -1,4 +1,4 @@ -package org.dhis2.fhir.adapter.fhir.transform.impl.util.dstu3; +package org.dhis2.fhir.adapter.fhir.transform.fhir.impl.util.dstu3; /* * Copyright (c) 2004-2018, University of Oslo @@ -31,10 +31,10 @@ import org.dhis2.fhir.adapter.dhis.orgunit.OrganisationUnitService; import org.dhis2.fhir.adapter.fhir.metadata.repository.RemoteSubscriptionResourceRepository; import org.dhis2.fhir.adapter.fhir.model.FhirVersion; -import org.dhis2.fhir.adapter.fhir.repository.RemoteFhirRepository; -import org.dhis2.fhir.adapter.fhir.repository.RemoteHierarchicallyFhirRepository; +import org.dhis2.fhir.adapter.fhir.repository.RemoteFhirResourceRepository; +import org.dhis2.fhir.adapter.fhir.repository.RemoteHierarchicallyFhirResourceRepository; import org.dhis2.fhir.adapter.fhir.script.ScriptExecutionContext; -import org.dhis2.fhir.adapter.fhir.transform.impl.util.AbstractOrganizationFhirToDhisTransformerUtils; +import org.dhis2.fhir.adapter.fhir.transform.fhir.impl.util.AbstractOrganizationFhirToDhisTransformerUtils; import org.dhis2.fhir.adapter.scriptable.Scriptable; import org.hl7.fhir.dstu3.model.Bundle; import org.hl7.fhir.dstu3.model.Organization; @@ -62,10 +62,10 @@ public class Dstu3OrganizationFhirToDhisTransformerUtils extends AbstractOrganiz public Dstu3OrganizationFhirToDhisTransformerUtils( @Nonnull ScriptExecutionContext scriptExecutionContext, @Nonnull OrganisationUnitService organisationUnitService, @Nonnull RemoteSubscriptionResourceRepository subscriptionResourceRepository, - @Nonnull RemoteFhirRepository remoteFhirRepository, - @Nonnull RemoteHierarchicallyFhirRepository remoteHierarchicallyFhirRepository ) + @Nonnull RemoteFhirResourceRepository remoteFhirResourceRepository, + @Nonnull RemoteHierarchicallyFhirResourceRepository remoteHierarchicallyFhirResourceRepository ) { - super( scriptExecutionContext, organisationUnitService, subscriptionResourceRepository, remoteFhirRepository, remoteHierarchicallyFhirRepository ); + super( scriptExecutionContext, organisationUnitService, subscriptionResourceRepository, remoteFhirResourceRepository, remoteHierarchicallyFhirResourceRepository ); } @Nonnull diff --git a/fhir-dstu3/src/main/java/org/dhis2/fhir/adapter/fhir/transform/impl/util/dstu3/Dstu3PatientFhirToDhisTransformerUtils.java b/fhir-dstu3/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/dstu3/Dstu3PatientFhirToDhisTransformerUtils.java similarity index 95% rename from fhir-dstu3/src/main/java/org/dhis2/fhir/adapter/fhir/transform/impl/util/dstu3/Dstu3PatientFhirToDhisTransformerUtils.java rename to fhir-dstu3/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/dstu3/Dstu3PatientFhirToDhisTransformerUtils.java index 9f21a1df..3a6b69bf 100644 --- a/fhir-dstu3/src/main/java/org/dhis2/fhir/adapter/fhir/transform/impl/util/dstu3/Dstu3PatientFhirToDhisTransformerUtils.java +++ b/fhir-dstu3/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/dstu3/Dstu3PatientFhirToDhisTransformerUtils.java @@ -1,4 +1,4 @@ -package org.dhis2.fhir.adapter.fhir.transform.impl.util.dstu3; +package org.dhis2.fhir.adapter.fhir.transform.fhir.impl.util.dstu3; /* * Copyright (c) 2004-2018, University of Oslo @@ -31,7 +31,7 @@ import org.dhis2.fhir.adapter.fhir.model.FhirVersion; import org.dhis2.fhir.adapter.fhir.script.ScriptExecutionContext; import org.dhis2.fhir.adapter.fhir.transform.TransformerMappingException; -import org.dhis2.fhir.adapter.fhir.transform.impl.util.AbstractPatientFhirToDhisTransformerUtils; +import org.dhis2.fhir.adapter.fhir.transform.fhir.impl.util.AbstractPatientFhirToDhisTransformerUtils; import org.dhis2.fhir.adapter.scriptable.Scriptable; import org.hl7.fhir.dstu3.model.Address; import org.hl7.fhir.dstu3.model.Extension; diff --git a/fhir-dstu3/src/main/java/org/dhis2/fhir/adapter/fhir/transform/impl/util/dstu3/Dstu3VitalSignFhirToDhisTransformerUtils.java b/fhir-dstu3/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/dstu3/Dstu3VitalSignFhirToDhisTransformerUtils.java similarity index 96% rename from fhir-dstu3/src/main/java/org/dhis2/fhir/adapter/fhir/transform/impl/util/dstu3/Dstu3VitalSignFhirToDhisTransformerUtils.java rename to fhir-dstu3/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/dstu3/Dstu3VitalSignFhirToDhisTransformerUtils.java index 2f9782ba..ade26e6e 100644 --- a/fhir-dstu3/src/main/java/org/dhis2/fhir/adapter/fhir/transform/impl/util/dstu3/Dstu3VitalSignFhirToDhisTransformerUtils.java +++ b/fhir-dstu3/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/dstu3/Dstu3VitalSignFhirToDhisTransformerUtils.java @@ -1,4 +1,4 @@ -package org.dhis2.fhir.adapter.fhir.transform.impl.util.dstu3; +package org.dhis2.fhir.adapter.fhir.transform.fhir.impl.util.dstu3; /* * Copyright (c) 2004-2018, University of Oslo @@ -32,7 +32,7 @@ import org.dhis2.fhir.adapter.fhir.script.ScriptExecutionContext; import org.dhis2.fhir.adapter.fhir.transform.TransformerDataException; import org.dhis2.fhir.adapter.fhir.transform.TransformerMappingException; -import org.dhis2.fhir.adapter.fhir.transform.impl.util.AbstractVitalSignFhirToDhisTransformerUtils; +import org.dhis2.fhir.adapter.fhir.transform.fhir.impl.util.AbstractVitalSignFhirToDhisTransformerUtils; import org.dhis2.fhir.adapter.model.WeightUnit; import org.dhis2.fhir.adapter.scriptable.Scriptable; import org.hl7.fhir.dstu3.model.Quantity; diff --git a/fhir-dstu3/src/test/java/org/dhis2/fhir/adapter/fhir/transform/impl/util/ReferenceFhirToDhisTransformerUtilsTest.java b/fhir-dstu3/src/test/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/ReferenceFhirToDhisTransformerUtilsTest.java similarity index 91% rename from fhir-dstu3/src/test/java/org/dhis2/fhir/adapter/fhir/transform/impl/util/ReferenceFhirToDhisTransformerUtilsTest.java rename to fhir-dstu3/src/test/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/ReferenceFhirToDhisTransformerUtilsTest.java index 5a686e9e..cfa6098a 100644 --- a/fhir-dstu3/src/test/java/org/dhis2/fhir/adapter/fhir/transform/impl/util/ReferenceFhirToDhisTransformerUtilsTest.java +++ b/fhir-dstu3/src/test/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/ReferenceFhirToDhisTransformerUtilsTest.java @@ -1,4 +1,4 @@ -package org.dhis2.fhir.adapter.fhir.transform.impl.util; +package org.dhis2.fhir.adapter.fhir.transform.fhir.impl.util; /* * Copyright (c) 2004-2018, University of Oslo @@ -35,12 +35,12 @@ import org.dhis2.fhir.adapter.fhir.metadata.model.SubscriptionFhirEndpoint; import org.dhis2.fhir.adapter.fhir.metadata.repository.RemoteSubscriptionResourceRepository; import org.dhis2.fhir.adapter.fhir.model.FhirVersion; -import org.dhis2.fhir.adapter.fhir.repository.RemoteFhirRepository; +import org.dhis2.fhir.adapter.fhir.repository.RemoteFhirResourceRepository; import org.dhis2.fhir.adapter.fhir.script.ScriptExecution; import org.dhis2.fhir.adapter.fhir.script.ScriptExecutionContext; -import org.dhis2.fhir.adapter.fhir.transform.FhirToDhisTransformerContext; -import org.dhis2.fhir.adapter.fhir.transform.model.FhirRequest; -import org.dhis2.fhir.adapter.fhir.transform.model.ResourceSystem; +import org.dhis2.fhir.adapter.fhir.transform.fhir.FhirToDhisTransformerContext; +import org.dhis2.fhir.adapter.fhir.transform.fhir.model.FhirRequest; +import org.dhis2.fhir.adapter.fhir.transform.fhir.model.ResourceSystem; import org.hl7.fhir.dstu3.model.IdType; import org.hl7.fhir.dstu3.model.Patient; import org.hl7.fhir.dstu3.model.Reference; @@ -74,7 +74,7 @@ public class ReferenceFhirToDhisTransformerUtilsTest private RemoteSubscriptionResourceRepository subscriptionResourceRepository; @Mock - private RemoteFhirRepository remoteFhirRepository; + private RemoteFhirResourceRepository remoteFhirResourceRepository; @Mock private FhirToDhisTransformerContext context; @@ -153,14 +153,14 @@ public void getResource() Mockito.doReturn( FhirVersion.DSTU3 ).when( request ).getVersion(); Mockito.doReturn( Optional.of( resourceSystem ) ).when( request ).getOptionalResourceSystem( FhirResourceType.ORGANIZATION ); Mockito.doReturn( Optional.of( remoteSubscriptionResource ) ).when( subscriptionResourceRepository ).findByIdCached( Mockito.eq( remoteSubscriptionResourceId ) ); - Mockito.doReturn( Optional.of( fhirContext ) ).when( remoteFhirRepository ).findFhirContext( Mockito.eq( FhirVersion.DSTU3 ) ); + Mockito.doReturn( Optional.of( fhirContext ) ).when( remoteFhirResourceRepository ).findFhirContext( Mockito.eq( FhirVersion.DSTU3 ) ); final Patient resource = new Patient(); final IIdType id = new IdType( "Patient", "123" ); resource.setId( id ); final Reference reference = new Reference( id ); - Mockito.doReturn( Optional.of( resource ) ).when( remoteFhirRepository ) + Mockito.doReturn( Optional.of( resource ) ).when( remoteFhirResourceRepository ) .find( Mockito.eq( remoteSubscriptionId ), Mockito.eq( FhirVersion.DSTU3 ), Mockito.same( subscriptionFhirEndpoint ), Mockito.eq( "Patient" ), Mockito.eq( "123" ) ); @@ -169,7 +169,7 @@ public void getResource() Assert.assertEquals( id, result.getIdElement() ); Assert.assertNotSame( resource, result ); - Mockito.verify( remoteFhirRepository ).find( Mockito.eq( remoteSubscriptionId ), Mockito.eq( FhirVersion.DSTU3 ), + Mockito.verify( remoteFhirResourceRepository ).find( Mockito.eq( remoteSubscriptionId ), Mockito.eq( FhirVersion.DSTU3 ), Mockito.same( subscriptionFhirEndpoint ), Mockito.eq( "Patient" ), Mockito.eq( "123" ) ); } @@ -196,14 +196,14 @@ public void getResourceRefreshed() Mockito.doReturn( FhirVersion.DSTU3 ).when( request ).getVersion(); Mockito.doReturn( Optional.of( resourceSystem ) ).when( request ).getOptionalResourceSystem( FhirResourceType.ORGANIZATION ); Mockito.doReturn( Optional.of( remoteSubscriptionResource ) ).when( subscriptionResourceRepository ).findByIdCached( Mockito.eq( remoteSubscriptionResourceId ) ); - Mockito.doReturn( Optional.of( fhirContext ) ).when( remoteFhirRepository ).findFhirContext( Mockito.eq( FhirVersion.DSTU3 ) ); + Mockito.doReturn( Optional.of( fhirContext ) ).when( remoteFhirResourceRepository ).findFhirContext( Mockito.eq( FhirVersion.DSTU3 ) ); final Patient resource = new Patient(); final IIdType id = new IdType( "Patient", "123" ); resource.setId( id ); final Reference reference = new Reference( id ); - Mockito.doReturn( Optional.of( resource ) ).when( remoteFhirRepository ) + Mockito.doReturn( Optional.of( resource ) ).when( remoteFhirResourceRepository ) .findRefreshed( Mockito.eq( remoteSubscriptionId ), Mockito.eq( FhirVersion.DSTU3 ), Mockito.same( subscriptionFhirEndpoint ), Mockito.eq( "Patient" ), Mockito.eq( "123" ) ); @@ -212,7 +212,7 @@ public void getResourceRefreshed() Assert.assertEquals( id, result.getIdElement() ); Assert.assertNotSame( resource, result ); - Mockito.verify( remoteFhirRepository ).findRefreshed( Mockito.eq( remoteSubscriptionId ), Mockito.eq( FhirVersion.DSTU3 ), + Mockito.verify( remoteFhirResourceRepository ).findRefreshed( Mockito.eq( remoteSubscriptionId ), Mockito.eq( FhirVersion.DSTU3 ), Mockito.same( subscriptionFhirEndpoint ), Mockito.eq( "Patient" ), Mockito.eq( "123" ) ); } @@ -239,14 +239,14 @@ public void initReference() Mockito.doReturn( FhirVersion.DSTU3 ).when( request ).getVersion(); Mockito.doReturn( Optional.of( resourceSystem ) ).when( request ).getOptionalResourceSystem( FhirResourceType.ORGANIZATION ); Mockito.doReturn( Optional.of( remoteSubscriptionResource ) ).when( subscriptionResourceRepository ).findByIdCached( Mockito.eq( remoteSubscriptionResourceId ) ); - Mockito.doReturn( Optional.of( fhirContext ) ).when( remoteFhirRepository ).findFhirContext( Mockito.eq( FhirVersion.DSTU3 ) ); + Mockito.doReturn( Optional.of( fhirContext ) ).when( remoteFhirResourceRepository ).findFhirContext( Mockito.eq( FhirVersion.DSTU3 ) ); final Patient resource = new Patient(); final IIdType id = new IdType( "Patient", "123" ); resource.setId( id ); final Reference reference = new Reference( id ); - Mockito.doReturn( Optional.of( resource ) ).when( remoteFhirRepository ) + Mockito.doReturn( Optional.of( resource ) ).when( remoteFhirResourceRepository ) .find( Mockito.eq( remoteSubscriptionId ), Mockito.eq( FhirVersion.DSTU3 ), Mockito.same( subscriptionFhirEndpoint ), Mockito.eq( "Patient" ), Mockito.eq( "123" ) ); @@ -255,7 +255,7 @@ public void initReference() Assert.assertEquals( id, reference.getResource().getIdElement() ); Assert.assertNotSame( resource, reference.getResource() ); - Mockito.verify( remoteFhirRepository ).find( Mockito.eq( remoteSubscriptionId ), Mockito.eq( FhirVersion.DSTU3 ), + Mockito.verify( remoteFhirResourceRepository ).find( Mockito.eq( remoteSubscriptionId ), Mockito.eq( FhirVersion.DSTU3 ), Mockito.same( subscriptionFhirEndpoint ), Mockito.eq( "Patient" ), Mockito.eq( "123" ) ); } } \ No newline at end of file diff --git a/fhir-dstu3/src/test/java/org/dhis2/fhir/adapter/fhir/transform/impl/util/dstu3/Dstu3AddressFhirToDhisTransformerUtilsTest.java b/fhir-dstu3/src/test/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/dstu3/Dstu3AddressFhirToDhisTransformerUtilsTest.java similarity index 99% rename from fhir-dstu3/src/test/java/org/dhis2/fhir/adapter/fhir/transform/impl/util/dstu3/Dstu3AddressFhirToDhisTransformerUtilsTest.java rename to fhir-dstu3/src/test/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/dstu3/Dstu3AddressFhirToDhisTransformerUtilsTest.java index 0cb1a2c6..3bf21f91 100644 --- a/fhir-dstu3/src/test/java/org/dhis2/fhir/adapter/fhir/transform/impl/util/dstu3/Dstu3AddressFhirToDhisTransformerUtilsTest.java +++ b/fhir-dstu3/src/test/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/dstu3/Dstu3AddressFhirToDhisTransformerUtilsTest.java @@ -1,4 +1,4 @@ -package org.dhis2.fhir.adapter.fhir.transform.impl.util.dstu3; +package org.dhis2.fhir.adapter.fhir.transform.fhir.impl.util.dstu3; /* * Copyright (c) 2004-2018, University of Oslo diff --git a/fhir-dstu3/src/test/java/org/dhis2/fhir/adapter/fhir/transform/impl/util/dstu3/Dstu3CodeFhirToDhisTransformerUtilsTest.java b/fhir-dstu3/src/test/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/dstu3/Dstu3CodeFhirToDhisTransformerUtilsTest.java similarity index 98% rename from fhir-dstu3/src/test/java/org/dhis2/fhir/adapter/fhir/transform/impl/util/dstu3/Dstu3CodeFhirToDhisTransformerUtilsTest.java rename to fhir-dstu3/src/test/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/dstu3/Dstu3CodeFhirToDhisTransformerUtilsTest.java index 1fa881e3..ed08b8a4 100644 --- a/fhir-dstu3/src/test/java/org/dhis2/fhir/adapter/fhir/transform/impl/util/dstu3/Dstu3CodeFhirToDhisTransformerUtilsTest.java +++ b/fhir-dstu3/src/test/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/dstu3/Dstu3CodeFhirToDhisTransformerUtilsTest.java @@ -1,4 +1,4 @@ -package org.dhis2.fhir.adapter.fhir.transform.impl.util.dstu3; +package org.dhis2.fhir.adapter.fhir.transform.fhir.impl.util.dstu3; /* * Copyright (c) 2004-2018, University of Oslo @@ -37,9 +37,9 @@ import org.dhis2.fhir.adapter.fhir.model.SystemCodeValue; import org.dhis2.fhir.adapter.fhir.script.ScriptExecution; import org.dhis2.fhir.adapter.fhir.script.ScriptExecutionContext; -import org.dhis2.fhir.adapter.fhir.transform.FhirToDhisTransformerContext; -import org.dhis2.fhir.adapter.fhir.transform.model.FhirRequest; -import org.dhis2.fhir.adapter.fhir.transform.model.ResourceSystem; +import org.dhis2.fhir.adapter.fhir.transform.fhir.FhirToDhisTransformerContext; +import org.dhis2.fhir.adapter.fhir.transform.fhir.model.FhirRequest; +import org.dhis2.fhir.adapter.fhir.transform.fhir.model.ResourceSystem; import org.hl7.fhir.dstu3.model.CodeableConcept; import org.hl7.fhir.dstu3.model.Coding; import org.hl7.fhir.dstu3.model.Observation; diff --git a/fhir-dstu3/src/test/java/org/dhis2/fhir/adapter/fhir/transform/impl/util/dstu3/Dstu3ContactPointFhirToDhisTransformerUtilsTest.java b/fhir-dstu3/src/test/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/dstu3/Dstu3ContactPointFhirToDhisTransformerUtilsTest.java similarity index 99% rename from fhir-dstu3/src/test/java/org/dhis2/fhir/adapter/fhir/transform/impl/util/dstu3/Dstu3ContactPointFhirToDhisTransformerUtilsTest.java rename to fhir-dstu3/src/test/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/dstu3/Dstu3ContactPointFhirToDhisTransformerUtilsTest.java index 5094a621..ce04d57a 100644 --- a/fhir-dstu3/src/test/java/org/dhis2/fhir/adapter/fhir/transform/impl/util/dstu3/Dstu3ContactPointFhirToDhisTransformerUtilsTest.java +++ b/fhir-dstu3/src/test/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/dstu3/Dstu3ContactPointFhirToDhisTransformerUtilsTest.java @@ -1,4 +1,4 @@ -package org.dhis2.fhir.adapter.fhir.transform.impl.util.dstu3; +package org.dhis2.fhir.adapter.fhir.transform.fhir.impl.util.dstu3; /* * Copyright (c) 2004-2018, University of Oslo diff --git a/fhir-dstu3/src/test/java/org/dhis2/fhir/adapter/fhir/transform/impl/util/dstu3/Dstu3DateTimeFhirToDhisTransformerUtilsTest.java b/fhir-dstu3/src/test/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/dstu3/Dstu3DateTimeFhirToDhisTransformerUtilsTest.java similarity index 99% rename from fhir-dstu3/src/test/java/org/dhis2/fhir/adapter/fhir/transform/impl/util/dstu3/Dstu3DateTimeFhirToDhisTransformerUtilsTest.java rename to fhir-dstu3/src/test/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/dstu3/Dstu3DateTimeFhirToDhisTransformerUtilsTest.java index ba3e7c1b..a7651d73 100644 --- a/fhir-dstu3/src/test/java/org/dhis2/fhir/adapter/fhir/transform/impl/util/dstu3/Dstu3DateTimeFhirToDhisTransformerUtilsTest.java +++ b/fhir-dstu3/src/test/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/dstu3/Dstu3DateTimeFhirToDhisTransformerUtilsTest.java @@ -1,4 +1,4 @@ -package org.dhis2.fhir.adapter.fhir.transform.impl.util.dstu3; +package org.dhis2.fhir.adapter.fhir.transform.fhir.impl.util.dstu3; /* * Copyright (c) 2004-2018, University of Oslo diff --git a/fhir-dstu3/src/test/java/org/dhis2/fhir/adapter/fhir/transform/impl/util/dstu3/Dstu3GeoFhirToDhisTransformerUtilsTest.java b/fhir-dstu3/src/test/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/dstu3/Dstu3GeoFhirToDhisTransformerUtilsTest.java similarity index 97% rename from fhir-dstu3/src/test/java/org/dhis2/fhir/adapter/fhir/transform/impl/util/dstu3/Dstu3GeoFhirToDhisTransformerUtilsTest.java rename to fhir-dstu3/src/test/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/dstu3/Dstu3GeoFhirToDhisTransformerUtilsTest.java index db8d8e15..749db70a 100644 --- a/fhir-dstu3/src/test/java/org/dhis2/fhir/adapter/fhir/transform/impl/util/dstu3/Dstu3GeoFhirToDhisTransformerUtilsTest.java +++ b/fhir-dstu3/src/test/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/dstu3/Dstu3GeoFhirToDhisTransformerUtilsTest.java @@ -1,4 +1,4 @@ -package org.dhis2.fhir.adapter.fhir.transform.impl.util.dstu3; +package org.dhis2.fhir.adapter.fhir.transform.fhir.impl.util.dstu3; /* * Copyright (c) 2004-2018, University of Oslo diff --git a/fhir-dstu3/src/test/java/org/dhis2/fhir/adapter/fhir/transform/impl/util/dstu3/Dstu3HumanNameFhirToDhisTransformerUtilsTest.java b/fhir-dstu3/src/test/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/dstu3/Dstu3HumanNameFhirToDhisTransformerUtilsTest.java similarity index 98% rename from fhir-dstu3/src/test/java/org/dhis2/fhir/adapter/fhir/transform/impl/util/dstu3/Dstu3HumanNameFhirToDhisTransformerUtilsTest.java rename to fhir-dstu3/src/test/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/dstu3/Dstu3HumanNameFhirToDhisTransformerUtilsTest.java index 1126060e..a126ab58 100644 --- a/fhir-dstu3/src/test/java/org/dhis2/fhir/adapter/fhir/transform/impl/util/dstu3/Dstu3HumanNameFhirToDhisTransformerUtilsTest.java +++ b/fhir-dstu3/src/test/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/dstu3/Dstu3HumanNameFhirToDhisTransformerUtilsTest.java @@ -1,4 +1,4 @@ -package org.dhis2.fhir.adapter.fhir.transform.impl.util.dstu3; +package org.dhis2.fhir.adapter.fhir.transform.fhir.impl.util.dstu3; /* * Copyright (c) 2004-2018, University of Oslo diff --git a/fhir-dstu3/src/test/java/org/dhis2/fhir/adapter/fhir/transform/impl/util/dstu3/Dstu3IdentifierFhirToDhisTransformerUtilsTest.java b/fhir-dstu3/src/test/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/dstu3/Dstu3IdentifierFhirToDhisTransformerUtilsTest.java similarity index 94% rename from fhir-dstu3/src/test/java/org/dhis2/fhir/adapter/fhir/transform/impl/util/dstu3/Dstu3IdentifierFhirToDhisTransformerUtilsTest.java rename to fhir-dstu3/src/test/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/dstu3/Dstu3IdentifierFhirToDhisTransformerUtilsTest.java index c32c1557..067e2998 100644 --- a/fhir-dstu3/src/test/java/org/dhis2/fhir/adapter/fhir/transform/impl/util/dstu3/Dstu3IdentifierFhirToDhisTransformerUtilsTest.java +++ b/fhir-dstu3/src/test/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/dstu3/Dstu3IdentifierFhirToDhisTransformerUtilsTest.java @@ -1,4 +1,4 @@ -package org.dhis2.fhir.adapter.fhir.transform.impl.util.dstu3; +package org.dhis2.fhir.adapter.fhir.transform.fhir.impl.util.dstu3; /* * Copyright (c) 2004-2018, University of Oslo @@ -31,10 +31,10 @@ import org.dhis2.fhir.adapter.fhir.metadata.model.FhirResourceType; import org.dhis2.fhir.adapter.fhir.script.ScriptExecution; import org.dhis2.fhir.adapter.fhir.script.ScriptExecutionContext; -import org.dhis2.fhir.adapter.fhir.transform.FhirToDhisTransformerContext; -import org.dhis2.fhir.adapter.fhir.transform.impl.util.ReferenceFhirToDhisTransformerUtils; -import org.dhis2.fhir.adapter.fhir.transform.model.FhirRequest; -import org.dhis2.fhir.adapter.fhir.transform.model.ResourceSystem; +import org.dhis2.fhir.adapter.fhir.transform.fhir.FhirToDhisTransformerContext; +import org.dhis2.fhir.adapter.fhir.transform.fhir.impl.util.ReferenceFhirToDhisTransformerUtils; +import org.dhis2.fhir.adapter.fhir.transform.fhir.model.FhirRequest; +import org.dhis2.fhir.adapter.fhir.transform.fhir.model.ResourceSystem; import org.hl7.fhir.dstu3.model.IdType; import org.hl7.fhir.dstu3.model.Patient; import org.hl7.fhir.dstu3.model.Reference; diff --git a/fhir-dstu3/src/test/java/org/dhis2/fhir/adapter/fhir/transform/impl/util/dstu3/Dstu3OrganizationFhirToDhisTransformerUtilsTest.java b/fhir-dstu3/src/test/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/dstu3/Dstu3OrganizationFhirToDhisTransformerUtilsTest.java similarity index 92% rename from fhir-dstu3/src/test/java/org/dhis2/fhir/adapter/fhir/transform/impl/util/dstu3/Dstu3OrganizationFhirToDhisTransformerUtilsTest.java rename to fhir-dstu3/src/test/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/dstu3/Dstu3OrganizationFhirToDhisTransformerUtilsTest.java index 296bb185..0ac2c15b 100644 --- a/fhir-dstu3/src/test/java/org/dhis2/fhir/adapter/fhir/transform/impl/util/dstu3/Dstu3OrganizationFhirToDhisTransformerUtilsTest.java +++ b/fhir-dstu3/src/test/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/dstu3/Dstu3OrganizationFhirToDhisTransformerUtilsTest.java @@ -1,4 +1,4 @@ -package org.dhis2.fhir.adapter.fhir.transform.impl.util.dstu3; +package org.dhis2.fhir.adapter.fhir.transform.fhir.impl.util.dstu3; /* * Copyright (c) 2004-2018, University of Oslo @@ -39,13 +39,13 @@ import org.dhis2.fhir.adapter.fhir.metadata.model.SubscriptionFhirEndpoint; import org.dhis2.fhir.adapter.fhir.metadata.repository.RemoteSubscriptionResourceRepository; import org.dhis2.fhir.adapter.fhir.model.FhirVersion; -import org.dhis2.fhir.adapter.fhir.repository.RemoteFhirRepository; -import org.dhis2.fhir.adapter.fhir.repository.RemoteHierarchicallyFhirRepository; +import org.dhis2.fhir.adapter.fhir.repository.RemoteFhirResourceRepository; +import org.dhis2.fhir.adapter.fhir.repository.RemoteHierarchicallyFhirResourceRepository; import org.dhis2.fhir.adapter.fhir.script.ScriptExecution; import org.dhis2.fhir.adapter.fhir.script.ScriptExecutionContext; -import org.dhis2.fhir.adapter.fhir.transform.FhirToDhisTransformerContext; -import org.dhis2.fhir.adapter.fhir.transform.model.FhirRequest; -import org.dhis2.fhir.adapter.fhir.transform.model.ResourceSystem; +import org.dhis2.fhir.adapter.fhir.transform.fhir.FhirToDhisTransformerContext; +import org.dhis2.fhir.adapter.fhir.transform.fhir.model.FhirRequest; +import org.dhis2.fhir.adapter.fhir.transform.fhir.model.ResourceSystem; import org.hl7.fhir.dstu3.model.Bundle; import org.hl7.fhir.dstu3.model.IdType; import org.hl7.fhir.dstu3.model.Organization; @@ -83,10 +83,10 @@ public class Dstu3OrganizationFhirToDhisTransformerUtilsTest private RemoteSubscriptionResourceRepository subscriptionResourceRepository; @Mock - private RemoteFhirRepository remoteFhirRepository; + private RemoteFhirResourceRepository remoteFhirResourceRepository; @Mock - private RemoteHierarchicallyFhirRepository remoteHierarchicallyFhirRepository; + private RemoteHierarchicallyFhirResourceRepository remoteHierarchicallyFhirResourceRepository; @Mock private FhirToDhisTransformerContext context; @@ -172,7 +172,7 @@ public void findHierarchy() Mockito.doReturn( FhirVersion.DSTU3 ).when( request ).getVersion(); Mockito.doReturn( Optional.of( resourceSystem ) ).when( request ).getOptionalResourceSystem( FhirResourceType.ORGANIZATION ); Mockito.doReturn( Optional.of( remoteSubscriptionResource ) ).when( subscriptionResourceRepository ).findByIdCached( Mockito.eq( remoteSubscriptionResourceId ) ); - Mockito.doReturn( Optional.of( fhirContext ) ).when( remoteFhirRepository ).findFhirContext( Mockito.eq( FhirVersion.DSTU3 ) ); + Mockito.doReturn( Optional.of( fhirContext ) ).when( remoteFhirResourceRepository ).findFhirContext( Mockito.eq( FhirVersion.DSTU3 ) ); final Organization org1 = (Organization) new Organization().setId( new IdType( "Organization", "1" ) ); final Organization org2 = (Organization) new Organization().setId( new IdType( "2" ) ); @@ -180,15 +180,14 @@ public void findHierarchy() final Organization org4 = (Organization) new Organization().setId( new IdType( "Organization", "4" ) ); Mockito.doAnswer( invocation -> { - @SuppressWarnings( "unchecked" ) final Function parentReferenceFunction = - (Function) invocation.getArgument( 6 ); + final Function parentReferenceFunction = invocation.getArgument( 6 ); Assert.assertEquals( org3.getPartOf(), parentReferenceFunction.apply( org3 ) ); Assert.assertEquals( org4.getPartOf(), parentReferenceFunction.apply( org4 ) ); return new Bundle() .addEntry( new Bundle.BundleEntryComponent().setResource( org3 ) ) .addEntry( new Bundle.BundleEntryComponent().setResource( org4 ) ); } ) - .when( remoteHierarchicallyFhirRepository ) + .when( remoteHierarchicallyFhirResourceRepository ) .findWithParents( Mockito.eq( remoteSubscriptionResourceId ), Mockito.eq( FhirVersion.DSTU3 ), Mockito.same( subscriptionFhirEndpoint ), Mockito.eq( "Organization" ), Mockito.eq( "3" ), Mockito.eq( "organizationPartOf" ), Mockito.any() ); diff --git a/fhir-dstu3/src/test/java/org/dhis2/fhir/adapter/fhir/transform/impl/util/dstu3/Dstu3PatientFhirToDhisTransformerUtilsTest.java b/fhir-dstu3/src/test/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/dstu3/Dstu3PatientFhirToDhisTransformerUtilsTest.java similarity index 97% rename from fhir-dstu3/src/test/java/org/dhis2/fhir/adapter/fhir/transform/impl/util/dstu3/Dstu3PatientFhirToDhisTransformerUtilsTest.java rename to fhir-dstu3/src/test/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/dstu3/Dstu3PatientFhirToDhisTransformerUtilsTest.java index 9144e361..cc21acab 100644 --- a/fhir-dstu3/src/test/java/org/dhis2/fhir/adapter/fhir/transform/impl/util/dstu3/Dstu3PatientFhirToDhisTransformerUtilsTest.java +++ b/fhir-dstu3/src/test/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/dstu3/Dstu3PatientFhirToDhisTransformerUtilsTest.java @@ -1,4 +1,4 @@ -package org.dhis2.fhir.adapter.fhir.transform.impl.util.dstu3; +package org.dhis2.fhir.adapter.fhir.transform.fhir.impl.util.dstu3; /* * Copyright (c) 2004-2018, University of Oslo diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/queue/FhirQueueConfig.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/queue/FhirQueueConfig.java index b40d7b80..2bec7616 100644 --- a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/queue/FhirQueueConfig.java +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/queue/FhirQueueConfig.java @@ -28,9 +28,13 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +import com.google.common.collect.ImmutableMap; import org.apache.activemq.artemis.jms.server.config.JMSQueueConfiguration; import org.apache.activemq.artemis.jms.server.config.impl.JMSQueueConfigurationImpl; +import org.dhis2.fhir.adapter.dhis.queue.JmsJsonTypeIdMapping; import org.dhis2.fhir.adapter.fhir.remote.impl.RemoteConfig; +import org.dhis2.fhir.adapter.fhir.remote.impl.RemoteRestHookRequest; +import org.dhis2.fhir.adapter.fhir.repository.RemoteFhirResource; import org.dhis2.fhir.adapter.fhir.repository.impl.RepositoryConfig; import org.springframework.boot.autoconfigure.jms.artemis.ArtemisConfigurationCustomizer; import org.springframework.context.annotation.Bean; @@ -41,6 +45,7 @@ import javax.annotation.Nonnull; import javax.jms.ConnectionFactory; +import java.util.Map; /** * Configuration of queues that are used by the adapter. @@ -121,4 +126,21 @@ protected JmsTemplate fhirResourceQueueJmsTemplate( @Nonnull ConnectionFactory c jmsTemplate.setMessageConverter( jmsMessageConverter ); return jmsTemplate; } + + @Bean + @Nonnull + protected JmsJsonTypeIdMapping dhisJmsJsonTypeIdMapping() + { + return new JmsJsonTypeIdMapping() + { + @Nonnull + @Override + public Map> getTypeIdMappings() + { + return ImmutableMap.of( + "fhirRestHookRequest", RemoteRestHookRequest.class, + "fhirResource", RemoteFhirResource.class ); + } + }; + } } diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/repository/DhisRepository.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/repository/DhisRepository.java new file mode 100644 index 00000000..fdd1f28d --- /dev/null +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/repository/DhisRepository.java @@ -0,0 +1,44 @@ +package org.dhis2.fhir.adapter.fhir.repository; + +/* + * Copyright (c) 2004-2018, University of Oslo + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * Neither the name of the HISP project nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +import org.dhis2.fhir.adapter.dhis.metadata.model.DhisSyncGroup; +import org.dhis2.fhir.adapter.dhis.model.DhisResource; + +import javax.annotation.Nonnull; + +/** + * The repository that is used to store DHIS 2 Resources. + * + * @author volsch + */ +public interface DhisRepository +{ + void save( @Nonnull DhisSyncGroup syncGroup, @Nonnull DhisResource resource ); +} diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/repository/RemoteFhirRepository.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/repository/RemoteFhirResourceRepository.java similarity index 91% rename from fhir/src/main/java/org/dhis2/fhir/adapter/fhir/repository/RemoteFhirRepository.java rename to fhir/src/main/java/org/dhis2/fhir/adapter/fhir/repository/RemoteFhirResourceRepository.java index a2c1021b..7b3ec3c8 100644 --- a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/repository/RemoteFhirRepository.java +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/repository/RemoteFhirResourceRepository.java @@ -29,6 +29,7 @@ */ import ca.uhn.fhir.context.FhirContext; +import org.dhis2.fhir.adapter.fhir.metadata.model.RemoteSubscriptionResource; import org.dhis2.fhir.adapter.fhir.metadata.model.SubscriptionFhirEndpoint; import org.dhis2.fhir.adapter.fhir.model.FhirVersion; import org.hl7.fhir.instance.model.api.IBaseResource; @@ -42,7 +43,7 @@ * * @author volsch */ -public interface RemoteFhirRepository +public interface RemoteFhirResourceRepository { @Nonnull Optional findFhirContext( @Nonnull FhirVersion fhirVersion ); @@ -52,4 +53,7 @@ public interface RemoteFhirRepository @Nonnull Optional find( @Nonnull UUID remoteSubscriptionId, @Nonnull FhirVersion fhirVersion, @Nonnull SubscriptionFhirEndpoint fhirEndpoint, @Nonnull String resourceType, @Nonnull String resourceId ); + + @Nonnull + IBaseResource save( @Nonnull RemoteSubscriptionResource subscriptionResource, @Nonnull IBaseResource resource ); } diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/repository/RemoteHierarchicallyFhirRepository.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/repository/RemoteHierarchicallyFhirResourceRepository.java similarity index 94% rename from fhir/src/main/java/org/dhis2/fhir/adapter/fhir/repository/RemoteHierarchicallyFhirRepository.java rename to fhir/src/main/java/org/dhis2/fhir/adapter/fhir/repository/RemoteHierarchicallyFhirResourceRepository.java index 62845759..4db309e2 100644 --- a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/repository/RemoteHierarchicallyFhirRepository.java +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/repository/RemoteHierarchicallyFhirResourceRepository.java @@ -40,12 +40,12 @@ import java.util.function.Function; /** - * Facade for {@link RemoteFhirRepository} to handle parent child relationships on + * Facade for {@link RemoteFhirResourceRepository} to handle parent child relationships on * to request the complete hierarchy up to the root. * * @author volsch */ -public interface RemoteHierarchicallyFhirRepository +public interface RemoteHierarchicallyFhirResourceRepository { @Nonnull IBaseBundle findWithParents( @Nonnull UUID remoteSubscriptionId, @Nonnull FhirVersion fhirVersion, @Nonnull SubscriptionFhirEndpoint fhirEndpoint, diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/repository/impl/AbstractRemoteFhirRepositoryImpl.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/repository/impl/AbstractRemoteFhirResourceRepositoryImpl.java similarity index 89% rename from fhir/src/main/java/org/dhis2/fhir/adapter/fhir/repository/impl/AbstractRemoteFhirRepositoryImpl.java rename to fhir/src/main/java/org/dhis2/fhir/adapter/fhir/repository/impl/AbstractRemoteFhirResourceRepositoryImpl.java index 610ef4f1..c4b483a9 100644 --- a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/repository/impl/AbstractRemoteFhirRepositoryImpl.java +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/repository/impl/AbstractRemoteFhirResourceRepositoryImpl.java @@ -41,7 +41,7 @@ import org.dhis2.fhir.adapter.fhir.metadata.repository.event.AutoCreatedRemoteSubscriptionResourceEvent; import org.dhis2.fhir.adapter.fhir.model.FhirVersion; import org.dhis2.fhir.adapter.fhir.repository.FhirClientUtils; -import org.dhis2.fhir.adapter.fhir.repository.RemoteFhirRepository; +import org.dhis2.fhir.adapter.fhir.repository.RemoteFhirResourceRepository; import org.dhis2.fhir.adapter.rest.RestBadRequestException; import org.hl7.fhir.instance.model.api.IAnyResource; import org.hl7.fhir.instance.model.api.IBaseResource; @@ -63,12 +63,12 @@ import java.util.stream.Collectors; /** - * Implementation of {@link RemoteFhirRepository}. + * Implementation of {@link RemoteFhirResourceRepository}. * * @author volsch */ @CacheConfig( cacheNames = "fhirResources", cacheManager = "fhirCacheManager" ) -public abstract class AbstractRemoteFhirRepositoryImpl implements RemoteFhirRepository +public abstract class AbstractRemoteFhirResourceRepositoryImpl implements RemoteFhirResourceRepository { private final Logger logger = LoggerFactory.getLogger( getClass() ); @@ -76,7 +76,7 @@ public abstract class AbstractRemoteFhirRepositoryImpl implements RemoteFhirRepo private final Map fhirContexts; - public AbstractRemoteFhirRepositoryImpl( @Nonnull RemoteSubscriptionRepository repository, @Nonnull ObjectProvider> fhirContexts ) + public AbstractRemoteFhirResourceRepositoryImpl( @Nonnull RemoteSubscriptionRepository repository, @Nonnull ObjectProvider> fhirContexts ) { this.repository = repository; this.fhirContexts = fhirContexts.getIfAvailable( Collections::emptyList ).stream().filter( fc -> (FhirVersion.get( fc.getVersion().getVersion() ) != null) ) @@ -125,6 +125,16 @@ public Optional find( @Nonnull UUID remoteSubscriptionId, @Nonnul return findRefreshed( remoteSubscriptionId, fhirVersion, fhirEndpoint, resourceType, resourceId ); } + @HystrixCommand + @Cacheable( key = "{#subscriptionResource.remoteSubscription.id, #subscriptionResource.remoteSubscription.fhirVersion, " + + "T(org.dhis2.fhir.adapter.fhir.metadata.model.FhirResourceType).getByResource(#resource).getResourceTypeName(), #resource.getIdElement().getIdPart()}", unless = "#result==null" ) + @Nonnull + @Override + public IBaseResource save( @Nonnull RemoteSubscriptionResource subscriptionResource, @Nonnull IBaseResource resource ) + { + throw new UnsupportedOperationException( "Must be implemented!" ); + } + @TransactionalEventListener( phase = TransactionPhase.BEFORE_COMMIT, classes = AutoCreatedRemoteSubscriptionResourceEvent.class ) public void autoCreatedSubscriptionResource( @Nonnull AutoCreatedRemoteSubscriptionResourceEvent event ) { diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/repository/impl/AbstractRemoteHierarchicallyFhirRepositoryImpl.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/repository/impl/AbstractRemoteHierarchicallyFhirResourceRepositoryImpl.java similarity index 85% rename from fhir/src/main/java/org/dhis2/fhir/adapter/fhir/repository/impl/AbstractRemoteHierarchicallyFhirRepositoryImpl.java rename to fhir/src/main/java/org/dhis2/fhir/adapter/fhir/repository/impl/AbstractRemoteHierarchicallyFhirResourceRepositoryImpl.java index ab69f9c1..1f8daae5 100644 --- a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/repository/impl/AbstractRemoteHierarchicallyFhirRepositoryImpl.java +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/repository/impl/AbstractRemoteHierarchicallyFhirResourceRepositoryImpl.java @@ -30,8 +30,8 @@ import org.dhis2.fhir.adapter.fhir.metadata.model.SubscriptionFhirEndpoint; import org.dhis2.fhir.adapter.fhir.model.FhirVersion; -import org.dhis2.fhir.adapter.fhir.repository.RemoteFhirRepository; -import org.dhis2.fhir.adapter.fhir.repository.RemoteHierarchicallyFhirRepository; +import org.dhis2.fhir.adapter.fhir.repository.RemoteFhirResourceRepository; +import org.dhis2.fhir.adapter.fhir.repository.RemoteHierarchicallyFhirResourceRepository; import org.hl7.fhir.instance.model.api.IBaseBundle; import org.hl7.fhir.instance.model.api.IBaseReference; import org.hl7.fhir.instance.model.api.IBaseResource; @@ -49,18 +49,18 @@ import java.util.function.Function; /** - * Implementation of {@link RemoteHierarchicallyFhirRepository}. + * Implementation of {@link RemoteHierarchicallyFhirResourceRepository}. * * @author volsch */ @CacheConfig( cacheNames = "hierarchicallyFhirResources", cacheManager = "fhirCacheManager" ) -public abstract class AbstractRemoteHierarchicallyFhirRepositoryImpl implements RemoteHierarchicallyFhirRepository +public abstract class AbstractRemoteHierarchicallyFhirResourceRepositoryImpl implements RemoteHierarchicallyFhirResourceRepository { - private final RemoteFhirRepository remoteFhirRepository; + private final RemoteFhirResourceRepository remoteFhirResourceRepository; - public AbstractRemoteHierarchicallyFhirRepositoryImpl( @Nonnull RemoteFhirRepository remoteFhirRepository ) + public AbstractRemoteHierarchicallyFhirResourceRepositoryImpl( @Nonnull RemoteFhirResourceRepository remoteFhirResourceRepository ) { - this.remoteFhirRepository = remoteFhirRepository; + this.remoteFhirResourceRepository = remoteFhirResourceRepository; } @Nonnull @@ -75,7 +75,7 @@ public IBaseBundle findWithParents( @Nonnull UUID remoteSubscriptionId, @Nonnull return createBundle( Collections.emptyList() ); } - IBaseResource child = remoteFhirRepository.find( remoteSubscriptionId, fhirVersion, fhirEndpoint, resourceType, resourceId ).orElse( null ); + IBaseResource child = remoteFhirResourceRepository.find( remoteSubscriptionId, fhirVersion, fhirEndpoint, resourceType, resourceId ).orElse( null ); if ( child == null ) { return createBundle( Collections.emptyList() ); @@ -99,7 +99,7 @@ public IBaseBundle findWithParents( @Nonnull UUID remoteSubscriptionId, @Nonnull // there is a dependency loop and search must be interrupted break; } - child = remoteFhirRepository.find( remoteSubscriptionId, fhirVersion, fhirEndpoint, + child = remoteFhirResourceRepository.find( remoteSubscriptionId, fhirVersion, fhirEndpoint, childResourceType, parentReference.getReferenceElement().getIdPart() ).orElse( null ); } else diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/repository/impl/DhisRepositoryImpl.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/repository/impl/DhisRepositoryImpl.java new file mode 100644 index 00000000..73e9839b --- /dev/null +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/repository/impl/DhisRepositoryImpl.java @@ -0,0 +1,261 @@ +package org.dhis2.fhir.adapter.fhir.repository.impl; + +/* + * Copyright (c) 2004-2018, University of Oslo + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * Neither the name of the HISP project nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand; +import com.netflix.hystrix.strategy.concurrency.HystrixRequestContext; +import org.dhis2.fhir.adapter.auth.Authorization; +import org.dhis2.fhir.adapter.auth.AuthorizationContext; +import org.dhis2.fhir.adapter.data.model.ProcessedItemInfo; +import org.dhis2.fhir.adapter.data.repository.IgnoredQueuedItemException; +import org.dhis2.fhir.adapter.dhis.data.model.QueuedDhisResourceId; +import org.dhis2.fhir.adapter.dhis.data.repository.QueuedDhisResourceRepository; +import org.dhis2.fhir.adapter.dhis.metadata.model.DhisSyncGroup; +import org.dhis2.fhir.adapter.dhis.metadata.repository.DhisSyncGroupRepository; +import org.dhis2.fhir.adapter.dhis.model.DhisResource; +import org.dhis2.fhir.adapter.dhis.model.DhisResourceId; +import org.dhis2.fhir.adapter.dhis.sync.DhisResourceQueueItem; +import org.dhis2.fhir.adapter.dhis.sync.DhisResourceRepository; +import org.dhis2.fhir.adapter.dhis.sync.StoredDhisResourceService; +import org.dhis2.fhir.adapter.fhir.metadata.repository.RemoteSubscriptionSystemRepository; +import org.dhis2.fhir.adapter.fhir.repository.DhisRepository; +import org.dhis2.fhir.adapter.fhir.repository.RemoteFhirResourceRepository; +import org.dhis2.fhir.adapter.fhir.security.AdapterSystemAuthenticationToken; +import org.dhis2.fhir.adapter.fhir.transform.TransformerDataException; +import org.dhis2.fhir.adapter.fhir.transform.TransformerMappingException; +import org.dhis2.fhir.adapter.fhir.transform.dhis.DhisToFhirTransformOutcome; +import org.dhis2.fhir.adapter.fhir.transform.dhis.DhisToFhirTransformerRequest; +import org.dhis2.fhir.adapter.fhir.transform.dhis.DhisToFhirTransformerService; +import org.dhis2.fhir.adapter.fhir.transform.dhis.model.WritableDhisRequest; +import org.dhis2.fhir.adapter.lock.LockContext; +import org.dhis2.fhir.adapter.lock.LockManager; +import org.dhis2.fhir.adapter.queue.RetryQueueDeliveryException; +import org.hl7.fhir.instance.model.api.IBaseResource; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.slf4j.MDC; +import org.springframework.jms.annotation.JmsListener; +import org.springframework.security.core.context.SecurityContextHolder; +import org.springframework.stereotype.Component; +import org.springframework.transaction.annotation.Propagation; +import org.springframework.transaction.annotation.Transactional; + +import javax.annotation.Nonnull; +import javax.annotation.Nullable; +import java.time.Instant; +import java.util.Objects; +import java.util.Optional; + +/** + * Implementation of {@link DhisRepository}. + * + * @author volsch + */ +@Component +public class DhisRepositoryImpl implements DhisRepository +{ + private final Logger logger = LoggerFactory.getLogger( getClass() ); + + private final AuthorizationContext authorizationContext; + + private final Authorization systemDhis2Authorization; + + private final LockManager lockManager; + + private final RemoteSubscriptionSystemRepository remoteSubscriptionSystemRepository; + + private final DhisSyncGroupRepository dhisSyncGroupRepository; + + private final QueuedDhisResourceRepository queuedDhisResourceRepository; + + private final StoredDhisResourceService storedItemService; + + private final DhisResourceRepository dhisResourceRepository; + + private final DhisToFhirTransformerService dhisToFhirTransformerService; + + private final RemoteFhirResourceRepository remoteFhirResourceRepository; + + public DhisRepositoryImpl( + @Nonnull AuthorizationContext authorizationContext, + @Nonnull Authorization systemDhis2Authorization, + @Nonnull LockManager lockManager, + @Nonnull RemoteSubscriptionSystemRepository remoteSubscriptionSystemRepository, + @Nonnull DhisSyncGroupRepository dhisSyncGroupRepository, + @Nonnull QueuedDhisResourceRepository queuedDhisResourceRepository, + @Nonnull StoredDhisResourceService storedItemService, + @Nonnull DhisResourceRepository dhisResourceRepository, + // TODO + @Nullable DhisToFhirTransformerService dhisToFhirTransformerService, + @Nonnull RemoteFhirResourceRepository remoteFhirResourceRepository ) + { + this.authorizationContext = authorizationContext; + this.systemDhis2Authorization = systemDhis2Authorization; + this.lockManager = lockManager; + this.remoteSubscriptionSystemRepository = remoteSubscriptionSystemRepository; + this.dhisSyncGroupRepository = dhisSyncGroupRepository; + this.queuedDhisResourceRepository = queuedDhisResourceRepository; + this.storedItemService = storedItemService; + this.dhisResourceRepository = dhisResourceRepository; + this.dhisToFhirTransformerService = dhisToFhirTransformerService; + this.remoteFhirResourceRepository = remoteFhirResourceRepository; + } + + @Override + public void save( @Nonnull DhisSyncGroup syncGroup, @Nonnull DhisResource resource ) + { + authorizationContext.setAuthorization( systemDhis2Authorization ); + try + { + saveInternally( syncGroup, resource ); + } + finally + { + authorizationContext.resetAuthorization(); + } + } + + @HystrixCommand( ignoreExceptions = RetryQueueDeliveryException.class ) + @Transactional( propagation = Propagation.NOT_SUPPORTED ) + @JmsListener( destination = "#{@dhisSyncConfig.dhisResourceQueue.queueName}", + concurrency = "#{@dhisSyncConfig.dhisResourceQueue.listener.concurrency}" ) + public void receive( @Nonnull DhisResourceQueueItem queueItem ) + { + SecurityContextHolder.getContext().setAuthentication( new AdapterSystemAuthenticationToken() ); + try + { + receiveAuthenticated( queueItem ); + } + finally + { + SecurityContextHolder.clearContext(); + } + } + + protected void receiveAuthenticated( @Nonnull DhisResourceQueueItem queueItem ) + { + logger.info( "Processing DHIS resource {} for sync group {}.", queueItem.getId(), queueItem.getDataGroupId() ); + final DhisSyncGroup syncGroup = + dhisSyncGroupRepository.findByIdCached( queueItem.getDataGroupId().getId() ).orElse( null ); + if ( syncGroup == null ) + { + logger.warn( "Sync group {} is no longer available. Skipping processing of updated DHIS resource {}.", + queueItem.getDataGroupId(), queueItem.getId() ); + return; + } + + try + { + queuedDhisResourceRepository.dequeued( new QueuedDhisResourceId( syncGroup, queueItem.getId() ) ); + } + catch ( IgnoredQueuedItemException e ) + { + // has already been logged with sufficient details + return; + } + + final Optional resource = dhisResourceRepository.findRefreshed( Objects.requireNonNull( DhisResourceId.parse( queueItem.getId() ) ) ); + if ( resource.isPresent() ) + { + final ProcessedItemInfo processedItemInfo = getProcessedItemInfo( resource.get() ); + if ( storedItemService.contains( syncGroup, processedItemInfo.toIdString( Instant.now() ) ) ) + { + logger.info( "DHIS resource {} of sync group {} has already been stored.", + resource.get().getResourceId(), syncGroup.getId() ); + } + else + { + try ( final MDC.MDCCloseable c = MDC.putCloseable( "dhisId", syncGroup.getId() + ":" + resource.get().getResourceId() ) ) + { + logger.info( "Processing DHIS resource {} of sync group {}.", resource.get().getResourceId(), syncGroup.getId() ); + try + { + save( syncGroup, resource.get() ); + } + catch ( TransformerDataException | TransformerMappingException e ) + { + logger.warn( "Processing of data of DHIS resource caused a transformation error. Retrying processing later because of resolvable issue: {}", e.getMessage() ); + throw new RetryQueueDeliveryException( e ); + } + logger.info( "Processed DHIS resource {} for sync group {}.", resource.get().getResourceId(), syncGroup.getId() ); + } + } + } + else + { + logger.info( "DHIS resource {} for sync group {} is no longer available. Skipping processing of updated DHIS resource.", + queueItem.getId(), syncGroup.getId() ); + } + } + + @Nonnull + private ProcessedItemInfo getProcessedItemInfo( @Nonnull DhisResource resource ) + { + return new ProcessedItemInfo( resource.getResourceId().toString(), + Objects.requireNonNull( resource.getLastUpdated() ).toInstant() ); + } + + protected boolean saveInternally( @Nonnull DhisSyncGroup subscriptionResource, @Nonnull DhisResource resource ) + { + final WritableDhisRequest dhisRequest = new WritableDhisRequest(); + dhisRequest.setResourceType( resource.getResourceType() ); + dhisRequest.setLastUpdated( resource.getLastUpdated() ); + + boolean saved = false; + DhisToFhirTransformerRequest transformerRequest = dhisToFhirTransformerService.createTransformerRequest( dhisRequest, resource ); + do + { + DhisToFhirTransformOutcome outcome; + try ( final LockContext lockContext = lockManager.begin() ) + { + final HystrixRequestContext context = HystrixRequestContext.initializeContext(); + try + { + outcome = dhisToFhirTransformerService.transform( transformerRequest ); + } + finally + { + context.shutdown(); + } + if ( outcome == null ) + { + transformerRequest = null; + } + else + { + remoteFhirResourceRepository.save( outcome.getSubscriptionResource(), outcome.getResource() ); + saved = true; + transformerRequest = outcome.getNextTransformerRequest(); + } + } + } + while ( transformerRequest != null ); + return saved; + } +} diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/repository/impl/FhirRepositoryImpl.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/repository/impl/FhirRepositoryImpl.java index 1f874aa2..b0708e34 100644 --- a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/repository/impl/FhirRepositoryImpl.java +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/repository/impl/FhirRepositoryImpl.java @@ -37,11 +37,7 @@ import org.dhis2.fhir.adapter.data.repository.IgnoredQueuedItemException; import org.dhis2.fhir.adapter.dhis.DhisConflictException; import org.dhis2.fhir.adapter.dhis.model.DhisResource; -import org.dhis2.fhir.adapter.dhis.tracker.program.EnrollmentService; -import org.dhis2.fhir.adapter.dhis.tracker.program.Event; -import org.dhis2.fhir.adapter.dhis.tracker.program.EventService; -import org.dhis2.fhir.adapter.dhis.tracker.trackedentity.TrackedEntityInstance; -import org.dhis2.fhir.adapter.dhis.tracker.trackedentity.TrackedEntityService; +import org.dhis2.fhir.adapter.dhis.sync.DhisResourceRepository; import org.dhis2.fhir.adapter.fhir.data.model.QueuedRemoteFhirResourceId; import org.dhis2.fhir.adapter.fhir.data.repository.QueuedRemoteFhirResourceRepository; import org.dhis2.fhir.adapter.fhir.metadata.model.AuthenticationMethod; @@ -53,18 +49,19 @@ import org.dhis2.fhir.adapter.fhir.metadata.repository.RemoteSubscriptionSystemRepository; import org.dhis2.fhir.adapter.fhir.remote.StoredRemoteFhirResourceService; import org.dhis2.fhir.adapter.fhir.repository.FhirRepository; -import org.dhis2.fhir.adapter.fhir.repository.RemoteFhirRepository; import org.dhis2.fhir.adapter.fhir.repository.RemoteFhirResource; +import org.dhis2.fhir.adapter.fhir.repository.RemoteFhirResourceRepository; import org.dhis2.fhir.adapter.fhir.security.AdapterSystemAuthenticationToken; import org.dhis2.fhir.adapter.fhir.transform.FatalTransformerException; -import org.dhis2.fhir.adapter.fhir.transform.FhirToDhisTransformOutcome; -import org.dhis2.fhir.adapter.fhir.transform.FhirToDhisTransformerService; -import org.dhis2.fhir.adapter.fhir.transform.TrackedEntityInstanceNotFoundException; import org.dhis2.fhir.adapter.fhir.transform.TransformerDataException; import org.dhis2.fhir.adapter.fhir.transform.TransformerMappingException; -import org.dhis2.fhir.adapter.fhir.transform.model.FhirRequestMethod; -import org.dhis2.fhir.adapter.fhir.transform.model.ResourceSystem; -import org.dhis2.fhir.adapter.fhir.transform.model.WritableFhirRequest; +import org.dhis2.fhir.adapter.fhir.transform.fhir.FhirToDhisTransformOutcome; +import org.dhis2.fhir.adapter.fhir.transform.fhir.FhirToDhisTransformerRequest; +import org.dhis2.fhir.adapter.fhir.transform.fhir.FhirToDhisTransformerService; +import org.dhis2.fhir.adapter.fhir.transform.fhir.TrackedEntityInstanceNotFoundException; +import org.dhis2.fhir.adapter.fhir.transform.fhir.model.FhirRequestMethod; +import org.dhis2.fhir.adapter.fhir.transform.fhir.model.ResourceSystem; +import org.dhis2.fhir.adapter.fhir.transform.fhir.model.WritableFhirRequest; import org.dhis2.fhir.adapter.lock.LockContext; import org.dhis2.fhir.adapter.lock.LockManager; import org.dhis2.fhir.adapter.queue.RetryQueueDeliveryException; @@ -88,9 +85,7 @@ import java.time.ZonedDateTime; import java.util.Base64; import java.util.Collection; -import java.util.Collections; import java.util.Date; -import java.util.List; import java.util.Optional; import java.util.stream.Collectors; @@ -118,15 +113,11 @@ public class FhirRepositoryImpl implements FhirRepository private final StoredRemoteFhirResourceService storedItemService; - private final RemoteFhirRepository remoteFhirRepository; + private final RemoteFhirResourceRepository remoteFhirResourceRepository; private final FhirToDhisTransformerService fhirToDhisTransformerService; - private final TrackedEntityService trackedEntityService; - - private final EnrollmentService enrollmentService; - - private final EventService eventService; + private final DhisResourceRepository dhisResourceRepository; private final ZoneId zoneId = ZoneId.systemDefault(); @@ -135,8 +126,8 @@ public FhirRepositoryImpl( @Nonnull AuthorizationContext authorizationContext, @ @Nonnull RemoteSubscriptionResourceRepository remoteSubscriptionResourceRepository, @Nonnull QueuedRemoteFhirResourceRepository queuedRemoteFhirResourceRepository, @Nonnull StoredRemoteFhirResourceService storedItemService, - @Nonnull RemoteFhirRepository remoteFhirRepository, @Nonnull FhirToDhisTransformerService fhirToDhisTransformerService, - @Nonnull TrackedEntityService trackedEntityService, @Nonnull EnrollmentService enrollmentService, @Nonnull EventService eventService ) + @Nonnull RemoteFhirResourceRepository remoteFhirResourceRepository, @Nonnull FhirToDhisTransformerService fhirToDhisTransformerService, + @Nonnull DhisResourceRepository dhisResourceRepository ) { this.authorizationContext = authorizationContext; this.lockManager = lockManager; @@ -144,11 +135,9 @@ public FhirRepositoryImpl( @Nonnull AuthorizationContext authorizationContext, @ this.remoteSubscriptionResourceRepository = remoteSubscriptionResourceRepository; this.queuedRemoteFhirResourceRepository = queuedRemoteFhirResourceRepository; this.storedItemService = storedItemService; - this.remoteFhirRepository = remoteFhirRepository; + this.remoteFhirResourceRepository = remoteFhirResourceRepository; this.fhirToDhisTransformerService = fhirToDhisTransformerService; - this.trackedEntityService = trackedEntityService; - this.enrollmentService = enrollmentService; - this.eventService = eventService; + this.dhisResourceRepository = dhisResourceRepository; } @Override @@ -217,7 +206,7 @@ protected void receiveAuthenticated( @Nonnull RemoteFhirResource remoteFhirResou } final RemoteSubscription remoteSubscription = remoteSubscriptionResource.getRemoteSubscription(); - final Optional resource = remoteFhirRepository.findRefreshed( + final Optional resource = remoteFhirResourceRepository.findRefreshed( remoteSubscription.getId(), remoteSubscription.getFhirVersion(), remoteSubscription.getFhirEndpoint(), remoteSubscriptionResource.getFhirResourceType().getResourceTypeName(), remoteFhirResource.getId() ); if ( resource.isPresent() ) @@ -291,7 +280,9 @@ protected boolean saveRetriedWithoutTrackedEntityInstance( @Nonnull RemoteSubscr try { if ( !saveRetried( subscriptionResource, resource, false ) ) + { return false; + } } catch ( TrackedEntityInstanceNotFoundException e2 ) { @@ -360,7 +351,7 @@ protected boolean createTrackedEntityInstance( @Nonnull RemoteSubscriptionResour } final RemoteSubscription remoteSubscription = trackedEntityRemoteSubscriptionResource.getRemoteSubscription(); - final Optional optionalRefreshedResource = remoteFhirRepository.findRefreshed( + final Optional optionalRefreshedResource = remoteFhirResourceRepository.findRefreshed( remoteSubscription.getId(), remoteSubscription.getFhirVersion(), remoteSubscription.getFhirEndpoint(), fhirResourceType.getResourceTypeName(), resource.getIdElement().getIdPart() ); if ( !optionalRefreshedResource.isPresent() ) @@ -392,7 +383,6 @@ protected boolean saveRetried( @Nonnull RemoteSubscriptionResource subscriptionR throw lastException; } - @SuppressWarnings( "unchecked" ) protected boolean saveInternally( @Nonnull RemoteSubscriptionResource subscriptionResource, @Nonnull IBaseResource resource, boolean contained ) { final Collection systems = remoteSubscriptionSystemRepository.findByRemoteSubscription( subscriptionResource.getRemoteSubscription() ); @@ -411,98 +401,36 @@ protected boolean saveInternally( @Nonnull RemoteSubscriptionResource subscripti .map( s -> new ResourceSystem( s.getFhirResourceType(), s.getSystem().getSystemUri(), s.getCodePrefix() ) ) .collect( Collectors.toMap( ResourceSystem::getFhirResourceType, rs -> rs ) ) ); - final FhirToDhisTransformOutcome outcome; - try ( final LockContext lockContext = lockManager.begin() ) + boolean saved = false; + FhirToDhisTransformerRequest transformerRequest = fhirToDhisTransformerService.createTransformerRequest( fhirRequest, resource, contained ); + do { - final HystrixRequestContext context = HystrixRequestContext.initializeContext(); - try - { - outcome = fhirToDhisTransformerService.transform( fhirToDhisTransformerService.createContext( fhirRequest ), resource, contained ); - } - finally - { - context.shutdown(); - } - - if ( outcome != null ) + FhirToDhisTransformOutcome outcome; + try ( final LockContext lockContext = lockManager.begin() ) { - switch ( outcome.getResource().getResourceType() ) + final HystrixRequestContext context = HystrixRequestContext.initializeContext(); + try { - case TRACKED_ENTITY: - persistTrackedEntityOutcome( (FhirToDhisTransformOutcome) outcome ); - break; - case PROGRAM_STAGE_EVENT: - persistProgramStageEventOutcome( (FhirToDhisTransformOutcome) outcome ); - break; - default: - throw new AssertionError( "Unhandled DHIS resource type: " + outcome.getResource().getResourceType() ); + outcome = fhirToDhisTransformerService.transform( transformerRequest ); } - } - } - return (outcome != null); - } - - @Nonnull - private DhisResource persistTrackedEntityOutcome( @Nonnull FhirToDhisTransformOutcome outcome ) - { - final DhisResource dhisResource; - if ( outcome.getResource().isNewResource() || outcome.getResource().isModified() ) - { - logger.debug( "Persisting tracked entity instance." ); - dhisResource = trackedEntityService.createOrUpdate( outcome.getResource() ); - logger.info( "Persisted tracked entity instance {}.", dhisResource.getId() ); - } - else - { - dhisResource = outcome.getResource(); - logger.info( "Tracked entity instance {} has not been modified.", dhisResource.getId() ); - } - return dhisResource; - } - - @Nonnull - private DhisResource persistProgramStageEventOutcome( @Nonnull FhirToDhisTransformOutcome outcome ) - { - DhisResource dhisResource = null; - final Event event = outcome.getResource(); - if ( (event.getTrackedEntityInstance() != null) && event.getTrackedEntityInstance().isModified() ) - { - logger.debug( "Persisting tracked entity instance." ); - trackedEntityService.createOrUpdate( event.getTrackedEntityInstance() ); - logger.info( "Persisted tracked entity instance {}.", event.getTrackedEntityInstance().getId() ); - } - if ( event.getEnrollment().isNewResource() ) - { - logger.info( "Creating new enrollment." ); - event.getEnrollment().setEvents( Collections.singletonList( event ) ); - dhisResource = enrollmentService.create( event.getEnrollment() ).getEvents().get( 0 ); - logger.info( "Created new enrollment {} with new event.", event.getEnrollment().getId(), event.getId() ); - } - else - { - final List events = event.getEnrollment().getEvents(); - if ( event.getEnrollment().isModified() ) - { - logger.info( "Updating existing enrollment." ); - event.setEnrollment( enrollmentService.update( event.getEnrollment() ) ); - logger.info( "Updated existing enrollment {}.", event.getEnrollment().getId() ); - } - for ( final Event e : events ) - { - if ( e.isModified() || e.isAnyDataValueModified() ) + finally { - logger.debug( "Persisting event." ); - dhisResource = eventService.createOrMinimalUpdate( event ); - logger.info( "Persisted event {}.", dhisResource.getId() ); + context.shutdown(); + } + if ( outcome == null ) + { + transformerRequest = null; + } + else + { + dhisResourceRepository.save( outcome.getResource() ); + saved = true; + transformerRequest = outcome.getNextTransformerRequest(); } - } - if ( dhisResource == null ) - { - dhisResource = event; - logger.info( "Event {} has not been modified.", dhisResource.getId() ); } } - return dhisResource; + while ( transformerRequest != null ); + return saved; } @Nullable diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/dhis/DhisToFhirTransformOutcome.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/dhis/DhisToFhirTransformOutcome.java new file mode 100644 index 00000000..97a09501 --- /dev/null +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/dhis/DhisToFhirTransformOutcome.java @@ -0,0 +1,86 @@ +package org.dhis2.fhir.adapter.fhir.transform.dhis; + +/* + * Copyright (c) 2004-2018, University of Oslo + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * Neither the name of the HISP project nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +import org.dhis2.fhir.adapter.fhir.metadata.model.RemoteSubscriptionResource; +import org.hl7.fhir.instance.model.api.IBaseResource; + +import javax.annotation.Nonnull; +import javax.annotation.Nullable; +import java.io.Serializable; + +/** + * The outcome of the transformation between a DHIS 2 resource and a FHIR resource. + * + * @param the concrete type of the returned FHIR resource. + * @author volsch + */ +public class DhisToFhirTransformOutcome implements Serializable +{ + private static final long serialVersionUID = -1022009827965716982L; + + private final RemoteSubscriptionResource subscriptionResource; + + private final R resource; + + private final DhisToFhirTransformerRequest nextTransformerRequest; + + public DhisToFhirTransformOutcome( @Nonnull RemoteSubscriptionResource subscriptionResource, @Nonnull R resource ) + { + this.subscriptionResource = subscriptionResource; + this.resource = resource; + this.nextTransformerRequest = null; + } + + public DhisToFhirTransformOutcome( @Nonnull DhisToFhirTransformOutcome outcome, @Nullable DhisToFhirTransformerRequest nextTransformerRequest ) + { + this.subscriptionResource = outcome.getSubscriptionResource(); + this.resource = outcome.getResource(); + this.nextTransformerRequest = nextTransformerRequest; + } + + @Nonnull + public RemoteSubscriptionResource getSubscriptionResource() + { + return subscriptionResource; + } + + @Nonnull + public R getResource() + { + return resource; + } + + + @Nullable + public DhisToFhirTransformerRequest getNextTransformerRequest() + { + return nextTransformerRequest; + } +} diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/dhis/DhisToFhirTransformerContext.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/dhis/DhisToFhirTransformerContext.java new file mode 100644 index 00000000..b679200a --- /dev/null +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/dhis/DhisToFhirTransformerContext.java @@ -0,0 +1,68 @@ +package org.dhis2.fhir.adapter.fhir.transform.dhis; + +/* + * Copyright (c) 2004-2018, University of Oslo + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * Neither the name of the HISP project nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +import org.dhis2.fhir.adapter.fhir.transform.TransformerDataException; +import org.dhis2.fhir.adapter.fhir.transform.dhis.model.DhisRequest; +import org.dhis2.fhir.adapter.scriptable.ScriptMethod; +import org.dhis2.fhir.adapter.scriptable.ScriptMethodArg; +import org.dhis2.fhir.adapter.scriptable.ScriptType; +import org.dhis2.fhir.adapter.scriptable.Scriptable; + +import javax.annotation.Nonnull; +import java.time.ZonedDateTime; + +/** + * The context of the current transformation between a DHIS 2 resource to a FHIR resource. + * + * @author volsch + */ +@Scriptable +@ScriptType( value = "DhisContext", var = "context", description = "The context of the current transformation." ) +public interface DhisToFhirTransformerContext +{ + @Nonnull + @ScriptMethod( description = "Returns the DHIS request (type DhisRequest) that causes the current transformation execution." ) + DhisRequest getDhisRequest(); + + @Nonnull + @ScriptMethod( description = "Returns the current timestamp as date/time.", returnDescription = "The current timestamp as date/time." ) + ZonedDateTime now(); + + /** + * Ends the execution of the script with the specified message. This method can be used if the + * received data does not match any expectations. + * + * @param message the message that includes the reason why the transformations failed. + * @throws TransformerDataException the thrown exception with the specified message. + */ + @ScriptMethod( description = "Causes that the current transformation will fail with the specified message due to invalid data.", + args = @ScriptMethodArg( value = "message", description = "The reason that specifies why the transformation data is invalid." ) ) + void fail( @Nonnull String message ) throws TransformerDataException; +} diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/dhis/DhisToFhirTransformerRequest.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/dhis/DhisToFhirTransformerRequest.java new file mode 100644 index 00000000..a6d19ad2 --- /dev/null +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/dhis/DhisToFhirTransformerRequest.java @@ -0,0 +1,52 @@ +package org.dhis2.fhir.adapter.fhir.transform.dhis; + +/* + * Copyright (c) 2004-2018, University of Oslo + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * Neither the name of the HISP project nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +import org.hl7.fhir.instance.model.api.IBaseResource; + +import javax.annotation.Nonnull; +import java.io.Serializable; + +/** + * Contains the next request to the transformer, that may deliver further transformer + * outcomes. This is required when several rules can be applied to transform a resource. + * Also outcomes may depend on each other. If the second outcome of a transformation + * depends on the first outcome, then the first outcome must be stored before the + * second outcome. + * + * @author volsch + */ +public interface DhisToFhirTransformerRequest extends Serializable +{ + @Nonnull + DhisToFhirTransformerContext getContext(); + + @Nonnull + IBaseResource getInput(); +} diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/dhis/DhisToFhirTransformerService.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/dhis/DhisToFhirTransformerService.java new file mode 100644 index 00000000..c8c7c7ad --- /dev/null +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/dhis/DhisToFhirTransformerService.java @@ -0,0 +1,50 @@ +package org.dhis2.fhir.adapter.fhir.transform.dhis; + +/* + * Copyright (c) 2004-2018, University of Oslo + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * Neither the name of the HISP project nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +import org.dhis2.fhir.adapter.dhis.model.DhisResource; +import org.dhis2.fhir.adapter.fhir.transform.TransformerException; +import org.dhis2.fhir.adapter.fhir.transform.dhis.model.DhisRequest; + +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +/** + * Transforms a DHIS 2 resource to a FHIR resource by applying defines rules. + * + * @author volsch + */ +public interface DhisToFhirTransformerService +{ + @Nonnull + DhisToFhirTransformerRequest createTransformerRequest( @Nonnull DhisRequest dhisRequest, @Nonnull DhisResource resource ); + + @Nullable + DhisToFhirTransformOutcome transform( @Nonnull DhisToFhirTransformerRequest transformerRequest ) throws TransformerException; +} diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/dhis/model/DhisRequest.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/dhis/model/DhisRequest.java new file mode 100644 index 00000000..3294e70a --- /dev/null +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/dhis/model/DhisRequest.java @@ -0,0 +1,54 @@ +package org.dhis2.fhir.adapter.fhir.transform.dhis.model; + +/* + * Copyright (c) 2004-2018, University of Oslo + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * Neither the name of the HISP project nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +import org.dhis2.fhir.adapter.dhis.model.DhisResourceType; +import org.dhis2.fhir.adapter.scriptable.ScriptMethod; +import org.dhis2.fhir.adapter.scriptable.ScriptType; +import org.dhis2.fhir.adapter.scriptable.Scriptable; + +import javax.annotation.Nullable; +import java.time.ZonedDateTime; + +/** + * The DHIS request that caused the transformation from DHIS 2 to FHIR resource. + * + * @author volsch + */ +@Scriptable +@ScriptType( value = "DhisRequest", description = "The current DHIS 2 request (created or updated resource) that caused the execution of the transformation." ) +public interface DhisRequest +{ + @ScriptMethod( description = "Returns the processed DHIS 2 resource type as Java enumeration (e.g. TRACKED_ENTITY as enum constant)." ) + DhisResourceType getResourceType(); + + @Nullable + @ScriptMethod( description = "Returns the timestamp when the processed DHIS 2 resource has been updated the last time." ) + ZonedDateTime getLastUpdated(); +} diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/dhis/model/ImmutableDhisRequest.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/dhis/model/ImmutableDhisRequest.java new file mode 100644 index 00000000..608f1a22 --- /dev/null +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/dhis/model/ImmutableDhisRequest.java @@ -0,0 +1,69 @@ +package org.dhis2.fhir.adapter.fhir.transform.dhis.model; + +/* + * Copyright (c) 2004-2018, University of Oslo + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * Neither the name of the HISP project nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +import org.dhis2.fhir.adapter.dhis.model.DhisResourceType; +import org.dhis2.fhir.adapter.scriptable.Scriptable; + +import javax.annotation.Nonnull; +import javax.annotation.Nullable; +import java.io.Serializable; +import java.time.ZonedDateTime; + +/** + * The immutable DHIS request that caused the transformation from DHIS 2 to FHIR resource. + * This can be used in scripts safely. + * + * @author volsch + */ +@Scriptable +public class ImmutableDhisRequest implements DhisRequest, Serializable +{ + private static final long serialVersionUID = 8079249171843824509L; + + private final DhisRequest delegate; + + public ImmutableDhisRequest( @Nonnull DhisRequest delegate ) + { + this.delegate = delegate; + } + + @Override + public DhisResourceType getResourceType() + { + return delegate.getResourceType(); + } + + @Override + @Nullable + public ZonedDateTime getLastUpdated() + { + return delegate.getLastUpdated(); + } +} diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/dhis/model/WritableDhisRequest.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/dhis/model/WritableDhisRequest.java new file mode 100644 index 00000000..768223b7 --- /dev/null +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/dhis/model/WritableDhisRequest.java @@ -0,0 +1,72 @@ +package org.dhis2.fhir.adapter.fhir.transform.dhis.model; + +/* + * Copyright (c) 2004-2018, University of Oslo + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * Neither the name of the HISP project nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +import org.dhis2.fhir.adapter.dhis.model.DhisResourceType; + +import javax.annotation.Nullable; +import java.io.Serializable; +import java.time.ZonedDateTime; + +/** + * The mutable DHIS request that caused the transformation from DHIS 2 to FHIR resource. + * + * @author volsch + */ +public class WritableDhisRequest implements DhisRequest, Serializable +{ + private static final long serialVersionUID = 6482108680860344148L; + + private DhisResourceType resourceType; + + private ZonedDateTime lastUpdated; + + @Override + public DhisResourceType getResourceType() + { + return resourceType; + } + + public void setResourceType( DhisResourceType resourceType ) + { + this.resourceType = resourceType; + } + + @Nullable + @Override + public ZonedDateTime getLastUpdated() + { + return lastUpdated; + } + + public void setLastUpdated( ZonedDateTime lastUpdated ) + { + this.lastUpdated = lastUpdated; + } +} diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/FhirToDhisTransformOutcome.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/FhirToDhisTransformOutcome.java similarity index 74% rename from fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/FhirToDhisTransformOutcome.java rename to fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/FhirToDhisTransformOutcome.java index 01eb230a..232b6502 100644 --- a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/FhirToDhisTransformOutcome.java +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/FhirToDhisTransformOutcome.java @@ -1,4 +1,4 @@ -package org.dhis2.fhir.adapter.fhir.transform; +package org.dhis2.fhir.adapter.fhir.transform.fhir; /* * Copyright (c) 2004-2018, University of Oslo @@ -34,32 +34,42 @@ import javax.annotation.Nullable; import java.io.Serializable; +/** + * The outcome of the transformation between a FHIR resource and a DHIS 2 resource. + * + * @param the concrete type of the returned DHIS 2 resource. + * @author volsch + */ public class FhirToDhisTransformOutcome implements Serializable { private static final long serialVersionUID = -1022009827965716982L; - private final String id; - private final R resource; - public FhirToDhisTransformOutcome( @Nonnull R resource ) - { - this( null, resource ); - } + private final FhirToDhisTransformerRequest nextTransformerRequest; - public FhirToDhisTransformOutcome( @Nullable String id, @Nonnull R resource ) + public FhirToDhisTransformOutcome( @Nonnull R resource ) { - this.id = id; this.resource = resource; + this.nextTransformerRequest = null; } - public String getId() + public FhirToDhisTransformOutcome( @Nonnull FhirToDhisTransformOutcome outcome, @Nullable FhirToDhisTransformerRequest nextTransformerRequest ) { - return id; + this.resource = outcome.getResource(); + this.nextTransformerRequest = nextTransformerRequest; } + @Nonnull public R getResource() { return resource; } + + + @Nullable + public FhirToDhisTransformerRequest getNextTransformerRequest() + { + return nextTransformerRequest; + } } diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/FhirToDhisTransformerContext.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/FhirToDhisTransformerContext.java similarity index 89% rename from fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/FhirToDhisTransformerContext.java rename to fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/FhirToDhisTransformerContext.java index 2380984d..721fb360 100644 --- a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/FhirToDhisTransformerContext.java +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/FhirToDhisTransformerContext.java @@ -1,4 +1,4 @@ -package org.dhis2.fhir.adapter.fhir.transform; +package org.dhis2.fhir.adapter.fhir.transform.fhir; /* * Copyright (c) 2004-2018, University of Oslo @@ -30,8 +30,9 @@ import org.dhis2.fhir.adapter.dhis.model.Reference; import org.dhis2.fhir.adapter.dhis.model.ReferenceType; -import org.dhis2.fhir.adapter.fhir.transform.impl.TransformerScriptException; -import org.dhis2.fhir.adapter.fhir.transform.model.FhirRequest; +import org.dhis2.fhir.adapter.fhir.transform.TransformerDataException; +import org.dhis2.fhir.adapter.fhir.transform.fhir.impl.TransformerScriptException; +import org.dhis2.fhir.adapter.fhir.transform.fhir.model.FhirRequest; import org.dhis2.fhir.adapter.scriptable.ScriptMethod; import org.dhis2.fhir.adapter.scriptable.ScriptMethodArg; import org.dhis2.fhir.adapter.scriptable.ScriptType; @@ -41,8 +42,13 @@ import javax.annotation.Nullable; import java.time.ZonedDateTime; +/** + * The context of the current transformation between a FHIR resource to a DHIS 2 resource. + * + * @author volsch + */ @Scriptable -@ScriptType( value = "Context", var = "context", description = "The context of the current transformation." ) +@ScriptType( value = "FhirContext", var = "context", description = "The context of the current transformation." ) public interface FhirToDhisTransformerContext { @Nonnull diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/FhirToDhisTransformerRequest.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/FhirToDhisTransformerRequest.java new file mode 100644 index 00000000..2a4564aa --- /dev/null +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/FhirToDhisTransformerRequest.java @@ -0,0 +1,52 @@ +package org.dhis2.fhir.adapter.fhir.transform.fhir; + +/* + * Copyright (c) 2004-2018, University of Oslo + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * Neither the name of the HISP project nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +import org.hl7.fhir.instance.model.api.IBaseResource; + +import javax.annotation.Nonnull; +import java.io.Serializable; + +/** + * Contains the next request to the transformer, that may deliver further transformer + * outcomes. This is required when several rules can be applied to transform a resource. + * Also outcomes may depend on each other. If the second outcome of a transformation + * depends on the first outcome, then the first outcome must be stored before the + * second outcome. + * + * @author volsch + */ +public interface FhirToDhisTransformerRequest extends Serializable +{ + @Nonnull + FhirToDhisTransformerContext getContext(); + + @Nonnull + IBaseResource getInput(); +} diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/FhirToDhisTransformerService.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/FhirToDhisTransformerService.java similarity index 77% rename from fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/FhirToDhisTransformerService.java rename to fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/FhirToDhisTransformerService.java index 9abd98b9..5d4e3359 100644 --- a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/FhirToDhisTransformerService.java +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/FhirToDhisTransformerService.java @@ -1,4 +1,4 @@ -package org.dhis2.fhir.adapter.fhir.transform; +package org.dhis2.fhir.adapter.fhir.transform.fhir; /* * Copyright (c) 2004-2018, University of Oslo @@ -29,18 +29,23 @@ */ import org.dhis2.fhir.adapter.dhis.model.DhisResource; -import org.dhis2.fhir.adapter.fhir.transform.model.FhirRequest; +import org.dhis2.fhir.adapter.fhir.transform.TransformerException; +import org.dhis2.fhir.adapter.fhir.transform.fhir.model.FhirRequest; import org.hl7.fhir.instance.model.api.IBaseResource; import javax.annotation.Nonnull; import javax.annotation.Nullable; +/** + * Transforms a FHIR resource to a DHIS 2 resource by applying defines rules. + * + * @author volsch + */ public interface FhirToDhisTransformerService { @Nonnull - FhirToDhisTransformerContext createContext( @Nonnull FhirRequest fhirRequest ); + FhirToDhisTransformerRequest createTransformerRequest( @Nonnull FhirRequest fhirRequest, @Nonnull IBaseResource originalInput, boolean contained ); @Nullable - FhirToDhisTransformOutcome transform( @Nonnull FhirToDhisTransformerContext context, @Nonnull IBaseResource input, boolean contained ) - throws TransformerException; + FhirToDhisTransformOutcome transform( @Nonnull FhirToDhisTransformerRequest transformerRequest ) throws TransformerException; } diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/TrackedEntityInstanceNotFoundException.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/TrackedEntityInstanceNotFoundException.java similarity index 97% rename from fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/TrackedEntityInstanceNotFoundException.java rename to fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/TrackedEntityInstanceNotFoundException.java index 233c53e0..ab45e2e2 100644 --- a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/TrackedEntityInstanceNotFoundException.java +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/TrackedEntityInstanceNotFoundException.java @@ -1,4 +1,4 @@ -package org.dhis2.fhir.adapter.fhir.transform; +package org.dhis2.fhir.adapter.fhir.transform.fhir; /* * Copyright (c) 2004-2018, University of Oslo diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/impl/AbstractFhirToDhisTransformer.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/AbstractFhirToDhisTransformer.java similarity index 97% rename from fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/impl/AbstractFhirToDhisTransformer.java rename to fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/AbstractFhirToDhisTransformer.java index 7f146d3e..237a589b 100644 --- a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/impl/AbstractFhirToDhisTransformer.java +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/AbstractFhirToDhisTransformer.java @@ -1,4 +1,4 @@ -package org.dhis2.fhir.adapter.fhir.transform.impl; +package org.dhis2.fhir.adapter.fhir.transform.fhir.impl; /* * Copyright (c) 2004-2018, University of Oslo @@ -47,14 +47,14 @@ import org.dhis2.fhir.adapter.fhir.model.FhirVersion; import org.dhis2.fhir.adapter.fhir.script.ScriptExecutor; import org.dhis2.fhir.adapter.fhir.transform.FatalTransformerException; -import org.dhis2.fhir.adapter.fhir.transform.FhirToDhisTransformOutcome; -import org.dhis2.fhir.adapter.fhir.transform.FhirToDhisTransformerContext; -import org.dhis2.fhir.adapter.fhir.transform.TrackedEntityInstanceNotFoundException; import org.dhis2.fhir.adapter.fhir.transform.TransformerException; import org.dhis2.fhir.adapter.fhir.transform.TransformerMappingException; import org.dhis2.fhir.adapter.fhir.transform.TransformerRequestException; -import org.dhis2.fhir.adapter.fhir.transform.impl.util.AbstractIdentifierFhirToDhisTransformerUtils; -import org.dhis2.fhir.adapter.fhir.transform.model.ResourceSystem; +import org.dhis2.fhir.adapter.fhir.transform.fhir.FhirToDhisTransformOutcome; +import org.dhis2.fhir.adapter.fhir.transform.fhir.FhirToDhisTransformerContext; +import org.dhis2.fhir.adapter.fhir.transform.fhir.TrackedEntityInstanceNotFoundException; +import org.dhis2.fhir.adapter.fhir.transform.fhir.impl.util.AbstractIdentifierFhirToDhisTransformerUtils; +import org.dhis2.fhir.adapter.fhir.transform.fhir.model.ResourceSystem; import org.dhis2.fhir.adapter.geo.Location; import org.hl7.fhir.instance.model.api.IBaseResource; import org.hl7.fhir.instance.model.api.IDomainResource; diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/impl/FhirToDhisTransformer.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/FhirToDhisTransformer.java similarity index 85% rename from fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/impl/FhirToDhisTransformer.java rename to fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/FhirToDhisTransformer.java index 28b42c64..81ae2025 100644 --- a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/impl/FhirToDhisTransformer.java +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/FhirToDhisTransformer.java @@ -1,4 +1,4 @@ -package org.dhis2.fhir.adapter.fhir.transform.impl; +package org.dhis2.fhir.adapter.fhir.transform.fhir.impl; /* * Copyright (c) 2004-2018, University of Oslo @@ -32,15 +32,22 @@ import org.dhis2.fhir.adapter.dhis.model.DhisResourceType; import org.dhis2.fhir.adapter.fhir.metadata.model.AbstractRule; import org.dhis2.fhir.adapter.fhir.model.FhirVersionRestricted; -import org.dhis2.fhir.adapter.fhir.transform.FhirToDhisTransformOutcome; -import org.dhis2.fhir.adapter.fhir.transform.FhirToDhisTransformerContext; import org.dhis2.fhir.adapter.fhir.transform.TransformerException; +import org.dhis2.fhir.adapter.fhir.transform.fhir.FhirToDhisTransformOutcome; +import org.dhis2.fhir.adapter.fhir.transform.fhir.FhirToDhisTransformerContext; import org.hl7.fhir.instance.model.api.IBaseResource; import javax.annotation.Nonnull; import javax.annotation.Nullable; import java.util.Map; +/** + * Transforms a FHIR resource to a DHIS 2 resource. + * + * @param the concrete type of the DHIS 2 resource that is processed by this transformer. + * @param the concrete type of the transformer rule that is processed by this transformer. + * @author volsch + */ public interface FhirToDhisTransformer extends FhirVersionRestricted { @Nonnull diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/impl/FhirToDhisTransformerContextImpl.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/FhirToDhisTransformerContextImpl.java similarity index 92% rename from fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/impl/FhirToDhisTransformerContextImpl.java rename to fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/FhirToDhisTransformerContextImpl.java index 37304d5f..06eae1c2 100644 --- a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/impl/FhirToDhisTransformerContextImpl.java +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/FhirToDhisTransformerContextImpl.java @@ -1,4 +1,4 @@ -package org.dhis2.fhir.adapter.fhir.transform.impl; +package org.dhis2.fhir.adapter.fhir.transform.fhir.impl; /* * Copyright (c) 2004-2018, University of Oslo @@ -30,10 +30,10 @@ import org.dhis2.fhir.adapter.dhis.model.Reference; import org.dhis2.fhir.adapter.dhis.model.ReferenceType; -import org.dhis2.fhir.adapter.fhir.transform.FhirToDhisTransformerContext; import org.dhis2.fhir.adapter.fhir.transform.TransformerDataException; -import org.dhis2.fhir.adapter.fhir.transform.model.FhirRequest; -import org.dhis2.fhir.adapter.fhir.transform.model.ImmutableFhirRequest; +import org.dhis2.fhir.adapter.fhir.transform.fhir.FhirToDhisTransformerContext; +import org.dhis2.fhir.adapter.fhir.transform.fhir.model.FhirRequest; +import org.dhis2.fhir.adapter.fhir.transform.fhir.model.ImmutableFhirRequest; import javax.annotation.Nonnull; import javax.annotation.Nullable; diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/FhirToDhisTransformerRequestImpl.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/FhirToDhisTransformerRequestImpl.java new file mode 100644 index 00000000..4961c44b --- /dev/null +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/FhirToDhisTransformerRequestImpl.java @@ -0,0 +1,114 @@ +package org.dhis2.fhir.adapter.fhir.transform.fhir.impl; + +/* + * Copyright (c) 2004-2018, University of Oslo + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * Neither the name of the HISP project nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +import org.dhis2.fhir.adapter.fhir.metadata.model.AbstractRule; +import org.dhis2.fhir.adapter.fhir.transform.fhir.FhirToDhisTransformerContext; +import org.dhis2.fhir.adapter.fhir.transform.fhir.FhirToDhisTransformerRequest; +import org.dhis2.fhir.adapter.fhir.transform.fhir.impl.util.FhirToDhisTransformerUtils; +import org.hl7.fhir.instance.model.api.IBaseResource; + +import javax.annotation.Nonnull; +import javax.annotation.Nullable; +import java.util.List; +import java.util.Map; + +/** + * Implementation of {@link FhirToDhisTransformerContext}. + * + * @author volsch + */ +public class FhirToDhisTransformerRequestImpl implements FhirToDhisTransformerRequest +{ + private static final long serialVersionUID = 4181923310602004074L; + + private final FhirToDhisTransformerContext context; + + private final IBaseResource input; + + private final Map transformerUtils; + + private final List rules; + + private int ruleIndex; + + public FhirToDhisTransformerRequestImpl( @Nonnull FhirToDhisTransformerContext context, @Nonnull IBaseResource input, @Nonnull Map transformerUtils, @Nonnull List rules ) + { + this.context = context; + this.input = input; + this.transformerUtils = transformerUtils; + this.rules = rules; + } + + @Nonnull + @Override + public FhirToDhisTransformerContext getContext() + { + return context; + } + + @Nonnull + @Override + public IBaseResource getInput() + { + return input; + } + + @Nonnull + public Map getTransformerUtils() + { + return transformerUtils; + } + + @Nonnull + public List getRules() + { + return rules; + } + + public boolean isFirstRule() + { + return (ruleIndex == 0); + } + + public boolean isLastRule() + { + return (ruleIndex >= rules.size()); + } + + @Nullable + public AbstractRule nextRule() + { + if ( ruleIndex >= rules.size() ) + { + return null; + } + return rules.get( ruleIndex++ ); + } +} diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/impl/FhirToDhisTransformerServiceImpl.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/FhirToDhisTransformerServiceImpl.java similarity index 63% rename from fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/impl/FhirToDhisTransformerServiceImpl.java rename to fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/FhirToDhisTransformerServiceImpl.java index 83bf8758..11a73174 100644 --- a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/impl/FhirToDhisTransformerServiceImpl.java +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/FhirToDhisTransformerServiceImpl.java @@ -1,4 +1,4 @@ -package org.dhis2.fhir.adapter.fhir.transform.impl; +package org.dhis2.fhir.adapter.fhir.transform.fhir.impl; /* * Copyright (c) 2004-2018, University of Oslo @@ -36,18 +36,19 @@ import org.dhis2.fhir.adapter.fhir.metadata.repository.RuleRepository; import org.dhis2.fhir.adapter.fhir.model.FhirVersion; import org.dhis2.fhir.adapter.fhir.model.FhirVersionedValue; -import org.dhis2.fhir.adapter.fhir.repository.RemoteFhirRepository; +import org.dhis2.fhir.adapter.fhir.repository.RemoteFhirResourceRepository; import org.dhis2.fhir.adapter.fhir.script.ScriptExecutor; import org.dhis2.fhir.adapter.fhir.transform.FatalTransformerException; -import org.dhis2.fhir.adapter.fhir.transform.FhirToDhisTransformOutcome; -import org.dhis2.fhir.adapter.fhir.transform.FhirToDhisTransformerContext; -import org.dhis2.fhir.adapter.fhir.transform.FhirToDhisTransformerService; import org.dhis2.fhir.adapter.fhir.transform.TransformerException; import org.dhis2.fhir.adapter.fhir.transform.TransformerMappingException; -import org.dhis2.fhir.adapter.fhir.transform.impl.util.AbstractCodeFhirToDhisTransformerUtils; -import org.dhis2.fhir.adapter.fhir.transform.impl.util.BeanTransformerUtils; -import org.dhis2.fhir.adapter.fhir.transform.impl.util.FhirToDhisTransformerUtils; -import org.dhis2.fhir.adapter.fhir.transform.model.FhirRequest; +import org.dhis2.fhir.adapter.fhir.transform.fhir.FhirToDhisTransformOutcome; +import org.dhis2.fhir.adapter.fhir.transform.fhir.FhirToDhisTransformerContext; +import org.dhis2.fhir.adapter.fhir.transform.fhir.FhirToDhisTransformerRequest; +import org.dhis2.fhir.adapter.fhir.transform.fhir.FhirToDhisTransformerService; +import org.dhis2.fhir.adapter.fhir.transform.fhir.impl.util.AbstractCodeFhirToDhisTransformerUtils; +import org.dhis2.fhir.adapter.fhir.transform.fhir.impl.util.BeanTransformerUtils; +import org.dhis2.fhir.adapter.fhir.transform.fhir.impl.util.FhirToDhisTransformerUtils; +import org.dhis2.fhir.adapter.fhir.transform.fhir.model.FhirRequest; import org.dhis2.fhir.adapter.lock.LockContext; import org.dhis2.fhir.adapter.lock.LockManager; import org.hl7.fhir.instance.model.api.IBaseResource; @@ -62,6 +63,7 @@ import java.util.List; import java.util.Map; import java.util.Objects; +import java.util.stream.Collectors; @Service public class FhirToDhisTransformerServiceImpl implements FhirToDhisTransformerService @@ -70,7 +72,7 @@ public class FhirToDhisTransformerServiceImpl implements FhirToDhisTransformerSe private final LockManager lockManager; - private final RemoteFhirRepository remoteFhirRepository; + private final RemoteFhirResourceRepository remoteFhirResourceRepository; private final RuleRepository ruleRepository; @@ -81,13 +83,13 @@ public class FhirToDhisTransformerServiceImpl implements FhirToDhisTransformerSe private final ScriptExecutor scriptExecutor; public FhirToDhisTransformerServiceImpl( @Nonnull LockManager lockManager, - @Nonnull RemoteFhirRepository remoteFhirRepository, @Nonnull RuleRepository ruleRepository, + @Nonnull RemoteFhirResourceRepository remoteFhirResourceRepository, @Nonnull RuleRepository ruleRepository, @Nonnull ObjectProvider>> transformersProvider, @Nonnull ObjectProvider> transformUtilsProvider, @Nonnull ScriptExecutor scriptExecutor ) { this.lockManager = lockManager; - this.remoteFhirRepository = remoteFhirRepository; + this.remoteFhirResourceRepository = remoteFhirResourceRepository; this.ruleRepository = ruleRepository; this.scriptExecutor = scriptExecutor; @@ -115,62 +117,75 @@ public FhirToDhisTransformerServiceImpl( @Nonnull LockManager lockManager, @Nonnull @Override - public FhirToDhisTransformerContext createContext( @Nonnull FhirRequest fhirRequest ) + public FhirToDhisTransformerRequest createTransformerRequest( @Nonnull FhirRequest fhirRequest, @Nonnull IBaseResource originalInput, boolean contained ) { - return new FhirToDhisTransformerContextImpl( fhirRequest, false ); + final Map transformerUtils = this.transformerUtils.get( fhirRequest.getVersion() ); + if ( transformerUtils == null ) + { + throw new TransformerMappingException( "No transformer utils can be found for FHIR version " + fhirRequest.getVersion() ); + } + final AbstractCodeFhirToDhisTransformerUtils codeTransformerUtils = (AbstractCodeFhirToDhisTransformerUtils) transformerUtils.get( ScriptVariable.CODE_UTILS.getVariableName() ); + if ( codeTransformerUtils == null ) + { + throw new TransformerMappingException( "Code transformer utils can be found for FHIR version " + fhirRequest.getVersion() ); + } + + final FhirContext fhirContext = remoteFhirResourceRepository.findFhirContext( fhirRequest.getVersion() ) + .orElseThrow( () -> new FatalTransformerException( "FHIR context for FHIR version " + fhirRequest.getVersion() + " is not available." ) ); + final IBaseResource input = Objects.requireNonNull( BeanTransformerUtils.clone( fhirContext, originalInput ) ); + final List rules = ruleRepository.findAllByInputData( fhirRequest.getResourceType(), codeTransformerUtils.getResourceCodes( input ) ) + .stream().filter( r -> !contained || r.isContainedAllowed() ).collect( Collectors.toList() ); + + return new FhirToDhisTransformerRequestImpl( new FhirToDhisTransformerContextImpl( fhirRequest, false ), input, transformerUtils, rules ); } @Nullable @Override - public FhirToDhisTransformOutcome transform( @Nonnull FhirToDhisTransformerContext context, @Nonnull IBaseResource originalInput, boolean contained ) throws TransformerException + public FhirToDhisTransformOutcome transform( @Nonnull FhirToDhisTransformerRequest transformerRequest ) throws TransformerException { - final FhirContext fhirContext = remoteFhirRepository.findFhirContext( context.getFhirRequest().getVersion() ) - .orElseThrow( () -> new FatalTransformerException( "FHIR context for FHIR version " + context.getFhirRequest().getVersion() + " is not available." ) ); - final IBaseResource input = Objects.requireNonNull( BeanTransformerUtils.clone( fhirContext, originalInput ) ); - - final Map transformerUtils = this.transformerUtils.get( context.getFhirRequest().getVersion() ); - if ( transformerUtils == null ) - { - throw new TransformerMappingException( "No transformer utils can be found for FHIR version " + context.getFhirRequest().getVersion() ); - } + final FhirToDhisTransformerRequestImpl transformerRequestImpl = (FhirToDhisTransformerRequestImpl) transformerRequest; + final Map transformerUtils = transformerRequestImpl.getTransformerUtils(); final AbstractCodeFhirToDhisTransformerUtils codeTransformerUtils = (AbstractCodeFhirToDhisTransformerUtils) transformerUtils.get( ScriptVariable.CODE_UTILS.getVariableName() ); if ( codeTransformerUtils == null ) { - throw new TransformerMappingException( "Code transformer utils can be found for FHIR version " + context.getFhirRequest().getVersion() ); + throw new TransformerMappingException( "Code transformer utils can be found for FHIR version " + + transformerRequestImpl.getContext().getFhirRequest().getVersion() ); } - final List rules = ruleRepository.findAllByInputData( context.getFhirRequest().getResourceType(), - codeTransformerUtils.getResourceCodes( input ) ); - for ( final AbstractRule rule : rules ) + final boolean firstRule = transformerRequestImpl.isFirstRule(); + AbstractRule rule; + while ( (rule = transformerRequestImpl.nextRule()) != null ) { - if ( contained && !rule.isContainedAllowed() ) - { - continue; - } - - final FhirToDhisTransformer transformer = this.transformers.get( new FhirVersionedValue<>( context.getFhirRequest().getVersion(), rule.getDhisResourceType() ) ); + final FhirToDhisTransformer transformer = this.transformers.get( + new FhirVersionedValue<>( transformerRequestImpl.getContext().getFhirRequest().getVersion(), rule.getDhisResourceType() ) ); if ( transformer == null ) { - throw new TransformerMappingException( "No transformer can be found for FHIR version " + context.getFhirRequest().getVersion() + " mapping of DHIS resource type " + rule.getDhisResourceType() ); + throw new TransformerMappingException( "No transformer can be found for FHIR version " + + transformerRequestImpl.getContext().getFhirRequest().getVersion() + + " mapping of DHIS resource type " + rule.getDhisResourceType() ); } final Map scriptVariables = new HashMap<>( transformerUtils ); - scriptVariables.put( ScriptVariable.CONTEXT.getVariableName(), context ); - scriptVariables.put( ScriptVariable.INPUT.getVariableName(), input ); - if ( isApplicable( context, input, rule, scriptVariables ) ) + scriptVariables.put( ScriptVariable.CONTEXT.getVariableName(), transformerRequestImpl.getContext() ); + scriptVariables.put( ScriptVariable.INPUT.getVariableName(), transformerRequestImpl.getInput() ); + if ( isApplicable( transformerRequestImpl.getContext(), transformerRequestImpl.getInput(), rule, scriptVariables ) ) { - final FhirToDhisTransformOutcome outcome = transformer.transformCasted( context, input, rule, scriptVariables ); + final FhirToDhisTransformOutcome outcome = transformer.transformCasted( + transformerRequestImpl.getContext(), transformerRequestImpl.getInput(), rule, scriptVariables ); if ( outcome != null ) { - logger.info( "Rule {} used successfully for transformation of {}.", rule, input.getIdElement() ); - return outcome; + logger.info( "Rule {} used successfully for transformation of {}.", rule, transformerRequestImpl.getInput().getIdElement() ); + return new FhirToDhisTransformOutcome<>( outcome, transformerRequestImpl.isLastRule() ? null : transformerRequestImpl ); } // if the previous transformation caused a lock of any resource this must be released since the transformation has been rolled back lockManager.getCurrentLockContext().ifPresent( LockContext::unlockAll ); } } - logger.info( "No matching rule for {}.", input.getIdElement() ); + if ( firstRule ) + { + logger.info( "No matching rule for {}.", transformerRequestImpl.getInput().getIdElement() ); + } return null; } diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/impl/TransformationConfig.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/TransformationConfig.java similarity index 98% rename from fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/impl/TransformationConfig.java rename to fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/TransformationConfig.java index 6ef20533..5133fd3c 100644 --- a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/impl/TransformationConfig.java +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/TransformationConfig.java @@ -1,4 +1,4 @@ -package org.dhis2.fhir.adapter.fhir.transform.impl; +package org.dhis2.fhir.adapter.fhir.transform.fhir.impl; /* * Copyright (c) 2004-2018, University of Oslo diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/impl/TransformerScriptException.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/TransformerScriptException.java similarity index 97% rename from fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/impl/TransformerScriptException.java rename to fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/TransformerScriptException.java index 4daa7a3a..6c28dff0 100644 --- a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/impl/TransformerScriptException.java +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/TransformerScriptException.java @@ -1,4 +1,4 @@ -package org.dhis2.fhir.adapter.fhir.transform.impl; +package org.dhis2.fhir.adapter.fhir.transform.fhir.impl; /* * Copyright (c) 2004-2018, University of Oslo diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/impl/program/EventComparator.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/program/EventComparator.java similarity index 97% rename from fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/impl/program/EventComparator.java rename to fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/program/EventComparator.java index f376f265..66cb9608 100644 --- a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/impl/program/EventComparator.java +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/program/EventComparator.java @@ -1,4 +1,4 @@ -package org.dhis2.fhir.adapter.fhir.transform.impl.program; +package org.dhis2.fhir.adapter.fhir.transform.fhir.impl.program; /* * Copyright (c) 2004-2018, University of Oslo diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/impl/program/EventInfo.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/program/EventInfo.java similarity index 95% rename from fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/impl/program/EventInfo.java rename to fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/program/EventInfo.java index eaaa53df..e59777d3 100644 --- a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/impl/program/EventInfo.java +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/program/EventInfo.java @@ -1,4 +1,4 @@ -package org.dhis2.fhir.adapter.fhir.transform.impl.program; +package org.dhis2.fhir.adapter.fhir.transform.fhir.impl.program; /* * Copyright (c) 2004-2018, University of Oslo @@ -33,7 +33,7 @@ import org.dhis2.fhir.adapter.dhis.tracker.program.Program; import org.dhis2.fhir.adapter.dhis.tracker.program.ProgramStage; import org.dhis2.fhir.adapter.dhis.tracker.trackedentity.TrackedEntityType; -import org.dhis2.fhir.adapter.fhir.transform.impl.trackedentity.ScriptedTrackedEntityInstance; +import org.dhis2.fhir.adapter.fhir.transform.scripted.ScriptedTrackedEntityInstance; import javax.annotation.Nonnull; import javax.annotation.Nullable; diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/impl/program/FhirToDhisOptionSetUtils.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/program/FhirToDhisOptionSetUtils.java similarity index 97% rename from fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/impl/program/FhirToDhisOptionSetUtils.java rename to fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/program/FhirToDhisOptionSetUtils.java index 6a27a071..d196675d 100644 --- a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/impl/program/FhirToDhisOptionSetUtils.java +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/program/FhirToDhisOptionSetUtils.java @@ -1,4 +1,4 @@ -package org.dhis2.fhir.adapter.fhir.transform.impl.program; +package org.dhis2.fhir.adapter.fhir.transform.fhir.impl.program; /* * Copyright (c) 2004-2018, University of Oslo @@ -30,7 +30,7 @@ import org.dhis2.fhir.adapter.dhis.model.Option; import org.dhis2.fhir.adapter.dhis.model.OptionSet; -import org.dhis2.fhir.adapter.fhir.transform.impl.TransformerScriptException; +import org.dhis2.fhir.adapter.fhir.transform.fhir.impl.TransformerScriptException; import javax.annotation.Nonnull; import javax.annotation.Nullable; diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/impl/program/FhirToProgramStageTransformer.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/program/FhirToProgramStageTransformer.java similarity index 98% rename from fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/impl/program/FhirToProgramStageTransformer.java rename to fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/program/FhirToProgramStageTransformer.java index 78560ade..65069bbe 100644 --- a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/impl/program/FhirToProgramStageTransformer.java +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/program/FhirToProgramStageTransformer.java @@ -1,4 +1,4 @@ -package org.dhis2.fhir.adapter.fhir.transform.impl.program; +package org.dhis2.fhir.adapter.fhir.transform.fhir.impl.program; /* * Copyright (c) 2004-2018, University of Oslo @@ -57,13 +57,15 @@ import org.dhis2.fhir.adapter.fhir.model.EventDecisionType; import org.dhis2.fhir.adapter.fhir.script.ScriptExecutor; import org.dhis2.fhir.adapter.fhir.transform.FatalTransformerException; -import org.dhis2.fhir.adapter.fhir.transform.FhirToDhisTransformOutcome; -import org.dhis2.fhir.adapter.fhir.transform.FhirToDhisTransformerContext; import org.dhis2.fhir.adapter.fhir.transform.TransformerException; import org.dhis2.fhir.adapter.fhir.transform.TransformerMappingException; -import org.dhis2.fhir.adapter.fhir.transform.impl.AbstractFhirToDhisTransformer; -import org.dhis2.fhir.adapter.fhir.transform.impl.trackedentity.ScriptedTrackedEntityInstance; -import org.dhis2.fhir.adapter.fhir.transform.impl.trackedentity.WritableScriptedTrackedEntityInstance; +import org.dhis2.fhir.adapter.fhir.transform.fhir.FhirToDhisTransformOutcome; +import org.dhis2.fhir.adapter.fhir.transform.fhir.FhirToDhisTransformerContext; +import org.dhis2.fhir.adapter.fhir.transform.fhir.impl.AbstractFhirToDhisTransformer; +import org.dhis2.fhir.adapter.fhir.transform.scripted.ScriptedTrackedEntityInstance; +import org.dhis2.fhir.adapter.fhir.transform.scripted.WritableScriptedEnrollment; +import org.dhis2.fhir.adapter.fhir.transform.scripted.WritableScriptedEvent; +import org.dhis2.fhir.adapter.fhir.transform.scripted.WritableScriptedTrackedEntityInstance; import org.dhis2.fhir.adapter.lock.LockManager; import org.dhis2.fhir.adapter.model.ValueType; import org.dhis2.fhir.adapter.spring.StaticObjectProvider; @@ -225,7 +227,7 @@ public FhirToDhisTransformOutcome transform( @Nonnull FhirToDhisTransform event.setTrackedEntityInstance( trackedEntityInstance ); scriptedProgramStageEvents.stream().filter( se -> se.isNewResource() || se.isModified() || se.isAnyDataValueModified() ).forEach( WritableScriptedEvent::validate ); - return new FhirToDhisTransformOutcome<>( event.getId(), event ); + return new FhirToDhisTransformOutcome<>( event ); } protected void addBasicScriptVariables( @Nonnull Map variables, @Nonnull ProgramStageRule rule ) throws TransformerException diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/impl/program/ImmutableScriptedEnrollment.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/program/ImmutableScriptedEnrollment.java similarity index 91% rename from fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/impl/program/ImmutableScriptedEnrollment.java rename to fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/program/ImmutableScriptedEnrollment.java index 6c419e31..a854e846 100644 --- a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/impl/program/ImmutableScriptedEnrollment.java +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/program/ImmutableScriptedEnrollment.java @@ -1,4 +1,4 @@ -package org.dhis2.fhir.adapter.fhir.transform.impl.program; +package org.dhis2.fhir.adapter.fhir.transform.fhir.impl.program; /* * Copyright (c) 2004-2018, University of Oslo @@ -29,6 +29,7 @@ */ import org.dhis2.fhir.adapter.fhir.transform.TransformerException; +import org.dhis2.fhir.adapter.fhir.transform.scripted.ScriptedEnrollment; import org.dhis2.fhir.adapter.geo.Location; import org.dhis2.fhir.adapter.scriptable.Scriptable; @@ -62,6 +63,13 @@ public String getId() return delegate.getId(); } + @Nullable + @Override + public ZonedDateTime getLastUpdated() + { + return delegate.getLastUpdated(); + } + @Override @Nullable public String getOrganizationUnitId() diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/impl/program/ImmutableScriptedEvent.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/program/ImmutableScriptedEvent.java similarity index 92% rename from fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/impl/program/ImmutableScriptedEvent.java rename to fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/program/ImmutableScriptedEvent.java index 24777ec8..3131e57d 100644 --- a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/impl/program/ImmutableScriptedEvent.java +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/program/ImmutableScriptedEvent.java @@ -1,4 +1,4 @@ -package org.dhis2.fhir.adapter.fhir.transform.impl.program; +package org.dhis2.fhir.adapter.fhir.transform.fhir.impl.program; /* * Copyright (c) 2004-2018, University of Oslo @@ -31,6 +31,7 @@ import org.dhis2.fhir.adapter.dhis.tracker.program.EventStatus; import org.dhis2.fhir.adapter.fhir.transform.TransformerException; +import org.dhis2.fhir.adapter.fhir.transform.scripted.ScriptedEvent; import org.dhis2.fhir.adapter.geo.Location; import org.dhis2.fhir.adapter.scriptable.Scriptable; @@ -64,6 +65,13 @@ public String getId() return delegate.getId(); } + @Nullable + @Override + public ZonedDateTime getLastUpdated() + { + return delegate.getLastUpdated(); + } + @Nullable @Override public String getOrganizationUnitId() diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/impl/trackedentity/FhirToTrackedEntityTransformer.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/trackedentity/FhirToTrackedEntityTransformer.java similarity index 96% rename from fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/impl/trackedentity/FhirToTrackedEntityTransformer.java rename to fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/trackedentity/FhirToTrackedEntityTransformer.java index 3fd9042c..a115d3aa 100644 --- a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/impl/trackedentity/FhirToTrackedEntityTransformer.java +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/trackedentity/FhirToTrackedEntityTransformer.java @@ -1,4 +1,4 @@ -package org.dhis2.fhir.adapter.fhir.transform.impl.trackedentity; +package org.dhis2.fhir.adapter.fhir.transform.fhir.impl.trackedentity; /* * Copyright (c) 2004-2018, University of Oslo @@ -44,12 +44,13 @@ import org.dhis2.fhir.adapter.fhir.metadata.model.TrackedEntityRule; import org.dhis2.fhir.adapter.fhir.script.ScriptExecutor; import org.dhis2.fhir.adapter.fhir.transform.FatalTransformerException; -import org.dhis2.fhir.adapter.fhir.transform.FhirToDhisTransformOutcome; -import org.dhis2.fhir.adapter.fhir.transform.FhirToDhisTransformerContext; -import org.dhis2.fhir.adapter.fhir.transform.TrackedEntityInstanceNotFoundException; import org.dhis2.fhir.adapter.fhir.transform.TransformerException; import org.dhis2.fhir.adapter.fhir.transform.TransformerMappingException; -import org.dhis2.fhir.adapter.fhir.transform.impl.AbstractFhirToDhisTransformer; +import org.dhis2.fhir.adapter.fhir.transform.fhir.FhirToDhisTransformOutcome; +import org.dhis2.fhir.adapter.fhir.transform.fhir.FhirToDhisTransformerContext; +import org.dhis2.fhir.adapter.fhir.transform.fhir.TrackedEntityInstanceNotFoundException; +import org.dhis2.fhir.adapter.fhir.transform.fhir.impl.AbstractFhirToDhisTransformer; +import org.dhis2.fhir.adapter.fhir.transform.scripted.WritableScriptedTrackedEntityInstance; import org.dhis2.fhir.adapter.lock.LockManager; import org.dhis2.fhir.adapter.spring.StaticObjectProvider; import org.hl7.fhir.instance.model.api.IBaseResource; @@ -163,7 +164,7 @@ public FhirToDhisTransformOutcome transform( @Nonnull Fhi Collections.singletonMap( RequiredValueType.ORG_UNIT_CODE, organisationUnit.get().getCode() ) ); scriptedTrackedEntityInstance.validate(); - return new FhirToDhisTransformOutcome<>( trackedEntityInstance.getId(), trackedEntityInstance ); + return new FhirToDhisTransformOutcome<>( trackedEntityInstance ); } protected boolean addScriptVariables( @Nonnull Map arguments, @Nonnull TrackedEntityRule rule ) throws TransformerException @@ -190,7 +191,7 @@ protected boolean isSyncRequired( @Nonnull FhirToDhisTransformerContext context, @Override protected Optional getResourceById( @Nullable String id ) throws TransformerException { - return (id == null) ? Optional.empty() : getTrackedEntityService().getById( id ); + return (id == null) ? Optional.empty() : getTrackedEntityService().findById( id ); } @Nonnull diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/impl/util/AbstractAddressFhirToDhisTransformerUtils.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/AbstractAddressFhirToDhisTransformerUtils.java similarity index 98% rename from fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/impl/util/AbstractAddressFhirToDhisTransformerUtils.java rename to fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/AbstractAddressFhirToDhisTransformerUtils.java index 2a5d1163..6b9d4a4c 100644 --- a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/impl/util/AbstractAddressFhirToDhisTransformerUtils.java +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/AbstractAddressFhirToDhisTransformerUtils.java @@ -1,4 +1,4 @@ -package org.dhis2.fhir.adapter.fhir.transform.impl.util; +package org.dhis2.fhir.adapter.fhir.transform.fhir.impl.util; /* * Copyright (c) 2004-2018, University of Oslo diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/impl/util/AbstractCodeFhirToDhisTransformerUtils.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/AbstractCodeFhirToDhisTransformerUtils.java similarity index 97% rename from fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/impl/util/AbstractCodeFhirToDhisTransformerUtils.java rename to fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/AbstractCodeFhirToDhisTransformerUtils.java index 331a2451..5a36f995 100644 --- a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/impl/util/AbstractCodeFhirToDhisTransformerUtils.java +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/AbstractCodeFhirToDhisTransformerUtils.java @@ -1,4 +1,4 @@ -package org.dhis2.fhir.adapter.fhir.transform.impl.util; +package org.dhis2.fhir.adapter.fhir.transform.fhir.impl.util; /* * Copyright (c) 2004-2018, University of Oslo @@ -38,11 +38,11 @@ import org.dhis2.fhir.adapter.fhir.script.ScriptArgUtils; import org.dhis2.fhir.adapter.fhir.script.ScriptExecutionContext; import org.dhis2.fhir.adapter.fhir.script.ScriptExecutionRequired; -import org.dhis2.fhir.adapter.fhir.transform.FhirToDhisTransformerContext; import org.dhis2.fhir.adapter.fhir.transform.TransformerException; import org.dhis2.fhir.adapter.fhir.transform.TransformerMappingException; -import org.dhis2.fhir.adapter.fhir.transform.impl.TransformerScriptException; -import org.dhis2.fhir.adapter.fhir.transform.model.ResourceSystem; +import org.dhis2.fhir.adapter.fhir.transform.fhir.FhirToDhisTransformerContext; +import org.dhis2.fhir.adapter.fhir.transform.fhir.impl.TransformerScriptException; +import org.dhis2.fhir.adapter.fhir.transform.fhir.model.ResourceSystem; import org.dhis2.fhir.adapter.scriptable.ScriptMethod; import org.dhis2.fhir.adapter.scriptable.ScriptMethodArg; import org.dhis2.fhir.adapter.scriptable.ScriptType; diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/impl/util/AbstractContactPointFhirToDhisTransformerUtils.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/AbstractContactPointFhirToDhisTransformerUtils.java similarity index 98% rename from fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/impl/util/AbstractContactPointFhirToDhisTransformerUtils.java rename to fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/AbstractContactPointFhirToDhisTransformerUtils.java index e4ebcaa1..af2ed4a5 100644 --- a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/impl/util/AbstractContactPointFhirToDhisTransformerUtils.java +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/AbstractContactPointFhirToDhisTransformerUtils.java @@ -1,4 +1,4 @@ -package org.dhis2.fhir.adapter.fhir.transform.impl.util; +package org.dhis2.fhir.adapter.fhir.transform.fhir.impl.util; /* * Copyright (c) 2004-2018, University of Oslo diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/impl/util/AbstractDateTimeFhirToDhisTransformerUtils.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/AbstractDateTimeFhirToDhisTransformerUtils.java similarity index 98% rename from fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/impl/util/AbstractDateTimeFhirToDhisTransformerUtils.java rename to fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/AbstractDateTimeFhirToDhisTransformerUtils.java index 99db8a7a..a56243d9 100644 --- a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/impl/util/AbstractDateTimeFhirToDhisTransformerUtils.java +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/AbstractDateTimeFhirToDhisTransformerUtils.java @@ -1,4 +1,4 @@ -package org.dhis2.fhir.adapter.fhir.transform.impl.util; +package org.dhis2.fhir.adapter.fhir.transform.fhir.impl.util; /* * Copyright (c) 2004-2018, University of Oslo @@ -29,7 +29,7 @@ */ import org.dhis2.fhir.adapter.fhir.script.ScriptExecutionContext; -import org.dhis2.fhir.adapter.fhir.transform.impl.TransformerScriptException; +import org.dhis2.fhir.adapter.fhir.transform.fhir.impl.TransformerScriptException; import org.dhis2.fhir.adapter.model.DateUnit; import org.dhis2.fhir.adapter.scriptable.ScriptMethod; import org.dhis2.fhir.adapter.scriptable.ScriptMethodArg; diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/impl/util/AbstractFhirClientFhirToDhisTransformerUtils.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/AbstractFhirClientFhirToDhisTransformerUtils.java similarity index 97% rename from fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/impl/util/AbstractFhirClientFhirToDhisTransformerUtils.java rename to fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/AbstractFhirClientFhirToDhisTransformerUtils.java index 1cb14a9b..cfde5b0b 100644 --- a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/impl/util/AbstractFhirClientFhirToDhisTransformerUtils.java +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/AbstractFhirClientFhirToDhisTransformerUtils.java @@ -1,4 +1,4 @@ -package org.dhis2.fhir.adapter.fhir.transform.impl.util; +package org.dhis2.fhir.adapter.fhir.transform.fhir.impl.util; /* * Copyright (c) 2004-2018, University of Oslo @@ -41,8 +41,8 @@ import org.dhis2.fhir.adapter.fhir.script.ScriptArgUtils; import org.dhis2.fhir.adapter.fhir.script.ScriptExecutionContext; import org.dhis2.fhir.adapter.fhir.script.ScriptExecutionException; -import org.dhis2.fhir.adapter.fhir.transform.FhirToDhisTransformerContext; import org.dhis2.fhir.adapter.fhir.transform.TransformerMappingException; +import org.dhis2.fhir.adapter.fhir.transform.fhir.FhirToDhisTransformerContext; import org.dhis2.fhir.adapter.scriptable.ScriptType; import org.dhis2.fhir.adapter.scriptable.Scriptable; import org.hl7.fhir.instance.model.api.IBaseBundle; @@ -135,7 +135,7 @@ protected IBaseResource queryLatestPrioritizedByMappedCodes( @Nonnull String res final int resultingMaxCount = (maxCount == null) ? systemCodes.size() : maxCount; final Map> filterMap = createFilter( referencedResourceParameter, referencedResourceType, referencedResourceId ); filterMap.put( codeParameter, Collections.singletonList( - String.join( ",", systemCodes.stream().map( sc -> sc.getCalculatedSystemCodeValue().toString() ).collect( Collectors.toList() ) ) ) ); + systemCodes.stream().map( sc -> sc.getCalculatedSystemCodeValue().toString() ).collect( Collectors.joining( "," ) ) ) ); int processedResources = 0; int foundMinIndex = Integer.MAX_VALUE; diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/impl/util/AbstractFhirToDhisTransformerUtils.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/AbstractFhirToDhisTransformerUtils.java similarity index 95% rename from fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/impl/util/AbstractFhirToDhisTransformerUtils.java rename to fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/AbstractFhirToDhisTransformerUtils.java index a2b82170..cc90c814 100644 --- a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/impl/util/AbstractFhirToDhisTransformerUtils.java +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/AbstractFhirToDhisTransformerUtils.java @@ -1,4 +1,4 @@ -package org.dhis2.fhir.adapter.fhir.transform.impl.util; +package org.dhis2.fhir.adapter.fhir.transform.fhir.impl.util; /* * Copyright (c) 2004-2018, University of Oslo @@ -31,7 +31,7 @@ import org.dhis2.fhir.adapter.fhir.model.FhirVersion; import org.dhis2.fhir.adapter.fhir.script.ScriptExecution; import org.dhis2.fhir.adapter.fhir.script.ScriptExecutionContext; -import org.dhis2.fhir.adapter.fhir.transform.impl.TransformerScriptException; +import org.dhis2.fhir.adapter.fhir.transform.fhir.impl.TransformerScriptException; import javax.annotation.Nonnull; import java.util.Arrays; diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/impl/util/AbstractGeoFhirToDhisTransformerUtils.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/AbstractGeoFhirToDhisTransformerUtils.java similarity index 98% rename from fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/impl/util/AbstractGeoFhirToDhisTransformerUtils.java rename to fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/AbstractGeoFhirToDhisTransformerUtils.java index 4c1e94ec..ab61e75e 100644 --- a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/impl/util/AbstractGeoFhirToDhisTransformerUtils.java +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/AbstractGeoFhirToDhisTransformerUtils.java @@ -1,4 +1,4 @@ -package org.dhis2.fhir.adapter.fhir.transform.impl.util; +package org.dhis2.fhir.adapter.fhir.transform.fhir.impl.util; /* * Copyright (c) 2004-2018, University of Oslo diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/impl/util/AbstractHumanNameFhirToDhisTransformerUtils.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/AbstractHumanNameFhirToDhisTransformerUtils.java similarity index 98% rename from fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/impl/util/AbstractHumanNameFhirToDhisTransformerUtils.java rename to fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/AbstractHumanNameFhirToDhisTransformerUtils.java index 70e9584a..f5da3dc4 100644 --- a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/impl/util/AbstractHumanNameFhirToDhisTransformerUtils.java +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/AbstractHumanNameFhirToDhisTransformerUtils.java @@ -1,4 +1,4 @@ -package org.dhis2.fhir.adapter.fhir.transform.impl.util; +package org.dhis2.fhir.adapter.fhir.transform.fhir.impl.util; /* * Copyright (c) 2004-2018, University of Oslo diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/impl/util/AbstractIdentifierFhirToDhisTransformerUtils.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/AbstractIdentifierFhirToDhisTransformerUtils.java similarity index 97% rename from fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/impl/util/AbstractIdentifierFhirToDhisTransformerUtils.java rename to fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/AbstractIdentifierFhirToDhisTransformerUtils.java index 7247057a..23a7d522 100644 --- a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/impl/util/AbstractIdentifierFhirToDhisTransformerUtils.java +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/AbstractIdentifierFhirToDhisTransformerUtils.java @@ -1,4 +1,4 @@ -package org.dhis2.fhir.adapter.fhir.transform.impl.util; +package org.dhis2.fhir.adapter.fhir.transform.fhir.impl.util; /* * Copyright (c) 2004-2018, University of Oslo @@ -32,11 +32,11 @@ import org.dhis2.fhir.adapter.fhir.metadata.model.ScriptVariable; import org.dhis2.fhir.adapter.fhir.script.ScriptExecutionContext; import org.dhis2.fhir.adapter.fhir.script.ScriptExecutionRequired; -import org.dhis2.fhir.adapter.fhir.transform.FhirToDhisTransformerContext; import org.dhis2.fhir.adapter.fhir.transform.TransformerException; import org.dhis2.fhir.adapter.fhir.transform.TransformerMappingException; -import org.dhis2.fhir.adapter.fhir.transform.impl.TransformerScriptException; -import org.dhis2.fhir.adapter.fhir.transform.model.ResourceSystem; +import org.dhis2.fhir.adapter.fhir.transform.fhir.FhirToDhisTransformerContext; +import org.dhis2.fhir.adapter.fhir.transform.fhir.impl.TransformerScriptException; +import org.dhis2.fhir.adapter.fhir.transform.fhir.model.ResourceSystem; import org.dhis2.fhir.adapter.scriptable.ScriptMethod; import org.dhis2.fhir.adapter.scriptable.ScriptMethodArg; import org.dhis2.fhir.adapter.scriptable.ScriptType; diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/impl/util/AbstractImmunizationFhirToDhisTransformerUtils.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/AbstractImmunizationFhirToDhisTransformerUtils.java similarity index 97% rename from fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/impl/util/AbstractImmunizationFhirToDhisTransformerUtils.java rename to fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/AbstractImmunizationFhirToDhisTransformerUtils.java index e5052ae5..110bdf4b 100644 --- a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/impl/util/AbstractImmunizationFhirToDhisTransformerUtils.java +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/AbstractImmunizationFhirToDhisTransformerUtils.java @@ -1,4 +1,4 @@ -package org.dhis2.fhir.adapter.fhir.transform.impl.util; +package org.dhis2.fhir.adapter.fhir.transform.fhir.impl.util; /* * Copyright (c) 2004-2018, University of Oslo diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/impl/util/AbstractObservationFhirToDhisTransformerUtils.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/AbstractObservationFhirToDhisTransformerUtils.java similarity index 98% rename from fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/impl/util/AbstractObservationFhirToDhisTransformerUtils.java rename to fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/AbstractObservationFhirToDhisTransformerUtils.java index 825faa01..0984886e 100644 --- a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/impl/util/AbstractObservationFhirToDhisTransformerUtils.java +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/AbstractObservationFhirToDhisTransformerUtils.java @@ -1,4 +1,4 @@ -package org.dhis2.fhir.adapter.fhir.transform.impl.util; +package org.dhis2.fhir.adapter.fhir.transform.fhir.impl.util; /* * Copyright (c) 2004-2018, University of Oslo diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/impl/util/AbstractOrganizationFhirToDhisTransformerUtils.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/AbstractOrganizationFhirToDhisTransformerUtils.java similarity index 90% rename from fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/impl/util/AbstractOrganizationFhirToDhisTransformerUtils.java rename to fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/AbstractOrganizationFhirToDhisTransformerUtils.java index c21ac07a..48aa0b91 100644 --- a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/impl/util/AbstractOrganizationFhirToDhisTransformerUtils.java +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/AbstractOrganizationFhirToDhisTransformerUtils.java @@ -1,4 +1,4 @@ -package org.dhis2.fhir.adapter.fhir.transform.impl.util; +package org.dhis2.fhir.adapter.fhir.transform.fhir.impl.util; /* * Copyright (c) 2004-2018, University of Oslo @@ -38,15 +38,15 @@ import org.dhis2.fhir.adapter.fhir.metadata.model.RemoteSubscriptionResource; import org.dhis2.fhir.adapter.fhir.metadata.model.ScriptVariable; import org.dhis2.fhir.adapter.fhir.metadata.repository.RemoteSubscriptionResourceRepository; -import org.dhis2.fhir.adapter.fhir.repository.RemoteFhirRepository; -import org.dhis2.fhir.adapter.fhir.repository.RemoteHierarchicallyFhirRepository; +import org.dhis2.fhir.adapter.fhir.repository.RemoteFhirResourceRepository; +import org.dhis2.fhir.adapter.fhir.repository.RemoteHierarchicallyFhirResourceRepository; import org.dhis2.fhir.adapter.fhir.script.ScriptExecutionContext; import org.dhis2.fhir.adapter.fhir.script.ScriptExecutionRequired; import org.dhis2.fhir.adapter.fhir.transform.FatalTransformerException; -import org.dhis2.fhir.adapter.fhir.transform.FhirToDhisTransformerContext; import org.dhis2.fhir.adapter.fhir.transform.TransformerDataException; import org.dhis2.fhir.adapter.fhir.transform.TransformerMappingException; -import org.dhis2.fhir.adapter.fhir.transform.model.ResourceSystem; +import org.dhis2.fhir.adapter.fhir.transform.fhir.FhirToDhisTransformerContext; +import org.dhis2.fhir.adapter.fhir.transform.fhir.model.ResourceSystem; import org.dhis2.fhir.adapter.scriptable.ScriptMethod; import org.dhis2.fhir.adapter.scriptable.ScriptMethodArg; import org.dhis2.fhir.adapter.scriptable.ScriptType; @@ -83,21 +83,21 @@ public abstract class AbstractOrganizationFhirToDhisTransformerUtils extends Abs private final RemoteSubscriptionResourceRepository subscriptionResourceRepository; - private final RemoteFhirRepository remoteFhirRepository; + private final RemoteFhirResourceRepository remoteFhirResourceRepository; - private final RemoteHierarchicallyFhirRepository remoteHierarchicallyFhirRepository; + private final RemoteHierarchicallyFhirResourceRepository remoteHierarchicallyFhirResourceRepository; public AbstractOrganizationFhirToDhisTransformerUtils( @Nonnull ScriptExecutionContext scriptExecutionContext, @Nonnull OrganisationUnitService organisationUnitService, @Nonnull RemoteSubscriptionResourceRepository subscriptionResourceRepository, - @Nonnull RemoteFhirRepository remoteFhirRepository, - @Nonnull RemoteHierarchicallyFhirRepository remoteHierarchicallyFhirRepository ) + @Nonnull RemoteFhirResourceRepository remoteFhirResourceRepository, + @Nonnull RemoteHierarchicallyFhirResourceRepository remoteHierarchicallyFhirResourceRepository ) { super( scriptExecutionContext ); this.organisationUnitService = organisationUnitService; this.subscriptionResourceRepository = subscriptionResourceRepository; - this.remoteFhirRepository = remoteFhirRepository; - this.remoteHierarchicallyFhirRepository = remoteHierarchicallyFhirRepository; + this.remoteFhirResourceRepository = remoteFhirResourceRepository; + this.remoteHierarchicallyFhirResourceRepository = remoteHierarchicallyFhirResourceRepository; } @Nonnull @@ -205,11 +205,11 @@ protected List findHierarchy( @Nullable IBaseReference final RemoteSubscriptionResource subscriptionResource = subscriptionResourceRepository.findByIdCached( resourceId ) .orElseThrow( () -> new TransformerMappingException( "Could not find remote subscription resource with ID " + resourceId ) ); - final FhirContext fhirContext = remoteFhirRepository.findFhirContext( context.getFhirRequest().getVersion() ) + final FhirContext fhirContext = remoteFhirResourceRepository.findFhirContext( context.getFhirRequest().getVersion() ) .orElseThrow( () -> new FatalTransformerException( "FHIR context for FHIR version " + context.getFhirRequest().getVersion() + " is not available." ) ); final RemoteSubscription remoteSubscription = subscriptionResource.getRemoteSubscription(); - final IBaseBundle hierarchyBundle = remoteHierarchicallyFhirRepository.findWithParents( remoteSubscription.getId(), remoteSubscription.getFhirVersion(), remoteSubscription.getFhirEndpoint(), + final IBaseBundle hierarchyBundle = remoteHierarchicallyFhirResourceRepository.findWithParents( remoteSubscription.getId(), remoteSubscription.getFhirVersion(), remoteSubscription.getFhirEndpoint(), FhirResourceType.ORGANIZATION.getResourceTypeName(), childReference.getReferenceElement().getIdPart(), "organizationPartOf", this::getParentReference ); final List hierarchy = extractResources( hierarchyBundle ); return hierarchy.isEmpty() ? null : BeanTransformerUtils.clone( fhirContext, hierarchy ); diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/impl/util/AbstractPatientFhirToDhisTransformerUtils.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/AbstractPatientFhirToDhisTransformerUtils.java similarity index 98% rename from fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/impl/util/AbstractPatientFhirToDhisTransformerUtils.java rename to fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/AbstractPatientFhirToDhisTransformerUtils.java index 8c4c110a..d686b0ad 100644 --- a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/impl/util/AbstractPatientFhirToDhisTransformerUtils.java +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/AbstractPatientFhirToDhisTransformerUtils.java @@ -1,4 +1,4 @@ -package org.dhis2.fhir.adapter.fhir.transform.impl.util; +package org.dhis2.fhir.adapter.fhir.transform.fhir.impl.util; /* * Copyright (c) 2004-2018, University of Oslo diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/impl/util/AbstractVitalSignFhirToDhisTransformerUtils.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/AbstractVitalSignFhirToDhisTransformerUtils.java similarity index 97% rename from fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/impl/util/AbstractVitalSignFhirToDhisTransformerUtils.java rename to fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/AbstractVitalSignFhirToDhisTransformerUtils.java index 8f59844a..cea04e5a 100644 --- a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/impl/util/AbstractVitalSignFhirToDhisTransformerUtils.java +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/AbstractVitalSignFhirToDhisTransformerUtils.java @@ -1,4 +1,4 @@ -package org.dhis2.fhir.adapter.fhir.transform.impl.util; +package org.dhis2.fhir.adapter.fhir.transform.fhir.impl.util; /* * Copyright (c) 2004-2018, University of Oslo diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/impl/util/BeanTransformerUtils.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/BeanTransformerUtils.java similarity index 97% rename from fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/impl/util/BeanTransformerUtils.java rename to fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/BeanTransformerUtils.java index 6f9b5daf..9752c967 100644 --- a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/impl/util/BeanTransformerUtils.java +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/BeanTransformerUtils.java @@ -1,4 +1,4 @@ -package org.dhis2.fhir.adapter.fhir.transform.impl.util; +package org.dhis2.fhir.adapter.fhir.transform.fhir.impl.util; /* * Copyright (c) 2004-2018, University of Oslo diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/impl/util/FhirToDhisTransformerUtils.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/FhirToDhisTransformerUtils.java similarity index 96% rename from fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/impl/util/FhirToDhisTransformerUtils.java rename to fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/FhirToDhisTransformerUtils.java index 0405ca72..ddb10430 100644 --- a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/impl/util/FhirToDhisTransformerUtils.java +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/FhirToDhisTransformerUtils.java @@ -1,4 +1,4 @@ -package org.dhis2.fhir.adapter.fhir.transform.impl.util; +package org.dhis2.fhir.adapter.fhir.transform.fhir.impl.util; /* * Copyright (c) 2004-2018, University of Oslo diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/impl/util/ReferenceFhirToDhisTransformerUtils.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/ReferenceFhirToDhisTransformerUtils.java similarity index 91% rename from fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/impl/util/ReferenceFhirToDhisTransformerUtils.java rename to fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/ReferenceFhirToDhisTransformerUtils.java index 657711d9..d38e6272 100644 --- a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/impl/util/ReferenceFhirToDhisTransformerUtils.java +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/ReferenceFhirToDhisTransformerUtils.java @@ -1,4 +1,4 @@ -package org.dhis2.fhir.adapter.fhir.transform.impl.util; +package org.dhis2.fhir.adapter.fhir.transform.fhir.impl.util; /* * Copyright (c) 2004-2018, University of Oslo @@ -35,13 +35,13 @@ import org.dhis2.fhir.adapter.fhir.metadata.model.ScriptVariable; import org.dhis2.fhir.adapter.fhir.metadata.repository.RemoteSubscriptionResourceRepository; import org.dhis2.fhir.adapter.fhir.model.FhirVersion; -import org.dhis2.fhir.adapter.fhir.repository.RemoteFhirRepository; +import org.dhis2.fhir.adapter.fhir.repository.RemoteFhirResourceRepository; import org.dhis2.fhir.adapter.fhir.script.ScriptExecutionContext; import org.dhis2.fhir.adapter.fhir.transform.FatalTransformerException; -import org.dhis2.fhir.adapter.fhir.transform.FhirToDhisTransformerContext; import org.dhis2.fhir.adapter.fhir.transform.TransformerDataException; import org.dhis2.fhir.adapter.fhir.transform.TransformerMappingException; -import org.dhis2.fhir.adapter.fhir.transform.impl.TransformerScriptException; +import org.dhis2.fhir.adapter.fhir.transform.fhir.FhirToDhisTransformerContext; +import org.dhis2.fhir.adapter.fhir.transform.fhir.impl.TransformerScriptException; import org.dhis2.fhir.adapter.scriptable.ScriptMethod; import org.dhis2.fhir.adapter.scriptable.ScriptMethodArg; import org.dhis2.fhir.adapter.scriptable.ScriptType; @@ -75,15 +75,15 @@ public class ReferenceFhirToDhisTransformerUtils extends AbstractFhirToDhisTrans private final RemoteSubscriptionResourceRepository subscriptionResourceRepository; - private final RemoteFhirRepository remoteFhirRepository; + private final RemoteFhirResourceRepository remoteFhirResourceRepository; public ReferenceFhirToDhisTransformerUtils( @Nonnull ScriptExecutionContext scriptExecutionContext, @Nonnull RemoteSubscriptionResourceRepository subscriptionResourceRepository, - @Nonnull RemoteFhirRepository remoteFhirRepository ) + @Nonnull RemoteFhirResourceRepository remoteFhirResourceRepository ) { super( scriptExecutionContext ); this.subscriptionResourceRepository = subscriptionResourceRepository; - this.remoteFhirRepository = remoteFhirRepository; + this.remoteFhirResourceRepository = remoteFhirResourceRepository; } @Nonnull @@ -207,13 +207,13 @@ public IBaseResource getResource( @Nullable IBaseReference reference, @Nullable final RemoteSubscriptionResource subscriptionResource = subscriptionResourceRepository.findByIdCached( resourceId ) .orElseThrow( () -> new TransformerMappingException( "Could not find remote subscription resource with ID " + resourceId ) ); - final FhirContext fhirContext = remoteFhirRepository.findFhirContext( context.getFhirRequest().getVersion() ) + final FhirContext fhirContext = remoteFhirResourceRepository.findFhirContext( context.getFhirRequest().getVersion() ) .orElseThrow( () -> new FatalTransformerException( "FHIR context for FHIR version " + context.getFhirRequest().getVersion() + " is not available." ) ); final RemoteSubscription remoteSubscription = subscriptionResource.getRemoteSubscription(); final Optional optionalResource = refreshed ? - remoteFhirRepository.findRefreshed( remoteSubscription.getId(), remoteSubscription.getFhirVersion(), remoteSubscription.getFhirEndpoint(), + remoteFhirResourceRepository.findRefreshed( remoteSubscription.getId(), remoteSubscription.getFhirVersion(), remoteSubscription.getFhirEndpoint(), finalResourceType, reference.getReferenceElement().getIdPart() ) : - remoteFhirRepository.find( remoteSubscription.getId(), remoteSubscription.getFhirVersion(), remoteSubscription.getFhirEndpoint(), + remoteFhirResourceRepository.find( remoteSubscription.getId(), remoteSubscription.getFhirVersion(), remoteSubscription.getFhirEndpoint(), finalResourceType, reference.getReferenceElement().getIdPart() ); final IBaseResource resource = optionalResource.map( r -> BeanTransformerUtils.clone( fhirContext, r ) ) .orElseThrow( () -> new TransformerDataException( "Referenced FHIR resource " + reference.getReferenceElement() + " does not exist for remote subscription resource " + resourceId ) ); diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/impl/util/ScriptedDateTimeUtils.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/ScriptedDateTimeUtils.java similarity index 97% rename from fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/impl/util/ScriptedDateTimeUtils.java rename to fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/ScriptedDateTimeUtils.java index fd28b2e7..70d90e20 100644 --- a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/impl/util/ScriptedDateTimeUtils.java +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/ScriptedDateTimeUtils.java @@ -1,4 +1,4 @@ -package org.dhis2.fhir.adapter.fhir.transform.impl.util; +package org.dhis2.fhir.adapter.fhir.transform.fhir.impl.util; /* * Copyright (c) 2004-2018, University of Oslo diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/impl/util/TransformerComparatorUtils.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/TransformerComparatorUtils.java similarity index 97% rename from fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/impl/util/TransformerComparatorUtils.java rename to fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/TransformerComparatorUtils.java index 2e02815d..e6adde89 100644 --- a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/impl/util/TransformerComparatorUtils.java +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/TransformerComparatorUtils.java @@ -1,4 +1,4 @@ -package org.dhis2.fhir.adapter.fhir.transform.impl.util; +package org.dhis2.fhir.adapter.fhir.transform.fhir.impl.util; /* * Copyright (c) 2004-2018, University of Oslo diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/model/FhirRequest.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/model/FhirRequest.java similarity index 94% rename from fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/model/FhirRequest.java rename to fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/model/FhirRequest.java index c19aa6bc..b7ba9116 100644 --- a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/model/FhirRequest.java +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/model/FhirRequest.java @@ -1,4 +1,4 @@ -package org.dhis2.fhir.adapter.fhir.transform.model; +package org.dhis2.fhir.adapter.fhir.transform.fhir.model; /* * Copyright (c) 2004-2018, University of Oslo @@ -40,6 +40,12 @@ import java.util.Optional; import java.util.UUID; +/** + * The request that has caused the transformation between the FHIR resource + * and the DHIS 2 resource. + * + * @author volsch + */ @Scriptable @ScriptType( value = "FhirRequest", description = "The current FHIR request that caused the execution of the transformation." ) public interface FhirRequest diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/model/FhirRequestMethod.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/model/FhirRequestMethod.java similarity index 97% rename from fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/model/FhirRequestMethod.java rename to fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/model/FhirRequestMethod.java index 6a2a6b02..70588bc4 100644 --- a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/model/FhirRequestMethod.java +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/model/FhirRequestMethod.java @@ -1,4 +1,4 @@ -package org.dhis2.fhir.adapter.fhir.transform.model; +package org.dhis2.fhir.adapter.fhir.transform.fhir.model; /* * Copyright (c) 2004-2018, University of Oslo diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/model/ImmutableFhirRequest.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/model/ImmutableFhirRequest.java similarity index 94% rename from fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/model/ImmutableFhirRequest.java rename to fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/model/ImmutableFhirRequest.java index bad823e6..cd697109 100644 --- a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/model/ImmutableFhirRequest.java +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/model/ImmutableFhirRequest.java @@ -1,4 +1,4 @@ -package org.dhis2.fhir.adapter.fhir.transform.model; +package org.dhis2.fhir.adapter.fhir.transform.fhir.model; /* * Copyright (c) 2004-2018, University of Oslo @@ -39,6 +39,12 @@ import java.util.Optional; import java.util.UUID; +/** + * The immutable request that has caused the transformation between the FHIR resource + * and the DHIS 2 resource. This can be used by scripts safely. + * + * @author volsch + */ @Scriptable public class ImmutableFhirRequest implements FhirRequest, Serializable { diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/model/ResourceSystem.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/model/ResourceSystem.java similarity index 98% rename from fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/model/ResourceSystem.java rename to fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/model/ResourceSystem.java index a2d64525..67f306df 100644 --- a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/model/ResourceSystem.java +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/model/ResourceSystem.java @@ -1,4 +1,4 @@ -package org.dhis2.fhir.adapter.fhir.transform.model; +package org.dhis2.fhir.adapter.fhir.transform.fhir.model; /* * Copyright (c) 2004-2018, University of Oslo diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/model/WritableFhirRequest.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/model/WritableFhirRequest.java similarity index 96% rename from fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/model/WritableFhirRequest.java rename to fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/model/WritableFhirRequest.java index f69a31a1..fa79dc63 100644 --- a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/model/WritableFhirRequest.java +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/model/WritableFhirRequest.java @@ -1,4 +1,4 @@ -package org.dhis2.fhir.adapter.fhir.transform.model; +package org.dhis2.fhir.adapter.fhir.transform.fhir.model; /* * Copyright (c) 2004-2018, University of Oslo @@ -40,6 +40,12 @@ import java.util.Optional; import java.util.UUID; +/** + * The mutable request that has caused the transformation between the FHIR resource + * and the DHIS 2 resource. + * + * @author volsch + */ public class WritableFhirRequest implements FhirRequest, Serializable { private static final long serialVersionUID = 6482108680860344148L; diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/impl/ScriptedDhisResource.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/scripted/ScriptedDhisResource.java similarity index 83% rename from fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/impl/ScriptedDhisResource.java rename to fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/scripted/ScriptedDhisResource.java index 711bd856..58987255 100644 --- a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/impl/ScriptedDhisResource.java +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/scripted/ScriptedDhisResource.java @@ -1,4 +1,4 @@ -package org.dhis2.fhir.adapter.fhir.transform.impl; +package org.dhis2.fhir.adapter.fhir.transform.scripted; /* * Copyright (c) 2004-2018, University of Oslo @@ -31,10 +31,27 @@ import org.dhis2.fhir.adapter.fhir.transform.TransformerException; import org.dhis2.fhir.adapter.scriptable.Scriptable; +import javax.annotation.Nullable; +import java.time.ZonedDateTime; + +/** + * Mutable or immutable DHIS 2 resource that can be used by scripts safely. + * + * @author volsch + */ @Scriptable public interface ScriptedDhisResource { + @Nullable + String getId(); + boolean isNewResource(); + @Nullable + ZonedDateTime getLastUpdated(); + + @Nullable + String getOrganizationUnitId(); + void validate() throws TransformerException; } diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/impl/program/ScriptedEnrollment.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/scripted/ScriptedEnrollment.java similarity index 89% rename from fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/impl/program/ScriptedEnrollment.java rename to fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/scripted/ScriptedEnrollment.java index 72eb94ca..8ff24d2a 100644 --- a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/impl/program/ScriptedEnrollment.java +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/scripted/ScriptedEnrollment.java @@ -1,4 +1,4 @@ -package org.dhis2.fhir.adapter.fhir.transform.impl.program; +package org.dhis2.fhir.adapter.fhir.transform.scripted; /* * Copyright (c) 2004-2018, University of Oslo @@ -28,22 +28,20 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -import org.dhis2.fhir.adapter.fhir.transform.impl.ScriptedDhisResource; import org.dhis2.fhir.adapter.geo.Location; import org.dhis2.fhir.adapter.scriptable.Scriptable; import javax.annotation.Nullable; import java.time.ZonedDateTime; +/** + * Mutable or immutable enrollment resource that can be used by scripts safely. + * + * @author volsch + */ @Scriptable public interface ScriptedEnrollment extends ScriptedDhisResource { - @Nullable - String getId(); - - @Nullable - String getOrganizationUnitId(); - @Nullable ZonedDateTime getEnrollmentDate(); diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/impl/program/ScriptedEvent.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/scripted/ScriptedEvent.java similarity index 90% rename from fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/impl/program/ScriptedEvent.java rename to fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/scripted/ScriptedEvent.java index 63ae33d9..e9c07ce5 100644 --- a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/impl/program/ScriptedEvent.java +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/scripted/ScriptedEvent.java @@ -1,4 +1,4 @@ -package org.dhis2.fhir.adapter.fhir.transform.impl.program; +package org.dhis2.fhir.adapter.fhir.transform.scripted; /* * Copyright (c) 2004-2018, University of Oslo @@ -29,22 +29,20 @@ */ import org.dhis2.fhir.adapter.dhis.tracker.program.EventStatus; -import org.dhis2.fhir.adapter.fhir.transform.impl.ScriptedDhisResource; import org.dhis2.fhir.adapter.geo.Location; import org.dhis2.fhir.adapter.scriptable.Scriptable; import javax.annotation.Nullable; import java.time.ZonedDateTime; +/** + * Mutable or immutable event resource that can be used by scripts safely. + * + * @author volsch + */ @Scriptable public interface ScriptedEvent extends ScriptedDhisResource { - @Nullable - String getId(); - - @Nullable - String getOrganizationUnitId(); - @Nullable EventStatus getStatus(); diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/impl/trackedentity/ScriptedTrackedEntityInstance.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/scripted/ScriptedTrackedEntityInstance.java similarity index 90% rename from fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/impl/trackedentity/ScriptedTrackedEntityInstance.java rename to fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/scripted/ScriptedTrackedEntityInstance.java index 478643ca..ac60036f 100644 --- a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/impl/trackedentity/ScriptedTrackedEntityInstance.java +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/scripted/ScriptedTrackedEntityInstance.java @@ -1,4 +1,4 @@ -package org.dhis2.fhir.adapter.fhir.transform.impl.trackedentity; +package org.dhis2.fhir.adapter.fhir.transform.scripted; /* * Copyright (c) 2004-2018, University of Oslo @@ -29,24 +29,22 @@ */ import org.dhis2.fhir.adapter.dhis.model.Reference; -import org.dhis2.fhir.adapter.fhir.transform.impl.ScriptedDhisResource; import org.dhis2.fhir.adapter.scriptable.Scriptable; import javax.annotation.Nonnull; import javax.annotation.Nullable; +/** + * Mutable or immutable tracked entity instance resource that can be used by scripts safely. + * + * @author volsch + */ @Scriptable public interface ScriptedTrackedEntityInstance extends ScriptedDhisResource { - @Nullable - String getId(); - @Nonnull String getTypeId(); - @Nullable - String getOrganizationUnitId(); - @Nullable String getCoordinates(); diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/impl/program/WritableScriptedEnrollment.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/scripted/WritableScriptedEnrollment.java similarity index 90% rename from fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/impl/program/WritableScriptedEnrollment.java rename to fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/scripted/WritableScriptedEnrollment.java index 9b31049b..d727806d 100644 --- a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/impl/program/WritableScriptedEnrollment.java +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/scripted/WritableScriptedEnrollment.java @@ -1,4 +1,4 @@ -package org.dhis2.fhir.adapter.fhir.transform.impl.program; +package org.dhis2.fhir.adapter.fhir.transform.scripted; /* * Copyright (c) 2004-2018, University of Oslo @@ -33,9 +33,10 @@ import org.dhis2.fhir.adapter.dhis.tracker.program.Program; import org.dhis2.fhir.adapter.fhir.transform.TransformerException; import org.dhis2.fhir.adapter.fhir.transform.TransformerMappingException; -import org.dhis2.fhir.adapter.fhir.transform.impl.util.ScriptedDateTimeUtils; +import org.dhis2.fhir.adapter.fhir.transform.fhir.impl.util.ScriptedDateTimeUtils; import org.dhis2.fhir.adapter.geo.Location; import org.dhis2.fhir.adapter.model.ValueType; +import org.dhis2.fhir.adapter.scriptable.ScriptMethod; import org.dhis2.fhir.adapter.scriptable.Scriptable; import org.dhis2.fhir.adapter.util.DateTimeUtils; @@ -45,6 +46,11 @@ import java.time.ZonedDateTime; import java.util.Objects; +/** + * Mutable enrollment resource that can be used by scripts safely. + * + * @author volsch + */ @Scriptable public class WritableScriptedEnrollment implements ScriptedEnrollment, Serializable { @@ -76,6 +82,14 @@ public String getId() return enrollment.getId(); } + @Nullable + @Override + @ScriptMethod( description = "Returns the date and time when the resource has been updated the last time or null if this is a new resource." ) + public ZonedDateTime getLastUpdated() + { + return enrollment.getLastUpdated(); + } + @Nullable @Override public String getOrganizationUnitId() diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/impl/program/WritableScriptedEvent.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/scripted/WritableScriptedEvent.java similarity index 93% rename from fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/impl/program/WritableScriptedEvent.java rename to fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/scripted/WritableScriptedEvent.java index 030d8c8e..5188b0b1 100644 --- a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/impl/program/WritableScriptedEvent.java +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/scripted/WritableScriptedEvent.java @@ -1,4 +1,4 @@ -package org.dhis2.fhir.adapter.fhir.transform.impl.program; +package org.dhis2.fhir.adapter.fhir.transform.scripted; /* * Copyright (c) 2004-2018, University of Oslo @@ -37,13 +37,15 @@ import org.dhis2.fhir.adapter.dhis.tracker.program.EventStatus; import org.dhis2.fhir.adapter.dhis.tracker.program.ProgramStage; import org.dhis2.fhir.adapter.dhis.tracker.program.ProgramStageDataElement; -import org.dhis2.fhir.adapter.fhir.transform.FhirToDhisTransformerContext; import org.dhis2.fhir.adapter.fhir.transform.TransformerException; import org.dhis2.fhir.adapter.fhir.transform.TransformerMappingException; -import org.dhis2.fhir.adapter.fhir.transform.impl.TransformerScriptException; -import org.dhis2.fhir.adapter.fhir.transform.impl.util.ScriptedDateTimeUtils; +import org.dhis2.fhir.adapter.fhir.transform.fhir.FhirToDhisTransformerContext; +import org.dhis2.fhir.adapter.fhir.transform.fhir.impl.TransformerScriptException; +import org.dhis2.fhir.adapter.fhir.transform.fhir.impl.program.FhirToDhisOptionSetUtils; +import org.dhis2.fhir.adapter.fhir.transform.fhir.impl.util.ScriptedDateTimeUtils; import org.dhis2.fhir.adapter.geo.Location; import org.dhis2.fhir.adapter.model.ValueType; +import org.dhis2.fhir.adapter.scriptable.ScriptMethod; import org.dhis2.fhir.adapter.scriptable.Scriptable; import javax.annotation.Nonnull; @@ -54,6 +56,11 @@ import java.util.Objects; import java.util.regex.Pattern; +/** + * Mutable event resource that can be used by scripts safely. + * + * @author volsch + */ @Scriptable public class WritableScriptedEvent implements ScriptedEvent, Serializable { @@ -88,6 +95,14 @@ public String getId() return event.getId(); } + @Nullable + @Override + @ScriptMethod( description = "Returns the date and time when the resource has been updated the last time or null if this is a new resource." ) + public ZonedDateTime getLastUpdated() + { + return event.getLastUpdated(); + } + @Nullable @Override public String getOrganizationUnitId() diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/impl/trackedentity/WritableScriptedTrackedEntityInstance.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/scripted/WritableScriptedTrackedEntityInstance.java similarity index 97% rename from fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/impl/trackedentity/WritableScriptedTrackedEntityInstance.java rename to fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/scripted/WritableScriptedTrackedEntityInstance.java index 7b2bdb9d..e2302437 100644 --- a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/impl/trackedentity/WritableScriptedTrackedEntityInstance.java +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/scripted/WritableScriptedTrackedEntityInstance.java @@ -1,4 +1,4 @@ -package org.dhis2.fhir.adapter.fhir.transform.impl.trackedentity; +package org.dhis2.fhir.adapter.fhir.transform.scripted; /* * Copyright (c) 2004-2018, University of Oslo @@ -38,10 +38,10 @@ import org.dhis2.fhir.adapter.dhis.tracker.trackedentity.TrackedEntityInstance; import org.dhis2.fhir.adapter.dhis.tracker.trackedentity.TrackedEntityType; import org.dhis2.fhir.adapter.dhis.tracker.trackedentity.TrackedEntityTypeAttribute; -import org.dhis2.fhir.adapter.fhir.transform.FhirToDhisTransformerContext; import org.dhis2.fhir.adapter.fhir.transform.TransformerException; import org.dhis2.fhir.adapter.fhir.transform.TransformerMappingException; -import org.dhis2.fhir.adapter.fhir.transform.impl.util.ScriptedDateTimeUtils; +import org.dhis2.fhir.adapter.fhir.transform.fhir.FhirToDhisTransformerContext; +import org.dhis2.fhir.adapter.fhir.transform.fhir.impl.util.ScriptedDateTimeUtils; import org.dhis2.fhir.adapter.model.ValueType; import org.dhis2.fhir.adapter.scriptable.ScriptMethod; import org.dhis2.fhir.adapter.scriptable.ScriptMethodArg; @@ -99,6 +99,14 @@ public String getId() return trackedEntityInstance.getId(); } + @Nullable + @Override + @ScriptMethod( description = "Returns the date and time when the resource has been updated the last time or null if this is a new resource." ) + public ZonedDateTime getLastUpdated() + { + return trackedEntityInstance.getLastUpdated(); + } + @Nonnull @Override @ScriptMethod( description = "Returns the ID of the tracked entity type to which this tracked entity instance belongs to on DHIS2." ) diff --git a/fhir/src/test/java/org/dhis2/fhir/adapter/fhir/transform/impl/FhirToDhisTransformerContextImplTest.java b/fhir/src/test/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/FhirToDhisTransformerContextImplTest.java similarity index 94% rename from fhir/src/test/java/org/dhis2/fhir/adapter/fhir/transform/impl/FhirToDhisTransformerContextImplTest.java rename to fhir/src/test/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/FhirToDhisTransformerContextImplTest.java index b9dd308f..a9601969 100644 --- a/fhir/src/test/java/org/dhis2/fhir/adapter/fhir/transform/impl/FhirToDhisTransformerContextImplTest.java +++ b/fhir/src/test/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/FhirToDhisTransformerContextImplTest.java @@ -1,4 +1,4 @@ -package org.dhis2.fhir.adapter.fhir.transform.impl; +package org.dhis2.fhir.adapter.fhir.transform.fhir.impl; /* * Copyright (c) 2004-2018, University of Oslo @@ -30,8 +30,8 @@ import org.dhis2.fhir.adapter.dhis.model.Reference; import org.dhis2.fhir.adapter.dhis.model.ReferenceType; -import org.dhis2.fhir.adapter.fhir.transform.model.FhirRequest; -import org.dhis2.fhir.adapter.fhir.transform.model.ImmutableFhirRequest; +import org.dhis2.fhir.adapter.fhir.transform.fhir.model.FhirRequest; +import org.dhis2.fhir.adapter.fhir.transform.fhir.model.ImmutableFhirRequest; import org.junit.Assert; import org.junit.Before; import org.junit.Rule;