diff --git a/app/src/test/java/org/dhis2/fhir/adapter/fhir/server/AbstractProgramStageFhirRestAppTest.java b/app/src/test/java/org/dhis2/fhir/adapter/fhir/server/AbstractProgramStageFhirRestAppTest.java index d9d97212..fba6ac0b 100644 --- a/app/src/test/java/org/dhis2/fhir/adapter/fhir/server/AbstractProgramStageFhirRestAppTest.java +++ b/app/src/test/java/org/dhis2/fhir/adapter/fhir/server/AbstractProgramStageFhirRestAppTest.java @@ -67,13 +67,14 @@ protected void expectProgramStageMetadataRequests() throws Exception .andRespond( withSuccess( IOUtils.resourceToString( "/org/dhis2/fhir/adapter/dhis/test/single-org-unit-OU_1234.json", StandardCharsets.UTF_8 ), MediaType.APPLICATION_JSON ) ); systemDhis2Server.expect( ExpectedCount.between( 0, 1 ), method( HttpMethod.GET ) ).andExpect( header( "Authorization", testConfiguration.getDhis2SystemAuthorization() ) ) .andExpect( requestTo( dhis2BaseUrl + "/api/" + dhis2ApiVersion + "/programs/EPDyQuoRnXk.json?" + - "fields=id,name,code,selectIncidentDatesInFuture,selectEnrollmentDatesInFuture,displayIncidentDate,registration,withoutRegistration,captureCoordinates,trackedEntityType%5Bid%5D,programTrackedEntityAttributes%5Bid,name,valueType,mandatory," + - "allowFutureDate,trackedEntityAttribute%5Bid,name,code,valueType,generated%5D%5D,programStages%5Bid,name,repeatable,captureCoordinates,generatedByEnrollmentDate,minDaysFromStart,programStageDataElements%5Bid,compulsory," + + "fields=id,name,code,description,selectIncidentDatesInFuture,selectEnrollmentDatesInFuture,displayIncidentDate,registration,withoutRegistration,captureCoordinates,trackedEntityType%5Bid%5D,programTrackedEntityAttributes%5Bid,name,valueType," + + "mandatory,allowFutureDate,trackedEntityAttribute%5Bid,name,code,valueType,generated%5D%5D,programStages%5Bid,name,description,repeatable,captureCoordinates,generatedByEnrollmentDate,minDaysFromStart,programStageDataElements%5Bid,compulsory," + "allowProvidedElsewhere,dataElement%5Bid,name,code,formName,valueType,optionSetValue,optionSet%5Bid,name,options%5Bcode,name%5D%5D%5D%5D%5D" ) ) .andRespond( withSuccess( IOUtils.resourceToString( "/org/dhis2/fhir/adapter/dhis/test/single-program.json", StandardCharsets.UTF_8 ), MediaType.APPLICATION_JSON ) ); systemDhis2Server.expect( ExpectedCount.between( 0, 1 ), method( HttpMethod.GET ) ).andExpect( header( "Authorization", testConfiguration.getDhis2SystemAuthorization() ) ) - .andExpect( requestTo( dhis2BaseUrl + "/api/" + dhis2ApiVersion + "/programs.json?paging=false&fields=id,name,code,selectIncidentDatesInFuture,selectEnrollmentDatesInFuture,displayIncidentDate,registration," + + .andExpect( requestTo( dhis2BaseUrl + "/api/" + dhis2ApiVersion + "/programs.json?paging=false&fields=id,name,code,description,selectIncidentDatesInFuture,selectEnrollmentDatesInFuture,displayIncidentDate,registration," + "withoutRegistration,captureCoordinates,trackedEntityType%5Bid%5D,programTrackedEntityAttributes%5Bid,name,valueType,mandatory,allowFutureDate,trackedEntityAttribute%5Bid,name,code,valueType,generated%5D%5D,programStages%5Bid,name," + + "description," + "repeatable,captureCoordinates,generatedByEnrollmentDate,minDaysFromStart,programStageDataElements%5Bid,compulsory,allowProvidedElsewhere,dataElement%5Bid,name,code,formName,valueType,optionSetValue,optionSet%5Bid,name,options%5Bcode," + "name%5D%5D%5D%5D%5D&filter=name:eq:Child%20Programme" ) ) .andRespond( withSuccess( IOUtils.resourceToString( "/org/dhis2/fhir/adapter/dhis/test/default-program.json", StandardCharsets.UTF_8 ), MediaType.APPLICATION_JSON ) ); diff --git a/app/src/test/java/org/dhis2/fhir/adapter/fhir/server/dstu3/Dstu3OrgUnitFhirRestAppTest.java b/app/src/test/java/org/dhis2/fhir/adapter/fhir/server/dstu3/Dstu3OrgUnitFhirRestAppTest.java index 801abdd7..40c2903e 100644 --- a/app/src/test/java/org/dhis2/fhir/adapter/fhir/server/dstu3/Dstu3OrgUnitFhirRestAppTest.java +++ b/app/src/test/java/org/dhis2/fhir/adapter/fhir/server/dstu3/Dstu3OrgUnitFhirRestAppTest.java @@ -54,7 +54,7 @@ /** * DSTU3 tests for rest interfaces that access - * DHIS 2 organization units. + * DHIS2 organization units. * * @author volsch */ @@ -87,7 +87,7 @@ public void getLocationWithInvalidAuthorization() } @Test( expected = ResourceNotFoundException.class ) - public void getLocationNotExistsRepeated() throws Exception + public void getLocationNotExistsRepeated() { try { @@ -100,7 +100,7 @@ public void getLocationNotExistsRepeated() throws Exception } } - private void getLocationNotExists() throws Exception + private void getLocationNotExists() { systemDhis2Server.reset(); userDhis2Server.reset(); @@ -124,7 +124,7 @@ private void getLocationNotExists() throws Exception } @Test( expected = ResourceNotFoundException.class ) - public void getLocationRuleNotFoundRepeated() throws Exception + public void getLocationRuleNotFoundRepeated() { try { @@ -137,7 +137,7 @@ public void getLocationRuleNotFoundRepeated() throws Exception } } - private void getLocationRuleNotFound() throws Exception + private void getLocationRuleNotFound() { systemDhis2Server.reset(); userDhis2Server.reset(); diff --git a/app/src/test/java/org/dhis2/fhir/adapter/fhir/server/dstu3/Dstu3ProgramStageFhirRestAppTest.java b/app/src/test/java/org/dhis2/fhir/adapter/fhir/server/dstu3/Dstu3ProgramStageFhirRestAppTest.java index 0eb709b4..b5946776 100644 --- a/app/src/test/java/org/dhis2/fhir/adapter/fhir/server/dstu3/Dstu3ProgramStageFhirRestAppTest.java +++ b/app/src/test/java/org/dhis2/fhir/adapter/fhir/server/dstu3/Dstu3ProgramStageFhirRestAppTest.java @@ -58,7 +58,7 @@ /** * DSTU3 tests for rest interfaces that access - * DHIS 2 program stages. Some methods are executed twice in order to + * DHIS2 program stages. Some methods are executed twice in order to * verify that no cached data is used without authentication. * * @author volsch diff --git a/app/src/test/java/org/dhis2/fhir/adapter/fhir/server/dstu3/Dstu3TrackedEntityInstanceFhirRestAppTest.java b/app/src/test/java/org/dhis2/fhir/adapter/fhir/server/dstu3/Dstu3TrackedEntityInstanceFhirRestAppTest.java index ee32e225..ecc49753 100644 --- a/app/src/test/java/org/dhis2/fhir/adapter/fhir/server/dstu3/Dstu3TrackedEntityInstanceFhirRestAppTest.java +++ b/app/src/test/java/org/dhis2/fhir/adapter/fhir/server/dstu3/Dstu3TrackedEntityInstanceFhirRestAppTest.java @@ -57,7 +57,7 @@ /** * DSTU3 tests for rest interfaces that access - * DHIS 2 tracked entity instances. Some methods are executed twice in order to + * DHIS2 tracked entity instances. Some methods are executed twice in order to * verify that no cached data is used without authentication. * * @author volsch diff --git a/app/src/test/java/org/dhis2/fhir/adapter/fhir/server/r4/R4OrgUnitFhirRestAppTest.java b/app/src/test/java/org/dhis2/fhir/adapter/fhir/server/r4/R4OrgUnitFhirRestAppTest.java index 4121bc46..b5ff49c4 100644 --- a/app/src/test/java/org/dhis2/fhir/adapter/fhir/server/r4/R4OrgUnitFhirRestAppTest.java +++ b/app/src/test/java/org/dhis2/fhir/adapter/fhir/server/r4/R4OrgUnitFhirRestAppTest.java @@ -54,7 +54,7 @@ /** * R4 tests for rest interfaces that access - * DHIS 2 organization units. + * DHIS2 organization units. * * @author volsch */ @@ -118,7 +118,7 @@ private void getLocation() throws Exception } @Test( expected = ResourceNotFoundException.class ) - public void getLocationNotExistsRepeated() throws Exception + public void getLocationNotExistsRepeated() { try { @@ -131,7 +131,7 @@ public void getLocationNotExistsRepeated() throws Exception } } - private void getLocationNotExists() throws Exception + private void getLocationNotExists() { systemDhis2Server.reset(); userDhis2Server.reset(); @@ -155,7 +155,7 @@ private void getLocationNotExists() throws Exception } @Test( expected = ResourceNotFoundException.class ) - public void getLocationRuleNotFoundRepeated() throws Exception + public void getLocationRuleNotFoundRepeated() { try { @@ -168,7 +168,7 @@ public void getLocationRuleNotFoundRepeated() throws Exception } } - private void getLocationRuleNotFound() throws Exception + private void getLocationRuleNotFound() { systemDhis2Server.reset(); userDhis2Server.reset(); diff --git a/app/src/test/java/org/dhis2/fhir/adapter/fhir/server/r4/R4ProgramStageFhirRestAppTest.java b/app/src/test/java/org/dhis2/fhir/adapter/fhir/server/r4/R4ProgramStageFhirRestAppTest.java index b00b8858..308f7a25 100644 --- a/app/src/test/java/org/dhis2/fhir/adapter/fhir/server/r4/R4ProgramStageFhirRestAppTest.java +++ b/app/src/test/java/org/dhis2/fhir/adapter/fhir/server/r4/R4ProgramStageFhirRestAppTest.java @@ -58,7 +58,7 @@ /** * R4 tests for rest interfaces that access - * DHIS 2 program stages. Some methods are executed twice in order to + * DHIS2 program stages. Some methods are executed twice in order to * verify that no cached data is used without authentication. * * @author volsch @@ -129,7 +129,7 @@ private void getObservation( boolean skipCached ) throws Exception Assert.assertEquals( 0, observation.getIdentifier().size() ); Assert.assertEquals( "Patient/JeR2Ul4mZfx", observation.getSubject().getReference() ); Assert.assertEquals( "Organization/ldXIdLNUNEp", observation.getPerformerFirstRep().getReference() ); - Assert.assertEquals( "Encounter/ps-deR4kl4mnf7-9d342f13aec146299d654f03fd0e848c", observation.getEncounter().getReference() ); + Assert.assertEquals( "Encounter/deR4kl4mnf7", observation.getEncounter().getReference() ); systemDhis2Server.verify(); userDhis2Server.verify(); diff --git a/app/src/test/java/org/dhis2/fhir/adapter/fhir/server/r4/R4TrackedEntityInstanceFhirRestAppTest.java b/app/src/test/java/org/dhis2/fhir/adapter/fhir/server/r4/R4TrackedEntityInstanceFhirRestAppTest.java index b95e83ae..236f2580 100644 --- a/app/src/test/java/org/dhis2/fhir/adapter/fhir/server/r4/R4TrackedEntityInstanceFhirRestAppTest.java +++ b/app/src/test/java/org/dhis2/fhir/adapter/fhir/server/r4/R4TrackedEntityInstanceFhirRestAppTest.java @@ -57,7 +57,7 @@ /** * R4 tests for rest interfaces that access - * DHIS 2 tracked entity instances. Some methods are executed twice in order to + * DHIS2 tracked entity instances. Some methods are executed twice in order to * verify that no cached data is used without authentication. * * @author volsch diff --git a/app/src/test/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/enrollment/AbstractCarePlanToEnrollmentTransformationAppTest.java b/app/src/test/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/enrollment/AbstractCarePlanToEnrollmentTransformationAppTest.java index 691aca78..da42800d 100644 --- a/app/src/test/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/enrollment/AbstractCarePlanToEnrollmentTransformationAppTest.java +++ b/app/src/test/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/enrollment/AbstractCarePlanToEnrollmentTransformationAppTest.java @@ -45,7 +45,7 @@ import static org.springframework.test.web.client.response.MockRestResponseCreators.withSuccess; /** - * Tests the transformation of a FHIR CarePlan to a DHIS 2 Program Instance. + * Tests the transformation of a FHIR CarePlan to a DHIS2 Program Instance. * * @author volsch */ diff --git a/app/src/test/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/enrollment/AbstractEnrollmentTransformationAppTest.java b/app/src/test/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/enrollment/AbstractEnrollmentTransformationAppTest.java index 225503cc..f96cac5b 100644 --- a/app/src/test/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/enrollment/AbstractEnrollmentTransformationAppTest.java +++ b/app/src/test/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/enrollment/AbstractEnrollmentTransformationAppTest.java @@ -49,15 +49,16 @@ public abstract class AbstractEnrollmentTransformationAppTest extends AbstractAp protected void expectMetadataRequests() throws Exception { systemDhis2Server.expect( ExpectedCount.between( 0, 1 ), method( HttpMethod.GET ) ).andExpect( header( "Authorization", testConfiguration.getDhis2SystemAuthorization() ) ) - .andExpect( requestTo( dhis2BaseUrl + "/api/" + dhis2ApiVersion + "/programs/EPDyQuoRnXk.json?fields=id,name,code,selectIncidentDatesInFuture,selectEnrollmentDatesInFuture,displayIncidentDate,registration," + + .andExpect( requestTo( dhis2BaseUrl + "/api/" + dhis2ApiVersion + "/programs/EPDyQuoRnXk.json?fields=id,name,code,description,selectIncidentDatesInFuture,selectEnrollmentDatesInFuture,displayIncidentDate,registration," + "withoutRegistration,captureCoordinates,trackedEntityType%5Bid%5D,programTrackedEntityAttributes%5Bid,name,valueType,mandatory,allowFutureDate,trackedEntityAttribute%5Bid,name,code,valueType,generated%5D%5D,programStages%5Bid,name," + - "repeatable,captureCoordinates,generatedByEnrollmentDate,minDaysFromStart,programStageDataElements%5Bid,compulsory,allowProvidedElsewhere,dataElement%5Bid,name,code,formName,valueType,optionSetValue,optionSet%5Bid,name,options%5Bcode," + - "name%5D%5D%5D%5D%5D" ) ) + "description,repeatable,captureCoordinates,generatedByEnrollmentDate,minDaysFromStart,programStageDataElements%5Bid,compulsory,allowProvidedElsewhere,dataElement%5Bid,name,code,formName,valueType,optionSetValue,optionSet%5Bid,name," + + "options%5Bcode,name%5D%5D%5D%5D%5D" ) ) .andRespond( withSuccess( IOUtils.resourceToString( "/org/dhis2/fhir/adapter/dhis/test/single-program.json", StandardCharsets.UTF_8 ), MediaType.APPLICATION_JSON ) ); systemDhis2Server.expect( ExpectedCount.between( 0, 1 ), method( HttpMethod.GET ) ).andExpect( header( "Authorization", testConfiguration.getDhis2SystemAuthorization() ) ) - .andExpect( requestTo( dhis2BaseUrl + "/api/" + dhis2ApiVersion + "/programs.json?paging=false&fields=id,name,code,selectIncidentDatesInFuture,selectEnrollmentDatesInFuture,displayIncidentDate,registration,withoutRegistration,captureCoordinates," + - "trackedEntityType%5Bid%5D,programTrackedEntityAttributes%5Bid,name,valueType,mandatory,allowFutureDate,trackedEntityAttribute%5Bid,name,code,valueType,generated%5D%5D,programStages%5Bid,name,repeatable,captureCoordinates," + - "generatedByEnrollmentDate,minDaysFromStart,programStageDataElements%5Bid,compulsory,allowProvidedElsewhere,dataElement%5Bid,name,code,formName,valueType,optionSetValue,optionSet%5Bid,name,options%5Bcode," + + .andExpect( requestTo( dhis2BaseUrl + "/api/" + dhis2ApiVersion + "/programs.json?paging=false&fields=id,name,code,description,selectIncidentDatesInFuture,selectEnrollmentDatesInFuture,displayIncidentDate,registration,withoutRegistration," + + "captureCoordinates," + + "trackedEntityType%5Bid%5D,programTrackedEntityAttributes%5Bid,name,valueType,mandatory,allowFutureDate,trackedEntityAttribute%5Bid,name,code,valueType,generated%5D%5D,programStages%5Bid,name,description,repeatable,captureCoordinates," + + "generatedByEnrollmentDate,minDaysFromStart,programStageDataElements%5Bid,compulsory,allowProvidedElsewhere,dataElement%5Bid,name,code,description,formName,valueType,optionSetValue,optionSet%5Bid,name,options%5Bcode," + "name%5D%5D%5D%5D%5D&filter=name:eq:Child%20Programme" ) ) .andRespond( withSuccess( IOUtils.resourceToString( "/org/dhis2/fhir/adapter/dhis/test/all-programs.json", StandardCharsets.UTF_8 ), MediaType.APPLICATION_JSON ) ); systemDhis2Server.expect( ExpectedCount.between( 0, 1 ), method( HttpMethod.GET ) ).andExpect( header( "Authorization", testConfiguration.getDhis2SystemAuthorization() ) ) @@ -73,9 +74,9 @@ protected void expectMetadataRequests() throws Exception .andRespond( withSuccess( IOUtils.resourceToString( "/org/dhis2/fhir/adapter/dhis/test/default-tracked-entity-type.json", StandardCharsets.UTF_8 ), MediaType.APPLICATION_JSON ) ); systemDhis2Server.expect( ExpectedCount.between( 0, 1 ), method( HttpMethod.GET ) ).andExpect( header( "Authorization", testConfiguration.getDhis2SystemAuthorization() ) ) .andExpect( requestTo( dhis2BaseUrl + "/api/" + dhis2ApiVersion + "/programs.json?paging=false&" + - "fields=id,name,code,selectIncidentDatesInFuture,selectEnrollmentDatesInFuture,displayIncidentDate,registration,withoutRegistration,captureCoordinates,trackedEntityType%5Bid%5D,programTrackedEntityAttributes%5Bid,name,valueType," + - "mandatory,allowFutureDate,trackedEntityAttribute%5Bid,name,code,valueType,generated%5D%5D,programStages%5Bid,name,repeatable,captureCoordinates,generatedByEnrollmentDate,minDaysFromStart,programStageDataElements%5Bid,compulsory," + - "allowProvidedElsewhere,dataElement%5Bid,name,code,formName,valueType,optionSetValue,optionSet%5Bid,name,options%5Bcode,name%5D%5D%5D%5D%5D&filter=name:eq:Child%20Programme" ) ) + "fields=id,name,code,description,selectIncidentDatesInFuture,selectEnrollmentDatesInFuture,displayIncidentDate,registration,withoutRegistration,captureCoordinates,trackedEntityType%5Bid%5D,programTrackedEntityAttributes%5Bid,name,valueType," + + "mandatory,allowFutureDate,trackedEntityAttribute%5Bid,name,code,valueType,generated%5D%5D,programStages%5Bid,name,description,repeatable,captureCoordinates,generatedByEnrollmentDate,minDaysFromStart,programStageDataElements%5Bid,compulsory," + + "allowProvidedElsewhere,dataElement%5Bid,name,code,description,formName,valueType,optionSetValue,optionSet%5Bid,name,options%5Bcode,name%5D%5D%5D%5D%5D&filter=name:eq:Child%20Programme" ) ) .andRespond( withSuccess( IOUtils.resourceToString( "/org/dhis2/fhir/adapter/dhis/test/single-program.json", StandardCharsets.UTF_8 ), MediaType.APPLICATION_JSON ) ); } } diff --git a/app/src/test/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/enrollment/r4/R4CarePlanToEnrollmentTransformationAppTest.java b/app/src/test/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/enrollment/r4/R4CarePlanToEnrollmentTransformationAppTest.java index a39b7e7c..f33a2de1 100644 --- a/app/src/test/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/enrollment/r4/R4CarePlanToEnrollmentTransformationAppTest.java +++ b/app/src/test/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/enrollment/r4/R4CarePlanToEnrollmentTransformationAppTest.java @@ -34,7 +34,7 @@ import javax.annotation.Nonnull; /** - * Tests the transformation of a FHIR Care Plan to a DHIS 2 Program Instance. + * Tests the transformation of a FHIR Care Plan to a DHIS2 Program Instance. * * @author volsch */ diff --git a/app/src/test/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/programstage/AbstractObservationToProgramStageTransformationAppTest.java b/app/src/test/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/programstage/AbstractObservationToProgramStageTransformationAppTest.java index b03d507a..ebea222c 100644 --- a/app/src/test/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/programstage/AbstractObservationToProgramStageTransformationAppTest.java +++ b/app/src/test/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/programstage/AbstractObservationToProgramStageTransformationAppTest.java @@ -45,7 +45,7 @@ import static org.springframework.test.web.client.response.MockRestResponseCreators.withSuccess; /** - * Tests the transformation of a FHIR Observation to a DHIS 2 Program Stage Instance. + * Tests the transformation of a FHIR Observation to a DHIS2 Program Stage Instance. * * @author volsch */ diff --git a/app/src/test/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/programstage/AbstractProgramStageTransformationAppTest.java b/app/src/test/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/programstage/AbstractProgramStageTransformationAppTest.java index 47d6d1f4..b104bc05 100644 --- a/app/src/test/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/programstage/AbstractProgramStageTransformationAppTest.java +++ b/app/src/test/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/programstage/AbstractProgramStageTransformationAppTest.java @@ -50,8 +50,9 @@ public abstract class AbstractProgramStageTransformationAppTest extends Abstract protected void expectMetadataRequests() throws Exception { systemDhis2Server.expect( ExpectedCount.between( 0, 1 ), method( HttpMethod.GET ) ).andExpect( header( "Authorization", testConfiguration.getDhis2SystemAuthorization() ) ) - .andExpect( requestTo( dhis2BaseUrl + "/api/" + dhis2ApiVersion + "/programs.json?paging=false&fields=id,name,code,selectIncidentDatesInFuture,selectEnrollmentDatesInFuture,displayIncidentDate,registration,withoutRegistration,captureCoordinates," + - "trackedEntityType%5Bid%5D,programTrackedEntityAttributes%5Bid,name,valueType,mandatory,allowFutureDate,trackedEntityAttribute%5Bid,name,code,valueType,generated%5D%5D,programStages%5Bid,name,repeatable,captureCoordinates," + + .andExpect( requestTo( dhis2BaseUrl + "/api/" + dhis2ApiVersion + "/programs.json?paging=false&fields=id,name,code,description,selectIncidentDatesInFuture,selectEnrollmentDatesInFuture,displayIncidentDate,registration,withoutRegistration," + + "captureCoordinates,trackedEntityType%5Bid%5D,programTrackedEntityAttributes%5Bid,name,valueType,mandatory,allowFutureDate,trackedEntityAttribute%5Bid,name,code,valueType,generated%5D%5D,programStages%5Bid,name,description,repeatable," + + "captureCoordinates," + "generatedByEnrollmentDate,minDaysFromStart,programStageDataElements%5Bid,compulsory,allowProvidedElsewhere,dataElement%5Bid,name,code,formName,valueType,optionSetValue,optionSet%5Bid,name,options%5Bcode," + "name%5D%5D%5D%5D%5D&filter=name:eq:Child%20Programme" ) ) .andRespond( withSuccess( IOUtils.resourceToString( "/org/dhis2/fhir/adapter/dhis/test/all-programs.json", StandardCharsets.UTF_8 ), MediaType.APPLICATION_JSON ) ); @@ -68,9 +69,9 @@ protected void expectMetadataRequests() throws Exception .andRespond( withSuccess( IOUtils.resourceToString( "/org/dhis2/fhir/adapter/dhis/test/default-tracked-entity-type.json", StandardCharsets.UTF_8 ), MediaType.APPLICATION_JSON ) ); systemDhis2Server.expect( ExpectedCount.between( 0, 1 ), method( HttpMethod.GET ) ).andExpect( header( "Authorization", testConfiguration.getDhis2SystemAuthorization() ) ) .andExpect( requestTo( dhis2BaseUrl + "/api/" + dhis2ApiVersion + "/programs.json?paging=false&" + - "fields=id,name,code,selectIncidentDatesInFuture,selectEnrollmentDatesInFuture,displayIncidentDate,registration,withoutRegistration,captureCoordinates,trackedEntityType%5Bid%5D,programTrackedEntityAttributes%5Bid,name,valueType," + - "mandatory,allowFutureDate,trackedEntityAttribute%5Bid,name,code,valueType,generated%5D%5D,programStages%5Bid,name,repeatable,captureCoordinates,generatedByEnrollmentDate,minDaysFromStart,programStageDataElements%5Bid,compulsory," + - "allowProvidedElsewhere,dataElement%5Bid,name,code,formName,valueType,optionSetValue,optionSet%5Bid,name,options%5Bcode,name%5D%5D%5D%5D%5D&filter=name:eq:Child%20Programme" ) ) + "fields=id,name,code,description,selectIncidentDatesInFuture,selectEnrollmentDatesInFuture,displayIncidentDate,registration,withoutRegistration,captureCoordinates,trackedEntityType%5Bid%5D,programTrackedEntityAttributes%5Bid,name,valueType," + + "mandatory,allowFutureDate,trackedEntityAttribute%5Bid,name,code,valueType,generated%5D%5D,programStages%5Bid,name,description,repeatable,captureCoordinates,generatedByEnrollmentDate,minDaysFromStart,programStageDataElements%5Bid,compulsory," + + "allowProvidedElsewhere,dataElement%5Bid,name,code,description,formName,valueType,optionSetValue,optionSet%5Bid,name,options%5Bcode,name%5D%5D%5D%5D%5D&filter=name:eq:Child%20Programme" ) ) .andRespond( withSuccess( IOUtils.resourceToString( "/org/dhis2/fhir/adapter/dhis/test/single-program.json", StandardCharsets.UTF_8 ), MediaType.APPLICATION_JSON ) ); } } diff --git a/app/src/test/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/programstage/AbstractQuestionnaireResponseToProgramStageTransformationAppTest.java b/app/src/test/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/programstage/AbstractQuestionnaireResponseToProgramStageTransformationAppTest.java index 78460314..ad47daac 100644 --- a/app/src/test/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/programstage/AbstractQuestionnaireResponseToProgramStageTransformationAppTest.java +++ b/app/src/test/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/programstage/AbstractQuestionnaireResponseToProgramStageTransformationAppTest.java @@ -45,7 +45,7 @@ import static org.springframework.test.web.client.response.MockRestResponseCreators.withSuccess; /** - * Tests the transformation of a FHIR Questionnaire Response to a DHIS 2 Program Stage Instance. + * Tests the transformation of a FHIR Questionnaire Response to a DHIS2 Program Stage Instance. * * @author volsch */ diff --git a/app/src/test/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/programstage/dstu3/Dstu3ObservationToProgramStageTransformationAppTest.java b/app/src/test/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/programstage/dstu3/Dstu3ObservationToProgramStageTransformationAppTest.java index d4f3991e..2f56afa7 100644 --- a/app/src/test/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/programstage/dstu3/Dstu3ObservationToProgramStageTransformationAppTest.java +++ b/app/src/test/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/programstage/dstu3/Dstu3ObservationToProgramStageTransformationAppTest.java @@ -34,7 +34,7 @@ import javax.annotation.Nonnull; /** - * Tests the transformation of a FHIR Observation to a DHIS 2 Program Stage Instance. + * Tests the transformation of a FHIR Observation to a DHIS2 Program Stage Instance. * * @author volsch */ diff --git a/app/src/test/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/programstage/r4/R4ObservationToProgramStageTransformationAppTest.java b/app/src/test/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/programstage/r4/R4ObservationToProgramStageTransformationAppTest.java index d3f54523..222953e0 100644 --- a/app/src/test/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/programstage/r4/R4ObservationToProgramStageTransformationAppTest.java +++ b/app/src/test/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/programstage/r4/R4ObservationToProgramStageTransformationAppTest.java @@ -34,7 +34,7 @@ import javax.annotation.Nonnull; /** - * Tests the transformation of a FHIR Observation to a DHIS 2 Program Stage Instance. + * Tests the transformation of a FHIR Observation to a DHIS2 Program Stage Instance. * * @author volsch */ diff --git a/app/src/test/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/programstage/r4/R4QuestionnaireResponseToProgramStageTransformationAppTest.java b/app/src/test/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/programstage/r4/R4QuestionnaireResponseToProgramStageTransformationAppTest.java index d1c4f9b9..52a5ad4b 100644 --- a/app/src/test/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/programstage/r4/R4QuestionnaireResponseToProgramStageTransformationAppTest.java +++ b/app/src/test/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/programstage/r4/R4QuestionnaireResponseToProgramStageTransformationAppTest.java @@ -34,7 +34,7 @@ import javax.annotation.Nonnull; /** - * Tests the transformation of a FHIR Questionnaire Response to a DHIS 2 Program Stage Instance. + * Tests the transformation of a FHIR Questionnaire Response to a DHIS2 Program Stage Instance. * * @author volsch */ diff --git a/app/src/test/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/trackedentity/AbstractPatientToTrackedEntityInstanceTransformationAppTest.java b/app/src/test/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/trackedentity/AbstractPatientToTrackedEntityInstanceTransformationAppTest.java index 4681c402..15d11641 100644 --- a/app/src/test/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/trackedentity/AbstractPatientToTrackedEntityInstanceTransformationAppTest.java +++ b/app/src/test/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/trackedentity/AbstractPatientToTrackedEntityInstanceTransformationAppTest.java @@ -45,7 +45,7 @@ import static org.springframework.test.web.client.response.MockRestResponseCreators.withSuccess; /** - * Tests the transformation of a FHIR patient to a DHIS 2 Tracked Entity. + * Tests the transformation of a FHIR patient to a DHIS2 Tracked Entity. * * @author volsch */ diff --git a/app/src/test/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/trackedentity/dstu3/Dstu3PatientToTrackedEntityInstanceTransformationAppTest.java b/app/src/test/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/trackedentity/dstu3/Dstu3PatientToTrackedEntityInstanceTransformationAppTest.java index 61ae2fc2..869472a6 100644 --- a/app/src/test/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/trackedentity/dstu3/Dstu3PatientToTrackedEntityInstanceTransformationAppTest.java +++ b/app/src/test/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/trackedentity/dstu3/Dstu3PatientToTrackedEntityInstanceTransformationAppTest.java @@ -34,7 +34,7 @@ import javax.annotation.Nonnull; /** - * Tests the transformation of a FHIR patient to a DHIS 2 Tracked Entity. + * Tests the transformation of a FHIR patient to a DHIS2 Tracked Entity. * * @author volsch */ diff --git a/app/src/test/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/trackedentity/r4/R4PatientToTrackedEntityInstanceTransformationAppTest.java b/app/src/test/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/trackedentity/r4/R4PatientToTrackedEntityInstanceTransformationAppTest.java index 728b39ab..6b62c25e 100644 --- a/app/src/test/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/trackedentity/r4/R4PatientToTrackedEntityInstanceTransformationAppTest.java +++ b/app/src/test/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/trackedentity/r4/R4PatientToTrackedEntityInstanceTransformationAppTest.java @@ -34,7 +34,7 @@ import javax.annotation.Nonnull; /** - * Tests the transformation of a FHIR patient to a DHIS 2 Tracked Entity. + * Tests the transformation of a FHIR patient to a DHIS2 Tracked Entity. * * @author volsch */ diff --git a/app/src/test/resources/data.sql b/app/src/test/resources/data.sql index 9f1646ff..a8fc4c49 100644 --- a/app/src/test/resources/data.sql +++ b/app/src/test/resources/data.sql @@ -3072,12 +3072,12 @@ VALUES('0340bf441eab4c2a98a2aaf7ba35855c', 0, '46f0af46365440b38d4c7a633332c3b3' INSERT INTO fhir_client_system(id, version, fhir_client_id, fhir_resource_type, system_id) VALUES('789a91bd6bcb4f8496d0c6829b5fdeaa', 0, '46f0af46365440b38d4c7a633332c3b3', 'QUESTIONNAIRE_RESPONSE', '5bdff628d94f43dc83678c84fe48bdd9'); -INSERT INTO fhir_rule(id, version, fhir_resource_type, dhis_resource_type, name, description, enabled, imp_enabled, exp_enabled, contained_allowed, fhir_create_enabled, fhir_update_enabled, fhir_delete_enabled, grouping, evaluation_order, transform_imp_script_id) +INSERT INTO fhir_rule(id, version, fhir_resource_type, dhis_resource_type, name, description, enabled, imp_enabled, exp_enabled, contained_allowed, fhir_create_enabled, fhir_update_enabled, fhir_delete_enabled, grouping, evaluation_order, simple_fhir_id) VALUES('4a9ac195858b455eb34dc560e1855787', 0, 'PLAN_DEFINITION', 'PROGRAM_METADATA', 'Default DHIS2 Program Metadata to FHIR Plan Definition', 'Default rule that transforms a DHIS2 Program Metadata to a FHIR Care Plan.', -true, false, true, false, true, true, true, false, -2147483648, NULL); +true, false, true, false, true, true, true, false, -2147483648, TRUE); INSERT INTO fhir_program_metadata_rule(id) VALUES ('4a9ac195858b455eb34dc560e1855787'); -INSERT INTO fhir_rule(id, version, fhir_resource_type, dhis_resource_type, name, description, enabled, imp_enabled, exp_enabled, contained_allowed, fhir_create_enabled, fhir_update_enabled, fhir_delete_enabled, grouping, evaluation_order, transform_imp_script_id) +INSERT INTO fhir_rule(id, version, fhir_resource_type, dhis_resource_type, name, description, enabled, imp_enabled, exp_enabled, contained_allowed, fhir_create_enabled, fhir_update_enabled, fhir_delete_enabled, grouping, evaluation_order, simple_fhir_id) VALUES('1f97f85ae4ea46f1bcde77ea178226f4', 0, 'QUESTIONNAIRE', 'PROGRAM_STAGE_METADATA', 'Default DHIS2 Program Stage Metadata to FHIR Questionnaire', 'Default rule that transforms a DHIS2 Program Stage Metadata to a FHIR Questionnaire.', -true, false, true, false, true, true, true, false, -2147483648, NULL); +true, false, true, false, true, true, true, false, -2147483648, TRUE); INSERT INTO fhir_program_stage_metadata_rule(id) VALUES ('1f97f85ae4ea46f1bcde77ea178226f4'); diff --git a/common/src/main/java/org/dhis2/fhir/adapter/scriptable/generator/FromDhisJavaScriptGeneratorController.java b/common/src/main/java/org/dhis2/fhir/adapter/scriptable/generator/FromDhisJavaScriptGeneratorController.java index 1c21d546..bcfc2d41 100644 --- a/common/src/main/java/org/dhis2/fhir/adapter/scriptable/generator/FromDhisJavaScriptGeneratorController.java +++ b/common/src/main/java/org/dhis2/fhir/adapter/scriptable/generator/FromDhisJavaScriptGeneratorController.java @@ -1,7 +1,7 @@ package org.dhis2.fhir.adapter.scriptable.generator; /* - * Copyright (c) 2004-2018, University of Oslo + * Copyright (c) 2004-2019, University of Oslo * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -40,7 +40,7 @@ import javax.annotation.Nullable; /** - * Creates and provides the JavaScript for transformations from DHIS 2. + * Creates and provides the JavaScript for transformations from DHIS2. * * @author volsch */ diff --git a/common/src/main/java/org/dhis2/fhir/adapter/scriptable/generator/ToDhisJavaScriptGeneratorController.java b/common/src/main/java/org/dhis2/fhir/adapter/scriptable/generator/ToDhisJavaScriptGeneratorController.java index 3b2bb390..15c58f3b 100644 --- a/common/src/main/java/org/dhis2/fhir/adapter/scriptable/generator/ToDhisJavaScriptGeneratorController.java +++ b/common/src/main/java/org/dhis2/fhir/adapter/scriptable/generator/ToDhisJavaScriptGeneratorController.java @@ -1,7 +1,7 @@ package org.dhis2.fhir.adapter.scriptable.generator; /* - * Copyright (c) 2004-2018, University of Oslo + * Copyright (c) 2004-2019, University of Oslo * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -40,7 +40,7 @@ import javax.annotation.Nullable; /** - * Creates and provides the JavaScript for transformations into DHIS 2. + * Creates and provides the JavaScript for transformations into DHIS2. * * @author volsch */ diff --git a/common/src/main/java/org/dhis2/fhir/adapter/security/AdapterUserDetails.java b/common/src/main/java/org/dhis2/fhir/adapter/security/AdapterUserDetails.java index 489951cc..ba46d929 100644 --- a/common/src/main/java/org/dhis2/fhir/adapter/security/AdapterUserDetails.java +++ b/common/src/main/java/org/dhis2/fhir/adapter/security/AdapterUserDetails.java @@ -1,7 +1,7 @@ package org.dhis2.fhir.adapter.security; /* - * Copyright (c) 2004-2018, University of Oslo + * Copyright (c) 2004-2019, University of Oslo * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -40,7 +40,7 @@ public interface AdapterUserDetails extends UserDetails { /** - * @return the ID of the DHIS 2 user. + * @return the ID of the DHIS2 user. */ @Nonnull String getId(); diff --git a/dhis/src/main/java/org/dhis2/fhir/adapter/dhis/local/LocalDhisResourceRepository.java b/dhis/src/main/java/org/dhis2/fhir/adapter/dhis/local/LocalDhisResourceRepository.java index 9cdc0583..10292185 100644 --- a/dhis/src/main/java/org/dhis2/fhir/adapter/dhis/local/LocalDhisResourceRepository.java +++ b/dhis/src/main/java/org/dhis2/fhir/adapter/dhis/local/LocalDhisResourceRepository.java @@ -38,7 +38,7 @@ import java.util.function.Predicate; /** - * Repository that stores DHIS 2 resources locally. + * Repository that stores DHIS2 resources locally. * * @param the concrete type of the resource. * @author volsch diff --git a/dhis/src/main/java/org/dhis2/fhir/adapter/dhis/local/impl/LocalDhisResourceRepositoryImpl.java b/dhis/src/main/java/org/dhis2/fhir/adapter/dhis/local/impl/LocalDhisResourceRepositoryImpl.java index 65e49d3d..8caea50e 100644 --- a/dhis/src/main/java/org/dhis2/fhir/adapter/dhis/local/impl/LocalDhisResourceRepositoryImpl.java +++ b/dhis/src/main/java/org/dhis2/fhir/adapter/dhis/local/impl/LocalDhisResourceRepositoryImpl.java @@ -52,7 +52,7 @@ import java.util.stream.Collectors; /** - * Repository that stores DHIS 2 resources locally. + * Repository that stores DHIS2 resources locally. * * @param the concrete type of the resource. * @author volsch diff --git a/dhis/src/main/java/org/dhis2/fhir/adapter/dhis/model/DhisMetadata.java b/dhis/src/main/java/org/dhis2/fhir/adapter/dhis/model/DhisMetadata.java index 0e2dd4f1..748e4242 100644 --- a/dhis/src/main/java/org/dhis2/fhir/adapter/dhis/model/DhisMetadata.java +++ b/dhis/src/main/java/org/dhis2/fhir/adapter/dhis/model/DhisMetadata.java @@ -34,11 +34,11 @@ import java.util.Set; /** - * Implemented by DHIS 2 metadata. + * Implemented by DHIS2 metadata. * * @author volsch */ -public interface DhisMetadata extends Identifiable +public interface DhisMetadata extends DhisResource, Identifiable { /** * @return the unique code of the metadata or null if the type has no code. 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 98036216..140c9971 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 @@ -42,8 +42,8 @@ public interface DhisResource extends Identifiable, Serializable { /** - * @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. + * @return the unique ID of the DHIS2 organization unit to which this resource belongs, + * or null if this resource does not belong to any DHIS2 organization unit. */ String getOrgUnitId(); diff --git a/dhis/src/main/java/org/dhis2/fhir/adapter/dhis/model/DhisResourceType.java b/dhis/src/main/java/org/dhis2/fhir/adapter/dhis/model/DhisResourceType.java index 69dbb39d..654008ad 100644 --- a/dhis/src/main/java/org/dhis2/fhir/adapter/dhis/model/DhisResourceType.java +++ b/dhis/src/main/java/org/dhis2/fhir/adapter/dhis/model/DhisResourceType.java @@ -46,6 +46,11 @@ public enum DhisResourceType */ TRACKED_ENTITY( "trackedEntityInstances", "te" ), + /** + * Resource is a tracked entity type. + */ + TRACKED_ENTITY_TYPE( "trackedEntityTypes", "tt" ), + /** * The program metadata. */ diff --git a/dhis/src/main/java/org/dhis2/fhir/adapter/dhis/model/ImmutableDataElement.java b/dhis/src/main/java/org/dhis2/fhir/adapter/dhis/model/ImmutableDataElement.java index d3004552..5a0c9932 100644 --- a/dhis/src/main/java/org/dhis2/fhir/adapter/dhis/model/ImmutableDataElement.java +++ b/dhis/src/main/java/org/dhis2/fhir/adapter/dhis/model/ImmutableDataElement.java @@ -36,6 +36,7 @@ import javax.annotation.Nonnull; import java.io.Serializable; +import java.time.ZonedDateTime; import java.util.Set; /** @@ -72,6 +73,62 @@ public void setId( String id ) throw new UnsupportedOperationException(); } + @JsonIgnore + @Override + public String getOrgUnitId() + { + return delegate.getOrgUnitId(); + } + + @JsonIgnore + @Override + public DhisResourceId getResourceId() + { + return delegate.getResourceId(); + } + + @JsonIgnore + @Override + public boolean isDeleted() + { + return delegate.isDeleted(); + } + + @JsonIgnore + @Override + public ZonedDateTime getLastUpdated() + { + return delegate.getLastUpdated(); + } + + @JsonIgnore + @Override + @Nonnull + public DhisResourceType getResourceType() + { + return delegate.getResourceType(); + } + + @JsonIgnore + @Override + public boolean isLocal() + { + return delegate.isLocal(); + } + + @JsonIgnore + @Override + public boolean isNewResource() + { + return delegate.isNewResource(); + } + + @Override + public void resetNewResource() + { + // nothing to be done, read only + } + @JsonIgnore @Override public String getName() diff --git a/dhis/src/main/java/org/dhis2/fhir/adapter/dhis/model/WritableDataElement.java b/dhis/src/main/java/org/dhis2/fhir/adapter/dhis/model/WritableDataElement.java index 0dabcc03..b1dd5005 100644 --- a/dhis/src/main/java/org/dhis2/fhir/adapter/dhis/model/WritableDataElement.java +++ b/dhis/src/main/java/org/dhis2/fhir/adapter/dhis/model/WritableDataElement.java @@ -28,9 +28,12 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +import com.fasterxml.jackson.annotation.JsonIgnore; import org.dhis2.fhir.adapter.model.ValueType; +import javax.annotation.Nonnull; import java.io.Serializable; +import java.time.ZonedDateTime; /** * Writable implementation of {@link DataElement} that can also be used for @@ -67,6 +70,62 @@ public void setId( String id ) this.id = id; } + @JsonIgnore + @Override + public String getOrgUnitId() + { + return null; + } + + @JsonIgnore + @Override + public DhisResourceId getResourceId() + { + return getId() == null ? null : new DhisResourceId( getResourceType(), getId() ); + } + + @JsonIgnore + @Override + public boolean isDeleted() + { + return false; + } + + @JsonIgnore + @Override + public ZonedDateTime getLastUpdated() + { + return null; + } + + @JsonIgnore + @Nonnull + @Override + public DhisResourceType getResourceType() + { + return DhisResourceType.TRACKED_ENTITY_TYPE; + } + + @JsonIgnore + @Override + public boolean isLocal() + { + return false; + } + + @JsonIgnore + @Override + public boolean isNewResource() + { + return false; + } + + @Override + public void resetNewResource() + { + // nothing to be done + } + @Override public String getName() { diff --git a/dhis/src/main/java/org/dhis2/fhir/adapter/dhis/service/impl/DhisMetadataPolledItem.java b/dhis/src/main/java/org/dhis2/fhir/adapter/dhis/service/impl/DhisMetadataPolledItem.java index fca3a032..c66aa616 100644 --- a/dhis/src/main/java/org/dhis2/fhir/adapter/dhis/service/impl/DhisMetadataPolledItem.java +++ b/dhis/src/main/java/org/dhis2/fhir/adapter/dhis/service/impl/DhisMetadataPolledItem.java @@ -31,7 +31,7 @@ import org.dhis2.fhir.adapter.dhis.poll.PolledItem; /** - * The polled items of a DHIS 2 metadata. + * The polled items of a DHIS2 metadata. * * @author volsch */ diff --git a/dhis/src/main/java/org/dhis2/fhir/adapter/dhis/service/impl/DhisMetadataPolledItems.java b/dhis/src/main/java/org/dhis2/fhir/adapter/dhis/service/impl/DhisMetadataPolledItems.java index cb22ffde..9b2bbabe 100644 --- a/dhis/src/main/java/org/dhis2/fhir/adapter/dhis/service/impl/DhisMetadataPolledItems.java +++ b/dhis/src/main/java/org/dhis2/fhir/adapter/dhis/service/impl/DhisMetadataPolledItems.java @@ -35,7 +35,7 @@ import java.util.List; /** - * Polled items for DHIS 2 metadata. + * Polled items for DHIS2 metadata. * * @author volsch */ 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 index b77cdeaa..fef873ad 100644 --- 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 @@ -38,6 +38,7 @@ 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.program.ProgramMetadataService; import org.dhis2.fhir.adapter.dhis.tracker.trackedentity.TrackedEntityInstance; import org.dhis2.fhir.adapter.dhis.tracker.trackedentity.TrackedEntityService; import org.slf4j.Logger; @@ -62,16 +63,19 @@ public class DhisResourceRepositoryImpl implements DhisResourceRepository private final OrganizationUnitService organizationUnitService; + private final ProgramMetadataService programMetadataService; + private final TrackedEntityService trackedEntityService; private final EnrollmentService enrollmentService; private final EventService eventService; - public DhisResourceRepositoryImpl( @Nonnull OrganizationUnitService organizationUnitService, + public DhisResourceRepositoryImpl( @Nonnull OrganizationUnitService organizationUnitService, ProgramMetadataService programMetadataService, @Nonnull TrackedEntityService trackedEntityService, @Nonnull EnrollmentService enrollmentService, @Nonnull EventService eventService ) { this.organizationUnitService = organizationUnitService; + this.programMetadataService = programMetadataService; this.trackedEntityService = trackedEntityService; this.enrollmentService = enrollmentService; this.eventService = eventService; @@ -85,6 +89,8 @@ public Optional findRefreshed( @Nonnull DhisResourceId d { case ORGANIZATION_UNIT: return organizationUnitService.findOneByReference( new Reference( dhisResourceId.getId(), ReferenceType.ID ) ); + case PROGRAM_METADATA: + return programMetadataService.findOneByReference( new Reference( dhisResourceId.getId(), ReferenceType.ID ) ); case TRACKED_ENTITY: return trackedEntityService.findOneByIdRefreshed( dhisResourceId.getId() ); case PROGRAM_STAGE_EVENT: @@ -105,6 +111,7 @@ public Optional findRefreshedDeleted( @Nonnull DhisResou case PROGRAM_STAGE_EVENT: return eventService.findOneDeletedById( dhisResourceId.getId() ); case ORGANIZATION_UNIT: + case PROGRAM_METADATA: case TRACKED_ENTITY: case ENROLLMENT: throw new UnsupportedOperationException( "Retrieving deleted " + dhisResourceId.getType() + " DHIS resource items is not supported." ); diff --git a/dhis/src/main/java/org/dhis2/fhir/adapter/dhis/tracker/program/ImmutableProgram.java b/dhis/src/main/java/org/dhis2/fhir/adapter/dhis/tracker/program/ImmutableProgram.java index 076d9c21..96bf3b2b 100644 --- a/dhis/src/main/java/org/dhis2/fhir/adapter/dhis/tracker/program/ImmutableProgram.java +++ b/dhis/src/main/java/org/dhis2/fhir/adapter/dhis/tracker/program/ImmutableProgram.java @@ -93,6 +93,13 @@ public String getCode() return delegate.getCode(); } + @JsonIgnore + @Override + public String getDescription() + { + return delegate.getDescription(); + } + @JsonIgnore @Override public String getTrackedEntityTypeId() diff --git a/dhis/src/main/java/org/dhis2/fhir/adapter/dhis/tracker/program/ImmutableProgramStage.java b/dhis/src/main/java/org/dhis2/fhir/adapter/dhis/tracker/program/ImmutableProgramStage.java index 21f43efc..405d180e 100644 --- a/dhis/src/main/java/org/dhis2/fhir/adapter/dhis/tracker/program/ImmutableProgramStage.java +++ b/dhis/src/main/java/org/dhis2/fhir/adapter/dhis/tracker/program/ImmutableProgramStage.java @@ -93,6 +93,13 @@ public String getName() return delegate.getName(); } + @JsonIgnore + @Override + public String getDescription() + { + return delegate.getDescription(); + } + @JsonIgnore @Override public boolean isRepeatable() diff --git a/dhis/src/main/java/org/dhis2/fhir/adapter/dhis/tracker/program/Program.java b/dhis/src/main/java/org/dhis2/fhir/adapter/dhis/tracker/program/Program.java index 27e79901..b83e67ad 100644 --- a/dhis/src/main/java/org/dhis2/fhir/adapter/dhis/tracker/program/Program.java +++ b/dhis/src/main/java/org/dhis2/fhir/adapter/dhis/tracker/program/Program.java @@ -48,6 +48,8 @@ @Scriptable public interface Program extends DhisResource, DhisMetadata { + String getDescription(); + String getTrackedEntityTypeId(); boolean isSelectIncidentDatesInFuture(); diff --git a/dhis/src/main/java/org/dhis2/fhir/adapter/dhis/tracker/program/ProgramStage.java b/dhis/src/main/java/org/dhis2/fhir/adapter/dhis/tracker/program/ProgramStage.java index de69ff15..435f596b 100644 --- a/dhis/src/main/java/org/dhis2/fhir/adapter/dhis/tracker/program/ProgramStage.java +++ b/dhis/src/main/java/org/dhis2/fhir/adapter/dhis/tracker/program/ProgramStage.java @@ -56,6 +56,8 @@ public interface ProgramStage extends DhisResource, DhisMetadata int getMinDaysFromStart(); + String getDescription(); + List getDataElements(); @Nullable diff --git a/dhis/src/main/java/org/dhis2/fhir/adapter/dhis/tracker/program/WritableProgram.java b/dhis/src/main/java/org/dhis2/fhir/adapter/dhis/tracker/program/WritableProgram.java index bf7ac0cd..b6327539 100644 --- a/dhis/src/main/java/org/dhis2/fhir/adapter/dhis/tracker/program/WritableProgram.java +++ b/dhis/src/main/java/org/dhis2/fhir/adapter/dhis/tracker/program/WritableProgram.java @@ -57,6 +57,8 @@ public class WritableProgram extends AbstractDhisMetadata implements Program, Se private String code; + private String description; + private boolean selectIncidentDatesInFuture; private boolean selectEnrollmentDatesInFuture; @@ -120,6 +122,17 @@ public void setCode( String code ) this.code = code; } + @Override + public String getDescription() + { + return description; + } + + public void setDescription( String description ) + { + this.description = description; + } + @JsonIgnore @Override public String getTrackedEntityTypeId() diff --git a/dhis/src/main/java/org/dhis2/fhir/adapter/dhis/tracker/program/WritableProgramStage.java b/dhis/src/main/java/org/dhis2/fhir/adapter/dhis/tracker/program/WritableProgramStage.java index 31efc464..588b057c 100644 --- a/dhis/src/main/java/org/dhis2/fhir/adapter/dhis/tracker/program/WritableProgramStage.java +++ b/dhis/src/main/java/org/dhis2/fhir/adapter/dhis/tracker/program/WritableProgramStage.java @@ -60,6 +60,8 @@ public class WritableProgramStage extends AbstractDhisMetadata implements Progra private int minDaysFromStart; + private String description; + @JsonProperty( "programStageDataElements" ) private List dataElements; @@ -94,6 +96,17 @@ public void setName( String name ) this.name = name; } + @Override + public String getDescription() + { + return description; + } + + public void setDescription( String description ) + { + this.description = description; + } + @JsonIgnore @Override public String getCode() diff --git a/dhis/src/main/java/org/dhis2/fhir/adapter/dhis/tracker/program/impl/ProgramMetadataServiceImpl.java b/dhis/src/main/java/org/dhis2/fhir/adapter/dhis/tracker/program/impl/ProgramMetadataServiceImpl.java index f0f5cb9a..070f1d71 100644 --- a/dhis/src/main/java/org/dhis2/fhir/adapter/dhis/tracker/program/impl/ProgramMetadataServiceImpl.java +++ b/dhis/src/main/java/org/dhis2/fhir/adapter/dhis/tracker/program/impl/ProgramMetadataServiceImpl.java @@ -49,11 +49,11 @@ public class ProgramMetadataServiceImpl extends AbstractDhisMetadataServiceImpl implements ProgramMetadataService { protected static final String FIELDS = - "id,name,code,selectIncidentDatesInFuture,selectEnrollmentDatesInFuture,displayIncidentDate," + + "id,name,code,description,selectIncidentDatesInFuture,selectEnrollmentDatesInFuture,displayIncidentDate," + "registration,withoutRegistration,captureCoordinates,trackedEntityType[id]," + "programTrackedEntityAttributes[id,name,valueType,mandatory,allowFutureDate," + "trackedEntityAttribute[id,name,code,valueType,generated]]," + - "programStages[id,name,repeatable,captureCoordinates,generatedByEnrollmentDate,minDaysFromStart," + + "programStages[id,name,description,repeatable,captureCoordinates,generatedByEnrollmentDate,minDaysFromStart," + "programStageDataElements[id,compulsory,allowProvidedElsewhere," + "dataElement[id,name,code,formName,valueType,optionSetValue,optionSet[id,name,options[code,name]]]]]"; diff --git a/dhis/src/main/java/org/dhis2/fhir/adapter/dhis/tracker/trackedentity/ImmutableTrackedEntityType.java b/dhis/src/main/java/org/dhis2/fhir/adapter/dhis/tracker/trackedentity/ImmutableTrackedEntityType.java index 388ba642..ba24875d 100644 --- a/dhis/src/main/java/org/dhis2/fhir/adapter/dhis/tracker/trackedentity/ImmutableTrackedEntityType.java +++ b/dhis/src/main/java/org/dhis2/fhir/adapter/dhis/tracker/trackedentity/ImmutableTrackedEntityType.java @@ -31,6 +31,8 @@ import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonProperty; +import org.dhis2.fhir.adapter.dhis.model.DhisResourceId; +import org.dhis2.fhir.adapter.dhis.model.DhisResourceType; import org.dhis2.fhir.adapter.dhis.model.ImmutableDhisObject; import org.dhis2.fhir.adapter.dhis.model.Reference; import org.dhis2.fhir.adapter.scriptable.Scriptable; @@ -38,6 +40,7 @@ import javax.annotation.Nonnull; import javax.annotation.Nullable; import java.io.Serializable; +import java.time.ZonedDateTime; import java.util.List; import java.util.Optional; import java.util.Set; @@ -78,6 +81,62 @@ public void setId( String id ) throw new UnsupportedOperationException(); } + @JsonIgnore + @Override + public String getOrgUnitId() + { + return delegate.getOrgUnitId(); + } + + @JsonIgnore + @Override + public DhisResourceId getResourceId() + { + return delegate.getResourceId(); + } + + @JsonIgnore + @Override + public boolean isDeleted() + { + return delegate.isDeleted(); + } + + @JsonIgnore + @Override + public ZonedDateTime getLastUpdated() + { + return delegate.getLastUpdated(); + } + + @JsonIgnore + @Override + @Nonnull + public DhisResourceType getResourceType() + { + return delegate.getResourceType(); + } + + @JsonIgnore + @Override + public boolean isLocal() + { + return delegate.isLocal(); + } + + @JsonIgnore + @Override + public boolean isNewResource() + { + return delegate.isNewResource(); + } + + @Override + public void resetNewResource() + { + // nothing to be done, read only + } + @JsonIgnore @Override public String getCode() diff --git a/dhis/src/main/java/org/dhis2/fhir/adapter/dhis/tracker/trackedentity/WritableTrackedEntityType.java b/dhis/src/main/java/org/dhis2/fhir/adapter/dhis/tracker/trackedentity/WritableTrackedEntityType.java index a546c24c..69b1e73e 100644 --- a/dhis/src/main/java/org/dhis2/fhir/adapter/dhis/tracker/trackedentity/WritableTrackedEntityType.java +++ b/dhis/src/main/java/org/dhis2/fhir/adapter/dhis/tracker/trackedentity/WritableTrackedEntityType.java @@ -32,11 +32,14 @@ import com.fasterxml.jackson.annotation.JsonProperty; import org.apache.commons.lang3.StringUtils; import org.dhis2.fhir.adapter.dhis.model.AbstractDhisMetadata; +import org.dhis2.fhir.adapter.dhis.model.DhisResourceId; +import org.dhis2.fhir.adapter.dhis.model.DhisResourceType; import org.dhis2.fhir.adapter.dhis.model.Reference; import javax.annotation.Nonnull; import javax.annotation.Nullable; import java.io.Serializable; +import java.time.ZonedDateTime; import java.util.List; import java.util.Map; import java.util.Optional; @@ -104,6 +107,62 @@ public String getCode() return null; } + @JsonIgnore + @Override + public String getOrgUnitId() + { + return null; + } + + @JsonIgnore + @Override + public DhisResourceId getResourceId() + { + return getId() == null ? null : new DhisResourceId( getResourceType(), getId() ); + } + + @JsonIgnore + @Override + public boolean isDeleted() + { + return false; + } + + @JsonIgnore + @Override + public ZonedDateTime getLastUpdated() + { + return null; + } + + @JsonIgnore + @Nonnull + @Override + public DhisResourceType getResourceType() + { + return DhisResourceType.TRACKED_ENTITY_TYPE; + } + + @JsonIgnore + @Override + public boolean isLocal() + { + return false; + } + + @JsonIgnore + @Override + public boolean isNewResource() + { + return false; + } + + @Override + public void resetNewResource() + { + // nothing to be done + } + @Override public List getAttributes() { diff --git a/dhis/src/test/java/org/dhis2/fhir/adapter/dhis/tracker/program/impl/ProgramMetadataServiceImplTest.java b/dhis/src/test/java/org/dhis2/fhir/adapter/dhis/tracker/program/impl/ProgramMetadataServiceImplTest.java index abd1ec9f..b1aabe2f 100644 --- a/dhis/src/test/java/org/dhis2/fhir/adapter/dhis/tracker/program/impl/ProgramMetadataServiceImplTest.java +++ b/dhis/src/test/java/org/dhis2/fhir/adapter/dhis/tracker/program/impl/ProgramMetadataServiceImplTest.java @@ -81,8 +81,8 @@ public void setUp() @Test public void findMetadataByReferenceId() throws IOException { - mockServer.expect( requestTo( "http://localhost:8080/api/programs/93783.json?fields=id,name,code,selectIncidentDatesInFuture,selectEnrollmentDatesInFuture,displayIncidentDate,registration,withoutRegistration,captureCoordinates," + - "trackedEntityType%5Bid%5D,programTrackedEntityAttributes%5Bid,name,valueType,mandatory,allowFutureDate,trackedEntityAttribute%5Bid,name,code,valueType,generated%5D%5D,programStages%5Bid,name,repeatable,captureCoordinates," + + mockServer.expect( requestTo( "http://localhost:8080/api/programs/93783.json?fields=id,name,code,description,selectIncidentDatesInFuture,selectEnrollmentDatesInFuture,displayIncidentDate,registration,withoutRegistration,captureCoordinates," + + "trackedEntityType%5Bid%5D,programTrackedEntityAttributes%5Bid,name,valueType,mandatory,allowFutureDate,trackedEntityAttribute%5Bid,name,code,valueType,generated%5D%5D,programStages%5Bid,name,description,repeatable,captureCoordinates," + "generatedByEnrollmentDate,minDaysFromStart,programStageDataElements%5Bid,compulsory,allowProvidedElsewhere,dataElement%5Bid,name,code,formName,valueType,optionSetValue,optionSet%5Bid,name,options%5Bcode,name%5D%5D%5D%5D%5D" ) ) .andExpect( method( HttpMethod.GET ) ).andRespond( withSuccess( IOUtils.resourceToByteArray( "/org/dhis2/fhir/adapter/dhis/tracker/program/impl/program.json" ), MediaType.APPLICATION_JSON ) ); @@ -94,8 +94,8 @@ public void findMetadataByReferenceId() throws IOException @Test public void findMetadataByReferenceIdNotFound() { - mockServer.expect( requestTo( "http://localhost:8080/api/programs/93783.json?fields=id,name,code,selectIncidentDatesInFuture,selectEnrollmentDatesInFuture,displayIncidentDate,registration,withoutRegistration,captureCoordinates," + - "trackedEntityType%5Bid%5D,programTrackedEntityAttributes%5Bid,name,valueType,mandatory,allowFutureDate,trackedEntityAttribute%5Bid,name,code,valueType,generated%5D%5D,programStages%5Bid,name,repeatable,captureCoordinates," + + mockServer.expect( requestTo( "http://localhost:8080/api/programs/93783.json?fields=id,name,code,description,selectIncidentDatesInFuture,selectEnrollmentDatesInFuture,displayIncidentDate,registration,withoutRegistration,captureCoordinates," + + "trackedEntityType%5Bid%5D,programTrackedEntityAttributes%5Bid,name,valueType,mandatory,allowFutureDate,trackedEntityAttribute%5Bid,name,code,valueType,generated%5D%5D,programStages%5Bid,name,description,repeatable,captureCoordinates," + "generatedByEnrollmentDate,minDaysFromStart,programStageDataElements%5Bid,compulsory,allowProvidedElsewhere,dataElement%5Bid,name,code,formName,valueType,optionSetValue,optionSet%5Bid,name,options%5Bcode,name%5D%5D%5D%5D%5D" ) ).andExpect( method( HttpMethod.GET ) ) .andRespond( MockRestResponseCreators.withStatus( HttpStatus.NOT_FOUND ).body( "{}" ).contentType( MediaType.APPLICATION_JSON ) ); @@ -106,8 +106,8 @@ public void findMetadataByReferenceIdNotFound() @Test( expected = HttpServerErrorException.class ) public void findMetadataByReferenceIdServerError() { - mockServer.expect( requestTo( "http://localhost:8080/api/programs/93783.json?fields=id,name,code,selectIncidentDatesInFuture,selectEnrollmentDatesInFuture,displayIncidentDate,registration,withoutRegistration,captureCoordinates," + - "trackedEntityType%5Bid%5D,programTrackedEntityAttributes%5Bid,name,valueType,mandatory,allowFutureDate,trackedEntityAttribute%5Bid,name,code,valueType,generated%5D%5D,programStages%5Bid,name,repeatable,captureCoordinates," + + mockServer.expect( requestTo( "http://localhost:8080/api/programs/93783.json?fields=id,name,code,description,selectIncidentDatesInFuture,selectEnrollmentDatesInFuture,displayIncidentDate,registration,withoutRegistration,captureCoordinates," + + "trackedEntityType%5Bid%5D,programTrackedEntityAttributes%5Bid,name,valueType,mandatory,allowFutureDate,trackedEntityAttribute%5Bid,name,code,valueType,generated%5D%5D,programStages%5Bid,name,description,repeatable,captureCoordinates," + "generatedByEnrollmentDate,minDaysFromStart,programStageDataElements%5Bid,compulsory,allowProvidedElsewhere,dataElement%5Bid,name,code,formName,valueType,optionSetValue,optionSet%5Bid,name,options%5Bcode,name%5D%5D%5D%5D%5D" ) ).andExpect( method( HttpMethod.GET ) ) .andRespond( MockRestResponseCreators.withServerError() ); service.findMetadataByReference( new Reference( "93783", ReferenceType.ID ) ); @@ -116,8 +116,8 @@ public void findMetadataByReferenceIdServerError() @Test public void findMetadataByReferenceCode() throws IOException { - mockServer.expect( requestTo( "http://localhost:8080/api/programs.json?paging=false&fields=id,name,code,selectIncidentDatesInFuture,selectEnrollmentDatesInFuture,displayIncidentDate,registration,withoutRegistration,captureCoordinates," + - "trackedEntityType%5Bid%5D,programTrackedEntityAttributes%5Bid,name,valueType,mandatory,allowFutureDate,trackedEntityAttribute%5Bid,name,code,valueType,generated%5D%5D,programStages%5Bid,name,repeatable,captureCoordinates," + + mockServer.expect( requestTo( "http://localhost:8080/api/programs.json?paging=false&fields=id,name,code,description,selectIncidentDatesInFuture,selectEnrollmentDatesInFuture,displayIncidentDate,registration,withoutRegistration,captureCoordinates," + + "trackedEntityType%5Bid%5D,programTrackedEntityAttributes%5Bid,name,valueType,mandatory,allowFutureDate,trackedEntityAttribute%5Bid,name,code,valueType,generated%5D%5D,programStages%5Bid,name,description,repeatable,captureCoordinates," + "generatedByEnrollmentDate,minDaysFromStart,programStageDataElements%5Bid,compulsory,allowProvidedElsewhere,dataElement%5Bid,name,code,formName,valueType,optionSetValue,optionSet%5Bid,name,options%5Bcode," + "name%5D%5D%5D%5D%5D&filter=code:eq:OU_3783" ) ).andExpect( method( HttpMethod.GET ) ) .andRespond( withSuccess( IOUtils.resourceToByteArray( "/org/dhis2/fhir/adapter/dhis/tracker/program/impl/programs.json" ), MediaType.APPLICATION_JSON ) ); @@ -130,8 +130,8 @@ public void findMetadataByReferenceCode() throws IOException @Test public void findMetadataByReferenceCodeNotFound() throws IOException { - mockServer.expect( requestTo( "http://localhost:8080/api/programs.json?paging=false&fields=id,name,code,selectIncidentDatesInFuture,selectEnrollmentDatesInFuture,displayIncidentDate,registration,withoutRegistration,captureCoordinates," + - "trackedEntityType%5Bid%5D,programTrackedEntityAttributes%5Bid,name,valueType,mandatory,allowFutureDate,trackedEntityAttribute%5Bid,name,code,valueType,generated%5D%5D,programStages%5Bid,name,repeatable,captureCoordinates," + + mockServer.expect( requestTo( "http://localhost:8080/api/programs.json?paging=false&fields=id,name,code,description,selectIncidentDatesInFuture,selectEnrollmentDatesInFuture,displayIncidentDate,registration,withoutRegistration,captureCoordinates," + + "trackedEntityType%5Bid%5D,programTrackedEntityAttributes%5Bid,name,valueType,mandatory,allowFutureDate,trackedEntityAttribute%5Bid,name,code,valueType,generated%5D%5D,programStages%5Bid,name,description,repeatable,captureCoordinates," + "generatedByEnrollmentDate,minDaysFromStart,programStageDataElements%5Bid,compulsory,allowProvidedElsewhere,dataElement%5Bid,name,code,formName,valueType,optionSetValue,optionSet%5Bid,name,options%5Bcode," + "name%5D%5D%5D%5D%5D&filter=code:eq:OU_3783" ) ).andExpect( method( HttpMethod.GET ) ) .andRespond( withSuccess( IOUtils.resourceToByteArray( "/org/dhis2/fhir/adapter/dhis/tracker/program/impl/emptyPrograms.json" ), MediaType.APPLICATION_JSON ) ); @@ -143,8 +143,8 @@ public void findMetadataByReferenceCodeNotFound() throws IOException @Test public void findMetadataByReferenceName() throws IOException { - mockServer.expect( requestTo( "http://localhost:8080/api/programs.json?paging=false&fields=id,name,code,selectIncidentDatesInFuture,selectEnrollmentDatesInFuture,displayIncidentDate,registration,withoutRegistration,captureCoordinates," + - "trackedEntityType%5Bid%5D,programTrackedEntityAttributes%5Bid,name,valueType,mandatory,allowFutureDate,trackedEntityAttribute%5Bid,name,code,valueType,generated%5D%5D,programStages%5Bid,name,repeatable,captureCoordinates," + + mockServer.expect( requestTo( "http://localhost:8080/api/programs.json?paging=false&fields=id,name,code,description,selectIncidentDatesInFuture,selectEnrollmentDatesInFuture,displayIncidentDate,registration,withoutRegistration,captureCoordinates," + + "trackedEntityType%5Bid%5D,programTrackedEntityAttributes%5Bid,name,valueType,mandatory,allowFutureDate,trackedEntityAttribute%5Bid,name,code,valueType,generated%5D%5D,programStages%5Bid,name,description,repeatable,captureCoordinates," + "generatedByEnrollmentDate,minDaysFromStart,programStageDataElements%5Bid,compulsory,allowProvidedElsewhere,dataElement%5Bid,name,code,formName,valueType,optionSetValue,optionSet%5Bid,name,options%5Bcode," + "name%5D%5D%5D%5D%5D&filter=name:eq:Freetown" ) ).andExpect( method( HttpMethod.GET ) ) .andRespond( withSuccess( IOUtils.resourceToByteArray( "/org/dhis2/fhir/adapter/dhis/tracker/program/impl/programs.json" ), MediaType.APPLICATION_JSON ) ); @@ -157,8 +157,8 @@ public void findMetadataByReferenceName() throws IOException @Test public void findMetadataByReferenceNameNotFound() throws IOException { - mockServer.expect( requestTo( "http://localhost:8080/api/programs.json?paging=false&fields=id,name,code,selectIncidentDatesInFuture,selectEnrollmentDatesInFuture,displayIncidentDate,registration,withoutRegistration,captureCoordinates," + - "trackedEntityType%5Bid%5D,programTrackedEntityAttributes%5Bid,name,valueType,mandatory,allowFutureDate,trackedEntityAttribute%5Bid,name,code,valueType,generated%5D%5D,programStages%5Bid,name,repeatable,captureCoordinates," + + mockServer.expect( requestTo( "http://localhost:8080/api/programs.json?paging=false&fields=id,name,code,description,selectIncidentDatesInFuture,selectEnrollmentDatesInFuture,displayIncidentDate,registration,withoutRegistration,captureCoordinates," + + "trackedEntityType%5Bid%5D,programTrackedEntityAttributes%5Bid,name,valueType,mandatory,allowFutureDate,trackedEntityAttribute%5Bid,name,code,valueType,generated%5D%5D,programStages%5Bid,name,description,repeatable,captureCoordinates," + "generatedByEnrollmentDate,minDaysFromStart,programStageDataElements%5Bid,compulsory,allowProvidedElsewhere,dataElement%5Bid,name,code,formName,valueType,optionSetValue,optionSet%5Bid,name,options%5Bcode," + "name%5D%5D%5D%5D%5D&filter=name:eq:Freetown" ) ).andExpect( method( HttpMethod.GET ) ) .andRespond( withSuccess( IOUtils.resourceToByteArray( "/org/dhis2/fhir/adapter/dhis/tracker/program/impl/emptyPrograms.json" ), MediaType.APPLICATION_JSON ) ); diff --git a/docs/fhir/profiles/TrackerProgramPlanDefinition.StructureDefinition.xml b/docs/fhir/profiles/TrackerProgramPlanDefinition.StructureDefinition.xml index 9dbe8bd0..38b47048 100644 --- a/docs/fhir/profiles/TrackerProgramPlanDefinition.StructureDefinition.xml +++ b/docs/fhir/profiles/TrackerProgramPlanDefinition.StructureDefinition.xml @@ -200,10 +200,18 @@ + + + + + + + + @@ -286,6 +294,7 @@ + diff --git a/fhir-r4/src/main/java/org/dhis2/fhir/adapter/fhir/transform/dhis/impl/metadata/r4/R4ProgramMetadataToFhirCarePlanTransformer.java b/fhir-r4/src/main/java/org/dhis2/fhir/adapter/fhir/transform/dhis/impl/metadata/r4/R4ProgramMetadataToFhirCarePlanTransformer.java index 2869b0c6..4fbd6e20 100644 --- a/fhir-r4/src/main/java/org/dhis2/fhir/adapter/fhir/transform/dhis/impl/metadata/r4/R4ProgramMetadataToFhirCarePlanTransformer.java +++ b/fhir-r4/src/main/java/org/dhis2/fhir/adapter/fhir/transform/dhis/impl/metadata/r4/R4ProgramMetadataToFhirCarePlanTransformer.java @@ -29,31 +29,47 @@ */ import org.dhis2.fhir.adapter.dhis.orgunit.OrganizationUnitService; -import org.dhis2.fhir.adapter.dhis.tracker.program.ProgramMetadataService; +import org.dhis2.fhir.adapter.dhis.tracker.program.Program; +import org.dhis2.fhir.adapter.dhis.tracker.trackedentity.TrackedEntityMetadataService; import org.dhis2.fhir.adapter.fhir.data.repository.FhirDhisAssignmentRepository; +import org.dhis2.fhir.adapter.fhir.metadata.model.FhirClient; import org.dhis2.fhir.adapter.fhir.metadata.model.FhirResourceType; +import org.dhis2.fhir.adapter.fhir.metadata.model.ProgramMetadataRule; +import org.dhis2.fhir.adapter.fhir.metadata.model.RuleInfo; import org.dhis2.fhir.adapter.fhir.metadata.repository.SystemRepository; +import org.dhis2.fhir.adapter.fhir.metadata.repository.TrackedEntityRuleRepository; import org.dhis2.fhir.adapter.fhir.model.FhirVersion; import org.dhis2.fhir.adapter.fhir.repository.FhirResourceRepository; import org.dhis2.fhir.adapter.fhir.script.ScriptExecutor; -import org.dhis2.fhir.adapter.fhir.transform.dhis.impl.metadata.AbstractProgramMetadataToFhirCarePlanTransformer; +import org.dhis2.fhir.adapter.fhir.transform.dhis.DhisToFhirTransformerContext; +import org.dhis2.fhir.adapter.fhir.transform.dhis.impl.metadata.program.AbstractProgramMetadataToFhirCarePlanTransformer; +import org.dhis2.fhir.adapter.fhir.transform.scripted.AccessibleScriptedDhisMetadata; import org.dhis2.fhir.adapter.lock.LockManager; +import org.hl7.fhir.instance.model.api.IBaseResource; +import org.hl7.fhir.r4.model.CanonicalType; +import org.hl7.fhir.r4.model.Enumerations; import org.hl7.fhir.r4.model.PlanDefinition; +import org.hl7.fhir.r4.model.PlanDefinition.PlanDefinitionActionComponent; +import org.springframework.stereotype.Component; import javax.annotation.Nonnull; +import java.util.Map; import java.util.Set; /** - * R4 specific version of DHIS 2 Program Metadata to FHIR Plan Definition transformer. + * R4 specific version of DHIS2 Program Metadata to FHIR Plan Definition transformer. * * @author volsch */ +@Component public class R4ProgramMetadataToFhirCarePlanTransformer extends AbstractProgramMetadataToFhirCarePlanTransformer { public R4ProgramMetadataToFhirCarePlanTransformer( @Nonnull ScriptExecutor scriptExecutor, @Nonnull LockManager lockManager, @Nonnull SystemRepository systemRepository, @Nonnull FhirResourceRepository fhirResourceRepository, - @Nonnull FhirDhisAssignmentRepository fhirDhisAssignmentRepository, @Nonnull OrganizationUnitService organizationUnitService, @Nonnull ProgramMetadataService programMetadataService ) + @Nonnull FhirDhisAssignmentRepository fhirDhisAssignmentRepository, @Nonnull OrganizationUnitService organizationUnitService, + @Nonnull TrackedEntityMetadataService trackedEntityMetadataService, @Nonnull TrackedEntityRuleRepository trackedEntityRuleRepository ) { - super( scriptExecutor, lockManager, systemRepository, fhirResourceRepository, fhirDhisAssignmentRepository, organizationUnitService, programMetadataService ); + super( scriptExecutor, lockManager, systemRepository, fhirResourceRepository, fhirDhisAssignmentRepository, organizationUnitService, + trackedEntityMetadataService, trackedEntityRuleRepository ); } @Nonnull @@ -63,10 +79,35 @@ public Set getFhirVersions() return FhirVersion.R4_ONLY; } - @Nonnull @Override - protected FhirResourceType getFhirResourceType() + protected boolean transformInternal( @Nonnull FhirClient fhirClient, @Nonnull DhisToFhirTransformerContext context, @Nonnull RuleInfo ruleInfo, @Nonnull Map scriptVariables, + @Nonnull AccessibleScriptedDhisMetadata input, @Nonnull IBaseResource output ) { - return FhirResourceType.PLAN_DEFINITION; + final Program dhisProgram = (Program) input.getDhisResource(); + final PlanDefinition fhirPlanDefinition = (PlanDefinition) output; + + if ( !isApplicableProgram( dhisProgram ) ) + { + return false; + } + + fhirPlanDefinition.setUrl( dhisProgram.getId() ); + fhirPlanDefinition.setName( dhisProgram.getName() ); + fhirPlanDefinition.setStatus( Enumerations.PublicationStatus.ACTIVE ); + fhirPlanDefinition.setDescription( dhisProgram.getDescription() ); + fhirPlanDefinition.setAction( null ); + + dhisProgram.getStages().forEach( dhisProgramStage -> { + final PlanDefinitionActionComponent action = fhirPlanDefinition.addAction(); + + action.setId( dhisProgramStage.getId() ); + action.setTitle( dhisProgramStage.getName() ); + action.setDescription( dhisProgramStage.getDescription() ); + action.setCardinalityBehavior( dhisProgramStage.isRepeatable() ? + PlanDefinition.ActionCardinalityBehavior.MULTIPLE : PlanDefinition.ActionCardinalityBehavior.SINGLE ); + action.setDefinition( new CanonicalType( FhirResourceType.QUESTIONNAIRE.getResourceTypeName() + "/" + dhisProgramStage.getId() ) ); + } ); + + return true; } } diff --git a/fhir-r4/src/main/java/org/dhis2/fhir/adapter/fhir/transform/dhis/impl/metadata/r4/R4ProgramMetadataToFhirDataProvider.java b/fhir-r4/src/main/java/org/dhis2/fhir/adapter/fhir/transform/dhis/impl/metadata/r4/R4ProgramMetadataToFhirDataProvider.java new file mode 100644 index 00000000..180a4560 --- /dev/null +++ b/fhir-r4/src/main/java/org/dhis2/fhir/adapter/fhir/transform/dhis/impl/metadata/r4/R4ProgramMetadataToFhirDataProvider.java @@ -0,0 +1,70 @@ +package org.dhis2.fhir.adapter.fhir.transform.dhis.impl.metadata.r4; + +/* + * Copyright (c) 2004-2019, 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.tracker.program.ProgramMetadataService; +import org.dhis2.fhir.adapter.fhir.metadata.model.ProgramMetadataRule; +import org.dhis2.fhir.adapter.fhir.metadata.model.RuleInfo; +import org.dhis2.fhir.adapter.fhir.model.FhirVersion; +import org.dhis2.fhir.adapter.fhir.script.ScriptExecutor; +import org.dhis2.fhir.adapter.fhir.transform.dhis.impl.metadata.program.AbstractProgramMetadataToFhirDataProvider; +import org.dhis2.fhir.adapter.fhir.transform.dhis.search.SearchFilter; +import org.dhis2.fhir.adapter.fhir.transform.dhis.search.SearchParamType; +import org.hl7.fhir.r4.model.PlanDefinition; +import org.springframework.stereotype.Component; + +import javax.annotation.Nonnull; +import java.util.Set; + +/** + * R4 specific version of DHIS2 Program Metadata data provider. + * + * @author volsch + */ +@Component +public class R4ProgramMetadataToFhirDataProvider extends AbstractProgramMetadataToFhirDataProvider +{ + public R4ProgramMetadataToFhirDataProvider( @Nonnull ScriptExecutor scriptExecutor, @Nonnull ProgramMetadataService programMetadataService ) + { + super( scriptExecutor, programMetadataService ); + } + + @Nonnull + @Override + public Set getFhirVersions() + { + return FhirVersion.R4_ONLY; + } + + @Override + protected void initSearchFilter( @Nonnull FhirVersion fhirVersion, @Nonnull RuleInfo ruleInfo, @Nonnull SearchFilter searchFilter ) + { + searchFilter.add( PlanDefinition.SP_NAME, SearchParamType.STRING, "name" ); + } +} diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/converter/AbstractStringToAdministrativeGenderConverter.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/converter/AbstractStringToAdministrativeGenderConverter.java index 29e20d48..a4d08fbf 100644 --- a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/converter/AbstractStringToAdministrativeGenderConverter.java +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/converter/AbstractStringToAdministrativeGenderConverter.java @@ -1,7 +1,7 @@ package org.dhis2.fhir.adapter.fhir.converter; /* - * Copyright (c) 2004-2018, University of Oslo + * Copyright (c) 2004-2019, University of Oslo * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -40,7 +40,7 @@ import static org.dhis2.fhir.adapter.fhir.converter.AbstractAdministrativeGenderToStringConverter.GENDER_MALE_CONSTANT_CODE; /** - * Abstract implementation of the converter that converts the DHIS 2 option value + * Abstract implementation of the converter that converts the DHIS2 option value * for the gender to the FHIR administrative gender. * * @param the concrete FHIR version specific type of the administrative gender. diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/repository/DhisMissingResourceException.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/repository/DhisMissingResourceException.java index dfb32540..32605c06 100644 --- a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/repository/DhisMissingResourceException.java +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/repository/DhisMissingResourceException.java @@ -33,7 +33,7 @@ import javax.annotation.Nonnull; /** - * Thrown if the included DHIS 2 resource is missing on FHIR client and it should + * Thrown if the included DHIS2 resource is missing on FHIR client and it should * be tried to create the missing FHIR resource before retrying to process the * current resource again. * 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 index 704317e5..fc4fcdb4 100644 --- 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 @@ -46,7 +46,7 @@ import java.util.Set; /** - * The repository that is used to store DHIS 2 Resources. + * The repository that is used to store DHIS2 Resources. * * @author volsch */ diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/repository/MissingDhisResourceException.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/repository/MissingDhisResourceException.java index 8e59c850..dfac1a61 100644 --- a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/repository/MissingDhisResourceException.java +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/repository/MissingDhisResourceException.java @@ -33,7 +33,7 @@ import javax.annotation.Nonnull; /** - * Thrown if the included DHIS 2 resource is missing on FHIR client and it should + * Thrown if the included DHIS2 resource is missing on FHIR client and it should * be tried to create the missing FHIR resource before retrying to process the * current resource again. * 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 index c9f0936c..a613d7a2 100644 --- 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 @@ -503,8 +503,7 @@ public Optional read( @Nonnull FhirClient fhirClient, @Nonnull Fh dhisRequest.setCompleteTransformation( matchingRule ); dhisRequest.setIncludeReferences( matchingRule ); - final DhisToFhirTransformOutcome outcome = - dhisToFhirTransformerService.transform( transformerRequest ); + final DhisToFhirTransformOutcome outcome = dhisToFhirTransformerService.transform( transformerRequest ); if ( outcome == null ) { transformerRequest = null; diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/script/ScriptExecutionContext.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/script/ScriptExecutionContext.java index 7de25e1d..83fa5b30 100644 --- a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/script/ScriptExecutionContext.java +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/script/ScriptExecutionContext.java @@ -39,6 +39,12 @@ */ public interface ScriptExecutionContext { + /** + * @return true if there is an active script execution, + * false otherwise. + */ + boolean hasScriptExecution(); + /*** * Gets or creates a script execution that is bound to the current scope. * diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/script/ScriptExecutionForbidden.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/script/ScriptExecutionForbidden.java new file mode 100644 index 00000000..8276fb5b --- /dev/null +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/script/ScriptExecutionForbidden.java @@ -0,0 +1,50 @@ +package org.dhis2.fhir.adapter.fhir.script; + +/* + * Copyright (c) 2004-2019, 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 java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Methods may be marked with this annotation to identify that execution of + * these methods forbid an available {@link ScriptExecutionContext}. Methods + * marked with this annotation must not be invoked by scripts. + * + * @author volsch + */ +@Target( { ElementType.METHOD } ) +@Retention( RetentionPolicy.CLASS ) +@Documented +public @interface ScriptExecutionForbidden +{ + // nothing to declare +} diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/script/impl/ThreadLocalScriptExecutionContext.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/script/impl/ThreadLocalScriptExecutionContext.java index 2e72524a..31962f9a 100644 --- a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/script/impl/ThreadLocalScriptExecutionContext.java +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/script/impl/ThreadLocalScriptExecutionContext.java @@ -1,7 +1,7 @@ package org.dhis2.fhir.adapter.fhir.script.impl; /* - * Copyright (c) 2004-2018, University of Oslo + * Copyright (c) 2004-2019, University of Oslo * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -44,16 +44,23 @@ public class ThreadLocalScriptExecutionContext implements ScriptExecutionContext { private static final ThreadLocal THREAD_LOCAL = new ThreadLocal<>(); + public boolean hasScriptExecution() + { + return THREAD_LOCAL.get() != null; + } + @Nonnull @Override public ScriptExecution getScriptExecution() { ScriptExecution scriptExecution = THREAD_LOCAL.get(); + if ( scriptExecution == null ) { scriptExecution = new ScriptExecutionImpl(); THREAD_LOCAL.set( scriptExecution ); } + return scriptExecution; } @@ -63,6 +70,7 @@ public ScriptExecution setScriptExecution( @Nonnull ScriptExecution scriptExecut { final ScriptExecution currentScriptExecution = THREAD_LOCAL.get(); THREAD_LOCAL.set( scriptExecution ); + return currentScriptExecution; } 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 index f6b92b15..9887d1dd 100644 --- 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 @@ -1,7 +1,7 @@ package org.dhis2.fhir.adapter.fhir.transform.dhis; /* - * Copyright (c) 2004-2018, University of Oslo + * Copyright (c) 2004-2019, University of Oslo * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -36,7 +36,7 @@ import java.io.Serializable; /** - * The outcome of the transformation between a DHIS 2 resource and a FHIR resource. + * The outcome of the transformation between a DHIS2 resource and a FHIR resource. * * @param the concrete type of the returned FHIR resource. * @author volsch 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 index d3fcba0c..db8973ed 100644 --- 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 @@ -53,7 +53,7 @@ import java.util.UUID; /** - * The context of the current transformation between a DHIS 2 resource to a FHIR resource. + * The context of the current transformation between a DHIS2 resource to a FHIR resource. * * @author volsch */ 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 index aa6e3917..fb9b58ca 100644 --- 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 @@ -47,7 +47,7 @@ import java.util.UUID; /** - * Transforms a DHIS 2 resource to a FHIR resource by applying defines rules. + * Transforms a DHIS2 resource to a FHIR resource by applying defines rules. * * @author volsch */ diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/dhis/impl/AbstractDhisToFhirDataProvider.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/dhis/impl/AbstractDhisToFhirDataProvider.java index 131d5c26..fb0448d5 100644 --- a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/dhis/impl/AbstractDhisToFhirDataProvider.java +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/dhis/impl/AbstractDhisToFhirDataProvider.java @@ -74,11 +74,11 @@ protected AbstractDhisToFhirDataProvider( @Nonnull ScriptExecutor scriptExecutor protected SearchFilterCollector apply( @Nonnull FhirVersion fhirVersion, @Nonnull List> ruleInfos, @Nonnull SearchFilterCollector searchFilterCollector ) { ruleInfos.forEach( ruleInfo -> { + final SearchFilter searchFilter = new SearchFilter( searchFilterCollector, onlyStringContains ); + initSearchFilter( fhirVersion, ruleInfo, searchFilter ); + if ( ruleInfo.getRule().getFilterScript() != null ) { - final SearchFilter searchFilter = new SearchFilter( searchFilterCollector, onlyStringContains ); - initSearchFilter( fhirVersion, ruleInfo, searchFilter ); - final Boolean result = scriptExecutor.execute( ruleInfo.getRule().getFilterScript(), fhirVersion, Collections.singletonMap( ScriptVariable.SEARCH_FILTER.getVariableName(), searchFilter ), Collections.emptyMap(), Boolean.class ); diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/dhis/impl/AbstractDhisToFhirTransformer.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/dhis/impl/AbstractDhisToFhirTransformer.java index c9f13381..222cdbeb 100644 --- a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/dhis/impl/AbstractDhisToFhirTransformer.java +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/dhis/impl/AbstractDhisToFhirTransformer.java @@ -73,9 +73,9 @@ import java.util.Optional; /** - * Transforms a DHIS 2 resource to a FHIR resource. + * Transforms a DHIS2 resource to a FHIR resource. * - * @param the concrete type of the DHIS 2 resource that is processed by this transformer. + * @param the concrete type of the DHIS2 resource that is processed by this transformer. * @param the concrete type of the transformer rule that is processed by this transformer. * @author volsch */ @@ -198,19 +198,20 @@ protected Optional getResource( @Nonnull FhirClient fhi if ( context.getDhisRequest().isDhisFhirId() ) { final IBaseResource baseResource = createResource( fhirClient, context, ruleInfo, scriptVariables, false ); + if ( baseResource == null ) { return Optional.empty(); } - final ScriptedDhisResource scriptedDhisResource = - TransformerUtils.getScriptVariable( scriptVariables, ScriptVariable.INPUT, ScriptedDhisResource.class ); - baseResource.setId( new IdDt( ruleInfo.getRule().getFhirResourceType().getResourceTypeName(), - DhisFhirResourceId.toString( scriptedDhisResource.getResourceType(), Objects.requireNonNull( scriptedDhisResource.getId() ), ruleInfo.getRule().getId() ) ) ); + final ScriptedDhisResource scriptedDhisResource = TransformerUtils.getScriptVariable( scriptVariables, ScriptVariable.INPUT, ScriptedDhisResource.class ); + baseResource.setId( new IdDt( ruleInfo.getRule().getFhirResourceType().getResourceTypeName(), createDhisFhirResourceId( ruleInfo, scriptedDhisResource ) ) ); + if ( context.getDhisRequest().getLastUpdated() != null ) { baseResource.getMeta().setLastUpdated( Date.from( context.getDhisRequest().getLastUpdated().toInstant() ) ); } + // FHIR resource will be filled with read data return Optional.of( baseResource ); } @@ -234,6 +235,19 @@ protected Optional getResource( @Nonnull FhirClient fhi return Optional.ofNullable( resource ); } + @Nonnull + protected String createDhisFhirResourceId( @Nonnull RuleInfo ruleInfo, @Nonnull ScriptedDhisResource dhisResource ) + { + if ( ruleInfo.getRule().isSimpleFhirId() ) + { + return DhisFhirResourceId.toString( null, Objects.requireNonNull( dhisResource.getId() ), null ); + } + else + { + return DhisFhirResourceId.toString( dhisResource.getResourceType(), Objects.requireNonNull( dhisResource.getId() ), ruleInfo.getRule().getId() ); + } + } + @Nonnull protected Optional getResourceByAdapterIdentifier( @Nonnull FhirClient fhirClient, @Nonnull DhisToFhirTransformerContext context, @@ -330,6 +344,7 @@ protected IBaseResource createResource( @Nonnull FhirClient fhirClient, @Nonnull { return null; } + return resource; } @@ -339,8 +354,8 @@ protected boolean updateIdentifiers( @Nonnull DhisToFhirTransformerContext conte getDhisResourceClass().cast( TransformerUtils.getScriptVariable( scriptVariables, ScriptVariable.INPUT, ScriptedDhisResource.class ) ); final AbstractIdentifierDhisToFhirTransformerUtils identifierUtils = TransformerUtils.getScriptVariable( scriptVariables, ScriptVariable.IDENTIFIER_UTILS, AbstractIdentifierDhisToFhirTransformerUtils.class ); - final ResourceSystem resourceSystem = context.getResourceSystem( ruleInfo.getRule().getFhirResourceType() ); + if ( resourceSystem != null ) { final String identifierValue = getIdentifierValue( context, ruleInfo, null, scriptedDhisResource, scriptVariables ); @@ -356,11 +371,14 @@ protected boolean updateIdentifiers( @Nonnull DhisToFhirTransformerContext conte identifierValue, resourceSystem.getCodePrefix(), ruleInfo.getRule().getFhirResourceType() ); return false; } + final SystemCodeValue identifier = new SystemCodeValue( resourceSystem.getSystem(), identifierValue.substring( StringUtils.length( resourceSystem.getCodePrefix() ) ) ); + if ( sync ) { lockFhirIdentifier( context, identifier ); } + identifierUtils.addOrUpdateIdentifier( resource, identifier, resourceSystem.getFhirDisplayName() ); } } @@ -369,12 +387,15 @@ protected boolean updateIdentifiers( @Nonnull DhisToFhirTransformerContext conte { final System adapterIdentifierSystem = getAdapterIdentifierSystem(); final SystemCodeValue identifier = new SystemCodeValue( adapterIdentifierSystem.getSystemUri(), createAdapterIdentifierValue( ruleInfo, scriptedDhisResource ) ); + if ( sync ) { lockFhirIdentifier( context, identifier ); } + identifierUtils.addOrUpdateIdentifier( resource, identifier, adapterIdentifierSystem.getFhirDisplayName(), true ); } + return true; } diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/dhis/impl/DhisToFhirRequestResolver.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/dhis/impl/DhisToFhirRequestResolver.java index f98dc87a..ee7d7494 100644 --- a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/dhis/impl/DhisToFhirRequestResolver.java +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/dhis/impl/DhisToFhirRequestResolver.java @@ -41,8 +41,8 @@ import java.util.Optional; /** - * Resolves the rules for transformations from DHIS 2 resources to FHIR resources - * depending on the DHIS 2 resource type. + * Resolves the rules for transformations from DHIS2 resources to FHIR resources + * depending on the DHIS2 resource type. * * @author volsch */ diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/dhis/impl/DhisToFhirTransformer.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/dhis/impl/DhisToFhirTransformer.java index 64929cfb..ae5737a8 100644 --- a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/dhis/impl/DhisToFhirTransformer.java +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/dhis/impl/DhisToFhirTransformer.java @@ -44,9 +44,9 @@ import java.util.Map; /** - * Transforms a DHIS 2 resource to a FHIR resource. + * Transforms a DHIS2 resource to a FHIR resource. * - * @param the concrete type of the DHIS 2 resource that is processed by this transformer. + * @param the concrete type of the DHIS2 resource that is processed by this transformer. * @param the concrete type of the transformer rule that is processed by this transformer. * @author volsch */ diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/dhis/impl/DhisToFhirTransformerServiceImpl.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/dhis/impl/DhisToFhirTransformerServiceImpl.java index 2caf885c..ef9c1666 100644 --- a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/dhis/impl/DhisToFhirTransformerServiceImpl.java +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/dhis/impl/DhisToFhirTransformerServiceImpl.java @@ -50,6 +50,7 @@ import org.dhis2.fhir.adapter.fhir.model.FhirVersion; import org.dhis2.fhir.adapter.fhir.model.FhirVersionedValue; import org.dhis2.fhir.adapter.fhir.model.SystemCodeValue; +import org.dhis2.fhir.adapter.fhir.script.ScriptExecutionContext; import org.dhis2.fhir.adapter.fhir.script.ScriptExecutor; import org.dhis2.fhir.adapter.fhir.transform.FatalTransformerException; import org.dhis2.fhir.adapter.fhir.transform.TransformerDataException; @@ -135,6 +136,8 @@ public class DhisToFhirTransformerServiceImpl implements DhisToFhirTransformerSe private final ScriptExecutor scriptExecutor; + private final ScriptExecutionContext scriptExecutionContext; + public DhisToFhirTransformerServiceImpl( @Nonnull LockManager lockManager, @Nonnull FhirClientResourceRepository fhirClientResourceRepository, @Nonnull FhirClientSystemRepository fhirClientSystemRepository, @@ -145,7 +148,7 @@ public DhisToFhirTransformerServiceImpl( @Nonnull LockManager lockManager, @Nonnull ObjectProvider>> dataProviders, @Nonnull ObjectProvider>> transformersProvider, @Nonnull ObjectProvider> transformUtilsProvider, - @Nonnull ScriptExecutor scriptExecutor ) + @Nonnull ScriptExecutor scriptExecutor, @Nonnull ScriptExecutionContext scriptExecutionContext ) { this.lockManager = lockManager; this.fhirClientResourceRepository = fhirClientResourceRepository; @@ -154,6 +157,7 @@ public DhisToFhirTransformerServiceImpl( @Nonnull LockManager lockManager, this.ruleRepository = ruleRepository; this.requestCacheService = requestCacheService; this.scriptExecutor = scriptExecutor; + this.scriptExecutionContext = scriptExecutionContext; requestResolvers.ifAvailable( resolvers -> resolvers.forEach( r -> this.requestResolvers.put( r.getDhisResourceType(), r ) ) ); @@ -499,6 +503,7 @@ public DhisToFhirTransformOutcome transform( @Nonnull D { transformerRequestCache.put( transformerRequestKey, outcome.getResource() ); } + return new DhisToFhirTransformOutcome<>( 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 @@ -521,7 +526,7 @@ private ScriptedOrganizationUnit getScriptedOrganizationUnit( @Nonnull ScriptedD } final OrganizationUnit organizationUnit = organizationUnitService.findMetadataByReference( new Reference( dhisResource.getOrganizationUnitId(), ReferenceType.ID ) ) .orElseThrow( () -> new TransformerDataException( "DHIS resource " + dhisResource.getResourceId() + " reference organization unit " + dhisResource.getOrganizationUnitId() + " that cannot be found." ) ); - return new ImmutableScriptedOrganizationUnit( new WritableScriptedOrganizationUnit( organizationUnit ) ); + return new ImmutableScriptedOrganizationUnit( new WritableScriptedOrganizationUnit( organizationUnit, scriptExecutionContext ) ); } private boolean isApplicable( @Nonnull DhisToFhirTransformerContext context, @Nonnull ScriptedDhisResource input, diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/dhis/impl/metadata/AbstractDhisMetadataToFhirDataProvider.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/dhis/impl/metadata/AbstractDhisMetadataToFhirDataProvider.java index 30a363b1..a8d569e6 100644 --- a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/dhis/impl/metadata/AbstractDhisMetadataToFhirDataProvider.java +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/dhis/impl/metadata/AbstractDhisMetadataToFhirDataProvider.java @@ -57,7 +57,7 @@ /** * Implementation of {@link DhisToFhirDataProvider} for DHIS2 metadata resources. * - * @param the concrete type of the DHIS 2 resource. + * @param the concrete type of the DHIS2 resource. * @param the concrete type of the rule that performs the transformation. * @author volsch */ diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/dhis/impl/metadata/AbstractReadOnlyDhisMetadataToFhirTransformer.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/dhis/impl/metadata/AbstractReadOnlyDhisMetadataToFhirTransformer.java index 98dc19e0..38fd98dd 100644 --- a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/dhis/impl/metadata/AbstractReadOnlyDhisMetadataToFhirTransformer.java +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/dhis/impl/metadata/AbstractReadOnlyDhisMetadataToFhirTransformer.java @@ -57,10 +57,10 @@ import java.util.Optional; /** - * Abstract Implementation of {@link DhisToFhirTransformer} for transforming DHIS 2 + * Abstract Implementation of {@link DhisToFhirTransformer} for transforming DHIS2 * read-only metadata to FHIR resource. * - * @param the concrete type of the DHIS 2 resource that is processed by this transformer. + * @param the concrete type of the DHIS2 resource that is processed by this transformer. * @param the concrete type of the transformer rule that is processed by this transformer. * @author volsch */ @@ -96,7 +96,11 @@ public DhisToFhirTransformOutcome transform( @Nonnull F } variables.put( ScriptVariable.OUTPUT.getVariableName(), modifiedResource ); - transform( fhirClient, context, ruleInfo, scriptVariables, input, modifiedResource ); + + if ( !transformInternal( fhirClient, context, ruleInfo, scriptVariables, input, modifiedResource ) ) + { + return null; + } if ( !transform( context, ruleInfo, variables ) ) { @@ -117,9 +121,10 @@ protected void addAdditionalVariables( @Nonnull FhirClient fhirClient, @Nonnull // method can be overridden } - protected void transform( @Nonnull FhirClient fhirClient, @Nonnull DhisToFhirTransformerContext context, @Nonnull RuleInfo ruleInfo, @Nonnull Map scriptVariables, @Nonnull R input, @Nonnull IBaseResource output ) + protected boolean transformInternal( @Nonnull FhirClient fhirClient, @Nonnull DhisToFhirTransformerContext context, @Nonnull RuleInfo ruleInfo, @Nonnull Map scriptVariables, @Nonnull R input, @Nonnull IBaseResource output ) { // method can be overridden + return true; } @Nonnull diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/dhis/impl/metadata/AbstractReadOnlyDhisMetadataToTypedFhirTransformer.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/dhis/impl/metadata/AbstractReadOnlyDhisMetadataToTypedFhirTransformer.java index 18d80d1a..1338dfe6 100644 --- a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/dhis/impl/metadata/AbstractReadOnlyDhisMetadataToTypedFhirTransformer.java +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/dhis/impl/metadata/AbstractReadOnlyDhisMetadataToTypedFhirTransformer.java @@ -50,11 +50,11 @@ import java.util.Optional; /** - * Abstract Implementation of {@link DhisToFhirTransformer} for transforming DHIS 2 + * Abstract Implementation of {@link DhisToFhirTransformer} for transforming DHIS2 * read-only metadata to a specific FHIR resource. * - * @param the concrete type of the DHIS 2 resource that is processed by this transformer. - * @param the concrete type of the FHIR resource to which the DHIS 2 resource should be transformed. + * @param the concrete type of the DHIS2 resource that is processed by this transformer. + * @param the concrete type of the FHIR resource to which the DHIS2 resource should be transformed. * @param the concrete type of the transformer rule that is processed by this transformer. * @author volsch */ @@ -73,12 +73,12 @@ protected AbstractReadOnlyDhisMetadataToTypedFhirTransformer( @Nonnull ScriptExe @Override public final DhisToFhirTransformOutcome transform( @Nonnull FhirClient fhirClient, @Nonnull DhisToFhirTransformerContext context, @Nonnull R input, @Nonnull RuleInfo ruleInfo, @Nonnull Map scriptVariables ) throws TransformerException { - if ( getFhirResourceType().equals( ruleInfo.getRule().getFhirResourceType() ) ) + if ( !getFhirResourceType().equals( ruleInfo.getRule().getFhirResourceType() ) ) { return null; } - return transformInternal( fhirClient, context, input, ruleInfo, scriptVariables ); + return super.transform( fhirClient, context, input, ruleInfo, scriptVariables ); } @Nonnull @@ -87,12 +87,4 @@ protected Optional getActiveResource( @Nonnull FhirClie { return Optional.empty(); } - - @Nullable - protected DhisToFhirTransformOutcome transformInternal( @Nonnull FhirClient fhirClient, @Nonnull DhisToFhirTransformerContext context, @Nonnull R input, - @Nonnull RuleInfo ruleInfo, @Nonnull Map scriptVariables ) throws TransformerException - { - // method can be overridden - return null; - } } diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/dhis/impl/metadata/PreparedDhisMetadataToFhirSearch.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/dhis/impl/metadata/PreparedDhisMetadataToFhirSearch.java index 31675dcd..2ac7cf22 100644 --- a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/dhis/impl/metadata/PreparedDhisMetadataToFhirSearch.java +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/dhis/impl/metadata/PreparedDhisMetadataToFhirSearch.java @@ -41,7 +41,7 @@ import java.util.Map; /** - * Implementation of {@link PreparedDhisToFhirSearch} for DHIS 2 metadata. + * Implementation of {@link PreparedDhisToFhirSearch} for DHIS2 metadata. * * @param the concrete type of the rule that processes the metadata. * @author volsch diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/dhis/impl/metadata/orgunit/OrganizationUnitResolver.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/dhis/impl/metadata/orgunit/OrganizationUnitResolver.java index e518b293..2660f5a1 100644 --- a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/dhis/impl/metadata/orgunit/OrganizationUnitResolver.java +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/dhis/impl/metadata/orgunit/OrganizationUnitResolver.java @@ -40,6 +40,7 @@ import org.dhis2.fhir.adapter.fhir.metadata.model.ScriptVariable; import org.dhis2.fhir.adapter.fhir.model.SystemCodeValue; import org.dhis2.fhir.adapter.fhir.repository.FhirResourceRepository; +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.dhis.DhisToFhirTransformerContext; @@ -80,10 +81,12 @@ public class OrganizationUnitResolver private final Map scriptVariables; + private final ScriptExecutionContext scriptExecutionContext; + public OrganizationUnitResolver( @Nonnull OrganizationUnitService organizationUnitService, @Nonnull FhirResourceRepository fhirResourceRepository, @Nonnull FhirClient fhirClient, @Nonnull DhisToFhirTransformerContext context, @Nonnull RuleInfo ruleInfo, @Nonnull Map scriptVariables, - @Nonnull IdentifierValueProvider identifierValueProvider ) + @Nonnull IdentifierValueProvider identifierValueProvider, @Nonnull ScriptExecutionContext scriptExecutionContext ) { this.organizationUnitService = organizationUnitService; this.fhirResourceRepository = fhirResourceRepository; @@ -92,6 +95,7 @@ public OrganizationUnitResolver( this.ruleInfo = ruleInfo; this.scriptVariables = scriptVariables; this.identifierValueProvider = identifierValueProvider; + this.scriptExecutionContext = scriptExecutionContext; } @Nonnull @@ -99,7 +103,7 @@ public ScriptedOrganizationUnit getMandatoryById( @Nonnull String id ) { final OrganizationUnit organizationUnit = organizationUnitService.findMetadataByReference( new Reference( id, ReferenceType.ID ) ) .orElseThrow( () -> new TransformerDataException( "Could not find mandatory DHIS organization unit " + id + "." ) ); - return new ImmutableScriptedOrganizationUnit( new WritableScriptedOrganizationUnit( organizationUnit ) ); + return new ImmutableScriptedOrganizationUnit( new WritableScriptedOrganizationUnit( organizationUnit, scriptExecutionContext ) ); } @Nullable diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/dhis/impl/metadata/orgunit/OrganizationUnitToFhirRequestResolver.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/dhis/impl/metadata/orgunit/OrganizationUnitToFhirRequestResolver.java index 31891a8c..d548465a 100644 --- a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/dhis/impl/metadata/orgunit/OrganizationUnitToFhirRequestResolver.java +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/dhis/impl/metadata/orgunit/OrganizationUnitToFhirRequestResolver.java @@ -33,6 +33,7 @@ import org.dhis2.fhir.adapter.dhis.orgunit.OrganizationUnit; import org.dhis2.fhir.adapter.fhir.metadata.repository.FhirClientRepository; import org.dhis2.fhir.adapter.fhir.metadata.repository.RuleRepository; +import org.dhis2.fhir.adapter.fhir.script.ScriptExecutionContext; import org.dhis2.fhir.adapter.fhir.transform.dhis.impl.DhisToFhirRequestResolver; import org.dhis2.fhir.adapter.fhir.transform.dhis.impl.metadata.AbstractDhisMetadataToFhirRequestResolver; import org.dhis2.fhir.adapter.fhir.transform.dhis.model.DhisRequest; @@ -51,9 +52,12 @@ @Component public class OrganizationUnitToFhirRequestResolver extends AbstractDhisMetadataToFhirRequestResolver { - public OrganizationUnitToFhirRequestResolver( @Nonnull FhirClientRepository fhirClientRepository, @Nonnull RuleRepository ruleRepository ) + private final ScriptExecutionContext scriptExecutionContext; + + public OrganizationUnitToFhirRequestResolver( @Nonnull FhirClientRepository fhirClientRepository, @Nonnull RuleRepository ruleRepository, @Nonnull ScriptExecutionContext scriptExecutionContext ) { super( fhirClientRepository, ruleRepository ); + this.scriptExecutionContext = scriptExecutionContext; } @Nonnull @@ -67,6 +71,6 @@ public DhisResourceType getDhisResourceType() @Override public ScriptedDhisResource convert( @Nonnull DhisResource dhisResource, @Nonnull DhisRequest dhisRequest ) { - return new ImmutableScriptedOrganizationUnit( new WritableScriptedOrganizationUnit( (OrganizationUnit) dhisResource ) ); + return new ImmutableScriptedOrganizationUnit( new WritableScriptedOrganizationUnit( (OrganizationUnit) dhisResource, scriptExecutionContext ) ); } } diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/dhis/impl/metadata/orgunit/OrganizationUnitToFhirTransformer.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/dhis/impl/metadata/orgunit/OrganizationUnitToFhirTransformer.java index 89b8a2a2..9fccb590 100644 --- a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/dhis/impl/metadata/orgunit/OrganizationUnitToFhirTransformer.java +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/dhis/impl/metadata/orgunit/OrganizationUnitToFhirTransformer.java @@ -39,6 +39,7 @@ import org.dhis2.fhir.adapter.fhir.metadata.repository.SystemRepository; import org.dhis2.fhir.adapter.fhir.model.FhirVersion; import org.dhis2.fhir.adapter.fhir.repository.FhirResourceRepository; +import org.dhis2.fhir.adapter.fhir.script.ScriptExecutionContext; import org.dhis2.fhir.adapter.fhir.script.ScriptExecutor; import org.dhis2.fhir.adapter.fhir.transform.dhis.DhisToFhirTransformerContext; import org.dhis2.fhir.adapter.fhir.transform.dhis.impl.DhisToFhirTransformer; @@ -55,7 +56,7 @@ import java.util.Set; /** - * Implementation of {@link DhisToFhirTransformer} for transforming DHIS 2 + * Implementation of {@link DhisToFhirTransformer} for transforming DHIS2 * organization unit to FHIR resources. * * @author volsch @@ -67,11 +68,14 @@ public class OrganizationUnitToFhirTransformer extends AbstractReadOnlyDhisMetad private final OrganizationUnitService organizationUnitService; + private final ScriptExecutionContext scriptExecutionContext; + public OrganizationUnitToFhirTransformer( @Nonnull ScriptExecutor scriptExecutor, @Nonnull LockManager lockManager, @Nonnull SystemRepository systemRepository, @Nonnull FhirResourceRepository fhirResourceRepository, - @Nonnull FhirDhisAssignmentRepository fhirDhisAssignmentRepository, @Nonnull OrganizationUnitService organizationUnitService ) + @Nonnull FhirDhisAssignmentRepository fhirDhisAssignmentRepository, @Nonnull OrganizationUnitService organizationUnitService, @Nonnull ScriptExecutionContext scriptExecutionContext ) { super( scriptExecutor, lockManager, systemRepository, fhirResourceRepository, fhirDhisAssignmentRepository ); this.organizationUnitService = organizationUnitService; + this.scriptExecutionContext = scriptExecutionContext; } @Nonnull @@ -107,7 +111,7 @@ protected void addAdditionalVariables( @Nonnull FhirClient fhirClient, @Nonnull { variables.put( ScriptVariable.ORGANIZATION_UNIT_RESOLVER.getVariableName(), new OrganizationUnitResolver( organizationUnitService, getFhirResourceRepository(), fhirClient, context, ruleInfo, variables, - new DefaultIdentifierValueProvider() ) ); + new DefaultIdentifierValueProvider(), scriptExecutionContext ) ); } @Override diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/dhis/impl/metadata/AbstractProgramMetadataToFhirCarePlanTransformer.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/dhis/impl/metadata/program/AbstractProgramMetadataToFhirCarePlanTransformer.java similarity index 62% rename from fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/dhis/impl/metadata/AbstractProgramMetadataToFhirCarePlanTransformer.java rename to fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/dhis/impl/metadata/program/AbstractProgramMetadataToFhirCarePlanTransformer.java index 4ec531e3..8707f71d 100644 --- a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/dhis/impl/metadata/AbstractProgramMetadataToFhirCarePlanTransformer.java +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/dhis/impl/metadata/program/AbstractProgramMetadataToFhirCarePlanTransformer.java @@ -1,4 +1,4 @@ -package org.dhis2.fhir.adapter.fhir.transform.dhis.impl.metadata; +package org.dhis2.fhir.adapter.fhir.transform.dhis.impl.metadata.program; /* * Copyright (c) 2004-2019, University of Oslo @@ -29,15 +29,22 @@ */ import org.dhis2.fhir.adapter.dhis.model.DhisResourceType; +import org.dhis2.fhir.adapter.dhis.model.Reference; +import org.dhis2.fhir.adapter.dhis.model.ReferenceType; import org.dhis2.fhir.adapter.dhis.orgunit.OrganizationUnitService; -import org.dhis2.fhir.adapter.dhis.tracker.program.ProgramMetadataService; +import org.dhis2.fhir.adapter.dhis.tracker.program.Program; +import org.dhis2.fhir.adapter.dhis.tracker.trackedentity.TrackedEntityMetadataService; +import org.dhis2.fhir.adapter.dhis.tracker.trackedentity.TrackedEntityType; import org.dhis2.fhir.adapter.fhir.data.repository.FhirDhisAssignmentRepository; +import org.dhis2.fhir.adapter.fhir.metadata.model.FhirResourceType; import org.dhis2.fhir.adapter.fhir.metadata.model.ProgramMetadataRule; import org.dhis2.fhir.adapter.fhir.metadata.repository.SystemRepository; +import org.dhis2.fhir.adapter.fhir.metadata.repository.TrackedEntityRuleRepository; import org.dhis2.fhir.adapter.fhir.repository.FhirResourceRepository; import org.dhis2.fhir.adapter.fhir.script.ScriptExecutor; import org.dhis2.fhir.adapter.fhir.transform.dhis.impl.DhisToFhirTransformer; -import org.dhis2.fhir.adapter.fhir.transform.scripted.ScriptedDhisMetadata; +import org.dhis2.fhir.adapter.fhir.transform.dhis.impl.metadata.AbstractReadOnlyDhisMetadataToTypedFhirTransformer; +import org.dhis2.fhir.adapter.fhir.transform.scripted.AccessibleScriptedDhisMetadata; import org.dhis2.fhir.adapter.lock.LockManager; import org.hl7.fhir.instance.model.api.IBaseResource; import org.slf4j.Logger; @@ -46,23 +53,27 @@ import javax.annotation.Nonnull; /** - * Implementation of {@link DhisToFhirTransformer} for transforming DHIS 2 + * Implementation of {@link DhisToFhirTransformer} for transforming DHIS2 * program metadata to FHIR Plan Definition. * - * @param the concrete type of the FHIR resource into which the DHIS 2 resource should be transformed. + * @param the concrete type of the FHIR resource into which the DHIS2 resource should be transformed. * @author volsch */ -public abstract class AbstractProgramMetadataToFhirCarePlanTransformer extends AbstractReadOnlyDhisMetadataToTypedFhirTransformer +public abstract class AbstractProgramMetadataToFhirCarePlanTransformer extends AbstractReadOnlyDhisMetadataToTypedFhirTransformer { private final Logger logger = LoggerFactory.getLogger( getClass() ); - private final ProgramMetadataService programMetadataService; + private final TrackedEntityMetadataService trackedEntityMetadataService; + + private final TrackedEntityRuleRepository trackedEntityRuleRepository; public AbstractProgramMetadataToFhirCarePlanTransformer( @Nonnull ScriptExecutor scriptExecutor, @Nonnull LockManager lockManager, @Nonnull SystemRepository systemRepository, @Nonnull FhirResourceRepository fhirResourceRepository, - @Nonnull FhirDhisAssignmentRepository fhirDhisAssignmentRepository, @Nonnull OrganizationUnitService organizationUnitService, @Nonnull ProgramMetadataService programMetadataService ) + @Nonnull FhirDhisAssignmentRepository fhirDhisAssignmentRepository, @Nonnull OrganizationUnitService organizationUnitService, + @Nonnull TrackedEntityMetadataService trackedEntityMetadataService, @Nonnull TrackedEntityRuleRepository trackedEntityRuleRepository ) { super( scriptExecutor, lockManager, systemRepository, fhirResourceRepository, fhirDhisAssignmentRepository ); - this.programMetadataService = programMetadataService; + this.trackedEntityMetadataService = trackedEntityMetadataService; + this.trackedEntityRuleRepository = trackedEntityRuleRepository; } @Nonnull @@ -74,9 +85,16 @@ public DhisResourceType getDhisResourceType() @Nonnull @Override - public Class getDhisResourceClass() + protected FhirResourceType getFhirResourceType() + { + return FhirResourceType.PLAN_DEFINITION; + } + + @Nonnull + @Override + public Class getDhisResourceClass() { - return ScriptedDhisMetadata.class; + return AccessibleScriptedDhisMetadata.class; } @Nonnull @@ -86,5 +104,20 @@ public Class getRuleClass() return ProgramMetadataRule.class; } + protected boolean isApplicableProgram( @Nonnull Program program ) + { + if ( program.isWithoutRegistration() || program.getTrackedEntityTypeId() == null ) + { + return false; + } + + final TrackedEntityType trackedEntityType = trackedEntityMetadataService.findTypeByReference( new Reference( program.getTrackedEntityTypeId(), ReferenceType.ID ) ).orElse( null ); + if ( trackedEntityType == null ) + { + return false; + } + + return !trackedEntityRuleRepository.findByTypeRefs( trackedEntityType.getAllReferences() ).isEmpty(); + } } diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/dhis/impl/metadata/program/ProgramMetadataToFhirDataProvider.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/dhis/impl/metadata/program/AbstractProgramMetadataToFhirDataProvider.java similarity index 80% rename from fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/dhis/impl/metadata/program/ProgramMetadataToFhirDataProvider.java rename to fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/dhis/impl/metadata/program/AbstractProgramMetadataToFhirDataProvider.java index 0cb8c4e1..e8f6d109 100644 --- a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/dhis/impl/metadata/program/ProgramMetadataToFhirDataProvider.java +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/dhis/impl/metadata/program/AbstractProgramMetadataToFhirDataProvider.java @@ -32,35 +32,24 @@ import org.dhis2.fhir.adapter.dhis.tracker.program.Program; import org.dhis2.fhir.adapter.dhis.tracker.program.ProgramMetadataService; import org.dhis2.fhir.adapter.fhir.metadata.model.ProgramMetadataRule; -import org.dhis2.fhir.adapter.fhir.model.FhirVersion; import org.dhis2.fhir.adapter.fhir.script.ScriptExecutor; import org.dhis2.fhir.adapter.fhir.transform.dhis.DhisToFhirDataProvider; import org.dhis2.fhir.adapter.fhir.transform.dhis.impl.metadata.AbstractDhisMetadataToFhirDataProvider; -import org.springframework.stereotype.Component; import javax.annotation.Nonnull; -import java.util.Set; /** - * Implementation of {@link DhisToFhirDataProvider} for DHIS2 Program Metadata. + * Abstract implementation of {@link DhisToFhirDataProvider} for DHIS2 Program Metadata. * * @author volsch */ -@Component -public class ProgramMetadataToFhirDataProvider extends AbstractDhisMetadataToFhirDataProvider +public abstract class AbstractProgramMetadataToFhirDataProvider extends AbstractDhisMetadataToFhirDataProvider { - public ProgramMetadataToFhirDataProvider( @Nonnull ScriptExecutor scriptExecutor, @Nonnull ProgramMetadataService programMetadataService ) + public AbstractProgramMetadataToFhirDataProvider( @Nonnull ScriptExecutor scriptExecutor, @Nonnull ProgramMetadataService programMetadataService ) { super( scriptExecutor, programMetadataService ); } - @Nonnull - @Override - public Set getFhirVersions() - { - return FhirVersion.ALL; - } - @Nonnull @Override public DhisResourceType getDhisResourceType() diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/dhis/impl/metadata/program/ProgramMetadataToFhirRequestResolver.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/dhis/impl/metadata/program/ProgramMetadataToFhirRequestResolver.java index f5a16ce4..5d0db5c6 100644 --- a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/dhis/impl/metadata/program/ProgramMetadataToFhirRequestResolver.java +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/dhis/impl/metadata/program/ProgramMetadataToFhirRequestResolver.java @@ -33,6 +33,7 @@ import org.dhis2.fhir.adapter.dhis.model.DhisResourceType; import org.dhis2.fhir.adapter.fhir.metadata.repository.FhirClientRepository; import org.dhis2.fhir.adapter.fhir.metadata.repository.RuleRepository; +import org.dhis2.fhir.adapter.fhir.script.ScriptExecutionContext; import org.dhis2.fhir.adapter.fhir.transform.dhis.impl.DhisToFhirRequestResolver; import org.dhis2.fhir.adapter.fhir.transform.dhis.impl.metadata.AbstractDhisMetadataToFhirRequestResolver; import org.dhis2.fhir.adapter.fhir.transform.dhis.model.DhisRequest; @@ -51,9 +52,12 @@ @Component public class ProgramMetadataToFhirRequestResolver extends AbstractDhisMetadataToFhirRequestResolver { - public ProgramMetadataToFhirRequestResolver( @Nonnull FhirClientRepository fhirClientRepository, @Nonnull RuleRepository ruleRepository ) + private final ScriptExecutionContext scriptExecutionContext; + + public ProgramMetadataToFhirRequestResolver( @Nonnull FhirClientRepository fhirClientRepository, @Nonnull RuleRepository ruleRepository, @Nonnull ScriptExecutionContext scriptExecutionContext ) { super( fhirClientRepository, ruleRepository ); + this.scriptExecutionContext = scriptExecutionContext; } @Nonnull @@ -67,6 +71,6 @@ public DhisResourceType getDhisResourceType() @Override public ScriptedDhisResource convert( @Nonnull DhisResource dhisResource, @Nonnull DhisRequest dhisRequest ) { - return new ImmutableScriptedDhisMetadata( new WritableScriptedDhisMetadata<>( (DhisResource & DhisMetadata) dhisResource ) ); + return new ImmutableScriptedDhisMetadata( new WritableScriptedDhisMetadata( (DhisMetadata) dhisResource, scriptExecutionContext ) ); } } diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/dhis/impl/program/ProgramStageToFhirTransformer.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/dhis/impl/program/ProgramStageToFhirTransformer.java index 934deab1..5754fc6f 100644 --- a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/dhis/impl/program/ProgramStageToFhirTransformer.java +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/dhis/impl/program/ProgramStageToFhirTransformer.java @@ -71,7 +71,7 @@ import java.util.Set; /** - * Implementation of {@link DhisToFhirTransformer} for transforming DHIS 2 + * Implementation of {@link DhisToFhirTransformer} for transforming DHIS2 * program stage based events. * * @author volsch diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/dhis/impl/trackedentity/TrackedEntityToFhirTransformer.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/dhis/impl/trackedentity/TrackedEntityToFhirTransformer.java index fed42a30..224de586 100644 --- a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/dhis/impl/trackedentity/TrackedEntityToFhirTransformer.java +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/dhis/impl/trackedentity/TrackedEntityToFhirTransformer.java @@ -63,7 +63,7 @@ import java.util.Set; /** - * Implementation of {@link DhisToFhirTransformer} for transforming DHIS 2 tracked + * Implementation of {@link DhisToFhirTransformer} for transforming DHIS2 tracked * entity instances to FHIR resources. * * @author volsch diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/dhis/impl/util/DhisToFhirTransformerUtils.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/dhis/impl/util/DhisToFhirTransformerUtils.java index 190df456..14259403 100644 --- a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/dhis/impl/util/DhisToFhirTransformerUtils.java +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/dhis/impl/util/DhisToFhirTransformerUtils.java @@ -1,7 +1,7 @@ package org.dhis2.fhir.adapter.fhir.transform.dhis.impl.util; /* - * Copyright (c) 2004-2018, University of Oslo + * Copyright (c) 2004-2019, University of Oslo * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -36,7 +36,7 @@ /** * Base interface for FHIR version restricted domain specific transformations - * utilities methods for DHIS 2 resource to FHIR resource transformations. + * utilities methods for DHIS2 resource to FHIR resource transformations. * * @author volsch */ 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 index 85786597..c026cc14 100644 --- 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 @@ -38,22 +38,22 @@ import java.time.ZonedDateTime; /** - * The DHIS request that caused the transformation from DHIS 2 to FHIR resource. + * The DHIS request that caused the transformation from DHIS2 to FHIR resource. * * @author volsch */ @Scriptable -@ScriptType( value = "DhisRequest", transformType = ScriptTransformType.EXP, description = "The current DHIS 2 request (created or updated resource) that caused the execution of the transformation." ) +@ScriptType( value = "DhisRequest", transformType = ScriptTransformType.EXP, description = "The current DHIS2 request (created or updated resource) that caused the execution of the transformation." ) public interface DhisRequest { @ScriptMethod( description = "Returns if the request uses DHIS FHIR IDs instead of FHIR IDs of a remote FHIR system." ) boolean isDhisFhirId(); - @ScriptMethod( description = "Returns the processed DHIS 2 resource type as Java enumeration (e.g. TRACKED_ENTITY as enum constant)." ) + @ScriptMethod( description = "Returns the processed DHIS2 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." ) + @ScriptMethod( description = "Returns the timestamp when the processed DHIS2 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 index 4dbec30f..66e7e6a0 100644 --- 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 @@ -37,7 +37,7 @@ import java.time.ZonedDateTime; /** - * The immutable DHIS request that caused the transformation from DHIS 2 to FHIR resource. + * The immutable DHIS request that caused the transformation from DHIS2 to FHIR resource. * This can be used in scripts safely. * * @author volsch 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 index b3754a2a..9b17397b 100644 --- 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 @@ -35,7 +35,7 @@ import java.time.ZonedDateTime; /** - * The mutable DHIS request that caused the transformation from DHIS 2 to FHIR resource. + * The mutable DHIS request that caused the transformation from DHIS2 to FHIR resource. * * @author volsch */ diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/dhis/search/SearchFilter.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/dhis/search/SearchFilter.java index ba7bab39..feba74a4 100644 --- a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/dhis/search/SearchFilter.java +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/dhis/search/SearchFilter.java @@ -45,7 +45,7 @@ /** * A generic search filter that prepares the URL filter values - * of requests to DHIS 2. + * of requests to DHIS2. * * @author volsch */ diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/FhirToDhisBaseTransformOutcome.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/FhirToDhisBaseTransformOutcome.java index 70b60d44..39170081 100644 --- a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/FhirToDhisBaseTransformOutcome.java +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/FhirToDhisBaseTransformOutcome.java @@ -35,9 +35,9 @@ import java.io.Serializable; /** - * The base outcome of the transformation between a FHIR resource and a DHIS 2 resource. + * The base outcome of the transformation between a FHIR resource and a DHIS2 resource. * - * @param the concrete type of the returned DHIS 2 resource. + * @param the concrete type of the returned DHIS2 resource. * @author volsch */ public class FhirToDhisBaseTransformOutcome implements Serializable diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/FhirToDhisDeleteTransformOutcome.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/FhirToDhisDeleteTransformOutcome.java index 0454b4e3..69866c8e 100644 --- a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/FhirToDhisDeleteTransformOutcome.java +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/FhirToDhisDeleteTransformOutcome.java @@ -34,10 +34,10 @@ import javax.annotation.Nonnull; /** - * The outcome of the transformation between a FHIR resource and a DHIS 2 resource + * The outcome of the transformation between a FHIR resource and a DHIS2 resource * when a deletion has been requested. * - * @param the concrete type of the returned DHIS 2 resource. + * @param the concrete type of the returned DHIS2 resource. * @author volsch */ public class FhirToDhisDeleteTransformOutcome extends FhirToDhisBaseTransformOutcome diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/FhirToDhisTransformOutcome.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/FhirToDhisTransformOutcome.java index 6464ec16..7da0209a 100644 --- a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/FhirToDhisTransformOutcome.java +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/FhirToDhisTransformOutcome.java @@ -35,9 +35,9 @@ import javax.annotation.Nullable; /** - * The outcome of the transformation between a FHIR resource and a DHIS 2 resource. + * The outcome of the transformation between a FHIR resource and a DHIS2 resource. * - * @param the concrete type of the returned DHIS 2 resource. + * @param the concrete type of the returned DHIS2 resource. * @author volsch */ public class FhirToDhisTransformOutcome extends FhirToDhisBaseTransformOutcome diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/FhirToDhisTransformerContext.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/FhirToDhisTransformerContext.java index 7e8e2759..865b8524 100644 --- a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/FhirToDhisTransformerContext.java +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/FhirToDhisTransformerContext.java @@ -45,7 +45,7 @@ import java.time.ZonedDateTime; /** - * The context of the current transformation between a FHIR resource to a DHIS 2 resource. + * The context of the current transformation between a FHIR resource to a DHIS2 resource. * * @author volsch */ diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/FhirToDhisTransformerService.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/FhirToDhisTransformerService.java index 3c9cfde9..93a30a04 100644 --- a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/FhirToDhisTransformerService.java +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/FhirToDhisTransformerService.java @@ -39,7 +39,7 @@ import javax.annotation.Nullable; /** - * Transforms a FHIR resource to a DHIS 2 resource by applying defines rules. + * Transforms a FHIR resource to a DHIS2 resource by applying defines rules. * * @author volsch */ diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/AbstractFhirToDhisTransformer.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/AbstractFhirToDhisTransformer.java index d93decdf..1a13cf19 100644 --- a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/AbstractFhirToDhisTransformer.java +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/AbstractFhirToDhisTransformer.java @@ -77,7 +77,7 @@ import java.util.Optional; /** - * Abstract base class for all transformers from FHIR to DHIS 2 resources. + * Abstract base class for all transformers from FHIR to DHIS2 resources. * * @param the concrete type of the FHIR resource. * @param the concrete type of transformation rule that this transformer processes. diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/FhirToDhisTransformer.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/FhirToDhisTransformer.java index c1938971..7175fc96 100644 --- a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/FhirToDhisTransformer.java +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/FhirToDhisTransformer.java @@ -46,9 +46,9 @@ import java.util.Map; /** - * Transforms a FHIR resource to a DHIS 2 resource. + * Transforms a FHIR resource to a DHIS2 resource. * - * @param the concrete type of the DHIS 2 resource that is processed by this transformer. + * @param the concrete type of the DHIS2 resource that is processed by this transformer. * @param the concrete type of the transformer rule that is processed by this transformer. * @author volsch */ diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/program/FhirToEnrollmentTransformer.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/program/FhirToEnrollmentTransformer.java index f69ac3c4..cfa8305e 100644 --- a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/program/FhirToEnrollmentTransformer.java +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/program/FhirToEnrollmentTransformer.java @@ -263,7 +263,7 @@ public FhirToDhisTransformOutcome transform( @Nonnull FhirClientReso } @Override - public FhirToDhisDeleteTransformOutcome transformDeletion( @Nonnull FhirClientResource fhirClientResource, RuleInfo ruleInfo, DhisFhirResourceId dhisFhirResourceId ) throws TransformerException + public FhirToDhisDeleteTransformOutcome transformDeletion( @Nonnull FhirClientResource fhirClientResource, @Nonnull RuleInfo ruleInfo, @Nonnull DhisFhirResourceId dhisFhirResourceId ) throws TransformerException { final Enrollment enrollment = new Enrollment(); enrollment.setId( dhisFhirResourceId.getId() ); diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/unsupported/AbstractUnsupportedFhirToDhisTransformer.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/unsupported/AbstractUnsupportedFhirToDhisTransformer.java index 183c3ab1..d48b7e8c 100644 --- a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/unsupported/AbstractUnsupportedFhirToDhisTransformer.java +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/unsupported/AbstractUnsupportedFhirToDhisTransformer.java @@ -54,7 +54,7 @@ import java.util.Set; /** - * Abstract base class for all unsupported transformers from FHIR to DHIS 2 resources. + * Abstract base class for all unsupported transformers from FHIR to DHIS2 resources. * * @param the concrete type of the FHIR resource. * @param the concrete type of transformation rule that this transformer processes. diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/FhirToDhisTransformerUtils.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/FhirToDhisTransformerUtils.java index a21fa678..5c967be2 100644 --- a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/FhirToDhisTransformerUtils.java +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/FhirToDhisTransformerUtils.java @@ -1,7 +1,7 @@ package org.dhis2.fhir.adapter.fhir.transform.fhir.impl.util; /* - * Copyright (c) 2004-2018, University of Oslo + * Copyright (c) 2004-2019, University of Oslo * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -36,7 +36,7 @@ /** * Base interface for FHIR version restricted domain specific transformations - * utilities methods for FHIR resource to DHIS 2 resource transformations. + * utilities methods for FHIR resource to DHIS2 resource transformations. * * @author volsch */ diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/model/FhirRequest.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/model/FhirRequest.java index 1d3b2764..a7119353 100644 --- a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/model/FhirRequest.java +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/model/FhirRequest.java @@ -44,7 +44,7 @@ /** * The request that has caused the transformation between the FHIR resource - * and the DHIS 2 resource. + * and the DHIS2 resource. * * @author volsch */ diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/model/ImmutableFhirRequest.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/model/ImmutableFhirRequest.java index b4d80caa..7cff8549 100644 --- a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/model/ImmutableFhirRequest.java +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/model/ImmutableFhirRequest.java @@ -42,7 +42,7 @@ /** * The immutable request that has caused the transformation between the FHIR resource - * and the DHIS 2 resource. This can be used by scripts safely. + * and the DHIS2 resource. This can be used by scripts safely. * * @author volsch */ diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/model/WritableFhirRequest.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/model/WritableFhirRequest.java index 66e5d33d..440e180c 100644 --- a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/model/WritableFhirRequest.java +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/model/WritableFhirRequest.java @@ -43,7 +43,7 @@ /** * The mutable request that has caused the transformation between the FHIR resource - * and the DHIS 2 resource. + * and the DHIS2 resource. * * @author volsch */ diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/scripted/AccessibleScriptedDhisMetadata.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/scripted/AccessibleScriptedDhisMetadata.java new file mode 100644 index 00000000..8004c5ef --- /dev/null +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/scripted/AccessibleScriptedDhisMetadata.java @@ -0,0 +1,49 @@ +package org.dhis2.fhir.adapter.fhir.transform.scripted; + +/* + * Copyright (c) 2004-2019, 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.DhisMetadata; +import org.dhis2.fhir.adapter.fhir.script.ScriptExecutionForbidden; + +import javax.annotation.Nonnull; + +/** + * Scripted DHIS2 metadata that allows access to the included metadata instance. + * The access is only granted outside script execution. Within a script an exception + * will be thrown. + * + * @author volsch + */ +public interface AccessibleScriptedDhisMetadata extends AccessibleScriptedDhisResource, ScriptedDhisMetadata +{ + @Override + @Nonnull + @ScriptExecutionForbidden + DhisMetadata getDhisResource(); +} diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/scripted/AccessibleScriptedDhisResource.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/scripted/AccessibleScriptedDhisResource.java new file mode 100644 index 00000000..976abed4 --- /dev/null +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/scripted/AccessibleScriptedDhisResource.java @@ -0,0 +1,48 @@ +package org.dhis2.fhir.adapter.fhir.transform.scripted; + +/* + * Copyright (c) 2004-2019, 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.script.ScriptExecutionForbidden; + +import javax.annotation.Nonnull; + +/** + * Scripted DHIS2 resource that allows access to the included resource instance. + * The access is only granted outside script execution. Within a script an exception + * will be thrown. + * + * @author volsch + */ +public interface AccessibleScriptedDhisResource extends ScriptedDhisResource +{ + @Nonnull + @ScriptExecutionForbidden + DhisResource getDhisResource(); +} diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/scripted/ImmutableScriptedDhisMetadata.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/scripted/ImmutableScriptedDhisMetadata.java index b2198951..2b2f9b51 100644 --- a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/scripted/ImmutableScriptedDhisMetadata.java +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/scripted/ImmutableScriptedDhisMetadata.java @@ -28,108 +28,56 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -import org.dhis2.fhir.adapter.dhis.model.DhisResourceId; -import org.dhis2.fhir.adapter.dhis.model.DhisResourceType; -import org.dhis2.fhir.adapter.fhir.transform.TransformerException; +import com.fasterxml.jackson.annotation.JsonIgnore; +import org.dhis2.fhir.adapter.dhis.model.DhisMetadata; +import org.dhis2.fhir.adapter.fhir.script.ScriptExecutionForbidden; import javax.annotation.Nonnull; import javax.annotation.Nullable; import java.io.Serializable; -import java.time.ZonedDateTime; /** * Base implementation of scripted metadata. * * @author volsch */ -public class ImmutableScriptedDhisMetadata implements ScriptedDhisMetadata, Serializable +public class ImmutableScriptedDhisMetadata extends ImmutableScriptedDhisResource implements AccessibleScriptedDhisMetadata, ScriptedDhisMetadata, Serializable { private static final long serialVersionUID = -3081103677950925231L; - private final ScriptedDhisMetadata metadata; - - public ImmutableScriptedDhisMetadata( @Nonnull ScriptedDhisMetadata metadata ) - { - this.metadata = metadata; - } - - @Override - @Nullable - public String getCode() - { - return metadata.getCode(); - } - - @Override - @Nullable - public String getName() + public ImmutableScriptedDhisMetadata( @Nonnull AccessibleScriptedDhisMetadata delegate ) { - return metadata.getName(); + super( delegate ); } - @Override - @Nullable - public String getId() - { - return metadata.getId(); - } - - @Override + @JsonIgnore @Nonnull - public DhisResourceType getResourceType() - { - return metadata.getResourceType(); - } - - @Override - @Nullable - public DhisResourceId getResourceId() - { - return metadata.getResourceId(); - } - - @Override - public boolean isNewResource() + protected AccessibleScriptedDhisMetadata getDelegate() { - return metadata.isNewResource(); - } - - @Override - public boolean isLocal() - { - return metadata.isLocal(); + return (AccessibleScriptedDhisMetadata) super.getDelegate(); } + @Nonnull @Override - public boolean isDeleted() + @ScriptExecutionForbidden + public DhisMetadata getDhisResource() { - return metadata.isDeleted(); + return (DhisMetadata) super.getDhisResource(); } - @Override + @JsonIgnore @Nullable - public ZonedDateTime getLastUpdated() - { - return metadata.getLastUpdated(); - } - @Override - @Nullable - public String getOrganizationUnitId() + public String getCode() { - return metadata.getOrganizationUnitId(); + return getDelegate().getCode(); } - @Override + @JsonIgnore @Nullable - public ScriptedTrackedEntityInstance getTrackedEntityInstance() - { - return metadata.getTrackedEntityInstance(); - } - @Override - public void validate() throws TransformerException + public String getName() { - metadata.validate(); + return getDelegate().getName(); } } diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/scripted/ImmutableScriptedDhisResource.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/scripted/ImmutableScriptedDhisResource.java new file mode 100644 index 00000000..96ca1bc4 --- /dev/null +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/scripted/ImmutableScriptedDhisResource.java @@ -0,0 +1,150 @@ +package org.dhis2.fhir.adapter.fhir.transform.scripted; + +/* + * Copyright (c) 2004-2019, 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.fasterxml.jackson.annotation.JsonIgnore; +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.fhir.script.ScriptExecutionForbidden; +import org.dhis2.fhir.adapter.fhir.transform.TransformerException; + +import javax.annotation.Nonnull; +import javax.annotation.Nullable; +import java.io.Serializable; +import java.time.ZonedDateTime; + +/** + * Base implementation of scripted resource. + * + * @author volsch + */ +public class ImmutableScriptedDhisResource implements AccessibleScriptedDhisResource, Serializable +{ + private static final long serialVersionUID = -3081103677950925231L; + + protected final AccessibleScriptedDhisResource delegate; + + public ImmutableScriptedDhisResource( @Nonnull AccessibleScriptedDhisResource delegate ) + { + this.delegate = delegate; + } + + @JsonIgnore + @Nonnull + protected AccessibleScriptedDhisResource getDelegate() + { + return delegate; + } + + @JsonIgnore + @Nonnull + @Override + @ScriptExecutionForbidden + public DhisResource getDhisResource() + { + return delegate.getDhisResource(); + } + + @JsonIgnore + @Override + @Nullable + public String getId() + { + return delegate.getId(); + } + + @JsonIgnore + @Override + @Nonnull + public DhisResourceType getResourceType() + { + return delegate.getResourceType(); + } + + @JsonIgnore + @Override + @Nullable + public DhisResourceId getResourceId() + { + return delegate.getResourceId(); + } + + @JsonIgnore + @Override + public boolean isNewResource() + { + return delegate.isNewResource(); + } + + @JsonIgnore + @Override + public boolean isLocal() + { + return delegate.isLocal(); + } + + @JsonIgnore + @Override + public boolean isDeleted() + { + return delegate.isDeleted(); + } + + @JsonIgnore + @Override + @Nullable + public ZonedDateTime getLastUpdated() + { + return delegate.getLastUpdated(); + } + + @JsonIgnore + @Override + @Nullable + public String getOrganizationUnitId() + { + return delegate.getOrganizationUnitId(); + } + + @JsonIgnore + @Override + @Nullable + public ScriptedTrackedEntityInstance getTrackedEntityInstance() + { + return delegate.getTrackedEntityInstance(); + } + + @JsonIgnore + @Override + public void validate() throws TransformerException + { + delegate.validate(); + } +} diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/scripted/ScriptedDhisResource.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/scripted/ScriptedDhisResource.java index e3a3c9da..44ce851f 100644 --- a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/scripted/ScriptedDhisResource.java +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/scripted/ScriptedDhisResource.java @@ -38,7 +38,7 @@ import java.time.ZonedDateTime; /** - * Mutable or immutable DHIS 2 resource that can be used by scripts safely. + * Mutable or immutable DHIS2 resource that can be used by scripts safely. * * @author volsch */ diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/scripted/WritableScriptedDhisMetadata.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/scripted/WritableScriptedDhisMetadata.java index c07a6eb9..22531611 100644 --- a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/scripted/WritableScriptedDhisMetadata.java +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/scripted/WritableScriptedDhisMetadata.java @@ -29,112 +29,52 @@ */ import org.dhis2.fhir.adapter.dhis.model.DhisMetadata; -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.fhir.transform.TransformerException; +import org.dhis2.fhir.adapter.fhir.script.ScriptExecutionContext; +import org.dhis2.fhir.adapter.fhir.script.ScriptExecutionForbidden; import org.dhis2.fhir.adapter.scriptable.Scriptable; import javax.annotation.Nonnull; -import javax.annotation.Nullable; import java.io.Serializable; -import java.time.ZonedDateTime; /** - * Implementation of writable scripted metadata. + * Implementation of writable scripted metadata. The included metadata object can be accessed + * outside a script execution. Within a script execution {@link #getDhisResource()} will fail. * - * @param concrete metadata class. * @author volsch */ @Scriptable -public class WritableScriptedDhisMetadata implements ScriptedDhisMetadata, Serializable +public class WritableScriptedDhisMetadata extends WritableScriptedDhisResource implements AccessibleScriptedDhisMetadata, Serializable { private static final long serialVersionUID = 8245822986881397171L; - protected final M metadata; - - public WritableScriptedDhisMetadata( @Nonnull M metadata ) - { - this.metadata = metadata; - } - - @Nullable - @Override - public String getCode() - { - return metadata.getCode(); - } - - @Nullable - @Override - public String getName() - { - return metadata.getName(); - } - - @Nullable - @Override - public String getId() + public WritableScriptedDhisMetadata( @Nonnull DhisMetadata resource, @Nonnull ScriptExecutionContext scriptExecutionContext ) { - return metadata.getId(); + super( resource, scriptExecutionContext ); } @Nonnull - @Override - public DhisResourceType getResourceType() - { - return metadata.getResourceType(); - } - - @Nullable - @Override - public DhisResourceId getResourceId() + protected DhisMetadata getManagedResource() { - return metadata.getResourceId(); + return (DhisMetadata) resource; } + @Nonnull @Override - public boolean isNewResource() - { - return metadata.isNewResource(); - } - - @Override - public boolean isLocal() - { - return metadata.isLocal(); - } - - @Override - public boolean isDeleted() - { - return metadata.isDeleted(); - } - - @Nullable - @Override - public ZonedDateTime getLastUpdated() - { - return metadata.getLastUpdated(); - } - - @Nullable - @Override - public String getOrganizationUnitId() + @ScriptExecutionForbidden + public DhisMetadata getDhisResource() { - return metadata.getOrgUnitId(); + return (DhisMetadata) super.getDhisResource(); } - @Nullable @Override - public ScriptedTrackedEntityInstance getTrackedEntityInstance() + public String getCode() { - return null; + return getManagedResource().getCode(); } @Override - public void validate() throws TransformerException + public String getName() { - // nothing to be done + return getManagedResource().getName(); } } diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/scripted/WritableScriptedDhisResource.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/scripted/WritableScriptedDhisResource.java new file mode 100644 index 00000000..8b7b71d9 --- /dev/null +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/scripted/WritableScriptedDhisResource.java @@ -0,0 +1,143 @@ +package org.dhis2.fhir.adapter.fhir.transform.scripted; + +/* + * Copyright (c) 2004-2019, 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.model.DhisResourceType; +import org.dhis2.fhir.adapter.fhir.script.ScriptExecutionContext; +import org.dhis2.fhir.adapter.fhir.script.ScriptExecutionForbidden; +import org.dhis2.fhir.adapter.fhir.transform.FatalTransformerException; +import org.dhis2.fhir.adapter.fhir.transform.TransformerException; +import org.dhis2.fhir.adapter.scriptable.Scriptable; + +import javax.annotation.Nonnull; +import javax.annotation.Nullable; +import java.io.Serializable; +import java.time.ZonedDateTime; + +/** + * Implementation of writable scripted resource. The included metadata object can be accessed + * outside a script execution. Within a script execution {@link #getDhisResource()} will fail. + * + * @author volsch + */ +@Scriptable +public class WritableScriptedDhisResource implements AccessibleScriptedDhisResource, Serializable +{ + private static final long serialVersionUID = 8245822986881397171L; + + protected final DhisResource resource; + + protected final ScriptExecutionContext scriptExecutionContext; + + public WritableScriptedDhisResource( @Nonnull DhisResource resource, @Nonnull ScriptExecutionContext scriptExecutionContext ) + { + this.resource = resource; + this.scriptExecutionContext = scriptExecutionContext; + } + + @ScriptExecutionForbidden + @Nonnull + public DhisResource getDhisResource() + { + if ( scriptExecutionContext.hasScriptExecution() ) + { + throw new FatalTransformerException( "Resource instance cannot be accessed within script execution." ); + } + + return resource; + } + + @Nullable + @Override + public String getId() + { + return resource.getId(); + } + + @Nonnull + @Override + public DhisResourceType getResourceType() + { + return resource.getResourceType(); + } + + @Nullable + @Override + public DhisResourceId getResourceId() + { + return resource.getResourceId(); + } + + @Override + public boolean isNewResource() + { + return resource.isNewResource(); + } + + @Override + public boolean isLocal() + { + return resource.isLocal(); + } + + @Override + public boolean isDeleted() + { + return resource.isDeleted(); + } + + @Nullable + @Override + public ZonedDateTime getLastUpdated() + { + return resource.getLastUpdated(); + } + + @Nullable + @Override + public String getOrganizationUnitId() + { + return resource.getOrgUnitId(); + } + + @Nullable + @Override + public ScriptedTrackedEntityInstance getTrackedEntityInstance() + { + return null; + } + + @Override + public void validate() throws TransformerException + { + // nothing to be done + } +} diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/scripted/WritableScriptedOrganizationUnit.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/scripted/WritableScriptedOrganizationUnit.java index f5a1b5eb..7ce07447 100644 --- a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/scripted/WritableScriptedOrganizationUnit.java +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/scripted/WritableScriptedOrganizationUnit.java @@ -29,9 +29,11 @@ */ import org.dhis2.fhir.adapter.dhis.orgunit.OrganizationUnit; +import org.dhis2.fhir.adapter.fhir.script.ScriptExecutionContext; import org.dhis2.fhir.adapter.scriptable.ScriptType; import org.dhis2.fhir.adapter.scriptable.Scriptable; +import javax.annotation.Nonnull; import javax.annotation.Nullable; import java.io.Serializable; import java.time.ZonedDateTime; @@ -44,66 +46,73 @@ */ @Scriptable @ScriptType( value = "OrganizationUnit", transformDataType = "DHIS_ORGANIZATION_UNIT", description = "Organization unit." ) -public class WritableScriptedOrganizationUnit extends WritableScriptedDhisMetadata implements ScriptedOrganizationUnit, Serializable +public class WritableScriptedOrganizationUnit extends WritableScriptedDhisMetadata implements ScriptedOrganizationUnit, Serializable { private static final long serialVersionUID = -9043373621936561310L; - public WritableScriptedOrganizationUnit( OrganizationUnit organizationUnit ) + public WritableScriptedOrganizationUnit( @Nonnull OrganizationUnit organizationUnit, @Nonnull ScriptExecutionContext scriptExecutionContext ) { - super( organizationUnit ); + super( organizationUnit, scriptExecutionContext ); + } + + @Nonnull + @Override + protected OrganizationUnit getManagedResource() + { + return (OrganizationUnit) resource; } @Nullable @Override public String getShortName() { - return metadata.getShortName(); + return getManagedResource().getShortName(); } @Nullable @Override public String getDisplayName() { - return metadata.getDisplayName(); + return getManagedResource().getDisplayName(); } @Override public boolean isLeaf() { - return metadata.isLeaf(); + return getManagedResource().isLeaf(); } @Override public int getLevel() { - return metadata.getLevel(); + return getManagedResource().getLevel(); } @Nullable @Override public ZonedDateTime getOpeningDate() { - return metadata.getOpeningDate(); + return getManagedResource().getOpeningDate(); } @Nullable @Override public ZonedDateTime getClosedDate() { - return metadata.getClosedDate(); + return getManagedResource().getClosedDate(); } @Nullable @Override public String getParentId() { - return metadata.getParentId(); + return getManagedResource().getParentId(); } @Nullable @Override public String getCoordinates() { - return metadata.getCoordinates(); + return getManagedResource().getCoordinates(); } } diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/util/DhisBeanTransformerUtils.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/util/DhisBeanTransformerUtils.java index bb6ff68c..073c910a 100644 --- a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/util/DhisBeanTransformerUtils.java +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/util/DhisBeanTransformerUtils.java @@ -1,7 +1,7 @@ package org.dhis2.fhir.adapter.fhir.transform.util; /* - * Copyright (c) 2004-2018, University of Oslo + * Copyright (c) 2004-2019, University of Oslo * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -37,7 +37,7 @@ /** * Transformer utilities that clone a bean (cached instances must not be modified - * by several thread, e.g. DHIS 2 objects). + * by several thread, e.g. DHIS2 objects). * * @author volsch */ diff --git a/fhir/src/main/resources/db/migration/production/V1.1.0.41_0_0__Care_Resources_2.sql b/fhir/src/main/resources/db/migration/production/V1.1.0.41_0_0__Care_Resources_2.sql index a8f17f20..1874a871 100644 --- a/fhir/src/main/resources/db/migration/production/V1.1.0.41_0_0__Care_Resources_2.sql +++ b/fhir/src/main/resources/db/migration/production/V1.1.0.41_0_0__Care_Resources_2.sql @@ -82,12 +82,12 @@ CREATE TABLE IF NOT EXISTS fhir_program_stage_metadata_rule ( COMMENT ON TABLE fhir_program_stage_metadata_rule IS 'Contains rules for DHIS2 Program Stage Metadata Resource Types.'; COMMENT ON COLUMN fhir_program_stage_metadata_rule.id IS 'References the rule to which this Program Metadata Stage rule belongs to.'; -INSERT INTO fhir_rule(id, version, fhir_resource_type, dhis_resource_type, name, description, enabled, imp_enabled, exp_enabled, contained_allowed, fhir_create_enabled, fhir_update_enabled, fhir_delete_enabled, grouping, evaluation_order, transform_imp_script_id) +INSERT INTO fhir_rule(id, version, fhir_resource_type, dhis_resource_type, name, description, enabled, imp_enabled, exp_enabled, contained_allowed, fhir_create_enabled, fhir_update_enabled, fhir_delete_enabled, grouping, evaluation_order, simple_fhir_id) VALUES('4a9ac195-858b-455e-b34d-c560e1855787', 0, 'PLAN_DEFINITION', 'PROGRAM_METADATA', 'Default DHIS2 Program Metadata to FHIR Plan Definition', 'Default rule that transforms a DHIS2 Program Metadata to a FHIR Care Plan.', -true, false, true, false, true, true, true, false, -2147483648, NULL); +true, false, true, false, true, true, true, false, -2147483648, TRUE); INSERT INTO fhir_program_metadata_rule(id) VALUES ('4a9ac195-858b-455e-b34d-c560e1855787'); -INSERT INTO fhir_rule(id, version, fhir_resource_type, dhis_resource_type, name, description, enabled, imp_enabled, exp_enabled, contained_allowed, fhir_create_enabled, fhir_update_enabled, fhir_delete_enabled, grouping, evaluation_order, transform_imp_script_id) +INSERT INTO fhir_rule(id, version, fhir_resource_type, dhis_resource_type, name, description, enabled, imp_enabled, exp_enabled, contained_allowed, fhir_create_enabled, fhir_update_enabled, fhir_delete_enabled, grouping, evaluation_order, simple_fhir_id) VALUES('1f97f85a-e4ea-46f1-bcde-77ea178226f4', 0, 'QUESTIONNAIRE', 'PROGRAM_STAGE_METADATA', 'Default DHIS2 Program Stage Metadata to FHIR Questionnaire', 'Default rule that transforms a DHIS2 Program Stage Metadata to a FHIR Questionnaire.', -true, false, true, false, true, true, true, false, -2147483648, NULL); +true, false, true, false, true, true, true, false, -2147483648, TRUE); INSERT INTO fhir_program_stage_metadata_rule(id) VALUES ('1f97f85a-e4ea-46f1-bcde-77ea178226f4'); diff --git a/fhir/src/test/java/org/dhis2/fhir/adapter/fhir/metadata/repository/FhirClientRepositoryRestDocsTest.java b/fhir/src/test/java/org/dhis2/fhir/adapter/fhir/metadata/repository/FhirClientRepositoryRestDocsTest.java index d3fde072..58bcd9bc 100644 --- a/fhir/src/test/java/org/dhis2/fhir/adapter/fhir/metadata/repository/FhirClientRepositoryRestDocsTest.java +++ b/fhir/src/test/java/org/dhis2/fhir/adapter/fhir/metadata/repository/FhirClientRepositoryRestDocsTest.java @@ -83,7 +83,7 @@ public void createFhirClient() throws Exception "If the FHIR client has been locked (i.e. by automatic processes), no subscription notifications are processed from the corresponding FHIR service." ).type( JsonFieldType.BOOLEAN ), fields.withPath( "outEnabled" ).description( "Specifies if output transformation from DHIS to FHIR for this FHIR client is enabled (by default false)." ).type( JsonFieldType.BOOLEAN ).optional(), fields.withPath( "useAdapterIdentifier" ).description( "Specifies if the adapter should add an adapter specific identifier to created and updated resources (by default true). Using such identifiers makes it easier to map resources between " + - "FHIR and DHIS 2." ).type( JsonFieldType.BOOLEAN ).optional(), + "FHIR and DHIS2." ).type( JsonFieldType.BOOLEAN ).optional(), fields.withPath( "fhirVersion" ).description( "The FHIR version that should be used when communicating with the client FHIR service." ).type( JsonFieldType.STRING ), fields.withPath( "toleranceMillis" ).description( "The number of milli-seconds to subtract from the last updated timestamp when searching for created and updated resources." ).type( JsonFieldType.NUMBER ), fields.withPath( "autoCreatedSubscriptionResources" ).description( "Subscription resources for which the subscriptions should be created automatically when creating the subscription resource. This value will not be returned and can only " + @@ -167,7 +167,7 @@ public void readFhirClient() throws Exception "If the FHIR client has been locked (i.e. by automatic processes), no subscription notifications are processed from the corresponding FHIR service." ).type( JsonFieldType.BOOLEAN ), fields.withPath( "expEnabled" ).description( "Specifies if output transformation from DHIS to FHIR for this FHIR client is enabled." ).type( JsonFieldType.BOOLEAN ), fields.withPath( "useAdapterIdentifier" ).description( "Specifies if the adapter should add an adapter specific identifier to created and updated resources (by default true). Using such identifiers makes it easier to map resources " + - "between FHIR and DHIS 2." ).type( JsonFieldType.BOOLEAN ).optional(), + "between FHIR and DHIS2." ).type( JsonFieldType.BOOLEAN ).optional(), fields.withPath( "fhirVersion" ).description( "The FHIR version that should be used when communicating with the client FHIR service." ).type( JsonFieldType.STRING ), fields.withPath( "toleranceMillis" ).description( "The number of milli-seconds to subtract from the last updated timestamp when searching for created and updated resources." ).type( JsonFieldType.NUMBER ), fields.withPath( "autoCreatedSubscriptionResources" ).description( "Subscription resources for which the subscriptions should be created automatically when creating the subscription resource. This value will not be returned and can only " + diff --git a/fhir/src/test/java/org/dhis2/fhir/adapter/fhir/metadata/repository/FhirResourceMappingRepositoryRestDocsTest.java b/fhir/src/test/java/org/dhis2/fhir/adapter/fhir/metadata/repository/FhirResourceMappingRepositoryRestDocsTest.java index fca9d3d0..a225d592 100644 --- a/fhir/src/test/java/org/dhis2/fhir/adapter/fhir/metadata/repository/FhirResourceMappingRepositoryRestDocsTest.java +++ b/fhir/src/test/java/org/dhis2/fhir/adapter/fhir/metadata/repository/FhirResourceMappingRepositoryRestDocsTest.java @@ -78,7 +78,7 @@ public void createFhirResourceMapping() throws Exception attributes( key( "title" ).value( "Fields for FHIR resource mapping creation" ) ), fields.withPath( "fhirResourceType" ).description( "The unique FHIR resource type for which the definition is made." ).type( JsonFieldType.STRING ), fields.withPath( "trackedEntityFhirResourceType" ).description( "The FHIR resource type to which the DHIS tracked entity is mapped." ).type( JsonFieldType.STRING ), - fields.withPath( "deleteWhenAbsent" ).description( "Specifies if the FHIR resource should be deleted when the corresponding required DHIS 2 data elements are absent." ).type( JsonFieldType.BOOLEAN ).optional(), + fields.withPath( "deleteWhenAbsent" ).description( "Specifies if the FHIR resource should be deleted when the corresponding required DHIS2 data elements are absent." ).type( JsonFieldType.BOOLEAN ).optional(), fields.withPath( "impTeiLookupScript" ).description( "Link to the executable script that returns the FHIR resource for the TEI that is assigned to the evaluated mapped FHIR resource. The return type of the script must be FHIR_RESOURCE." ).type( JsonFieldType.STRING ).optional(), fields.withPath( "impEventOrgLookupScript" ).description( "Link to the executable evaluation script that returns a reference to a DHIS2 organization unit of an event. The return type of the script must be ORG_UNIT_REF." ).type( JsonFieldType.STRING ).optional(), fields.withPath( "impEventGeoLookupScript" ).description( "Link to the executable evaluation script that returns a location (longitude and latitude) of an event. The returns type of the script must be LOCATION." ).type( JsonFieldType.STRING ).optional(), @@ -88,19 +88,19 @@ public void createFhirResourceMapping() throws Exception fields.withPath( "impEnrollmentDateLookupScript" ).description( "Link to the executable evaluation script that returns the event date. The return type of the script must be DATE_TIME." ).type( JsonFieldType.STRING ).optional(), fields.withPath( "impEffectiveDateLookupScript" ).description( "Link to the executable evaluation script that extract the effective date when the data has been collected. The return type of the script must be DATE_TIME." ).type( JsonFieldType.STRING ).optional(), fields.withPath( "impProgramStageRefLookupScript" ).description( "Link to the executable evaluation script that extract the program stage reference (if any). The return type of the script must be PROGRAM_STAGE_REF." ).type( JsonFieldType.STRING ).optional(), - fields.withPath( "expAbsentTransformScript" ).description( "Link to the executable transformation script that sets in an existing exported FHIR resource a status that indicates that corresponding required DHIS 2 data elements are missing. " + fields.withPath( "expAbsentTransformScript" ).description( "Link to the executable transformation script that sets in an existing exported FHIR resource a status that indicates that corresponding required DHIS2 data elements are missing. " + "The return type must be BOOLEAN and indicates if the script was successful." ).type( JsonFieldType.STRING ).optional(), - fields.withPath( "expTeiTransformScript" ).description( "Link to the executable transformation script that sets the DHIS 2 tracked entity related FHIR resource in the transformed FHIR resource. " + fields.withPath( "expTeiTransformScript" ).description( "Link to the executable transformation script that sets the DHIS2 tracked entity related FHIR resource in the transformed FHIR resource. " + "The return type must be BOOLEAN and indicates if the script was successful." ).type( JsonFieldType.STRING ).optional(), - fields.withPath( "expOrgUnitTransformScript" ).description( "Link to the executable transformation script that sets the DHIS 2 organization unit related FHIR resource in the transformed FHIR resource. " + fields.withPath( "expOrgUnitTransformScript" ).description( "Link to the executable transformation script that sets the DHIS2 organization unit related FHIR resource in the transformed FHIR resource. " + "The return type must be BOOLEAN and indicates if the script was successful." ).type( JsonFieldType.STRING ).optional(), - fields.withPath( "expGeoTransformScript" ).description( "Link to the executable transformation script that sets the DHIS 2 GEO coordinate information in the transformed FHIR resource. " + fields.withPath( "expGeoTransformScript" ).description( "Link to the executable transformation script that sets the DHIS2 GEO coordinate information in the transformed FHIR resource. " + "The return type must be BOOLEAN and indicates if the script was successful." ).type( JsonFieldType.STRING ).optional(), - fields.withPath( "expStatusTransformScript" ).description( "Link to the executable transformation script that sets the DHIS 2 status (e.g. event status) in the transformed FHIR resource. " + fields.withPath( "expStatusTransformScript" ).description( "Link to the executable transformation script that sets the DHIS2 status (e.g. event status) in the transformed FHIR resource. " + "The return type must be BOOLEAN and indicates if the script was successful." ).type( JsonFieldType.STRING ).optional(), - fields.withPath( "expDateTransformScript" ).description( "Link to the executable transformation script that sets the DHIS 2 effective date (e.g. event date) in the transformed FHIR resource. " + fields.withPath( "expDateTransformScript" ).description( "Link to the executable transformation script that sets the DHIS2 effective date (e.g. event date) in the transformed FHIR resource. " + "The return type must be BOOLEAN and indicates if the script was successful." ).type( JsonFieldType.STRING ).optional(), - fields.withPath( "expGroupTransformScript" ).description( "Link to the executable transformation script that sets and collects DHIS 2 grouping information (e.g. FHIR encounter as DHIS 2 event) in the transformed FHIR resource. " + fields.withPath( "expGroupTransformScript" ).description( "Link to the executable transformation script that sets and collects DHIS2 grouping information (e.g. FHIR encounter as DHIS2 event) in the transformed FHIR resource. " + "The return type must be BOOLEAN and indicates if the script was successful." ).type( JsonFieldType.STRING ).optional() ) ) ).andReturn().getResponse().getHeader( "Location" ); @@ -132,19 +132,19 @@ public void readFhirResourceMapping() throws Exception linkWithRel( "impEnrollmentDateLookupScript" ).description( "Link to the executable evaluation script that returns the event date. The return type of the script must be DATE_TIME." ).optional(), linkWithRel( "impEffectiveDateLookupScript" ).description( "Link to the executable evaluation script that extract the effective date when the data has been collected. The return type of the script must be DATE_TIME." ).optional(), linkWithRel( "impProgramStageRefLookupScript" ).description( "Link to the executable evaluation script that extract the program stage reference (if any). The return type of the script must be PROGRAM_STAGE_REF." ).optional(), - linkWithRel( "expAbsentTransformScript" ).description( "Link to the executable transformation script that sets in an existing exported FHIR resource a status that indicates that corresponding required DHIS 2 data elements are missing. " + + linkWithRel( "expAbsentTransformScript" ).description( "Link to the executable transformation script that sets in an existing exported FHIR resource a status that indicates that corresponding required DHIS2 data elements are missing. " + "The return type must be BOOLEAN and indicates if the script was successful." ).optional(), - linkWithRel( "expTeiTransformScript" ).description( "Link to the executable transformation script that sets the DHIS 2 tracked entity related FHIR resource in the transformed FHIR resource. " + linkWithRel( "expTeiTransformScript" ).description( "Link to the executable transformation script that sets the DHIS2 tracked entity related FHIR resource in the transformed FHIR resource. " + "The return type must be BOOLEAN and indicates if the script was successful." ).optional(), - linkWithRel( "expOrgUnitTransformScript" ).description( "Link to the executable transformation script that sets the DHIS 2 organization unit related FHIR resource in the transformed FHIR resource. " + linkWithRel( "expOrgUnitTransformScript" ).description( "Link to the executable transformation script that sets the DHIS2 organization unit related FHIR resource in the transformed FHIR resource. " + "The return type must be BOOLEAN and indicates if the script was successful." ).optional(), - linkWithRel( "expGeoTransformScript" ).description( "Link to the executable transformation script that sets the DHIS 2 GEO coordinate information in the transformed FHIR resource. " + linkWithRel( "expGeoTransformScript" ).description( "Link to the executable transformation script that sets the DHIS2 GEO coordinate information in the transformed FHIR resource. " + "The return type must be BOOLEAN and indicates if the script was successful." ).optional(), - linkWithRel( "expStatusTransformScript" ).description( "Link to the executable transformation script that sets the DHIS 2 status (e.g. event status) in the transformed FHIR resource. " + linkWithRel( "expStatusTransformScript" ).description( "Link to the executable transformation script that sets the DHIS2 status (e.g. event status) in the transformed FHIR resource. " + "The return type must be BOOLEAN and indicates if the script was successful." ).optional(), - linkWithRel( "expDateTransformScript" ).description( "Link to the executable transformation script that sets the DHIS 2 effective date (e.g. event date) in the transformed FHIR resource. " + linkWithRel( "expDateTransformScript" ).description( "Link to the executable transformation script that sets the DHIS2 effective date (e.g. event date) in the transformed FHIR resource. " + "The return type must be BOOLEAN and indicates if the script was successful." ).optional(), - linkWithRel( "expGroupTransformScript" ).description( "Link to the executable transformation script that sets and collects DHIS 2 grouping information (e.g. FHIR encounter as DHIS 2 event) in the transformed FHIR resource. " + linkWithRel( "expGroupTransformScript" ).description( "Link to the executable transformation script that sets and collects DHIS2 grouping information (e.g. FHIR encounter as DHIS2 event) in the transformed FHIR resource. " + "The return type must be BOOLEAN and indicates if the script was successful." ).optional() ), responseFields( attributes( key( "title" ).value( "Fields for tracked entity reading" ) ), @@ -153,7 +153,7 @@ public void readFhirResourceMapping() throws Exception fields.withPath( "lastUpdatedAt" ).description( "The timestamp when the resource has been updated the last time." ).type( JsonFieldType.STRING ), fields.withPath( "fhirResourceType" ).description( "The unique FHIR resource type for which the definition is made." ).type( JsonFieldType.STRING ), fields.withPath( "trackedEntityFhirResourceType" ).description( "The FHIR resource type to which the DHIS tracked entity is mapped." ).type( JsonFieldType.STRING ), - fields.withPath( "deleteWhenAbsent" ).description( "Specifies if the FHIR resource should be deleted when the corresponding required DHIS 2 data elements are absent." ).type( JsonFieldType.BOOLEAN ).optional(), + fields.withPath( "deleteWhenAbsent" ).description( "Specifies if the FHIR resource should be deleted when the corresponding required DHIS2 data elements are absent." ).type( JsonFieldType.BOOLEAN ).optional(), subsectionWithPath( "_links" ).description( "Links to other resources" ) ) ) ); } diff --git a/fhir/src/test/java/org/dhis2/fhir/adapter/fhir/metadata/repository/OrganizationUnitRuleRepositoryRestDocsTest.java b/fhir/src/test/java/org/dhis2/fhir/adapter/fhir/metadata/repository/OrganizationUnitRuleRepositoryRestDocsTest.java index 2510c9ff..897f15a4 100644 --- a/fhir/src/test/java/org/dhis2/fhir/adapter/fhir/metadata/repository/OrganizationUnitRuleRepositoryRestDocsTest.java +++ b/fhir/src/test/java/org/dhis2/fhir/adapter/fhir/metadata/repository/OrganizationUnitRuleRepositoryRestDocsTest.java @@ -106,10 +106,10 @@ public void createOrganizationUnitRule() throws Exception "The script must be an evaluation script that returns a boolean value." ).type( JsonFieldType.STRING ).optional(), fields.withPath( "transformExpScript" ).description( "Link to the executable script reference that is used to transform the DHIS2 resource input to the FHIR resource." ).type( JsonFieldType.STRING ).optional(), fields.withPath( "identifierLookupScript" ).description( - "Link to the executable script reference that is used to extract the location identifier from the DHIS 2 organization unit. The script must be an evaluation script that returns a STRING." ) + "Link to the executable script reference that is used to extract the location identifier from the DHIS2 organization unit. The script must be an evaluation script that returns a STRING." ) .type( JsonFieldType.STRING ), fields.withPath( "managingOrgIdentifierLookupScript" ).description( - "Link to the executable script reference that is used to extract the managing organization unit identifier from the DHIS 2 organization unit. The script must be an evaluation script that returns a STRING." ) + "Link to the executable script reference that is used to extract the managing organization unit identifier from the DHIS2 organization unit. The script must be an evaluation script that returns a STRING." ) .type( JsonFieldType.STRING ).optional(), fields.withPath( "filterScript" ).description( "Link to the executable script that prepares the search filter." ).type( JsonFieldType.STRING ).optional() ) ) ).andReturn().getResponse().getHeader( "Location" ); @@ -149,8 +149,8 @@ public void readOrganizationUnitRule() throws Exception linkWithRel( "applicableExpScript" ).description( "Link to the executable script reference that is used to check if the incoming request is applicable for this rule when transforming a DHIS2 to FHIR resource. " + "The script must be an evaluation script that returns a boolean value." ).optional(), linkWithRel( "transformExpScript" ).description( "Link to the executable script reference that is used to transform the DHIS2 resource input to the FHIR resource." ).optional(), - linkWithRel( "identifierLookupScript" ).description( "Link to the executable script reference that is used to extract the location identifier from the DHIS 2 organization unit. The script must be an evaluation script that returns a STRING." ), - linkWithRel( "managingOrgIdentifierLookupScript" ).description( "Link to the executable script reference that is used to extract the managing organization unit identifier from the DHIS 2 organization unit. " + + linkWithRel( "identifierLookupScript" ).description( "Link to the executable script reference that is used to extract the location identifier from the DHIS2 organization unit. The script must be an evaluation script that returns a STRING." ), + linkWithRel( "managingOrgIdentifierLookupScript" ).description( "Link to the executable script reference that is used to extract the managing organization unit identifier from the DHIS2 organization unit. " + "The script must be an evaluation script that returns a STRING." ).optional() ), responseFields( attributes( key( "title" ).value( "Fields for rule reading" ) ), diff --git a/fhir/src/test/java/org/dhis2/fhir/adapter/fhir/transform/dhis/impl/DhisToFhirTransformerServiceImplTest.java b/fhir/src/test/java/org/dhis2/fhir/adapter/fhir/transform/dhis/impl/DhisToFhirTransformerServiceImplTest.java index 967efc05..328e963b 100644 --- a/fhir/src/test/java/org/dhis2/fhir/adapter/fhir/transform/dhis/impl/DhisToFhirTransformerServiceImplTest.java +++ b/fhir/src/test/java/org/dhis2/fhir/adapter/fhir/transform/dhis/impl/DhisToFhirTransformerServiceImplTest.java @@ -40,6 +40,7 @@ import org.dhis2.fhir.adapter.fhir.metadata.repository.FhirClientSystemRepository; import org.dhis2.fhir.adapter.fhir.metadata.repository.RuleRepository; import org.dhis2.fhir.adapter.fhir.model.FhirVersion; +import org.dhis2.fhir.adapter.fhir.script.ScriptExecutionContext; import org.dhis2.fhir.adapter.fhir.script.ScriptExecutor; import org.dhis2.fhir.adapter.fhir.transform.dhis.DhisToFhirTransformOutcome; import org.dhis2.fhir.adapter.fhir.transform.dhis.DhisToFhirTransformerContext; @@ -102,6 +103,9 @@ public class DhisToFhirTransformerServiceImplTest @Mock private ScriptedDhisResource scriptedDhisResource; + @Mock + private ScriptExecutionContext scriptExecutionContext; + @Mock private DhisToFhirTransformerRequestImpl transformerRequest; @@ -126,7 +130,7 @@ public void setUp() new StaticObjectProvider<>( new ArrayList<>() ), new StaticObjectProvider<>( new ArrayList<>() ), new StaticObjectProvider<>( Collections.singletonList( resourceTransformerUtils ) ), - scriptExecutor ); + scriptExecutor, scriptExecutionContext ); service = Mockito.spy( service ); } diff --git a/fhir/src/test/resources/data.sql b/fhir/src/test/resources/data.sql index 01f65e82..7a941cd0 100644 --- a/fhir/src/test/resources/data.sql +++ b/fhir/src/test/resources/data.sql @@ -883,12 +883,12 @@ VALUES('0340bf441eab4c2a98a2aaf7ba35855c', 0, '46f0af46365440b38d4c7a633332c3b3' INSERT INTO fhir_client_system(id, version, fhir_client_id, fhir_resource_type, system_id) VALUES('789a91bd6bcb4f8496d0c6829b5fdeaa', 0, '46f0af46365440b38d4c7a633332c3b3', 'QUESTIONNAIRE_RESPONSE', '5bdff628d94f43dc83678c84fe48bdd9'); -INSERT INTO fhir_rule(id, version, fhir_resource_type, dhis_resource_type, name, description, enabled, imp_enabled, exp_enabled, contained_allowed, fhir_create_enabled, fhir_update_enabled, fhir_delete_enabled, grouping, evaluation_order, transform_imp_script_id) +INSERT INTO fhir_rule(id, version, fhir_resource_type, dhis_resource_type, name, description, enabled, imp_enabled, exp_enabled, contained_allowed, fhir_create_enabled, fhir_update_enabled, fhir_delete_enabled, grouping, evaluation_order, simple_fhir_id) VALUES('4a9ac195858b455eb34dc560e1855787', 0, 'PLAN_DEFINITION', 'PROGRAM_METADATA', 'Default DHIS2 Program Metadata to FHIR Plan Definition', 'Default rule that transforms a DHIS2 Program Metadata to a FHIR Care Plan.', -true, false, true, false, true, true, true, false, -2147483648, NULL); +true, false, true, false, true, true, true, false, -2147483648, TRUE); INSERT INTO fhir_program_metadata_rule(id) VALUES ('4a9ac195858b455eb34dc560e1855787'); -INSERT INTO fhir_rule(id, version, fhir_resource_type, dhis_resource_type, name, description, enabled, imp_enabled, exp_enabled, contained_allowed, fhir_create_enabled, fhir_update_enabled, fhir_delete_enabled, grouping, evaluation_order, transform_imp_script_id) +INSERT INTO fhir_rule(id, version, fhir_resource_type, dhis_resource_type, name, description, enabled, imp_enabled, exp_enabled, contained_allowed, fhir_create_enabled, fhir_update_enabled, fhir_delete_enabled, grouping, evaluation_order, simple_fhir_id) VALUES('1f97f85ae4ea46f1bcde77ea178226f4', 0, 'QUESTIONNAIRE', 'PROGRAM_STAGE_METADATA', 'Default DHIS2 Program Stage Metadata to FHIR Questionnaire', 'Default rule that transforms a DHIS2 Program Stage Metadata to a FHIR Questionnaire.', -true, false, true, false, true, true, true, false, -2147483648, NULL); +true, false, true, false, true, true, true, false, -2147483648, TRUE); INSERT INTO fhir_program_stage_metadata_rule(id) VALUES ('1f97f85ae4ea46f1bcde77ea178226f4'); diff --git a/metadata-sheet/src/main/java/org/dhis2/fhir/adapter/metadata/sheet/processor/MetadataSheetRuleImportProcessor.java b/metadata-sheet/src/main/java/org/dhis2/fhir/adapter/metadata/sheet/processor/MetadataSheetRuleImportProcessor.java index bbed7227..40dd178d 100644 --- a/metadata-sheet/src/main/java/org/dhis2/fhir/adapter/metadata/sheet/processor/MetadataSheetRuleImportProcessor.java +++ b/metadata-sheet/src/main/java/org/dhis2/fhir/adapter/metadata/sheet/processor/MetadataSheetRuleImportProcessor.java @@ -515,7 +515,7 @@ MetadataSheetMessageSeverity.ERROR, new MetadataSheetLocation( RULES_SHEET_NAME, { messageCollector.addMessage( new MetadataSheetMessage( MetadataSheetMessageSeverity.ERROR, new MetadataSheetLocation( RULES_SHEET_NAME, rowNum, F2D_APPLICABLE_SCRIPT_CODE_COL ), - "FHIR to DHIS 2 transform script does not exist: " + f2dApplicableScriptCode ) ); + "FHIR to DHIS2 transform script does not exist: " + f2dApplicableScriptCode ) ); } } @@ -539,7 +539,7 @@ MetadataSheetMessageSeverity.ERROR, new MetadataSheetLocation( RULES_SHEET_NAME, { messageCollector.addMessage( new MetadataSheetMessage( MetadataSheetMessageSeverity.ERROR, new MetadataSheetLocation( RULES_SHEET_NAME, rowNum, D2F_APPLICABLE_SCRIPT_CODE_COL ), - "FHIR to DHIS 2 transform script does not exist: " + d2fApplicableScriptCode ) ); + "FHIR to DHIS2 transform script does not exist: " + d2fApplicableScriptCode ) ); } } @@ -565,8 +565,8 @@ MetadataSheetMessageSeverity.WARN, new MetadataSheetLocation( RULES_SHEET_NAME, { if ( newCodeSetCode ) { - codeSet = createCodeSet( messageCollector, rowNum, - codeSetCode, Objects.requireNonNull( codeSetDisplayName ), codeSetPreferred, Objects.requireNonNull( codeSetCodes ) ); + codeSet = createCodeSet( messageCollector, rowNum, codeSetCode, Objects.requireNonNull( codeSetDisplayName ), + Objects.requireNonNull( codeSetPreferred ), Objects.requireNonNull( codeSetCodes ) ); if ( codeSet != null ) { diff --git a/pom.xml b/pom.xml index efb0c883..86264bda 100644 --- a/pom.xml +++ b/pom.xml @@ -210,7 +210,7 @@ maven-surefire-plugin true - + -Duser.timezone=CET ${surefireArgLine} false