From b2760b8f7a2ae215239416eac9a07a5c5c5868ad Mon Sep 17 00:00:00 2001 From: Volker Schmidt Date: Tue, 19 Mar 2019 16:51:22 +0100 Subject: [PATCH] Updated test execution. --- .../fhir/adapter/util/NameUtilsTest.java | 14 ++ ...hirResourceDhisToFhirTransformerUtils.java | 3 +- .../Dstu3GeoDhisToFhirTransformerUtils.java | 2 +- ...eGenderDhisToFhirTransformerUtilsTest.java | 113 +++++++++ ...tu3CodeDhisToFhirTransformerUtilsTest.java | 238 ++++++++++++++++++ ...ateTimeDhisToFhirTransformerUtilsTest.java | 150 +++++++++++ ...counterDhisToFhirTransformerUtilsTest.java | 62 +++++ ...esourceDhisToFhirTransformerUtilsTest.java | 169 +++++++++++++ ...stu3GeoDhisToFhirTransformerUtilsTest.java | 126 ++++++++++ ...ocationDhisToFhirTransformerUtilsTest.java | 62 +++++ ...rvationDhisToFhirTransformerUtilsTest.java | 62 +++++ ...hirResourceDhisToFhirTransformerUtils.java | 3 +- .../r4/R4GeoDhisToFhirTransformerUtils.java | 2 +- ...eGenderDhisToFhirTransformerUtilsTest.java | 113 +++++++++ .../R4CodeDhisToFhirTransformerUtilsTest.java | 238 ++++++++++++++++++ ...ateTimeDhisToFhirTransformerUtilsTest.java | 150 +++++++++++ ...counterDhisToFhirTransformerUtilsTest.java | 62 +++++ ...esourceDhisToFhirTransformerUtilsTest.java | 169 +++++++++++++ .../R4GeoDhisToFhirTransformerUtilsTest.java | 126 ++++++++++ ...ocationDhisToFhirTransformerUtilsTest.java | 62 +++++ ...rvationDhisToFhirTransformerUtilsTest.java | 62 +++++ ...AbstractBeforeCreateSaveRuleValidator.java | 25 ++ ...SaveOrganizationUnitRuleValidatorTest.java | 21 ++ fhir/src/test/resources/data.sql | 19 ++ pom.xml | 38 ++- summary/pom.xml | 69 +++++ 26 files changed, 2144 insertions(+), 16 deletions(-) create mode 100644 fhir-dstu3/src/test/java/org/dhis2/fhir/adapter/fhir/transform/dhis/impl/util/dstu3/Dstu3AdministrativeGenderDhisToFhirTransformerUtilsTest.java create mode 100644 fhir-dstu3/src/test/java/org/dhis2/fhir/adapter/fhir/transform/dhis/impl/util/dstu3/Dstu3CodeDhisToFhirTransformerUtilsTest.java create mode 100644 fhir-dstu3/src/test/java/org/dhis2/fhir/adapter/fhir/transform/dhis/impl/util/dstu3/Dstu3DateTimeDhisToFhirTransformerUtilsTest.java create mode 100644 fhir-dstu3/src/test/java/org/dhis2/fhir/adapter/fhir/transform/dhis/impl/util/dstu3/Dstu3EncounterDhisToFhirTransformerUtilsTest.java create mode 100644 fhir-dstu3/src/test/java/org/dhis2/fhir/adapter/fhir/transform/dhis/impl/util/dstu3/Dstu3FhirResourceDhisToFhirTransformerUtilsTest.java create mode 100644 fhir-dstu3/src/test/java/org/dhis2/fhir/adapter/fhir/transform/dhis/impl/util/dstu3/Dstu3GeoDhisToFhirTransformerUtilsTest.java create mode 100644 fhir-dstu3/src/test/java/org/dhis2/fhir/adapter/fhir/transform/dhis/impl/util/dstu3/Dstu3LocationDhisToFhirTransformerUtilsTest.java create mode 100644 fhir-dstu3/src/test/java/org/dhis2/fhir/adapter/fhir/transform/dhis/impl/util/dstu3/Dstu3ObservationDhisToFhirTransformerUtilsTest.java create mode 100644 fhir-r4/src/test/java/org/dhis2/fhir/adapter/fhir/transform/dhis/impl/util/r4/R4AdministrativeGenderDhisToFhirTransformerUtilsTest.java create mode 100644 fhir-r4/src/test/java/org/dhis2/fhir/adapter/fhir/transform/dhis/impl/util/r4/R4CodeDhisToFhirTransformerUtilsTest.java create mode 100644 fhir-r4/src/test/java/org/dhis2/fhir/adapter/fhir/transform/dhis/impl/util/r4/R4DateTimeDhisToFhirTransformerUtilsTest.java create mode 100644 fhir-r4/src/test/java/org/dhis2/fhir/adapter/fhir/transform/dhis/impl/util/r4/R4EncounterDhisToFhirTransformerUtilsTest.java create mode 100644 fhir-r4/src/test/java/org/dhis2/fhir/adapter/fhir/transform/dhis/impl/util/r4/R4FhirResourceDhisToFhirTransformerUtilsTest.java create mode 100644 fhir-r4/src/test/java/org/dhis2/fhir/adapter/fhir/transform/dhis/impl/util/r4/R4GeoDhisToFhirTransformerUtilsTest.java create mode 100644 fhir-r4/src/test/java/org/dhis2/fhir/adapter/fhir/transform/dhis/impl/util/r4/R4LocationDhisToFhirTransformerUtilsTest.java create mode 100644 fhir-r4/src/test/java/org/dhis2/fhir/adapter/fhir/transform/dhis/impl/util/r4/R4ObservationDhisToFhirTransformerUtilsTest.java diff --git a/common/src/test/java/org/dhis2/fhir/adapter/util/NameUtilsTest.java b/common/src/test/java/org/dhis2/fhir/adapter/util/NameUtilsTest.java index 0969bf5b..e8f60a4c 100644 --- a/common/src/test/java/org/dhis2/fhir/adapter/util/NameUtilsTest.java +++ b/common/src/test/java/org/dhis2/fhir/adapter/util/NameUtilsTest.java @@ -35,6 +35,8 @@ /** * Unit tests for {@link NameUtils}. + * + * @author volsch */ public class NameUtilsTest { @@ -87,6 +89,18 @@ public void toEnumNameCamelCaseLower() Assert.assertEquals( "TEST_VALUE_1", NameUtils.toEnumName( "testValue1" ) ); } + @Test + public void toClassNameNull() + { + Assert.assertNull( NameUtils.toClassName( null ) ); + } + + @Test + public void toEnumNameEmpty() + { + Assert.assertEquals( "", NameUtils.toEnumName( "" ) ); + } + @Test public void toClassNameCamelCaseLower() { diff --git a/fhir-dstu3/src/main/java/org/dhis2/fhir/adapter/fhir/transform/dhis/impl/util/dstu3/Dstu3FhirResourceDhisToFhirTransformerUtils.java b/fhir-dstu3/src/main/java/org/dhis2/fhir/adapter/fhir/transform/dhis/impl/util/dstu3/Dstu3FhirResourceDhisToFhirTransformerUtils.java index e66c4fa3..ac082a24 100644 --- a/fhir-dstu3/src/main/java/org/dhis2/fhir/adapter/fhir/transform/dhis/impl/util/dstu3/Dstu3FhirResourceDhisToFhirTransformerUtils.java +++ b/fhir-dstu3/src/main/java/org/dhis2/fhir/adapter/fhir/transform/dhis/impl/util/dstu3/Dstu3FhirResourceDhisToFhirTransformerUtils.java @@ -40,7 +40,6 @@ import org.hl7.fhir.dstu3.model.Reference; import org.hl7.fhir.dstu3.model.Resource; import org.hl7.fhir.dstu3.model.ResourceFactory; -import org.hl7.fhir.dstu3.model.StringType; import org.hl7.fhir.exceptions.FHIRException; import org.hl7.fhir.instance.model.api.IBase; import org.hl7.fhir.instance.model.api.IBaseBundle; @@ -144,7 +143,7 @@ public boolean containsString( @Nonnull List> s { return false; } - return stringList.contains( new StringType( value ) ); + return stringList.stream().anyMatch( s -> value.equals( s.getValue() ) ); } @Override diff --git a/fhir-dstu3/src/main/java/org/dhis2/fhir/adapter/fhir/transform/dhis/impl/util/dstu3/Dstu3GeoDhisToFhirTransformerUtils.java b/fhir-dstu3/src/main/java/org/dhis2/fhir/adapter/fhir/transform/dhis/impl/util/dstu3/Dstu3GeoDhisToFhirTransformerUtils.java index 3fa33dc1..2749d5c8 100644 --- a/fhir-dstu3/src/main/java/org/dhis2/fhir/adapter/fhir/transform/dhis/impl/util/dstu3/Dstu3GeoDhisToFhirTransformerUtils.java +++ b/fhir-dstu3/src/main/java/org/dhis2/fhir/adapter/fhir/transform/dhis/impl/util/dstu3/Dstu3GeoDhisToFhirTransformerUtils.java @@ -72,7 +72,7 @@ public Set getFhirVersions() public void updateAddressLocation( @Nonnull IElement element, @Nullable Location location ) throws TransformerException { final Element e = (Element) element; - e.getExtension().removeIf( i -> i.hasExtension( GEO_LOCATION_URI ) ); + e.getExtension().removeIf( i -> GEO_LOCATION_URI.equals( i.getUrl() ) ); if ( location != null ) { e.addExtension().setUrl( GEO_LOCATION_URI ) diff --git a/fhir-dstu3/src/test/java/org/dhis2/fhir/adapter/fhir/transform/dhis/impl/util/dstu3/Dstu3AdministrativeGenderDhisToFhirTransformerUtilsTest.java b/fhir-dstu3/src/test/java/org/dhis2/fhir/adapter/fhir/transform/dhis/impl/util/dstu3/Dstu3AdministrativeGenderDhisToFhirTransformerUtilsTest.java new file mode 100644 index 00000000..4e57b9a6 --- /dev/null +++ b/fhir-dstu3/src/test/java/org/dhis2/fhir/adapter/fhir/transform/dhis/impl/util/dstu3/Dstu3AdministrativeGenderDhisToFhirTransformerUtilsTest.java @@ -0,0 +1,113 @@ +package org.dhis2.fhir.adapter.fhir.transform.dhis.impl.util.dstu3; + +/* + * 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.converter.ValueConverter; +import org.dhis2.fhir.adapter.fhir.converter.dstu3.Dstu3StringToAdministrativeGenderConverter; +import org.dhis2.fhir.adapter.fhir.metadata.model.Constant; +import org.dhis2.fhir.adapter.fhir.metadata.model.ConstantResolver; +import org.dhis2.fhir.adapter.fhir.script.ScriptExecutionContext; +import org.dhis2.fhir.adapter.spring.StaticObjectProvider; +import org.hl7.fhir.dstu3.model.Enumerations; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.junit.MockitoJUnit; +import org.mockito.junit.MockitoRule; +import org.springframework.core.convert.ConversionService; +import org.springframework.core.convert.support.DefaultConversionService; + +import java.util.Collections; +import java.util.Optional; + +/** + * Unit tests for {@link Dstu3AdministrativeGenderDhisToFhirTransformerUtils}. + * + * @author volsch + */ +public class Dstu3AdministrativeGenderDhisToFhirTransformerUtilsTest +{ + @Mock + private ScriptExecutionContext scriptExecutionContext; + + @Mock + private ConstantResolver constantResolver; + + private Dstu3AdministrativeGenderDhisToFhirTransformerUtils utils; + + @Rule + public MockitoRule rule = MockitoJUnit.rule(); + + @Before + public void before() + { + final ConversionService conversionService = new DefaultConversionService(); + final ValueConverter valueConverter = new ValueConverter( new StaticObjectProvider<>( + Collections.singletonList( new Dstu3StringToAdministrativeGenderConverter( constantResolver ) ) ), + conversionService ); + utils = new Dstu3AdministrativeGenderDhisToFhirTransformerUtils( scriptExecutionContext, valueConverter ); + } + + @Test + public void getAdministrativeGenderMale() + { + final Constant maleConstant = new Constant(); + maleConstant.setCode( "GENDER_MALE" ); + maleConstant.setValue( "Male" ); + + final Constant femaleConstant = new Constant(); + femaleConstant.setCode( "GENDER_FEMALE" ); + femaleConstant.setValue( "Female" ); + + Mockito.when( constantResolver.findOneByCode( Mockito.eq( "GENDER_MALE" ) ) ).thenReturn( Optional.of( maleConstant ) ); + Mockito.when( constantResolver.findOneByCode( Mockito.eq( "GENDER_FEMALE" ) ) ).thenReturn( Optional.of( femaleConstant ) ); + + Assert.assertEquals( Enumerations.AdministrativeGender.MALE, utils.getAdministrativeGender( "male" ) ); + } + + @Test + public void getAdministrativeGenderFemale() + { + final Constant maleConstant = new Constant(); + maleConstant.setCode( "GENDER_MALE" ); + maleConstant.setValue( "Male" ); + + final Constant femaleConstant = new Constant(); + femaleConstant.setCode( "GENDER_FEMALE" ); + femaleConstant.setValue( "Female" ); + + Mockito.when( constantResolver.findOneByCode( Mockito.eq( "GENDER_MALE" ) ) ).thenReturn( Optional.of( maleConstant ) ); + Mockito.when( constantResolver.findOneByCode( Mockito.eq( "GENDER_FEMALE" ) ) ).thenReturn( Optional.of( femaleConstant ) ); + + Assert.assertEquals( Enumerations.AdministrativeGender.FEMALE, utils.getAdministrativeGender( "FEMALE" ) ); + } +} \ No newline at end of file diff --git a/fhir-dstu3/src/test/java/org/dhis2/fhir/adapter/fhir/transform/dhis/impl/util/dstu3/Dstu3CodeDhisToFhirTransformerUtilsTest.java b/fhir-dstu3/src/test/java/org/dhis2/fhir/adapter/fhir/transform/dhis/impl/util/dstu3/Dstu3CodeDhisToFhirTransformerUtilsTest.java new file mode 100644 index 00000000..edd18f44 --- /dev/null +++ b/fhir-dstu3/src/test/java/org/dhis2/fhir/adapter/fhir/transform/dhis/impl/util/dstu3/Dstu3CodeDhisToFhirTransformerUtilsTest.java @@ -0,0 +1,238 @@ +package org.dhis2.fhir.adapter.fhir.transform.dhis.impl.util.dstu3; + +/* + * 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.fhir.metadata.model.CodeSet; +import org.dhis2.fhir.adapter.fhir.metadata.model.FhirResourceType; +import org.dhis2.fhir.adapter.fhir.metadata.model.ProgramStageRule; +import org.dhis2.fhir.adapter.fhir.metadata.model.RuleInfo; +import org.dhis2.fhir.adapter.fhir.metadata.model.ScriptVariable; +import org.dhis2.fhir.adapter.fhir.metadata.model.SystemCode; +import org.dhis2.fhir.adapter.fhir.metadata.repository.SystemCodeRepository; +import org.dhis2.fhir.adapter.fhir.model.SystemCodeValue; +import org.dhis2.fhir.adapter.fhir.model.SystemCodeValues; +import org.dhis2.fhir.adapter.fhir.script.ScriptExecution; +import org.dhis2.fhir.adapter.fhir.script.ScriptExecutionContext; +import org.dhis2.fhir.adapter.fhir.transform.dhis.DhisToFhirTransformerContext; +import org.dhis2.fhir.adapter.fhir.transform.fhir.model.ResourceSystem; +import org.dhis2.fhir.adapter.fhir.transform.util.TransformerUtils; +import org.hl7.fhir.dstu3.model.CodeableConcept; +import org.junit.Assert; +import org.junit.Rule; +import org.junit.Test; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.junit.MockitoJUnit; +import org.mockito.junit.MockitoRule; + +import java.util.Arrays; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; +import java.util.Objects; +import java.util.Optional; +import java.util.UUID; + +/** + * Unit tests for {@link Dstu3CodeDhisToFhirTransformerUtils}. + * + * @author volsch + */ +public class Dstu3CodeDhisToFhirTransformerUtilsTest +{ + @Mock + private ScriptExecutionContext scriptExecutionContext; + + @Mock + private ScriptExecution scriptExecution; + + @Mock + private SystemCodeRepository systemCodeRepository; + + @Mock + private DhisToFhirTransformerContext context; + + @InjectMocks + private Dstu3CodeDhisToFhirTransformerUtils utils; + + @Rule + public MockitoRule rule = MockitoJUnit.rule(); + + @Test + public void getRuleCodeableConceptNull() + { + final ProgramStageRule programStageRule = new ProgramStageRule(); + + final Map contextVariables = new HashMap<>(); + contextVariables.put( TransformerUtils.RULE_VAR_NAME, new RuleInfo<>( programStageRule, Collections.emptyList() ) ); + + Mockito.when( scriptExecutionContext.getScriptExecution() ).thenReturn( scriptExecution ); + Mockito.when( scriptExecution.getContextVariables() ).thenReturn( contextVariables ); + + Assert.assertNull( utils.getRuleCodeableConcept() ); + } + + @Test + public void getRuleCodeableConcept() + { + final CodeSet codeSet = new CodeSet(); + codeSet.setId( UUID.randomUUID() ); + final ProgramStageRule programStageRule = new ProgramStageRule(); + programStageRule.setApplicableCodeSet( codeSet ); + + final Map contextVariables = new HashMap<>(); + contextVariables.put( TransformerUtils.RULE_VAR_NAME, new RuleInfo<>( programStageRule, Collections.emptyList() ) ); + + final SystemCodeValues systemCodeValues = new SystemCodeValues( "testText", + Arrays.asList( new SystemCodeValue( "SNOMED CT", "837823" ), + new SystemCodeValue( "LOINC", "84878973-8", "Test Text" ) ) ); + + Mockito.when( scriptExecutionContext.getScriptExecution() ).thenReturn( scriptExecution ); + Mockito.when( scriptExecution.getContextVariables() ).thenReturn( contextVariables ); + Mockito.when( systemCodeRepository.findPreferredByCodeSetId( Mockito.eq( codeSet.getId() ) ) ) + .thenReturn( systemCodeValues ); + + final CodeableConcept codeableConcept = (CodeableConcept) Objects.requireNonNull( utils.getRuleCodeableConcept() ); + Assert.assertEquals( "testText", codeableConcept.getText() ); + Assert.assertEquals( 2, codeableConcept.getCoding().size() ); + Assert.assertEquals( "SNOMED CT", codeableConcept.getCoding().get( 0 ).getSystem() ); + Assert.assertEquals( "837823", codeableConcept.getCoding().get( 0 ).getCode() ); + Assert.assertNull( codeableConcept.getCoding().get( 0 ).getDisplay() ); + Assert.assertEquals( "LOINC", codeableConcept.getCoding().get( 1 ).getSystem() ); + Assert.assertEquals( "84878973-8", codeableConcept.getCoding().get( 1 ).getCode() ); + Assert.assertEquals( "Test Text", codeableConcept.getCoding().get( 1 ).getDisplay() ); + } + + @Test + public void getByMappedCodeNull() + { + Assert.assertNull( utils.getByMappedCode( null, FhirResourceType.ORGANIZATION ) ); + } + + @Test + public void getByMappedCode() + { + final ResourceSystem resourceSystem = new ResourceSystem( FhirResourceType.ORGANIZATION, "TestSystem", null, null, null ); + final SystemCode systemCode = new SystemCode(); + systemCode.setSystemCode( "837232" ); + + final Map variables = new HashMap<>(); + variables.put( ScriptVariable.CONTEXT.getVariableName(), context ); + + final SystemCodeValues systemCodeValues = new SystemCodeValues( "testText", + Arrays.asList( new SystemCodeValue( "SNOMED CT", "837823" ), + new SystemCodeValue( "LOINC", "84878973-8", "Test Text" ) ) ); + + Mockito.when( scriptExecutionContext.getScriptExecution() ).thenReturn( scriptExecution ); + Mockito.when( scriptExecution.getVariables() ).thenReturn( variables ); + Mockito.when( context.getOptionalResourceSystem( Mockito.eq( FhirResourceType.ORGANIZATION ) ) ) + .thenReturn( Optional.of( resourceSystem ) ); + Mockito.when( systemCodeRepository.findOneByMappedCode( Mockito.eq( "TestSystem" ), Mockito.eq( "TEST_1" ) ) ) + .thenReturn( Optional.of( systemCode ) ); + + Assert.assertEquals( "837232", utils.getByMappedCode( "TEST_1", FhirResourceType.ORGANIZATION ) ); + } + + @Test + public void getByMappedCodeNotFound() + { + final ResourceSystem resourceSystem = new ResourceSystem( FhirResourceType.ORGANIZATION, "TestSystem", null, null, null ); + + final Map variables = new HashMap<>(); + variables.put( ScriptVariable.CONTEXT.getVariableName(), context ); + + final SystemCodeValues systemCodeValues = new SystemCodeValues( "testText", + Arrays.asList( new SystemCodeValue( "SNOMED CT", "837823" ), + new SystemCodeValue( "LOINC", "84878973-8", "Test Text" ) ) ); + + Mockito.when( scriptExecutionContext.getScriptExecution() ).thenReturn( scriptExecution ); + Mockito.when( scriptExecution.getVariables() ).thenReturn( variables ); + Mockito.when( context.getOptionalResourceSystem( Mockito.eq( FhirResourceType.ORGANIZATION ) ) ) + .thenReturn( Optional.of( resourceSystem ) ); + Mockito.when( systemCodeRepository.findOneByMappedCode( Mockito.eq( "TestSystem" ), Mockito.eq( "TEST_1" ) ) ) + .thenReturn( Optional.empty() ); + + Assert.assertNull( utils.getByMappedCode( "TEST_1", FhirResourceType.ORGANIZATION ) ); + } + + @Test + public void getCodeWithoutPrefixPrefix() + { + final ResourceSystem resourceSystem = new ResourceSystem( FhirResourceType.ORGANIZATION, "TestSystem", "SE_", null, null ); + + final Map variables = new HashMap<>(); + variables.put( ScriptVariable.CONTEXT.getVariableName(), context ); + + Mockito.when( scriptExecutionContext.getScriptExecution() ).thenReturn( scriptExecution ); + Mockito.when( scriptExecution.getVariables() ).thenReturn( variables ); + Mockito.when( context.getOptionalResourceSystem( Mockito.eq( FhirResourceType.ORGANIZATION ) ) ) + .thenReturn( Optional.of( resourceSystem ) ); + + Assert.assertEquals( "TEST3", utils.getCodeWithoutPrefix( "SE_TEST3", FhirResourceType.ORGANIZATION ) ); + } + + @Test + public void getCodeWithoutPrefixNoPrefix() + { + final ResourceSystem resourceSystem = new ResourceSystem( FhirResourceType.ORGANIZATION, "TestSystem", "SE_", null, null ); + + final Map variables = new HashMap<>(); + variables.put( ScriptVariable.CONTEXT.getVariableName(), context ); + + Mockito.when( scriptExecutionContext.getScriptExecution() ).thenReturn( scriptExecution ); + Mockito.when( scriptExecution.getVariables() ).thenReturn( variables ); + Mockito.when( context.getOptionalResourceSystem( Mockito.eq( FhirResourceType.ORGANIZATION ) ) ) + .thenReturn( Optional.of( resourceSystem ) ); + + Assert.assertEquals( "TEST3", utils.getCodeWithoutPrefix( "TEST3", FhirResourceType.ORGANIZATION ) ); + } + + @Test + public void getCodeWithoutPrefixNoPrefixSystem() + { + final ResourceSystem resourceSystem = new ResourceSystem( FhirResourceType.ORGANIZATION, "TestSystem", null, null, null ); + + final Map variables = new HashMap<>(); + variables.put( ScriptVariable.CONTEXT.getVariableName(), context ); + + Mockito.when( scriptExecutionContext.getScriptExecution() ).thenReturn( scriptExecution ); + Mockito.when( scriptExecution.getVariables() ).thenReturn( variables ); + Mockito.when( context.getOptionalResourceSystem( Mockito.eq( FhirResourceType.ORGANIZATION ) ) ) + .thenReturn( Optional.of( resourceSystem ) ); + + Assert.assertEquals( "SE_TEST3", utils.getCodeWithoutPrefix( "SE_TEST3", FhirResourceType.ORGANIZATION ) ); + } + + @Test + public void getCodeWithoutPrefixNull() + { + Assert.assertNull( utils.getCodeWithoutPrefix( null, FhirResourceType.ORGANIZATION ) ); + } +} \ No newline at end of file diff --git a/fhir-dstu3/src/test/java/org/dhis2/fhir/adapter/fhir/transform/dhis/impl/util/dstu3/Dstu3DateTimeDhisToFhirTransformerUtilsTest.java b/fhir-dstu3/src/test/java/org/dhis2/fhir/adapter/fhir/transform/dhis/impl/util/dstu3/Dstu3DateTimeDhisToFhirTransformerUtilsTest.java new file mode 100644 index 00000000..ba5d6c83 --- /dev/null +++ b/fhir-dstu3/src/test/java/org/dhis2/fhir/adapter/fhir/transform/dhis/impl/util/dstu3/Dstu3DateTimeDhisToFhirTransformerUtilsTest.java @@ -0,0 +1,150 @@ +package org.dhis2.fhir.adapter.fhir.transform.dhis.impl.util.dstu3; + +/* + * 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 ca.uhn.fhir.model.api.TemporalPrecisionEnum; +import org.dhis2.fhir.adapter.fhir.script.ScriptExecutionContext; +import org.hl7.fhir.dstu3.model.DateTimeType; +import org.hl7.fhir.dstu3.model.DateType; +import org.junit.Assert; +import org.junit.Rule; +import org.junit.Test; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.MockitoJUnit; +import org.mockito.junit.MockitoRule; + +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.ZoneId; +import java.util.Date; +import java.util.Objects; + +/** + * Unit tests for {@link Dstu3DateTimeDhisToFhirTransformerUtils}. + * + * @author volsch + */ +public class Dstu3DateTimeDhisToFhirTransformerUtilsTest +{ + @Mock + private ScriptExecutionContext scriptExecutionContext; + + @InjectMocks + private Dstu3DateTimeDhisToFhirTransformerUtils utils; + + @Rule + public MockitoRule rule = MockitoJUnit.rule(); + + @Test + public void getPreciseDateElementMonthPrecision() + { + final DateTimeType dateTimeDt = new DateTimeType( new Date(), TemporalPrecisionEnum.MONTH ); + Assert.assertNull( utils.getPreciseDateElement( dateTimeDt ) ); + } + + @Test + public void getPreciseDateElementDayPrecision() + { + final DateTimeType dateTimeDt = new DateTimeType( new Date(), TemporalPrecisionEnum.DAY ); + Assert.assertEquals( new DateType( new Date() ).getValueAsString(), Objects.requireNonNull( utils.getPreciseDateElement( dateTimeDt ) ).getValueAsString() ); + } + + @Test + public void getPreciseDateElementDate() + { + Assert.assertEquals( new DateType( new Date() ).getValueAsString(), Objects.requireNonNull( utils.getPreciseDateElement( new Date() ) ).getValueAsString() ); + } + + @Test + public void getPreciseDateElementLocalDate() + { + Assert.assertEquals( new DateType( new Date() ).getValueAsString(), Objects.requireNonNull( utils.getPreciseDateElement( LocalDate.now() ) ).getValueAsString() ); + } + + @Test + public void getPreciseDateElementNull() + { + Assert.assertNull( utils.getPreciseDateElement( null ) ); + } + + @Test + public void getDateTimeElementNull() + { + Assert.assertNull( utils.getDateTimeElement( null ) ); + } + + @Test + public void getDateTimeElementDate() + { + final Date date = new Date(); + Assert.assertEquals( new DateTimeType( date, TemporalPrecisionEnum.MILLI ).getValueAsString(), Objects.requireNonNull( utils.getDateTimeElement( date ) ).getValueAsString() ); + } + + @Test + public void getDateTimeElementLocalDateTime() + { + final Date date = new Date(); + Assert.assertEquals( new DateTimeType( date, TemporalPrecisionEnum.MILLI ).getValueAsString(), Objects.requireNonNull( utils.getDateTimeElement( LocalDateTime.ofInstant( date.toInstant(), ZoneId.systemDefault() ) ) ).getValueAsString() ); + } + + @Test + public void getDateTimeElementElement() + { + final Date date = new Date(); + Assert.assertEquals( new DateTimeType( date, TemporalPrecisionEnum.MILLI ).getValueAsString(), Objects.requireNonNull( utils.getDateTimeElement( new DateTimeType( date ) ) ).getValueAsString() ); + } + + @Test + public void getDayDateTimeElementNull() + { + Assert.assertNull( utils.getDayDateTimeElement( null ) ); + } + + @Test + public void getDayDateTimeElementDate() + { + final Date date = new Date(); + Assert.assertEquals( new DateTimeType( date, TemporalPrecisionEnum.DAY ).getValueAsString(), Objects.requireNonNull( utils.getDayDateTimeElement( date ) ).getValueAsString() ); + } + + @Test + public void getDayDateTimeElementLocalDateTime() + { + final Date date = new Date(); + Assert.assertEquals( new DateTimeType( date, TemporalPrecisionEnum.DAY ).getValueAsString(), Objects.requireNonNull( utils.getDayDateTimeElement( LocalDateTime.ofInstant( date.toInstant(), ZoneId.systemDefault() ) ) ).getValueAsString() ); + } + + @Test + public void getDayDateTimeElementElement() + { + final Date date = new Date(); + Assert.assertEquals( new DateTimeType( date, TemporalPrecisionEnum.DAY ).getValueAsString(), Objects.requireNonNull( utils.getDayDateTimeElement( new DateTimeType( date ) ) ).getValueAsString() ); + } +} \ No newline at end of file diff --git a/fhir-dstu3/src/test/java/org/dhis2/fhir/adapter/fhir/transform/dhis/impl/util/dstu3/Dstu3EncounterDhisToFhirTransformerUtilsTest.java b/fhir-dstu3/src/test/java/org/dhis2/fhir/adapter/fhir/transform/dhis/impl/util/dstu3/Dstu3EncounterDhisToFhirTransformerUtilsTest.java new file mode 100644 index 00000000..5770585e --- /dev/null +++ b/fhir-dstu3/src/test/java/org/dhis2/fhir/adapter/fhir/transform/dhis/impl/util/dstu3/Dstu3EncounterDhisToFhirTransformerUtilsTest.java @@ -0,0 +1,62 @@ +package org.dhis2.fhir.adapter.fhir.transform.dhis.impl.util.dstu3; + +/* + * 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.fhir.script.ScriptExecutionContext; +import org.hl7.fhir.dstu3.model.Encounter; +import org.junit.Assert; +import org.junit.Rule; +import org.junit.Test; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.MockitoJUnit; +import org.mockito.junit.MockitoRule; + +/** + * Unit tests for {@link Dstu3EncounterDhisToFhirTransformerUtils}. + * + * @author volsch + */ +public class Dstu3EncounterDhisToFhirTransformerUtilsTest +{ + @Mock + private ScriptExecutionContext scriptExecutionContext; + + @InjectMocks + private Dstu3EncounterDhisToFhirTransformerUtils utils; + + @Rule + public MockitoRule rule = MockitoJUnit.rule(); + + @Test + public void getStatus() + { + Assert.assertEquals( Encounter.EncounterStatus.ARRIVED, utils.getEncounterStatus( "arrived" ) ); + } +} \ No newline at end of file diff --git a/fhir-dstu3/src/test/java/org/dhis2/fhir/adapter/fhir/transform/dhis/impl/util/dstu3/Dstu3FhirResourceDhisToFhirTransformerUtilsTest.java b/fhir-dstu3/src/test/java/org/dhis2/fhir/adapter/fhir/transform/dhis/impl/util/dstu3/Dstu3FhirResourceDhisToFhirTransformerUtilsTest.java new file mode 100644 index 00000000..cf4601e5 --- /dev/null +++ b/fhir-dstu3/src/test/java/org/dhis2/fhir/adapter/fhir/transform/dhis/impl/util/dstu3/Dstu3FhirResourceDhisToFhirTransformerUtilsTest.java @@ -0,0 +1,169 @@ +package org.dhis2.fhir.adapter.fhir.transform.dhis.impl.util.dstu3; + +/* + * 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.fhir.script.ScriptExecutionContext; +import org.hl7.fhir.dstu3.model.Bundle; +import org.hl7.fhir.dstu3.model.CodeableConcept; +import org.hl7.fhir.dstu3.model.DiagnosticReport; +import org.hl7.fhir.dstu3.model.EnrollmentRequest; +import org.hl7.fhir.dstu3.model.IdType; +import org.hl7.fhir.dstu3.model.Organization; +import org.hl7.fhir.dstu3.model.Patient; +import org.hl7.fhir.dstu3.model.Reference; +import org.hl7.fhir.dstu3.model.Resource; +import org.hl7.fhir.dstu3.model.StringType; +import org.hl7.fhir.instance.model.api.IBaseResource; +import org.junit.Assert; +import org.junit.Rule; +import org.junit.Test; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.MockitoJUnit; +import org.mockito.junit.MockitoRule; + +import java.util.Arrays; +import java.util.List; + +/** + * Unit tests for {@link Dstu3FhirResourceDhisToFhirTransformerUtils}. + * + * @author volsch + */ +public class Dstu3FhirResourceDhisToFhirTransformerUtilsTest +{ + @Mock + private ScriptExecutionContext scriptExecutionContext; + + @InjectMocks + private Dstu3FhirResourceDhisToFhirTransformerUtils utils; + + @Rule + public MockitoRule rule = MockitoJUnit.rule(); + + @Test + public void createResource() + { + Assert.assertEquals( DiagnosticReport.class, utils.createResource( "diagnostic-report" ).getClass() ); + } + + @Test + public void createType() + { + Assert.assertEquals( EnrollmentRequest.class, utils.createResource( "enrollment-request" ).getClass() ); + } + + @Test + public void createBundle() + { + final List resources = Arrays.asList( new Organization(), new Patient() ); + final Bundle bundle = (Bundle) utils.createBundle( resources ); + Assert.assertEquals( Bundle.BundleType.SEARCHSET, bundle.getType() ); + Assert.assertEquals( 2, bundle.getEntry().size() ); + } + + @Test + public void createCodeableConcept() + { + Assert.assertEquals( CodeableConcept.class, utils.createCodeableConcept().getClass() ); + } + + @Test + public void createLocalReference() + { + final Resource resource = new Patient(); + resource.setIdElement( new IdType( "#1234" ) ); + final Reference result = (Reference) utils.createReference( resource ); + Assert.assertSame( result.getResource(), resource ); + } + + @Test + public void createEmptyReference() + { + final Resource resource = new Patient(); + final Reference result = (Reference) utils.createReference( resource ); + Assert.assertSame( result.getResource(), resource ); + } + + @Test + public void createReference() + { + final Resource resource = new Patient(); + resource.setIdElement( (IdType) new IdType().setParts( "http://test.com/test", "Patient", "4711", "8379" ) ); + final Reference result = (Reference) utils.createReference( resource ); + Assert.assertNull( result.getResource() ); + Assert.assertEquals( "Patient/4711", resource.getIdElement().toUnqualifiedVersionless().toString() ); + } + + @Test + public void containsStringNull() + { + Assert.assertFalse( utils.containsString( Arrays.asList( new StringType( "abc" ), new StringType( "efg" ) ), null ) ); + } + + @Test + public void containsStringFalse() + { + Assert.assertFalse( utils.containsString( Arrays.asList( new StringType( "abc" ), new StringType( "efg" ) ), "test" ) ); + } + + @Test + public void containsStringTrue() + { + Assert.assertTrue( utils.containsString( Arrays.asList( new StringType( "abc" ), new StringType( "efg" ) ), "efg" ) ); + } + + @Test + public void equalsDeepFalse() + { + Patient p1 = new Patient(); + p1.setActive( true ); + p1.setManagingOrganization( new Reference( "1234" ) ); + + Patient p2 = new Patient(); + p2.setActive( true ); + p2.setManagingOrganization( new Reference( "1235" ) ); + + Assert.assertFalse( utils.equalsDeep( p1, p2 ) ); + } + + @Test + public void equalsDeepTrue() + { + Patient p1 = new Patient(); + p1.setActive( true ); + p1.setManagingOrganization( new Reference( "1234" ) ); + + Patient p2 = new Patient(); + p2.setActive( true ); + p2.setManagingOrganization( new Reference( "1234" ) ); + + Assert.assertTrue( utils.equalsDeep( p1, p2 ) ); + } +} \ No newline at end of file diff --git a/fhir-dstu3/src/test/java/org/dhis2/fhir/adapter/fhir/transform/dhis/impl/util/dstu3/Dstu3GeoDhisToFhirTransformerUtilsTest.java b/fhir-dstu3/src/test/java/org/dhis2/fhir/adapter/fhir/transform/dhis/impl/util/dstu3/Dstu3GeoDhisToFhirTransformerUtilsTest.java new file mode 100644 index 00000000..c5d49f48 --- /dev/null +++ b/fhir-dstu3/src/test/java/org/dhis2/fhir/adapter/fhir/transform/dhis/impl/util/dstu3/Dstu3GeoDhisToFhirTransformerUtilsTest.java @@ -0,0 +1,126 @@ +package org.dhis2.fhir.adapter.fhir.transform.dhis.impl.util.dstu3; + +/* + * 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.converter.ValueConverter; +import org.dhis2.fhir.adapter.fhir.script.ScriptExecutionContext; +import org.dhis2.fhir.adapter.geo.Location; +import org.dhis2.fhir.adapter.geo.StringToLocationConverter; +import org.dhis2.fhir.adapter.spring.StaticObjectProvider; +import org.hl7.fhir.dstu3.model.Address; +import org.hl7.fhir.dstu3.model.DecimalType; +import org.hl7.fhir.dstu3.model.Location.LocationPositionComponent; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.mockito.Mock; +import org.mockito.junit.MockitoJUnit; +import org.mockito.junit.MockitoRule; +import org.springframework.core.convert.ConversionService; +import org.springframework.core.convert.support.DefaultConversionService; + +import java.math.BigDecimal; +import java.util.Collections; +import java.util.Objects; + +/** + * Unit tests for {@link Dstu3GeoDhisToFhirTransformerUtils}. + * + * @author volsch + */ +public class Dstu3GeoDhisToFhirTransformerUtilsTest +{ + @Mock + private ScriptExecutionContext scriptExecutionContext; + + private Dstu3GeoDhisToFhirTransformerUtils utils; + + @Rule + public MockitoRule rule = MockitoJUnit.rule(); + + @Before + public void before() + { + final ConversionService conversionService = new DefaultConversionService(); + final ValueConverter valueConverter = new ValueConverter( new StaticObjectProvider<>( + Collections.singletonList( new StringToLocationConverter() ) ), + conversionService ); + utils = new Dstu3GeoDhisToFhirTransformerUtils( scriptExecutionContext, valueConverter ); + } + + @Test + public void createPositionNull() + { + Assert.assertNull( utils.createPosition( null ) ); + } + + @Test + public void createPosition() + { + final Location location = new Location( 47.1, -23.2 ); + final LocationPositionComponent position = (LocationPositionComponent) utils.createPosition( location ); + Assert.assertEquals( 47.1, Objects.requireNonNull( position ).getLongitude().doubleValue(), 0.0 ); + Assert.assertEquals( -23.2, Objects.requireNonNull( position ).getLatitude().doubleValue(), 0.0 ); + } + + @Test + public void updateAddressLocationNull() + { + final Address address = new Address(); + utils.updateAddressLocation( address, null ); + Assert.assertEquals( 0, address.getExtensionsByUrl( "http://hl7.org/fhir/StructureDefinition/geolocation" ).size() ); + } + + @Test + public void updateAddressLocationRemoved() + { + final Address address = new Address(); + address.addExtension().setUrl( "http://hl7.org/fhir/StructureDefinition/geolocation" ); + utils.updateAddressLocation( address, null ); + Assert.assertEquals( 0, address.getExtensionsByUrl( "http://hl7.org/fhir/StructureDefinition/geolocation" ).size() ); + } + + @Test + public void updateAddressLocationAddress() + { + final Address address = new Address(); + final Location location = new Location( 47.1, -23.2 ); + utils.updateAddressLocation( address, location ); + Assert.assertEquals( 1, address.getExtensionsByUrl( "http://hl7.org/fhir/StructureDefinition/geolocation" ).size() ); + Assert.assertEquals( 1, address.getExtensionsByUrl( "http://hl7.org/fhir/StructureDefinition/geolocation" ).get( 0 ) + .getExtensionsByUrl( "longitude" ).size() ); + Assert.assertEquals( BigDecimal.valueOf( 47.1 ), ( (DecimalType) address.getExtensionsByUrl( "http://hl7.org/fhir/StructureDefinition/geolocation" ).get( 0 ) + .getExtensionsByUrl( "longitude" ).get( 0 ).getValue() ).getValueAsNumber() ); + Assert.assertEquals( 1, address.getExtensionsByUrl( "http://hl7.org/fhir/StructureDefinition/geolocation" ).get( 0 ) + .getExtensionsByUrl( "latitude" ).size() ); + Assert.assertEquals( BigDecimal.valueOf( -23.2 ), ( (DecimalType) address.getExtensionsByUrl( "http://hl7.org/fhir/StructureDefinition/geolocation" ).get( 0 ) + .getExtensionsByUrl( "latitude" ).get( 0 ).getValue() ).getValueAsNumber() ); + } +} diff --git a/fhir-dstu3/src/test/java/org/dhis2/fhir/adapter/fhir/transform/dhis/impl/util/dstu3/Dstu3LocationDhisToFhirTransformerUtilsTest.java b/fhir-dstu3/src/test/java/org/dhis2/fhir/adapter/fhir/transform/dhis/impl/util/dstu3/Dstu3LocationDhisToFhirTransformerUtilsTest.java new file mode 100644 index 00000000..55fc83d7 --- /dev/null +++ b/fhir-dstu3/src/test/java/org/dhis2/fhir/adapter/fhir/transform/dhis/impl/util/dstu3/Dstu3LocationDhisToFhirTransformerUtilsTest.java @@ -0,0 +1,62 @@ +package org.dhis2.fhir.adapter.fhir.transform.dhis.impl.util.dstu3; + +/* + * 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.fhir.script.ScriptExecutionContext; +import org.hl7.fhir.dstu3.model.Location; +import org.junit.Assert; +import org.junit.Rule; +import org.junit.Test; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.MockitoJUnit; +import org.mockito.junit.MockitoRule; + +/** + * Unit tests for {@link Dstu3LocationDhisToFhirTransformerUtils}. + * + * @author volsch + */ +public class Dstu3LocationDhisToFhirTransformerUtilsTest +{ + @Mock + private ScriptExecutionContext scriptExecutionContext; + + @InjectMocks + private Dstu3LocationDhisToFhirTransformerUtils utils; + + @Rule + public MockitoRule rule = MockitoJUnit.rule(); + + @Test + public void getLocationStatus() + { + Assert.assertEquals( Location.LocationStatus.SUSPENDED, utils.getLocationStatus( "suspended" ) ); + } +} \ No newline at end of file diff --git a/fhir-dstu3/src/test/java/org/dhis2/fhir/adapter/fhir/transform/dhis/impl/util/dstu3/Dstu3ObservationDhisToFhirTransformerUtilsTest.java b/fhir-dstu3/src/test/java/org/dhis2/fhir/adapter/fhir/transform/dhis/impl/util/dstu3/Dstu3ObservationDhisToFhirTransformerUtilsTest.java new file mode 100644 index 00000000..9af9e57c --- /dev/null +++ b/fhir-dstu3/src/test/java/org/dhis2/fhir/adapter/fhir/transform/dhis/impl/util/dstu3/Dstu3ObservationDhisToFhirTransformerUtilsTest.java @@ -0,0 +1,62 @@ +package org.dhis2.fhir.adapter.fhir.transform.dhis.impl.util.dstu3; + +/* + * 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.fhir.script.ScriptExecutionContext; +import org.hl7.fhir.dstu3.model.Observation; +import org.junit.Assert; +import org.junit.Rule; +import org.junit.Test; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.MockitoJUnit; +import org.mockito.junit.MockitoRule; + +/** + * Unit tests for {@link Dstu3ObservationDhisToFhirTransformerUtils}. + * + * @author volsch + */ +public class Dstu3ObservationDhisToFhirTransformerUtilsTest +{ + @Mock + private ScriptExecutionContext scriptExecutionContext; + + @InjectMocks + private Dstu3ObservationDhisToFhirTransformerUtils utils; + + @Rule + public MockitoRule rule = MockitoJUnit.rule(); + + @Test + public void getObservationStatus() + { + Assert.assertEquals( Observation.ObservationStatus.AMENDED, utils.getObservationStatus( "amended" ) ); + } +} \ No newline at end of file diff --git a/fhir-r4/src/main/java/org/dhis2/fhir/adapter/fhir/transform/dhis/impl/util/r4/R4FhirResourceDhisToFhirTransformerUtils.java b/fhir-r4/src/main/java/org/dhis2/fhir/adapter/fhir/transform/dhis/impl/util/r4/R4FhirResourceDhisToFhirTransformerUtils.java index 937ca2a7..e5ad36aa 100644 --- a/fhir-r4/src/main/java/org/dhis2/fhir/adapter/fhir/transform/dhis/impl/util/r4/R4FhirResourceDhisToFhirTransformerUtils.java +++ b/fhir-r4/src/main/java/org/dhis2/fhir/adapter/fhir/transform/dhis/impl/util/r4/R4FhirResourceDhisToFhirTransformerUtils.java @@ -48,7 +48,6 @@ import org.hl7.fhir.r4.model.Reference; import org.hl7.fhir.r4.model.Resource; import org.hl7.fhir.r4.model.ResourceFactory; -import org.hl7.fhir.r4.model.StringType; import org.springframework.stereotype.Component; import javax.annotation.Nonnull; @@ -144,7 +143,7 @@ public boolean containsString( @Nonnull List> s { return false; } - return stringList.contains( new StringType( value ) ); + return stringList.stream().anyMatch( s -> value.equals( s.getValue() ) ); } @Override diff --git a/fhir-r4/src/main/java/org/dhis2/fhir/adapter/fhir/transform/dhis/impl/util/r4/R4GeoDhisToFhirTransformerUtils.java b/fhir-r4/src/main/java/org/dhis2/fhir/adapter/fhir/transform/dhis/impl/util/r4/R4GeoDhisToFhirTransformerUtils.java index 4b80511f..71874bb2 100644 --- a/fhir-r4/src/main/java/org/dhis2/fhir/adapter/fhir/transform/dhis/impl/util/r4/R4GeoDhisToFhirTransformerUtils.java +++ b/fhir-r4/src/main/java/org/dhis2/fhir/adapter/fhir/transform/dhis/impl/util/r4/R4GeoDhisToFhirTransformerUtils.java @@ -72,7 +72,7 @@ public Set getFhirVersions() public void updateAddressLocation( @Nonnull IElement element, @Nullable Location location ) throws TransformerException { final Element e = (Element) element; - e.getExtension().removeIf( i -> i.hasExtension( GEO_LOCATION_URI ) ); + e.getExtension().removeIf( i -> GEO_LOCATION_URI.equals( i.getUrl() ) ); if ( location != null ) { e.addExtension().setUrl( GEO_LOCATION_URI ) diff --git a/fhir-r4/src/test/java/org/dhis2/fhir/adapter/fhir/transform/dhis/impl/util/r4/R4AdministrativeGenderDhisToFhirTransformerUtilsTest.java b/fhir-r4/src/test/java/org/dhis2/fhir/adapter/fhir/transform/dhis/impl/util/r4/R4AdministrativeGenderDhisToFhirTransformerUtilsTest.java new file mode 100644 index 00000000..87db89e9 --- /dev/null +++ b/fhir-r4/src/test/java/org/dhis2/fhir/adapter/fhir/transform/dhis/impl/util/r4/R4AdministrativeGenderDhisToFhirTransformerUtilsTest.java @@ -0,0 +1,113 @@ +package org.dhis2.fhir.adapter.fhir.transform.dhis.impl.util.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.converter.ValueConverter; +import org.dhis2.fhir.adapter.fhir.converter.r4.R4StringToAdministrativeGenderConverter; +import org.dhis2.fhir.adapter.fhir.metadata.model.Constant; +import org.dhis2.fhir.adapter.fhir.metadata.model.ConstantResolver; +import org.dhis2.fhir.adapter.fhir.script.ScriptExecutionContext; +import org.dhis2.fhir.adapter.spring.StaticObjectProvider; +import org.hl7.fhir.r4.model.Enumerations; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.junit.MockitoJUnit; +import org.mockito.junit.MockitoRule; +import org.springframework.core.convert.ConversionService; +import org.springframework.core.convert.support.DefaultConversionService; + +import java.util.Collections; +import java.util.Optional; + +/** + * Unit tests for {@link R4AdministrativeGenderDhisToFhirTransformerUtils}. + * + * @author volsch + */ +public class R4AdministrativeGenderDhisToFhirTransformerUtilsTest +{ + @Mock + private ScriptExecutionContext scriptExecutionContext; + + @Mock + private ConstantResolver constantResolver; + + private R4AdministrativeGenderDhisToFhirTransformerUtils utils; + + @Rule + public MockitoRule rule = MockitoJUnit.rule(); + + @Before + public void before() + { + final ConversionService conversionService = new DefaultConversionService(); + final ValueConverter valueConverter = new ValueConverter( new StaticObjectProvider<>( + Collections.singletonList( new R4StringToAdministrativeGenderConverter( constantResolver ) ) ), + conversionService ); + utils = new R4AdministrativeGenderDhisToFhirTransformerUtils( scriptExecutionContext, valueConverter ); + } + + @Test + public void getAdministrativeGenderMale() + { + final Constant maleConstant = new Constant(); + maleConstant.setCode( "GENDER_MALE" ); + maleConstant.setValue( "Male" ); + + final Constant femaleConstant = new Constant(); + femaleConstant.setCode( "GENDER_FEMALE" ); + femaleConstant.setValue( "Female" ); + + Mockito.when( constantResolver.findOneByCode( Mockito.eq( "GENDER_MALE" ) ) ).thenReturn( Optional.of( maleConstant ) ); + Mockito.when( constantResolver.findOneByCode( Mockito.eq( "GENDER_FEMALE" ) ) ).thenReturn( Optional.of( femaleConstant ) ); + + Assert.assertEquals( Enumerations.AdministrativeGender.MALE, utils.getAdministrativeGender( "male" ) ); + } + + @Test + public void getAdministrativeGenderFemale() + { + final Constant maleConstant = new Constant(); + maleConstant.setCode( "GENDER_MALE" ); + maleConstant.setValue( "Male" ); + + final Constant femaleConstant = new Constant(); + femaleConstant.setCode( "GENDER_FEMALE" ); + femaleConstant.setValue( "Female" ); + + Mockito.when( constantResolver.findOneByCode( Mockito.eq( "GENDER_MALE" ) ) ).thenReturn( Optional.of( maleConstant ) ); + Mockito.when( constantResolver.findOneByCode( Mockito.eq( "GENDER_FEMALE" ) ) ).thenReturn( Optional.of( femaleConstant ) ); + + Assert.assertEquals( Enumerations.AdministrativeGender.FEMALE, utils.getAdministrativeGender( "FEMALE" ) ); + } +} \ No newline at end of file diff --git a/fhir-r4/src/test/java/org/dhis2/fhir/adapter/fhir/transform/dhis/impl/util/r4/R4CodeDhisToFhirTransformerUtilsTest.java b/fhir-r4/src/test/java/org/dhis2/fhir/adapter/fhir/transform/dhis/impl/util/r4/R4CodeDhisToFhirTransformerUtilsTest.java new file mode 100644 index 00000000..e4f30f9f --- /dev/null +++ b/fhir-r4/src/test/java/org/dhis2/fhir/adapter/fhir/transform/dhis/impl/util/r4/R4CodeDhisToFhirTransformerUtilsTest.java @@ -0,0 +1,238 @@ +package org.dhis2.fhir.adapter.fhir.transform.dhis.impl.util.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.fhir.metadata.model.CodeSet; +import org.dhis2.fhir.adapter.fhir.metadata.model.FhirResourceType; +import org.dhis2.fhir.adapter.fhir.metadata.model.ProgramStageRule; +import org.dhis2.fhir.adapter.fhir.metadata.model.RuleInfo; +import org.dhis2.fhir.adapter.fhir.metadata.model.ScriptVariable; +import org.dhis2.fhir.adapter.fhir.metadata.model.SystemCode; +import org.dhis2.fhir.adapter.fhir.metadata.repository.SystemCodeRepository; +import org.dhis2.fhir.adapter.fhir.model.SystemCodeValue; +import org.dhis2.fhir.adapter.fhir.model.SystemCodeValues; +import org.dhis2.fhir.adapter.fhir.script.ScriptExecution; +import org.dhis2.fhir.adapter.fhir.script.ScriptExecutionContext; +import org.dhis2.fhir.adapter.fhir.transform.dhis.DhisToFhirTransformerContext; +import org.dhis2.fhir.adapter.fhir.transform.fhir.model.ResourceSystem; +import org.dhis2.fhir.adapter.fhir.transform.util.TransformerUtils; +import org.hl7.fhir.r4.model.CodeableConcept; +import org.junit.Assert; +import org.junit.Rule; +import org.junit.Test; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.junit.MockitoJUnit; +import org.mockito.junit.MockitoRule; + +import java.util.Arrays; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; +import java.util.Objects; +import java.util.Optional; +import java.util.UUID; + +/** + * Unit tests for {@link R4CodeDhisToFhirTransformerUtils}. + * + * @author volsch + */ +public class R4CodeDhisToFhirTransformerUtilsTest +{ + @Mock + private ScriptExecutionContext scriptExecutionContext; + + @Mock + private ScriptExecution scriptExecution; + + @Mock + private SystemCodeRepository systemCodeRepository; + + @Mock + private DhisToFhirTransformerContext context; + + @InjectMocks + private R4CodeDhisToFhirTransformerUtils utils; + + @Rule + public MockitoRule rule = MockitoJUnit.rule(); + + @Test + public void getRuleCodeableConceptNull() + { + final ProgramStageRule programStageRule = new ProgramStageRule(); + + final Map contextVariables = new HashMap<>(); + contextVariables.put( TransformerUtils.RULE_VAR_NAME, new RuleInfo<>( programStageRule, Collections.emptyList() ) ); + + Mockito.when( scriptExecutionContext.getScriptExecution() ).thenReturn( scriptExecution ); + Mockito.when( scriptExecution.getContextVariables() ).thenReturn( contextVariables ); + + Assert.assertNull( utils.getRuleCodeableConcept() ); + } + + @Test + public void getRuleCodeableConcept() + { + final CodeSet codeSet = new CodeSet(); + codeSet.setId( UUID.randomUUID() ); + final ProgramStageRule programStageRule = new ProgramStageRule(); + programStageRule.setApplicableCodeSet( codeSet ); + + final Map contextVariables = new HashMap<>(); + contextVariables.put( TransformerUtils.RULE_VAR_NAME, new RuleInfo<>( programStageRule, Collections.emptyList() ) ); + + final SystemCodeValues systemCodeValues = new SystemCodeValues( "testText", + Arrays.asList( new SystemCodeValue( "SNOMED CT", "837823" ), + new SystemCodeValue( "LOINC", "84878973-8", "Test Text" ) ) ); + + Mockito.when( scriptExecutionContext.getScriptExecution() ).thenReturn( scriptExecution ); + Mockito.when( scriptExecution.getContextVariables() ).thenReturn( contextVariables ); + Mockito.when( systemCodeRepository.findPreferredByCodeSetId( Mockito.eq( codeSet.getId() ) ) ) + .thenReturn( systemCodeValues ); + + final CodeableConcept codeableConcept = (CodeableConcept) Objects.requireNonNull( utils.getRuleCodeableConcept() ); + Assert.assertEquals( "testText", codeableConcept.getText() ); + Assert.assertEquals( 2, codeableConcept.getCoding().size() ); + Assert.assertEquals( "SNOMED CT", codeableConcept.getCoding().get( 0 ).getSystem() ); + Assert.assertEquals( "837823", codeableConcept.getCoding().get( 0 ).getCode() ); + Assert.assertNull( codeableConcept.getCoding().get( 0 ).getDisplay() ); + Assert.assertEquals( "LOINC", codeableConcept.getCoding().get( 1 ).getSystem() ); + Assert.assertEquals( "84878973-8", codeableConcept.getCoding().get( 1 ).getCode() ); + Assert.assertEquals( "Test Text", codeableConcept.getCoding().get( 1 ).getDisplay() ); + } + + @Test + public void getByMappedCodeNull() + { + Assert.assertNull( utils.getByMappedCode( null, FhirResourceType.ORGANIZATION ) ); + } + + @Test + public void getByMappedCode() + { + final ResourceSystem resourceSystem = new ResourceSystem( FhirResourceType.ORGANIZATION, "TestSystem", null, null, null ); + final SystemCode systemCode = new SystemCode(); + systemCode.setSystemCode( "837232" ); + + final Map variables = new HashMap<>(); + variables.put( ScriptVariable.CONTEXT.getVariableName(), context ); + + final SystemCodeValues systemCodeValues = new SystemCodeValues( "testText", + Arrays.asList( new SystemCodeValue( "SNOMED CT", "837823" ), + new SystemCodeValue( "LOINC", "84878973-8", "Test Text" ) ) ); + + Mockito.when( scriptExecutionContext.getScriptExecution() ).thenReturn( scriptExecution ); + Mockito.when( scriptExecution.getVariables() ).thenReturn( variables ); + Mockito.when( context.getOptionalResourceSystem( Mockito.eq( FhirResourceType.ORGANIZATION ) ) ) + .thenReturn( Optional.of( resourceSystem ) ); + Mockito.when( systemCodeRepository.findOneByMappedCode( Mockito.eq( "TestSystem" ), Mockito.eq( "TEST_1" ) ) ) + .thenReturn( Optional.of( systemCode ) ); + + Assert.assertEquals( "837232", utils.getByMappedCode( "TEST_1", FhirResourceType.ORGANIZATION ) ); + } + + @Test + public void getByMappedCodeNotFound() + { + final ResourceSystem resourceSystem = new ResourceSystem( FhirResourceType.ORGANIZATION, "TestSystem", null, null, null ); + + final Map variables = new HashMap<>(); + variables.put( ScriptVariable.CONTEXT.getVariableName(), context ); + + final SystemCodeValues systemCodeValues = new SystemCodeValues( "testText", + Arrays.asList( new SystemCodeValue( "SNOMED CT", "837823" ), + new SystemCodeValue( "LOINC", "84878973-8", "Test Text" ) ) ); + + Mockito.when( scriptExecutionContext.getScriptExecution() ).thenReturn( scriptExecution ); + Mockito.when( scriptExecution.getVariables() ).thenReturn( variables ); + Mockito.when( context.getOptionalResourceSystem( Mockito.eq( FhirResourceType.ORGANIZATION ) ) ) + .thenReturn( Optional.of( resourceSystem ) ); + Mockito.when( systemCodeRepository.findOneByMappedCode( Mockito.eq( "TestSystem" ), Mockito.eq( "TEST_1" ) ) ) + .thenReturn( Optional.empty() ); + + Assert.assertNull( utils.getByMappedCode( "TEST_1", FhirResourceType.ORGANIZATION ) ); + } + + @Test + public void getCodeWithoutPrefixPrefix() + { + final ResourceSystem resourceSystem = new ResourceSystem( FhirResourceType.ORGANIZATION, "TestSystem", "SE_", null, null ); + + final Map variables = new HashMap<>(); + variables.put( ScriptVariable.CONTEXT.getVariableName(), context ); + + Mockito.when( scriptExecutionContext.getScriptExecution() ).thenReturn( scriptExecution ); + Mockito.when( scriptExecution.getVariables() ).thenReturn( variables ); + Mockito.when( context.getOptionalResourceSystem( Mockito.eq( FhirResourceType.ORGANIZATION ) ) ) + .thenReturn( Optional.of( resourceSystem ) ); + + Assert.assertEquals( "TEST3", utils.getCodeWithoutPrefix( "SE_TEST3", FhirResourceType.ORGANIZATION ) ); + } + + @Test + public void getCodeWithoutPrefixNoPrefix() + { + final ResourceSystem resourceSystem = new ResourceSystem( FhirResourceType.ORGANIZATION, "TestSystem", "SE_", null, null ); + + final Map variables = new HashMap<>(); + variables.put( ScriptVariable.CONTEXT.getVariableName(), context ); + + Mockito.when( scriptExecutionContext.getScriptExecution() ).thenReturn( scriptExecution ); + Mockito.when( scriptExecution.getVariables() ).thenReturn( variables ); + Mockito.when( context.getOptionalResourceSystem( Mockito.eq( FhirResourceType.ORGANIZATION ) ) ) + .thenReturn( Optional.of( resourceSystem ) ); + + Assert.assertEquals( "TEST3", utils.getCodeWithoutPrefix( "TEST3", FhirResourceType.ORGANIZATION ) ); + } + + @Test + public void getCodeWithoutPrefixNoPrefixSystem() + { + final ResourceSystem resourceSystem = new ResourceSystem( FhirResourceType.ORGANIZATION, "TestSystem", null, null, null ); + + final Map variables = new HashMap<>(); + variables.put( ScriptVariable.CONTEXT.getVariableName(), context ); + + Mockito.when( scriptExecutionContext.getScriptExecution() ).thenReturn( scriptExecution ); + Mockito.when( scriptExecution.getVariables() ).thenReturn( variables ); + Mockito.when( context.getOptionalResourceSystem( Mockito.eq( FhirResourceType.ORGANIZATION ) ) ) + .thenReturn( Optional.of( resourceSystem ) ); + + Assert.assertEquals( "SE_TEST3", utils.getCodeWithoutPrefix( "SE_TEST3", FhirResourceType.ORGANIZATION ) ); + } + + @Test + public void getCodeWithoutPrefixNull() + { + Assert.assertNull( utils.getCodeWithoutPrefix( null, FhirResourceType.ORGANIZATION ) ); + } +} \ No newline at end of file diff --git a/fhir-r4/src/test/java/org/dhis2/fhir/adapter/fhir/transform/dhis/impl/util/r4/R4DateTimeDhisToFhirTransformerUtilsTest.java b/fhir-r4/src/test/java/org/dhis2/fhir/adapter/fhir/transform/dhis/impl/util/r4/R4DateTimeDhisToFhirTransformerUtilsTest.java new file mode 100644 index 00000000..7de12464 --- /dev/null +++ b/fhir-r4/src/test/java/org/dhis2/fhir/adapter/fhir/transform/dhis/impl/util/r4/R4DateTimeDhisToFhirTransformerUtilsTest.java @@ -0,0 +1,150 @@ +package org.dhis2.fhir.adapter.fhir.transform.dhis.impl.util.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 ca.uhn.fhir.model.api.TemporalPrecisionEnum; +import org.dhis2.fhir.adapter.fhir.script.ScriptExecutionContext; +import org.hl7.fhir.r4.model.DateTimeType; +import org.hl7.fhir.r4.model.DateType; +import org.junit.Assert; +import org.junit.Rule; +import org.junit.Test; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.MockitoJUnit; +import org.mockito.junit.MockitoRule; + +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.ZoneId; +import java.util.Date; +import java.util.Objects; + +/** + * Unit tests for {@link R4DateTimeDhisToFhirTransformerUtils}. + * + * @author volsch + */ +public class R4DateTimeDhisToFhirTransformerUtilsTest +{ + @Mock + private ScriptExecutionContext scriptExecutionContext; + + @InjectMocks + private R4DateTimeDhisToFhirTransformerUtils utils; + + @Rule + public MockitoRule rule = MockitoJUnit.rule(); + + @Test + public void getPreciseDateElementMonthPrecision() + { + final DateTimeType dateTimeDt = new DateTimeType( new Date(), TemporalPrecisionEnum.MONTH ); + Assert.assertNull( utils.getPreciseDateElement( dateTimeDt ) ); + } + + @Test + public void getPreciseDateElementDayPrecision() + { + final DateTimeType dateTimeDt = new DateTimeType( new Date(), TemporalPrecisionEnum.DAY ); + Assert.assertEquals( new DateType( new Date() ).getValueAsString(), Objects.requireNonNull( utils.getPreciseDateElement( dateTimeDt ) ).getValueAsString() ); + } + + @Test + public void getPreciseDateElementDate() + { + Assert.assertEquals( new DateType( new Date() ).getValueAsString(), Objects.requireNonNull( utils.getPreciseDateElement( new Date() ) ).getValueAsString() ); + } + + @Test + public void getPreciseDateElementLocalDate() + { + Assert.assertEquals( new DateType( new Date() ).getValueAsString(), Objects.requireNonNull( utils.getPreciseDateElement( LocalDate.now() ) ).getValueAsString() ); + } + + @Test + public void getPreciseDateElementNull() + { + Assert.assertNull( utils.getPreciseDateElement( null ) ); + } + + @Test + public void getDateTimeElementNull() + { + Assert.assertNull( utils.getDateTimeElement( null ) ); + } + + @Test + public void getDateTimeElementDate() + { + final Date date = new Date(); + Assert.assertEquals( new DateTimeType( date, TemporalPrecisionEnum.MILLI ).getValueAsString(), Objects.requireNonNull( utils.getDateTimeElement( date ) ).getValueAsString() ); + } + + @Test + public void getDateTimeElementLocalDateTime() + { + final Date date = new Date(); + Assert.assertEquals( new DateTimeType( date, TemporalPrecisionEnum.MILLI ).getValueAsString(), Objects.requireNonNull( utils.getDateTimeElement( LocalDateTime.ofInstant( date.toInstant(), ZoneId.systemDefault() ) ) ).getValueAsString() ); + } + + @Test + public void getDateTimeElementElement() + { + final Date date = new Date(); + Assert.assertEquals( new DateTimeType( date, TemporalPrecisionEnum.MILLI ).getValueAsString(), Objects.requireNonNull( utils.getDateTimeElement( new DateTimeType( date ) ) ).getValueAsString() ); + } + + @Test + public void getDayDateTimeElementNull() + { + Assert.assertNull( utils.getDayDateTimeElement( null ) ); + } + + @Test + public void getDayDateTimeElementDate() + { + final Date date = new Date(); + Assert.assertEquals( new DateTimeType( date, TemporalPrecisionEnum.DAY ).getValueAsString(), Objects.requireNonNull( utils.getDayDateTimeElement( date ) ).getValueAsString() ); + } + + @Test + public void getDayDateTimeElementLocalDateTime() + { + final Date date = new Date(); + Assert.assertEquals( new DateTimeType( date, TemporalPrecisionEnum.DAY ).getValueAsString(), Objects.requireNonNull( utils.getDayDateTimeElement( LocalDateTime.ofInstant( date.toInstant(), ZoneId.systemDefault() ) ) ).getValueAsString() ); + } + + @Test + public void getDayDateTimeElementElement() + { + final Date date = new Date(); + Assert.assertEquals( new DateTimeType( date, TemporalPrecisionEnum.DAY ).getValueAsString(), Objects.requireNonNull( utils.getDayDateTimeElement( new DateTimeType( date ) ) ).getValueAsString() ); + } +} \ No newline at end of file diff --git a/fhir-r4/src/test/java/org/dhis2/fhir/adapter/fhir/transform/dhis/impl/util/r4/R4EncounterDhisToFhirTransformerUtilsTest.java b/fhir-r4/src/test/java/org/dhis2/fhir/adapter/fhir/transform/dhis/impl/util/r4/R4EncounterDhisToFhirTransformerUtilsTest.java new file mode 100644 index 00000000..4963e1af --- /dev/null +++ b/fhir-r4/src/test/java/org/dhis2/fhir/adapter/fhir/transform/dhis/impl/util/r4/R4EncounterDhisToFhirTransformerUtilsTest.java @@ -0,0 +1,62 @@ +package org.dhis2.fhir.adapter.fhir.transform.dhis.impl.util.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.fhir.script.ScriptExecutionContext; +import org.hl7.fhir.r4.model.Encounter; +import org.junit.Assert; +import org.junit.Rule; +import org.junit.Test; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.MockitoJUnit; +import org.mockito.junit.MockitoRule; + +/** + * Unit tests for {@link R4EncounterDhisToFhirTransformerUtils}. + * + * @author volsch + */ +public class R4EncounterDhisToFhirTransformerUtilsTest +{ + @Mock + private ScriptExecutionContext scriptExecutionContext; + + @InjectMocks + private R4EncounterDhisToFhirTransformerUtils utils; + + @Rule + public MockitoRule rule = MockitoJUnit.rule(); + + @Test + public void getStatus() + { + Assert.assertEquals( Encounter.EncounterStatus.ARRIVED, utils.getEncounterStatus( "arrived" ) ); + } +} \ No newline at end of file diff --git a/fhir-r4/src/test/java/org/dhis2/fhir/adapter/fhir/transform/dhis/impl/util/r4/R4FhirResourceDhisToFhirTransformerUtilsTest.java b/fhir-r4/src/test/java/org/dhis2/fhir/adapter/fhir/transform/dhis/impl/util/r4/R4FhirResourceDhisToFhirTransformerUtilsTest.java new file mode 100644 index 00000000..6cefb058 --- /dev/null +++ b/fhir-r4/src/test/java/org/dhis2/fhir/adapter/fhir/transform/dhis/impl/util/r4/R4FhirResourceDhisToFhirTransformerUtilsTest.java @@ -0,0 +1,169 @@ +package org.dhis2.fhir.adapter.fhir.transform.dhis.impl.util.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.fhir.script.ScriptExecutionContext; +import org.hl7.fhir.instance.model.api.IBaseResource; +import org.hl7.fhir.r4.model.Bundle; +import org.hl7.fhir.r4.model.CodeableConcept; +import org.hl7.fhir.r4.model.DiagnosticReport; +import org.hl7.fhir.r4.model.EnrollmentRequest; +import org.hl7.fhir.r4.model.IdType; +import org.hl7.fhir.r4.model.Organization; +import org.hl7.fhir.r4.model.Patient; +import org.hl7.fhir.r4.model.Reference; +import org.hl7.fhir.r4.model.Resource; +import org.hl7.fhir.r4.model.StringType; +import org.junit.Assert; +import org.junit.Rule; +import org.junit.Test; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.MockitoJUnit; +import org.mockito.junit.MockitoRule; + +import java.util.Arrays; +import java.util.List; + +/** + * Unit tests for {@link R4FhirResourceDhisToFhirTransformerUtils}. + * + * @author volsch + */ +public class R4FhirResourceDhisToFhirTransformerUtilsTest +{ + @Mock + private ScriptExecutionContext scriptExecutionContext; + + @InjectMocks + private R4FhirResourceDhisToFhirTransformerUtils utils; + + @Rule + public MockitoRule rule = MockitoJUnit.rule(); + + @Test + public void createResource() + { + Assert.assertEquals( DiagnosticReport.class, utils.createResource( "diagnostic-report" ).getClass() ); + } + + @Test + public void createType() + { + Assert.assertEquals( EnrollmentRequest.class, utils.createResource( "enrollment-request" ).getClass() ); + } + + @Test + public void createBundle() + { + final List resources = Arrays.asList( new Organization(), new Patient() ); + final Bundle bundle = (Bundle) utils.createBundle( resources ); + Assert.assertEquals( Bundle.BundleType.SEARCHSET, bundle.getType() ); + Assert.assertEquals( 2, bundle.getEntry().size() ); + } + + @Test + public void createCodeableConcept() + { + Assert.assertEquals( CodeableConcept.class, utils.createCodeableConcept().getClass() ); + } + + @Test + public void createLocalReference() + { + final Resource resource = new Patient(); + resource.setIdElement( new IdType( "#1234" ) ); + final Reference result = (Reference) utils.createReference( resource ); + Assert.assertSame( result.getResource(), resource ); + } + + @Test + public void createEmptyReference() + { + final Resource resource = new Patient(); + final Reference result = (Reference) utils.createReference( resource ); + Assert.assertSame( result.getResource(), resource ); + } + + @Test + public void createReference() + { + final Resource resource = new Patient(); + resource.setIdElement( (IdType) new IdType().setParts( "http://test.com/test", "Patient", "4711", "8379" ) ); + final Reference result = (Reference) utils.createReference( resource ); + Assert.assertNull( result.getResource() ); + Assert.assertEquals( "Patient/4711", resource.getIdElement().toUnqualifiedVersionless().toString() ); + } + + @Test + public void containsStringNull() + { + Assert.assertFalse( utils.containsString( Arrays.asList( new StringType( "abc" ), new StringType( "efg" ) ), null ) ); + } + + @Test + public void containsStringFalse() + { + Assert.assertFalse( utils.containsString( Arrays.asList( new StringType( "abc" ), new StringType( "efg" ) ), "test" ) ); + } + + @Test + public void containsStringTrue() + { + Assert.assertTrue( utils.containsString( Arrays.asList( new StringType( "abc" ), new StringType( "efg" ) ), "efg" ) ); + } + + @Test + public void equalsDeepFalse() + { + Patient p1 = new Patient(); + p1.setActive( true ); + p1.setManagingOrganization( new Reference( "1234" ) ); + + Patient p2 = new Patient(); + p2.setActive( true ); + p2.setManagingOrganization( new Reference( "1235" ) ); + + Assert.assertFalse( utils.equalsDeep( p1, p2 ) ); + } + + @Test + public void equalsDeepTrue() + { + Patient p1 = new Patient(); + p1.setActive( true ); + p1.setManagingOrganization( new Reference( "1234" ) ); + + Patient p2 = new Patient(); + p2.setActive( true ); + p2.setManagingOrganization( new Reference( "1234" ) ); + + Assert.assertTrue( utils.equalsDeep( p1, p2 ) ); + } +} \ No newline at end of file diff --git a/fhir-r4/src/test/java/org/dhis2/fhir/adapter/fhir/transform/dhis/impl/util/r4/R4GeoDhisToFhirTransformerUtilsTest.java b/fhir-r4/src/test/java/org/dhis2/fhir/adapter/fhir/transform/dhis/impl/util/r4/R4GeoDhisToFhirTransformerUtilsTest.java new file mode 100644 index 00000000..5b3ecd43 --- /dev/null +++ b/fhir-r4/src/test/java/org/dhis2/fhir/adapter/fhir/transform/dhis/impl/util/r4/R4GeoDhisToFhirTransformerUtilsTest.java @@ -0,0 +1,126 @@ +package org.dhis2.fhir.adapter.fhir.transform.dhis.impl.util.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.converter.ValueConverter; +import org.dhis2.fhir.adapter.fhir.script.ScriptExecutionContext; +import org.dhis2.fhir.adapter.geo.Location; +import org.dhis2.fhir.adapter.geo.StringToLocationConverter; +import org.dhis2.fhir.adapter.spring.StaticObjectProvider; +import org.hl7.fhir.r4.model.Address; +import org.hl7.fhir.r4.model.DecimalType; +import org.hl7.fhir.r4.model.Location.LocationPositionComponent; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.mockito.Mock; +import org.mockito.junit.MockitoJUnit; +import org.mockito.junit.MockitoRule; +import org.springframework.core.convert.ConversionService; +import org.springframework.core.convert.support.DefaultConversionService; + +import java.math.BigDecimal; +import java.util.Collections; +import java.util.Objects; + +/** + * Unit tests for {@link R4GeoDhisToFhirTransformerUtils}. + * + * @author volsch + */ +public class R4GeoDhisToFhirTransformerUtilsTest +{ + @Mock + private ScriptExecutionContext scriptExecutionContext; + + private R4GeoDhisToFhirTransformerUtils utils; + + @Rule + public MockitoRule rule = MockitoJUnit.rule(); + + @Before + public void before() + { + final ConversionService conversionService = new DefaultConversionService(); + final ValueConverter valueConverter = new ValueConverter( new StaticObjectProvider<>( + Collections.singletonList( new StringToLocationConverter() ) ), + conversionService ); + utils = new R4GeoDhisToFhirTransformerUtils( scriptExecutionContext, valueConverter ); + } + + @Test + public void createPositionNull() + { + Assert.assertNull( utils.createPosition( null ) ); + } + + @Test + public void createPosition() + { + final Location location = new Location( 47.1, -23.2 ); + final LocationPositionComponent position = (LocationPositionComponent) utils.createPosition( location ); + Assert.assertEquals( 47.1, Objects.requireNonNull( position ).getLongitude().doubleValue(), 0.0 ); + Assert.assertEquals( -23.2, Objects.requireNonNull( position ).getLatitude().doubleValue(), 0.0 ); + } + + @Test + public void updateAddressLocationNull() + { + final Address address = new Address(); + utils.updateAddressLocation( address, null ); + Assert.assertEquals( 0, address.getExtensionsByUrl( "http://hl7.org/fhir/StructureDefinition/geolocation" ).size() ); + } + + @Test + public void updateAddressLocationRemoved() + { + final Address address = new Address(); + address.addExtension().setUrl( "http://hl7.org/fhir/StructureDefinition/geolocation" ); + utils.updateAddressLocation( address, null ); + Assert.assertEquals( 0, address.getExtensionsByUrl( "http://hl7.org/fhir/StructureDefinition/geolocation" ).size() ); + } + + @Test + public void updateAddressLocationAddress() + { + final Address address = new Address(); + final Location location = new Location( 47.1, -23.2 ); + utils.updateAddressLocation( address, location ); + Assert.assertEquals( 1, address.getExtensionsByUrl( "http://hl7.org/fhir/StructureDefinition/geolocation" ).size() ); + Assert.assertEquals( 1, address.getExtensionsByUrl( "http://hl7.org/fhir/StructureDefinition/geolocation" ).get( 0 ) + .getExtensionsByUrl( "longitude" ).size() ); + Assert.assertEquals( BigDecimal.valueOf( 47.1 ), ( (DecimalType) address.getExtensionsByUrl( "http://hl7.org/fhir/StructureDefinition/geolocation" ).get( 0 ) + .getExtensionsByUrl( "longitude" ).get( 0 ).getValue() ).getValueAsNumber() ); + Assert.assertEquals( 1, address.getExtensionsByUrl( "http://hl7.org/fhir/StructureDefinition/geolocation" ).get( 0 ) + .getExtensionsByUrl( "latitude" ).size() ); + Assert.assertEquals( BigDecimal.valueOf( -23.2 ), ( (DecimalType) address.getExtensionsByUrl( "http://hl7.org/fhir/StructureDefinition/geolocation" ).get( 0 ) + .getExtensionsByUrl( "latitude" ).get( 0 ).getValue() ).getValueAsNumber() ); + } +} diff --git a/fhir-r4/src/test/java/org/dhis2/fhir/adapter/fhir/transform/dhis/impl/util/r4/R4LocationDhisToFhirTransformerUtilsTest.java b/fhir-r4/src/test/java/org/dhis2/fhir/adapter/fhir/transform/dhis/impl/util/r4/R4LocationDhisToFhirTransformerUtilsTest.java new file mode 100644 index 00000000..8544094b --- /dev/null +++ b/fhir-r4/src/test/java/org/dhis2/fhir/adapter/fhir/transform/dhis/impl/util/r4/R4LocationDhisToFhirTransformerUtilsTest.java @@ -0,0 +1,62 @@ +package org.dhis2.fhir.adapter.fhir.transform.dhis.impl.util.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.fhir.script.ScriptExecutionContext; +import org.hl7.fhir.r4.model.Location; +import org.junit.Assert; +import org.junit.Rule; +import org.junit.Test; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.MockitoJUnit; +import org.mockito.junit.MockitoRule; + +/** + * Unit tests for {@link R4LocationDhisToFhirTransformerUtils}. + * + * @author volsch + */ +public class R4LocationDhisToFhirTransformerUtilsTest +{ + @Mock + private ScriptExecutionContext scriptExecutionContext; + + @InjectMocks + private R4LocationDhisToFhirTransformerUtils utils; + + @Rule + public MockitoRule rule = MockitoJUnit.rule(); + + @Test + public void getLocationStatus() + { + Assert.assertEquals( Location.LocationStatus.SUSPENDED, utils.getLocationStatus( "suspended" ) ); + } +} \ No newline at end of file diff --git a/fhir-r4/src/test/java/org/dhis2/fhir/adapter/fhir/transform/dhis/impl/util/r4/R4ObservationDhisToFhirTransformerUtilsTest.java b/fhir-r4/src/test/java/org/dhis2/fhir/adapter/fhir/transform/dhis/impl/util/r4/R4ObservationDhisToFhirTransformerUtilsTest.java new file mode 100644 index 00000000..91f40489 --- /dev/null +++ b/fhir-r4/src/test/java/org/dhis2/fhir/adapter/fhir/transform/dhis/impl/util/r4/R4ObservationDhisToFhirTransformerUtilsTest.java @@ -0,0 +1,62 @@ +package org.dhis2.fhir.adapter.fhir.transform.dhis.impl.util.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.fhir.script.ScriptExecutionContext; +import org.hl7.fhir.r4.model.Observation; +import org.junit.Assert; +import org.junit.Rule; +import org.junit.Test; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.MockitoJUnit; +import org.mockito.junit.MockitoRule; + +/** + * Unit tests for {@link R4ObservationDhisToFhirTransformerUtils}. + * + * @author volsch + */ +public class R4ObservationDhisToFhirTransformerUtilsTest +{ + @Mock + private ScriptExecutionContext scriptExecutionContext; + + @InjectMocks + private R4ObservationDhisToFhirTransformerUtils utils; + + @Rule + public MockitoRule rule = MockitoJUnit.rule(); + + @Test + public void getObservationStatus() + { + Assert.assertEquals( Observation.ObservationStatus.AMENDED, utils.getObservationStatus( "amended" ) ); + } +} \ No newline at end of file diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/repository/validator/AbstractBeforeCreateSaveRuleValidator.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/repository/validator/AbstractBeforeCreateSaveRuleValidator.java index 7da43edf..ebc37263 100644 --- a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/repository/validator/AbstractBeforeCreateSaveRuleValidator.java +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/repository/validator/AbstractBeforeCreateSaveRuleValidator.java @@ -71,6 +71,7 @@ protected void validate( Object target, @Nonnull TransformDataType transformData checkValidApplicableInScript( errors, "applicableImpScript", rule.getFhirResourceType(), rule.getApplicableImpScript() ); checkValidTransformInScript( errors, "transformImpScript", rule.getFhirResourceType(), transformDataType, rule.getTransformImpScript() ); } + checkValidSearchFilterScript( errors, "filterScript", rule.getFilterScript() ); if ( rule.getDhisDataReferences() != null ) { @@ -163,4 +164,28 @@ protected static void checkValidTransformInScript( @NonNull Errors errors, @Nonn errors.rejectValue( field, "AbstractRule." + field + ".outputType", new Object[]{ transformDataType }, "Assigned output type for incoming transformation script must be {0}." ); } } + + protected static void checkValidSearchFilterScript( @NonNull Errors errors, @Nonnull String field, @Nullable ExecutableScript executableScript ) + { + if ( executableScript == null ) + { + return; + } + if ( executableScript.getScript().getScriptType() != ScriptType.SEARCH_FILTER ) + { + errors.rejectValue( field, "AbstractRule." + field + ".scriptType", "Assigned script type for search filter must be SEARCH_FILTER." ); + } + if ( executableScript.getScript().getReturnType() != DataType.BOOLEAN ) + { + errors.rejectValue( field, "AbstractRule." + field + ".returnType", "Assigned return type for search filter script must be BOOLEAN." ); + } + if ( executableScript.getScript().getInputType() != null ) + { + errors.rejectValue( field, "AbstractRule." + field + ".inputType", "Input type must not be specified." ); + } + if ( executableScript.getScript().getOutputType() != null ) + { + errors.rejectValue( field, "AbstractRule." + field + ".outputType", "Output type must not be specified." ); + } + } } diff --git a/fhir/src/test/java/org/dhis2/fhir/adapter/fhir/metadata/repository/validator/BeforeCreateSaveOrganizationUnitRuleValidatorTest.java b/fhir/src/test/java/org/dhis2/fhir/adapter/fhir/metadata/repository/validator/BeforeCreateSaveOrganizationUnitRuleValidatorTest.java index de75641e..419690ac 100644 --- a/fhir/src/test/java/org/dhis2/fhir/adapter/fhir/metadata/repository/validator/BeforeCreateSaveOrganizationUnitRuleValidatorTest.java +++ b/fhir/src/test/java/org/dhis2/fhir/adapter/fhir/metadata/repository/validator/BeforeCreateSaveOrganizationUnitRuleValidatorTest.java @@ -55,6 +55,8 @@ public class BeforeCreateSaveOrganizationUnitRuleValidatorTest extends AbstractJ private ExecutableScript identifierLookupScript; + private ExecutableScript filterScript; + private ExecutableScript otherTransformInScript; private CodeSet applicableCodeSet; @@ -66,6 +68,8 @@ public void before() { identifierLookupScript = entityManager.createQuery( "SELECT e FROM ExecutableScript e WHERE e.code=:code", ExecutableScript.class ) .setParameter( "code", "DHIS_ORG_UNIT_IDENTIFIER_LOC" ).getSingleResult(); + filterScript = entityManager.createQuery( "SELECT e FROM ExecutableScript e WHERE e.code=:code", ExecutableScript.class ) + .setParameter( "code", "SEARCH_FILTER_LOCATION" ).getSingleResult(); otherTransformInScript = entityManager.createQuery( "SELECT e FROM ExecutableScript e WHERE e.code=:code", ExecutableScript.class ) .setParameter( "code", "CP_OPV_DOSE" ).getSingleResult(); @@ -95,6 +99,7 @@ public void testNameLength() throws Exception mockMvc.perform( post( RESOURCE_PATH ).header( AUTHORIZATION_HEADER_NAME, AUTHORIZATION_HEADER_VALUE ) .contentType( MediaType.APPLICATION_JSON ).content( replaceJsonEntityReferences( entity, JsonEntityValue.create( "identifierLookupScript", "executableScripts", identifierLookupScript.getId().toString() ), + JsonEntityValue.create( "filterScript", "executableScripts", filterScript.getId().toString() ), JsonEntityValue.create( "managingOrgIdentifierLookupScript", "executableScripts", identifierLookupScript.getId().toString() ) ) ) ) .andExpect( status().isBadRequest() ).andExpect( jsonPath( "errors[0].property", Matchers.is( "name" ) ) ); } @@ -106,6 +111,7 @@ public void testFhirResourceTypeNull() throws Exception mockMvc.perform( post( RESOURCE_PATH ).header( AUTHORIZATION_HEADER_NAME, AUTHORIZATION_HEADER_VALUE ) .contentType( MediaType.APPLICATION_JSON ).content( replaceJsonEntityReferences( entity, JsonEntityValue.create( "identifierLookupScript", "executableScripts", identifierLookupScript.getId().toString() ), + JsonEntityValue.create( "filterScript", "executableScripts", filterScript.getId().toString() ), JsonEntityValue.create( "managingOrgIdentifierLookupScript", "executableScripts", identifierLookupScript.getId().toString() ) ) ) ) .andExpect( status().isBadRequest() ).andExpect( jsonPath( "errors[0].property", Matchers.is( "fhirResourceType" ) ) ); } @@ -116,6 +122,7 @@ public void testIdentifierLookupNull() throws Exception entity.setIdentifierLookupScript( null ); mockMvc.perform( post( RESOURCE_PATH ).header( AUTHORIZATION_HEADER_NAME, AUTHORIZATION_HEADER_VALUE ) .contentType( MediaType.APPLICATION_JSON ).content( replaceJsonEntityReferences( entity, + JsonEntityValue.create( "filterScript", "executableScripts", filterScript.getId().toString() ), JsonEntityValue.create( "managingOrgIdentifierLookupScript", "executableScripts", identifierLookupScript.getId().toString() ) ) ) ) .andExpect( status().isBadRequest() ).andExpect( jsonPath( "errors[0].property", Matchers.is( "identifierLookupScript" ) ) ); } @@ -126,6 +133,7 @@ public void testManagingOrgIdentifierLookupNull() throws Exception entity.setManagingOrgIdentifierLookupScript( null ); mockMvc.perform( post( RESOURCE_PATH ).header( AUTHORIZATION_HEADER_NAME, AUTHORIZATION_HEADER_VALUE ) .contentType( MediaType.APPLICATION_JSON ).content( replaceJsonEntityReferences( entity, + JsonEntityValue.create( "filterScript", "executableScripts", filterScript.getId().toString() ), JsonEntityValue.create( "identifierLookupScript", "executableScripts", identifierLookupScript.getId().toString() ) ) ) ) .andExpect( status().isCreated() ); } @@ -135,6 +143,7 @@ public void testIdentifierLookupInvalid() throws Exception { mockMvc.perform( post( RESOURCE_PATH ).header( AUTHORIZATION_HEADER_NAME, AUTHORIZATION_HEADER_VALUE ) .contentType( MediaType.APPLICATION_JSON ).content( replaceJsonEntityReferences( entity, + JsonEntityValue.create( "filterScript", "executableScripts", filterScript.getId().toString() ), JsonEntityValue.create( "identifierLookupScript", "executableScripts", otherTransformInScript.getId().toString() ), JsonEntityValue.create( "managingOrgIdentifierLookupScript", "executableScripts", identifierLookupScript.getId().toString() ) ) ) ) .andExpect( status().isBadRequest() ).andExpect( jsonPath( "errors[0].property", Matchers.is( "identifierLookupScript" ) ) ); @@ -145,8 +154,20 @@ public void testManagingOrgIdentifierLookupInvalid() throws Exception { mockMvc.perform( post( RESOURCE_PATH ).header( AUTHORIZATION_HEADER_NAME, AUTHORIZATION_HEADER_VALUE ) .contentType( MediaType.APPLICATION_JSON ).content( replaceJsonEntityReferences( entity, + JsonEntityValue.create( "filterScript", "executableScripts", filterScript.getId().toString() ), JsonEntityValue.create( "identifierLookupScript", "executableScripts", identifierLookupScript.getId().toString() ), JsonEntityValue.create( "managingOrgIdentifierLookupScript", "executableScripts", otherTransformInScript.getId().toString() ) ) ) ) .andExpect( status().isBadRequest() ).andExpect( jsonPath( "errors[0].property", Matchers.is( "managingOrgIdentifierLookupScript" ) ) ); } + + @Test + public void testFilterScriptInvalid() throws Exception + { + mockMvc.perform( post( RESOURCE_PATH ).header( AUTHORIZATION_HEADER_NAME, AUTHORIZATION_HEADER_VALUE ) + .contentType( MediaType.APPLICATION_JSON ).content( replaceJsonEntityReferences( entity, + JsonEntityValue.create( "identifierLookupScript", "executableScripts", identifierLookupScript.getId().toString() ), + JsonEntityValue.create( "filterScript", "executableScripts", identifierLookupScript.getId().toString() ), + JsonEntityValue.create( "managingOrgIdentifierLookupScript", "executableScripts", identifierLookupScript.getId().toString() ) ) ) ) + .andExpect( status().isBadRequest() ).andExpect( jsonPath( "errors[0].property", Matchers.is( "filterScript" ) ) ); + } } \ No newline at end of file diff --git a/fhir/src/test/resources/data.sql b/fhir/src/test/resources/data.sql index f3a64f1d..1d2b0830 100644 --- a/fhir/src/test/resources/data.sql +++ b/fhir/src/test/resources/data.sql @@ -698,3 +698,22 @@ VALUES ('a84850454d624b3a9cfd5c36760b8d45', 0, 'f8faecad964f402c8cb4a8271085528d INSERT INTO fhir_rule (id, version, name, description, enabled, evaluation_order, fhir_resource_type, dhis_resource_type, imp_enabled, applicable_exp_script_id, transform_exp_script_id) VALUES ('d0e1472a05e647c9b36bff1f06fec352', 0, 'DHIS Organization Unit to FHIR Organization', NULL, TRUE, 0, 'ORGANIZATION', 'ORGANIZATION_UNIT', FALSE, 'a84850454d624b3a9cfd5c36760b8d45', '50544af8cf524e1e9a5dd44c736bc8d8'); INSERT INTO fhir_organization_unit_rule(id, identifier_lookup_script_id) VALUES ('d0e1472a05e647c9b36bff1f06fec352', '66d12e44471c4318827a0b397f694b6a'); + +INSERT INTO fhir_script (id, version, code, name, description, script_type, return_type) +VALUES ('cf3072ec06ad4d62a8a075ad2ab330ba', 0, 'SEARCH_FILTER_LOCATION', 'Prepares Location Search Filter', 'Prepares Location Search Filter.', 'SEARCH_FILTER', 'BOOLEAN'); +INSERT INTO fhir_script_variable (script_id, variable) VALUES ('cf3072ec06ad4d62a8a075ad2ab330ba', 'SEARCH_FILTER'); +INSERT INTO fhir_script_source (id, version, script_id, source_text, source_type) +VALUES ('10200cc2f0604aa8a9070d12b199ff3b', 0, 'cf3072ec06ad4d62a8a075ad2ab330ba', +'searchFilter.add(''name'', ''string'', ''name''); +searchFilter.addReference(''partof'', ''location'', ''organizationunit'', ''parent''); +searchFilter.addToken(''status'', ''active'', ''closedDate'', ''null'', null); +searchFilter.addToken(''status'', ''inactive'', ''closedDate'', ''!null'', null); +true', 'JAVASCRIPT'); +INSERT INTO fhir_script_source_version (script_source_id, fhir_version) +VALUES ('10200cc2f0604aa8a9070d12b199ff3b', 'DSTU3'); +INSERT INTO fhir_script_source_version (script_source_id, fhir_version) +VALUES ('10200cc2f0604aa8a9070d12b199ff3b', 'R4'); +INSERT INTO fhir_executable_script (id, version, script_id, name, code) +VALUES ('27f50aeb0f564256ae166118e931524b', 0, 'cf3072ec06ad4d62a8a075ad2ab330ba', 'Prepares Location Search Filter', 'SEARCH_FILTER_LOCATION'); +UPDATE fhir_rule SET filter_script_id='27f50aeb0f564256ae166118e931524b' WHERE id='b9546b024adc4868a4cdd5d7789f0df0'; + diff --git a/pom.xml b/pom.xml index 921d1acc..d2cb51fa 100644 --- a/pom.xml +++ b/pom.xml @@ -224,19 +224,37 @@ org/dhis2/fhir/adapter/** + + **/QA* + **/QB* + **/QC* + **/QD* + **/QE* + **/QF* + **/QG* + **/QH* + **/QI* + **/QJ* + **/QK* + **/QL* + **/QM* + **/QN* + **/QO* + **/QP* + **/QQ* + **/QR* + **/QS* + **/QT* + **/QU* + **/QV* + **/QW* + **/QX* + **/QY* + **/QZ* + surefireArgLine - - report - prepare-package - - report - - - org/dhis2/fhir/adapter/** - - diff --git a/summary/pom.xml b/summary/pom.xml index 7c4f3391..d0d86c6d 100644 --- a/summary/pom.xml +++ b/summary/pom.xml @@ -93,10 +93,79 @@ report + prepare-package + + report + + + org/dhis2/fhir/adapter/** + + **/QA* + **/QB* + **/QC* + **/QD* + **/QE* + **/QF* + **/QG* + **/QH* + **/QI* + **/QJ* + **/QK* + **/QL* + **/QM* + **/QN* + **/QO* + **/QP* + **/QQ* + **/QR* + **/QS* + **/QT* + **/QU* + **/QV* + **/QW* + **/QX* + **/QY* + **/QZ* + + + + + report-aggregate verify report-aggregate + + org/dhis2/fhir/adapter/** + + **/QA* + **/QB* + **/QC* + **/QD* + **/QE* + **/QF* + **/QG* + **/QH* + **/QI* + **/QJ* + **/QK* + **/QL* + **/QM* + **/QN* + **/QO* + **/QP* + **/QQ* + **/QR* + **/QS* + **/QT* + **/QU* + **/QV* + **/QW* + **/QX* + **/QY* + **/QZ* + +