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 index 88fc7c6f..2a2d9db5 100644 --- 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 @@ -191,7 +191,7 @@ public void getByMappedCodeNull() @Test public void getByMappedCode() { - final ResourceSystem resourceSystem = new ResourceSystem( FhirResourceType.ORGANIZATION, "TestSystem", null, null, null ); + final ResourceSystem resourceSystem = new ResourceSystem( FhirResourceType.ORGANIZATION, "TestSystem", null, null, null, false ); final SystemCode systemCode = new SystemCode(); systemCode.setSystemCode( "837232" ); @@ -215,7 +215,7 @@ public void getByMappedCode() @Test public void getByMappedCodeNotFound() { - final ResourceSystem resourceSystem = new ResourceSystem( FhirResourceType.ORGANIZATION, "TestSystem", null, null, null ); + final ResourceSystem resourceSystem = new ResourceSystem( FhirResourceType.ORGANIZATION, "TestSystem", null, null, null, false ); final Map variables = new HashMap<>(); variables.put( ScriptVariable.CONTEXT.getVariableName(), context ); @@ -237,7 +237,7 @@ public void getByMappedCodeNotFound() @Test public void getCodeWithoutPrefixPrefix() { - final ResourceSystem resourceSystem = new ResourceSystem( FhirResourceType.ORGANIZATION, "TestSystem", "SE_", null, null ); + final ResourceSystem resourceSystem = new ResourceSystem( FhirResourceType.ORGANIZATION, "TestSystem", "SE_", null, null, false ); final Map variables = new HashMap<>(); variables.put( ScriptVariable.CONTEXT.getVariableName(), context ); @@ -253,7 +253,7 @@ public void getCodeWithoutPrefixPrefix() @Test public void getCodeWithoutPrefixNoPrefix() { - final ResourceSystem resourceSystem = new ResourceSystem( FhirResourceType.ORGANIZATION, "TestSystem", "SE_", null, null ); + final ResourceSystem resourceSystem = new ResourceSystem( FhirResourceType.ORGANIZATION, "TestSystem", "SE_", null, null, false ); final Map variables = new HashMap<>(); variables.put( ScriptVariable.CONTEXT.getVariableName(), context ); @@ -269,7 +269,7 @@ public void getCodeWithoutPrefixNoPrefix() @Test public void getCodeWithoutPrefixNoPrefixSystem() { - final ResourceSystem resourceSystem = new ResourceSystem( FhirResourceType.ORGANIZATION, "TestSystem", null, null, null ); + final ResourceSystem resourceSystem = new ResourceSystem( FhirResourceType.ORGANIZATION, "TestSystem", null, null, null, false ); final Map variables = new HashMap<>(); variables.put( ScriptVariable.CONTEXT.getVariableName(), context ); diff --git a/fhir-dstu3/src/test/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/ReferenceFhirToDhisTransformerUtilsTest.java b/fhir-dstu3/src/test/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/ReferenceFhirToDhisTransformerUtilsTest.java index d5f12295..c9ccd9be 100644 --- a/fhir-dstu3/src/test/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/ReferenceFhirToDhisTransformerUtilsTest.java +++ b/fhir-dstu3/src/test/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/ReferenceFhirToDhisTransformerUtilsTest.java @@ -144,7 +144,7 @@ public void getResource() final FhirClientResource fhirClientResource = new FhirClientResource(); fhirClientResource.setId( fhirClientResourceId ); fhirClientResource.setFhirClient( fhirClient ); - final ResourceSystem resourceSystem = new ResourceSystem( FhirResourceType.ORGANIZATION, "http://test.com", "OT_", null, null ); + final ResourceSystem resourceSystem = new ResourceSystem( FhirResourceType.ORGANIZATION, "http://test.com", "OT_", null, null, false ); Mockito.doReturn( scriptExecution ).when( scriptExecutionContext ).getScriptExecution(); Mockito.doReturn( variables ).when( scriptExecution ).getVariables(); Mockito.doReturn( context ).when( variables ).get( Mockito.eq( "context" ) ); @@ -187,7 +187,7 @@ public void getResourceRefreshed() final FhirClientResource fhirClientResource = new FhirClientResource(); fhirClientResource.setId( fhirClientResourceId ); fhirClientResource.setFhirClient( fhirClient ); - final ResourceSystem resourceSystem = new ResourceSystem( FhirResourceType.ORGANIZATION, "http://test.com", "OT_", null, null ); + final ResourceSystem resourceSystem = new ResourceSystem( FhirResourceType.ORGANIZATION, "http://test.com", "OT_", null, null, false ); Mockito.doReturn( scriptExecution ).when( scriptExecutionContext ).getScriptExecution(); Mockito.doReturn( variables ).when( scriptExecution ).getVariables(); Mockito.doReturn( context ).when( variables ).get( Mockito.eq( "context" ) ); @@ -230,7 +230,7 @@ public void initReference() final FhirClientResource fhirClientResource = new FhirClientResource(); fhirClientResource.setId( fhirClientResourceId ); fhirClientResource.setFhirClient( fhirClient ); - final ResourceSystem resourceSystem = new ResourceSystem( FhirResourceType.ORGANIZATION, "http://test.com", "OT_", null, null ); + final ResourceSystem resourceSystem = new ResourceSystem( FhirResourceType.ORGANIZATION, "http://test.com", "OT_", null, null, false ); Mockito.doReturn( scriptExecution ).when( scriptExecutionContext ).getScriptExecution(); Mockito.doReturn( variables ).when( scriptExecution ).getVariables(); Mockito.doReturn( context ).when( variables ).get( Mockito.eq( "context" ) ); diff --git a/fhir-dstu3/src/test/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/dstu3/Dstu3CodeFhirToDhisTransformerUtilsTest.java b/fhir-dstu3/src/test/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/dstu3/Dstu3CodeFhirToDhisTransformerUtilsTest.java index 1a612370..919d69f3 100644 --- a/fhir-dstu3/src/test/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/dstu3/Dstu3CodeFhirToDhisTransformerUtilsTest.java +++ b/fhir-dstu3/src/test/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/dstu3/Dstu3CodeFhirToDhisTransformerUtilsTest.java @@ -335,7 +335,7 @@ public void getResourceCodes() @Test public void getMappedCodeNotFound() { - final ResourceSystem resourceSystem = new ResourceSystem( FhirResourceType.ORGANIZATION, "http://test.com/2", null, null, null ); + final ResourceSystem resourceSystem = new ResourceSystem( FhirResourceType.ORGANIZATION, "http://test.com/2", null, null, null, false ); Mockito.doReturn( scriptExecution ).when( scriptExecutionContext ).getScriptExecution(); Mockito.doReturn( variables ).when( scriptExecution ).getVariables(); @@ -349,7 +349,7 @@ public void getMappedCodeNotFound() @Test public void getMappedCodeFound() { - final ResourceSystem resourceSystem = new ResourceSystem( FhirResourceType.ORGANIZATION, "http://test.com/2", null, null, null ); + final ResourceSystem resourceSystem = new ResourceSystem( FhirResourceType.ORGANIZATION, "http://test.com/2", null, null, null, false ); Mockito.doReturn( scriptExecution ).when( scriptExecutionContext ).getScriptExecution(); Mockito.doReturn( variables ).when( scriptExecution ).getVariables(); @@ -367,7 +367,7 @@ public void getMappedCodeFound() @Test public void getMappedCodeFoundMapped() { - final ResourceSystem resourceSystem = new ResourceSystem( FhirResourceType.ORGANIZATION, "http://test.com/2", null, null, null ); + final ResourceSystem resourceSystem = new ResourceSystem( FhirResourceType.ORGANIZATION, "http://test.com/2", null, null, null, false ); Mockito.doReturn( scriptExecution ).when( scriptExecutionContext ).getScriptExecution(); Mockito.doReturn( variables ).when( scriptExecution ).getVariables(); diff --git a/fhir-dstu3/src/test/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/dstu3/Dstu3FhirResourceFhirToDhisTransformerUtilsTest.java b/fhir-dstu3/src/test/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/dstu3/Dstu3FhirResourceFhirToDhisTransformerUtilsTest.java index 7087968e..66cf96f9 100644 --- a/fhir-dstu3/src/test/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/dstu3/Dstu3FhirResourceFhirToDhisTransformerUtilsTest.java +++ b/fhir-dstu3/src/test/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/dstu3/Dstu3FhirResourceFhirToDhisTransformerUtilsTest.java @@ -111,6 +111,8 @@ public void getIdentifierReferenceNull() @Test public void getCanonicalReferenceNull() { + Mockito.doReturn( scriptExecution ).when( scriptExecutionContext ).getScriptExecution(); + Mockito.doReturn( Collections.singletonMap( ScriptVariable.CONTEXT.getVariableName(), context ) ).when( scriptExecution ).getVariables(); Assert.assertNull( utils.getCanonicalAdapterReference( null, "MEASURE" ) ); } @@ -424,6 +426,22 @@ public void getAdapterReferenceDhisFhirIdentifierCode() Assert.assertEquals( new org.dhis2.fhir.adapter.dhis.model.Reference( "5678", ReferenceType.CODE ), adapterReference ); } + @Test + public void getAdapterReferenceDhisFhirIdCode() + { + Mockito.doReturn( request ).when( context ).getFhirRequest(); + Mockito.doReturn( true ).when( request ).isDhisFhirId(); + Mockito.doReturn( new ResourceSystem( FhirResourceType.PATIENT, "National ID", null, null, null, true ) ) + .when( request ).getResourceSystem( Mockito.eq( FhirResourceType.PATIENT ) ); + Mockito.doReturn( scriptExecution ).when( scriptExecutionContext ).getScriptExecution(); + Mockito.doReturn( Collections.singletonMap( ScriptVariable.CONTEXT.getVariableName(), context ) ).when( scriptExecution ).getVariables(); + + final org.dhis2.fhir.adapter.dhis.model.Reference adapterReference = utils.getAdapterReference( new Reference( "Patient/5678" ), "PATIENT" ); + + Assert.assertNotNull( adapterReference ); + Assert.assertEquals( new org.dhis2.fhir.adapter.dhis.model.Reference( "5678", ReferenceType.CODE ), adapterReference ); + } + @Test public void getAdapterReferenceDhisFhirIdOnly() { diff --git a/fhir-dstu3/src/test/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/dstu3/Dstu3IdentifierFhirToDhisTransformerUtilsTest.java b/fhir-dstu3/src/test/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/dstu3/Dstu3IdentifierFhirToDhisTransformerUtilsTest.java index 4c73b986..ee457ce4 100644 --- a/fhir-dstu3/src/test/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/dstu3/Dstu3IdentifierFhirToDhisTransformerUtilsTest.java +++ b/fhir-dstu3/src/test/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/dstu3/Dstu3IdentifierFhirToDhisTransformerUtilsTest.java @@ -130,7 +130,7 @@ public void getReferenceIdentifierWithDefaultSystem() final Patient patient = new Patient(); patient.addIdentifier().setSystem( "http://test.com" ).setValue( "ABC_123" ); - final ResourceSystem resourceSystem = new ResourceSystem( FhirResourceType.PATIENT, "http://test.com", null, null, null ); + final ResourceSystem resourceSystem = new ResourceSystem( FhirResourceType.PATIENT, "http://test.com", null, null, null, false ); Mockito.doReturn( scriptExecution ).when( scriptExecutionContext ).getScriptExecution(); Mockito.doReturn( variables ).when( scriptExecution ).getVariables(); Mockito.doReturn( context ).when( variables ).get( Mockito.eq( "context" ) ); @@ -152,7 +152,7 @@ public void getResourceIdentifierWithDefaultSystem() final Patient patient = new Patient(); patient.addIdentifier().setSystem( "http://test.com" ).setValue( "ABC_123" ); - final ResourceSystem resourceSystem = new ResourceSystem( FhirResourceType.PATIENT, "http://test.com", null, null, null ); + final ResourceSystem resourceSystem = new ResourceSystem( FhirResourceType.PATIENT, "http://test.com", null, null, null, false ); Mockito.doReturn( scriptExecution ).when( scriptExecutionContext ).getScriptExecution(); Mockito.doReturn( variables ).when( scriptExecution ).getVariables(); Mockito.doReturn( context ).when( variables ).get( Mockito.eq( "context" ) ); @@ -189,7 +189,7 @@ public void getIncludedReferenceIdentifierWithDefaultSystem() final Patient patient = new Patient(); patient.addIdentifier().setSystem( "http://test.com" ).setValue( "ABC_123" ); - final ResourceSystem resourceSystem = new ResourceSystem( FhirResourceType.PATIENT, "http://test.com", null, null, null ); + final ResourceSystem resourceSystem = new ResourceSystem( FhirResourceType.PATIENT, "http://test.com", null, null, null, false ); Mockito.doReturn( scriptExecution ).when( scriptExecutionContext ).getScriptExecution(); Mockito.doReturn( variables ).when( scriptExecution ).getVariables(); Mockito.doReturn( context ).when( variables ).get( Mockito.eq( "context" ) ); diff --git a/fhir-dstu3/src/test/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/dstu3/Dstu3LocationFhirToDhisTransformerUtilsTest.java b/fhir-dstu3/src/test/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/dstu3/Dstu3LocationFhirToDhisTransformerUtilsTest.java index 2ad17777..79ab00b8 100644 --- a/fhir-dstu3/src/test/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/dstu3/Dstu3LocationFhirToDhisTransformerUtilsTest.java +++ b/fhir-dstu3/src/test/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/dstu3/Dstu3LocationFhirToDhisTransformerUtilsTest.java @@ -111,7 +111,7 @@ public void findHierarchy() final UUID fhirClientResourceId = UUID.randomUUID(); final FhirClientResource fhirClientResource = new FhirClientResource(); fhirClientResource.setFhirClient( fhirClient ); - final ResourceSystem resourceSystem = new ResourceSystem( FhirResourceType.LOCATION, "http://test.com", "OT_", null, null ); + final ResourceSystem resourceSystem = new ResourceSystem( FhirResourceType.LOCATION, "http://test.com", "OT_", null, null, false ); Mockito.doReturn( scriptExecution ).when( scriptExecutionContext ).getScriptExecution(); Mockito.doReturn( variables ).when( scriptExecution ).getVariables(); Mockito.doReturn( context ).when( variables ).get( Mockito.eq( "context" ) ); diff --git a/fhir-dstu3/src/test/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/dstu3/Dstu3OrganizationFhirToDhisTransformerUtilsTest.java b/fhir-dstu3/src/test/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/dstu3/Dstu3OrganizationFhirToDhisTransformerUtilsTest.java index f3005ed4..27224dd7 100644 --- a/fhir-dstu3/src/test/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/dstu3/Dstu3OrganizationFhirToDhisTransformerUtilsTest.java +++ b/fhir-dstu3/src/test/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/dstu3/Dstu3OrganizationFhirToDhisTransformerUtilsTest.java @@ -126,7 +126,7 @@ public void existsNot() @Test public void existsWithPrefix() { - final ResourceSystem resourceSystem = new ResourceSystem( FhirResourceType.ORGANIZATION, "http://test.com", "OT_", null, null ); + final ResourceSystem resourceSystem = new ResourceSystem( FhirResourceType.ORGANIZATION, "http://test.com", "OT_", null, null, false ); Mockito.doReturn( scriptExecution ).when( scriptExecutionContext ).getScriptExecution(); Mockito.doReturn( variables ).when( scriptExecution ).getVariables(); Mockito.doReturn( context ).when( variables ).get( Mockito.eq( "context" ) ); @@ -142,7 +142,7 @@ public void existsWithPrefix() @Test public void existsNotWithPrefix() { - final ResourceSystem resourceSystem = new ResourceSystem( FhirResourceType.ORGANIZATION, "http://test.com", "OT_", null, null ); + final ResourceSystem resourceSystem = new ResourceSystem( FhirResourceType.ORGANIZATION, "http://test.com", "OT_", null, null, false ); Mockito.doReturn( scriptExecution ).when( scriptExecutionContext ).getScriptExecution(); Mockito.doReturn( variables ).when( scriptExecution ).getVariables(); Mockito.doReturn( context ).when( variables ).get( Mockito.eq( "context" ) ); @@ -164,7 +164,7 @@ public void findHierarchy() final UUID fhirClientResourceId = UUID.randomUUID(); final FhirClientResource fhirClientResource = new FhirClientResource(); fhirClientResource.setFhirClient( fhirClient ); - final ResourceSystem resourceSystem = new ResourceSystem( FhirResourceType.ORGANIZATION, "http://test.com", "OT_", null, null ); + final ResourceSystem resourceSystem = new ResourceSystem( FhirResourceType.ORGANIZATION, "http://test.com", "OT_", null, null, false ); Mockito.doReturn( scriptExecution ).when( scriptExecutionContext ).getScriptExecution(); Mockito.doReturn( variables ).when( scriptExecution ).getVariables(); Mockito.doReturn( context ).when( variables ).get( Mockito.eq( "context" ) ); 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 index 3b42bdff..b67d1933 100644 --- 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 @@ -191,7 +191,7 @@ public void getByMappedCodeNull() @Test public void getByMappedCode() { - final ResourceSystem resourceSystem = new ResourceSystem( FhirResourceType.ORGANIZATION, "TestSystem", null, null, null ); + final ResourceSystem resourceSystem = new ResourceSystem( FhirResourceType.ORGANIZATION, "TestSystem", null, null, null, false ); final SystemCode systemCode = new SystemCode(); systemCode.setSystemCode( "837232" ); @@ -215,7 +215,7 @@ public void getByMappedCode() @Test public void getByMappedCodeNotFound() { - final ResourceSystem resourceSystem = new ResourceSystem( FhirResourceType.ORGANIZATION, "TestSystem", null, null, null ); + final ResourceSystem resourceSystem = new ResourceSystem( FhirResourceType.ORGANIZATION, "TestSystem", null, null, null, false ); final Map variables = new HashMap<>(); variables.put( ScriptVariable.CONTEXT.getVariableName(), context ); @@ -237,7 +237,7 @@ public void getByMappedCodeNotFound() @Test public void getCodeWithoutPrefixPrefix() { - final ResourceSystem resourceSystem = new ResourceSystem( FhirResourceType.ORGANIZATION, "TestSystem", "SE_", null, null ); + final ResourceSystem resourceSystem = new ResourceSystem( FhirResourceType.ORGANIZATION, "TestSystem", "SE_", null, null, false ); final Map variables = new HashMap<>(); variables.put( ScriptVariable.CONTEXT.getVariableName(), context ); @@ -253,7 +253,7 @@ public void getCodeWithoutPrefixPrefix() @Test public void getCodeWithoutPrefixNoPrefix() { - final ResourceSystem resourceSystem = new ResourceSystem( FhirResourceType.ORGANIZATION, "TestSystem", "SE_", null, null ); + final ResourceSystem resourceSystem = new ResourceSystem( FhirResourceType.ORGANIZATION, "TestSystem", "SE_", null, null, false ); final Map variables = new HashMap<>(); variables.put( ScriptVariable.CONTEXT.getVariableName(), context ); @@ -269,7 +269,7 @@ public void getCodeWithoutPrefixNoPrefix() @Test public void getCodeWithoutPrefixNoPrefixSystem() { - final ResourceSystem resourceSystem = new ResourceSystem( FhirResourceType.ORGANIZATION, "TestSystem", null, null, null ); + final ResourceSystem resourceSystem = new ResourceSystem( FhirResourceType.ORGANIZATION, "TestSystem", null, null, null, false ); final Map variables = new HashMap<>(); variables.put( ScriptVariable.CONTEXT.getVariableName(), context ); diff --git a/fhir-r4/src/test/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/ReferenceFhirToDhisTransformerUtilsTest.java b/fhir-r4/src/test/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/ReferenceFhirToDhisTransformerUtilsTest.java index ba436b47..e6dfbbc6 100644 --- a/fhir-r4/src/test/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/ReferenceFhirToDhisTransformerUtilsTest.java +++ b/fhir-r4/src/test/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/ReferenceFhirToDhisTransformerUtilsTest.java @@ -144,7 +144,7 @@ public void getResource() final FhirClientResource fhirClientResource = new FhirClientResource(); fhirClientResource.setId( fhirClientResourceId ); fhirClientResource.setFhirClient( fhirClient ); - final ResourceSystem resourceSystem = new ResourceSystem( FhirResourceType.ORGANIZATION, "http://test.com", "OT_", null, null ); + final ResourceSystem resourceSystem = new ResourceSystem( FhirResourceType.ORGANIZATION, "http://test.com", "OT_", null, null, false ); Mockito.doReturn( scriptExecution ).when( scriptExecutionContext ).getScriptExecution(); Mockito.doReturn( variables ).when( scriptExecution ).getVariables(); Mockito.doReturn( context ).when( variables ).get( Mockito.eq( "context" ) ); @@ -187,7 +187,7 @@ public void getResourceRefreshed() final FhirClientResource fhirClientResource = new FhirClientResource(); fhirClientResource.setId( fhirClientResourceId ); fhirClientResource.setFhirClient( fhirClient ); - final ResourceSystem resourceSystem = new ResourceSystem( FhirResourceType.ORGANIZATION, "http://test.com", "OT_", null, null ); + final ResourceSystem resourceSystem = new ResourceSystem( FhirResourceType.ORGANIZATION, "http://test.com", "OT_", null, null, false ); Mockito.doReturn( scriptExecution ).when( scriptExecutionContext ).getScriptExecution(); Mockito.doReturn( variables ).when( scriptExecution ).getVariables(); Mockito.doReturn( context ).when( variables ).get( Mockito.eq( "context" ) ); @@ -230,7 +230,7 @@ public void initReference() final FhirClientResource fhirClientResource = new FhirClientResource(); fhirClientResource.setId( fhirClientResourceId ); fhirClientResource.setFhirClient( fhirClient ); - final ResourceSystem resourceSystem = new ResourceSystem( FhirResourceType.ORGANIZATION, "http://test.com", "OT_", null, null ); + final ResourceSystem resourceSystem = new ResourceSystem( FhirResourceType.ORGANIZATION, "http://test.com", "OT_", null, null, false ); Mockito.doReturn( scriptExecution ).when( scriptExecutionContext ).getScriptExecution(); Mockito.doReturn( variables ).when( scriptExecution ).getVariables(); Mockito.doReturn( context ).when( variables ).get( Mockito.eq( "context" ) ); diff --git a/fhir-r4/src/test/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/r4/R4CodeFhirToDhisTransformerUtilsTest.java b/fhir-r4/src/test/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/r4/R4CodeFhirToDhisTransformerUtilsTest.java index 21ec7c12..f06e35a5 100644 --- a/fhir-r4/src/test/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/r4/R4CodeFhirToDhisTransformerUtilsTest.java +++ b/fhir-r4/src/test/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/r4/R4CodeFhirToDhisTransformerUtilsTest.java @@ -335,7 +335,7 @@ public void getResourceCodes() @Test public void getMappedCodeNotFound() { - final ResourceSystem resourceSystem = new ResourceSystem( FhirResourceType.ORGANIZATION, "http://test.com/2", null, null, null ); + final ResourceSystem resourceSystem = new ResourceSystem( FhirResourceType.ORGANIZATION, "http://test.com/2", null, null, null, false ); Mockito.doReturn( scriptExecution ).when( scriptExecutionContext ).getScriptExecution(); Mockito.doReturn( variables ).when( scriptExecution ).getVariables(); @@ -349,7 +349,7 @@ public void getMappedCodeNotFound() @Test public void getMappedCodeFound() { - final ResourceSystem resourceSystem = new ResourceSystem( FhirResourceType.ORGANIZATION, "http://test.com/2", null, null, null ); + final ResourceSystem resourceSystem = new ResourceSystem( FhirResourceType.ORGANIZATION, "http://test.com/2", null, null, null, false ); Mockito.doReturn( scriptExecution ).when( scriptExecutionContext ).getScriptExecution(); Mockito.doReturn( variables ).when( scriptExecution ).getVariables(); @@ -367,7 +367,7 @@ public void getMappedCodeFound() @Test public void getMappedCodeFoundMapped() { - final ResourceSystem resourceSystem = new ResourceSystem( FhirResourceType.ORGANIZATION, "http://test.com/2", null, null, null ); + final ResourceSystem resourceSystem = new ResourceSystem( FhirResourceType.ORGANIZATION, "http://test.com/2", null, null, null, false ); Mockito.doReturn( scriptExecution ).when( scriptExecutionContext ).getScriptExecution(); Mockito.doReturn( variables ).when( scriptExecution ).getVariables(); diff --git a/fhir-r4/src/test/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/r4/R4FhirResourceFhirToDhisTransformerUtilsTest.java b/fhir-r4/src/test/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/r4/R4FhirResourceFhirToDhisTransformerUtilsTest.java index 724eb960..72cd77f5 100644 --- a/fhir-r4/src/test/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/r4/R4FhirResourceFhirToDhisTransformerUtilsTest.java +++ b/fhir-r4/src/test/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/r4/R4FhirResourceFhirToDhisTransformerUtilsTest.java @@ -112,6 +112,8 @@ public void getIdentifierReferenceNull() @Test public void getCanonicalReferenceNull() { + Mockito.doReturn( scriptExecution ).when( scriptExecutionContext ).getScriptExecution(); + Mockito.doReturn( Collections.singletonMap( ScriptVariable.CONTEXT.getVariableName(), context ) ).when( scriptExecution ).getVariables(); Assert.assertNull( utils.getCanonicalAdapterReference( null, "MEASURE" ) ); } @@ -198,6 +200,22 @@ public void getIdentifierReferenceNonDhisFhirIdNull() Assert.assertNull( reference ); } + @Test + public void getAdapterReferenceDhisFhirIdCode() + { + Mockito.doReturn( request ).when( context ).getFhirRequest(); + Mockito.doReturn( true ).when( request ).isDhisFhirId(); + Mockito.doReturn( new ResourceSystem( FhirResourceType.PATIENT, "National ID", null, null, null, true ) ) + .when( request ).getResourceSystem( Mockito.eq( FhirResourceType.PATIENT ) ); + Mockito.doReturn( scriptExecution ).when( scriptExecutionContext ).getScriptExecution(); + Mockito.doReturn( Collections.singletonMap( ScriptVariable.CONTEXT.getVariableName(), context ) ).when( scriptExecution ).getVariables(); + + final org.dhis2.fhir.adapter.dhis.model.Reference adapterReference = utils.getAdapterReference( new Reference( "Patient/5678" ), "PATIENT" ); + + Assert.assertNotNull( adapterReference ); + Assert.assertEquals( new org.dhis2.fhir.adapter.dhis.model.Reference( "5678", ReferenceType.CODE ), adapterReference ); + } + @Test public void getIdentifierReferenceNonDhisFhirId() { diff --git a/fhir-r4/src/test/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/r4/R4IdentifierFhirToDhisTransformerUtilsTest.java b/fhir-r4/src/test/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/r4/R4IdentifierFhirToDhisTransformerUtilsTest.java index 969e0dd1..24133577 100644 --- a/fhir-r4/src/test/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/r4/R4IdentifierFhirToDhisTransformerUtilsTest.java +++ b/fhir-r4/src/test/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/r4/R4IdentifierFhirToDhisTransformerUtilsTest.java @@ -130,7 +130,7 @@ public void getReferenceIdentifierWithDefaultSystem() final Patient patient = new Patient(); patient.addIdentifier().setSystem( "http://test.com" ).setValue( "ABC_123" ); - final ResourceSystem resourceSystem = new ResourceSystem( FhirResourceType.PATIENT, "http://test.com", null, null, null ); + final ResourceSystem resourceSystem = new ResourceSystem( FhirResourceType.PATIENT, "http://test.com", null, null, null, false ); Mockito.doReturn( scriptExecution ).when( scriptExecutionContext ).getScriptExecution(); Mockito.doReturn( variables ).when( scriptExecution ).getVariables(); Mockito.doReturn( context ).when( variables ).get( Mockito.eq( "context" ) ); @@ -152,7 +152,7 @@ public void getResourceIdentifierWithDefaultSystem() final Patient patient = new Patient(); patient.addIdentifier().setSystem( "http://test.com" ).setValue( "ABC_123" ); - final ResourceSystem resourceSystem = new ResourceSystem( FhirResourceType.PATIENT, "http://test.com", null, null, null ); + final ResourceSystem resourceSystem = new ResourceSystem( FhirResourceType.PATIENT, "http://test.com", null, null, null, false ); Mockito.doReturn( scriptExecution ).when( scriptExecutionContext ).getScriptExecution(); Mockito.doReturn( variables ).when( scriptExecution ).getVariables(); Mockito.doReturn( context ).when( variables ).get( Mockito.eq( "context" ) ); @@ -189,7 +189,7 @@ public void getIncludedReferenceIdentifierWithDefaultSystem() final Patient patient = new Patient(); patient.addIdentifier().setSystem( "http://test.com" ).setValue( "ABC_123" ); - final ResourceSystem resourceSystem = new ResourceSystem( FhirResourceType.PATIENT, "http://test.com", null, null, null ); + final ResourceSystem resourceSystem = new ResourceSystem( FhirResourceType.PATIENT, "http://test.com", null, null, null, false ); Mockito.doReturn( scriptExecution ).when( scriptExecutionContext ).getScriptExecution(); Mockito.doReturn( variables ).when( scriptExecution ).getVariables(); Mockito.doReturn( context ).when( variables ).get( Mockito.eq( "context" ) ); diff --git a/fhir-r4/src/test/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/r4/R4LocationFhirToDhisTransformerUtilsTest.java b/fhir-r4/src/test/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/r4/R4LocationFhirToDhisTransformerUtilsTest.java index 4de7225a..24f2d5a8 100644 --- a/fhir-r4/src/test/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/r4/R4LocationFhirToDhisTransformerUtilsTest.java +++ b/fhir-r4/src/test/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/r4/R4LocationFhirToDhisTransformerUtilsTest.java @@ -111,7 +111,7 @@ public void findHierarchy() final UUID fhirClientResourceId = UUID.randomUUID(); final FhirClientResource fhirClientResource = new FhirClientResource(); fhirClientResource.setFhirClient( fhirClient ); - final ResourceSystem resourceSystem = new ResourceSystem( FhirResourceType.LOCATION, "http://test.com", "OT_", null, null ); + final ResourceSystem resourceSystem = new ResourceSystem( FhirResourceType.LOCATION, "http://test.com", "OT_", null, null, false ); Mockito.doReturn( scriptExecution ).when( scriptExecutionContext ).getScriptExecution(); Mockito.doReturn( variables ).when( scriptExecution ).getVariables(); Mockito.doReturn( context ).when( variables ).get( Mockito.eq( "context" ) ); diff --git a/fhir-r4/src/test/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/r4/R4OrganizationFhirToDhisTransformerUtilsTest.java b/fhir-r4/src/test/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/r4/R4OrganizationFhirToDhisTransformerUtilsTest.java index b960f5e4..7f792f6b 100644 --- a/fhir-r4/src/test/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/r4/R4OrganizationFhirToDhisTransformerUtilsTest.java +++ b/fhir-r4/src/test/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/r4/R4OrganizationFhirToDhisTransformerUtilsTest.java @@ -126,7 +126,7 @@ public void existsNot() @Test public void existsWithPrefix() { - final ResourceSystem resourceSystem = new ResourceSystem( FhirResourceType.ORGANIZATION, "http://test.com", "OT_", null, null ); + final ResourceSystem resourceSystem = new ResourceSystem( FhirResourceType.ORGANIZATION, "http://test.com", "OT_", null, null, false ); Mockito.doReturn( scriptExecution ).when( scriptExecutionContext ).getScriptExecution(); Mockito.doReturn( variables ).when( scriptExecution ).getVariables(); Mockito.doReturn( context ).when( variables ).get( Mockito.eq( "context" ) ); @@ -142,7 +142,7 @@ public void existsWithPrefix() @Test public void existsNotWithPrefix() { - final ResourceSystem resourceSystem = new ResourceSystem( FhirResourceType.ORGANIZATION, "http://test.com", "OT_", null, null ); + final ResourceSystem resourceSystem = new ResourceSystem( FhirResourceType.ORGANIZATION, "http://test.com", "OT_", null, null, false ); Mockito.doReturn( scriptExecution ).when( scriptExecutionContext ).getScriptExecution(); Mockito.doReturn( variables ).when( scriptExecution ).getVariables(); Mockito.doReturn( context ).when( variables ).get( Mockito.eq( "context" ) ); @@ -164,7 +164,7 @@ public void findHierarchy() final UUID fhirClientResourceId = UUID.randomUUID(); final FhirClientResource fhirClientResource = new FhirClientResource(); fhirClientResource.setFhirClient( fhirClient ); - final ResourceSystem resourceSystem = new ResourceSystem( FhirResourceType.ORGANIZATION, "http://test.com", "OT_", null, null ); + final ResourceSystem resourceSystem = new ResourceSystem( FhirResourceType.ORGANIZATION, "http://test.com", "OT_", null, null, false ); Mockito.doReturn( scriptExecution ).when( scriptExecutionContext ).getScriptExecution(); Mockito.doReturn( variables ).when( scriptExecution ).getVariables(); Mockito.doReturn( context ).when( variables ).get( Mockito.eq( "context" ) ); diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/model/FhirClientSystem.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/model/FhirClientSystem.java index 755d7338..b88ba04d 100644 --- a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/model/FhirClientSystem.java +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/metadata/model/FhirClientSystem.java @@ -79,6 +79,8 @@ public class FhirClientSystem extends VersionedBaseMetadata implements Serializa @Size( max = MAX_DEFAULT_VALUE_LENGTH ) private String defaultValue; + private boolean fhirId; + public FhirClientSystem() { super(); @@ -150,4 +152,16 @@ public void setDefaultValue( String defaultValue ) { this.defaultValue = defaultValue; } + + @Basic + @Column( name = "fhir_id", nullable = false, columnDefinition = "BOOLEAN DEFAULT FALSE NOT NULL" ) + public boolean isFhirId() + { + return fhirId; + } + + public void setFhirId( boolean fhirId ) + { + this.fhirId = fhirId; + } } diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/model/SystemCodeValues.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/model/SystemCodeValues.java index f536043a..dd1ea6a0 100644 --- a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/model/SystemCodeValues.java +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/model/SystemCodeValues.java @@ -35,7 +35,6 @@ import javax.annotation.Nullable; import java.io.Serializable; import java.util.ArrayList; -import java.util.Collections; import java.util.List; /** @@ -55,7 +54,7 @@ public class SystemCodeValues implements Serializable public SystemCodeValues( @JsonProperty( "text" ) @Nullable String text, @JsonProperty( "systemCodeValues" ) @Nonnull List systemCodeValues ) { this.text = text; - this.systemCodeValues = systemCodeValues; + this.systemCodeValues = new ArrayList<>( systemCodeValues ); } public SystemCodeValues( @Nonnull SystemCodeValues systemCodeValues ) @@ -67,13 +66,13 @@ public SystemCodeValues( @Nonnull SystemCodeValues systemCodeValues ) public SystemCodeValues( @Nonnull List systemCodeValues ) { this.text = null; - this.systemCodeValues = systemCodeValues; + this.systemCodeValues = new ArrayList<>( systemCodeValues ); } public SystemCodeValues() { this.text = null; - this.systemCodeValues = Collections.emptyList(); + this.systemCodeValues = new ArrayList<>(); } @Nullable diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/repository/impl/AbstractFhirRepositoryResourceUtils.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/repository/impl/AbstractFhirRepositoryResourceUtils.java index a075507d..1c4489a4 100644 --- a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/repository/impl/AbstractFhirRepositoryResourceUtils.java +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/repository/impl/AbstractFhirRepositoryResourceUtils.java @@ -86,7 +86,7 @@ public ResourceSystem getResourceSystem( @Nullable Object resourceType ) } return fhirClientSystemRepository.findOneByFhirClientResourceType( fhirClientId, fhirResourceType ) - .map( s -> new ResourceSystem( s.getFhirResourceType(), s.getSystem().getSystemUri(), s.getCodePrefix(), s.getDefaultValue(), s.getSystem().getFhirDisplayName() ) ) + .map( s -> new ResourceSystem( s.getFhirResourceType(), s.getSystem().getSystemUri(), s.getCodePrefix(), s.getDefaultValue(), s.getSystem().getFhirDisplayName(), s.isFhirId() ) ) .orElse( null ); } diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/repository/impl/FhirRepositoryImpl.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/repository/impl/FhirRepositoryImpl.java index 931410d5..0ba9831b 100644 --- a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/repository/impl/FhirRepositoryImpl.java +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/repository/impl/FhirRepositoryImpl.java @@ -351,7 +351,7 @@ protected FhirRepositoryOperationOutcome saveInternally( @Nonnull FhirClientReso fhirRequest.setParameters( ArrayListMultimap.create() ); fhirRequest.setFhirClientCode( fhirClientResource.getFhirClient().getCode() ); fhirRequest.setResourceSystemsByType( systems.stream() - .map( s -> new ResourceSystem( s.getFhirResourceType(), s.getSystem().getSystemUri(), s.getCodePrefix(), s.getDefaultValue(), s.getSystem().getFhirDisplayName() ) ) + .map( s -> new ResourceSystem( s.getFhirResourceType(), s.getSystem().getSystemUri(), s.getCodePrefix(), s.getDefaultValue(), s.getSystem().getFhirDisplayName(), s.isFhirId() ) ) .collect( Collectors.toMap( ResourceSystem::getFhirResourceType, rs -> rs ) ) ); if ( fhirRepositoryOperation == null ) diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/dhis/impl/DhisToFhirTransformerServiceImpl.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/dhis/impl/DhisToFhirTransformerServiceImpl.java index 5b90e841..53683e35 100644 --- a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/dhis/impl/DhisToFhirTransformerServiceImpl.java +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/dhis/impl/DhisToFhirTransformerServiceImpl.java @@ -407,7 +407,7 @@ protected DhisToFhirTransformerRequest createTransformerRequest( boolean groupin final Collection systems = fhirClientSystemRepository.findByFhirClient( fhirClient ); final Map resourceSystemsByType = systems.stream() - .map( s -> new ResourceSystem( s.getFhirResourceType(), s.getSystem().getSystemUri(), s.getCodePrefix(), s.getDefaultValue(), s.getSystem().getFhirDisplayName() ) ) + .map( s -> new ResourceSystem( s.getFhirResourceType(), s.getSystem().getSystemUri(), s.getCodePrefix(), s.getDefaultValue(), s.getSystem().getFhirDisplayName(), s.isFhirId() ) ) .collect( Collectors.toMap( ResourceSystem::getFhirResourceType, rs -> rs ) ); final Map transformerUtils = this.transformerUtils.get( fhirClient.getFhirVersion() ); diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/AbstractFhirResourceFhirToDhisTransformerUtils.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/AbstractFhirResourceFhirToDhisTransformerUtils.java index 904148b3..747fd709 100644 --- a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/AbstractFhirResourceFhirToDhisTransformerUtils.java +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/impl/util/AbstractFhirResourceFhirToDhisTransformerUtils.java @@ -140,6 +140,7 @@ public IBaseReference getIdentifiedReference( @Nonnull FhirToDhisTransformerCont final IBaseReference fhirReference; SystemCodeValues identifiers = getIdentifiers( reference ); + boolean resetIdElement = false; boolean containsSufficientIdentifier = false; if ( identifiers.getSystemCodeValues().isEmpty() && reference.getResource() != null ) @@ -147,6 +148,13 @@ public IBaseReference getIdentifiedReference( @Nonnull FhirToDhisTransformerCont identifiers = getIdentifiers( reference.getResource() ); } + if ( resourceSystem != null && resourceSystem.isFhirId() && reference.getReferenceElement().hasIdPart() && !reference.getReferenceElement().isLocal() && + identifiers.getSystemCodeValues().stream().noneMatch( scv -> Objects.equals( resourceSystem.getSystem(), scv.getSystem() ) ) ) + { + identifiers.getSystemCodeValues().add( new SystemCodeValue( resourceSystem.getSystem(), reference.getReferenceElement().getIdPart() ) ); + resetIdElement = true; + } + if ( !identifiers.getSystemCodeValues().isEmpty() ) { containsSufficientIdentifier = containsSufficientIdentifier( identifiers, resourceSystem ); @@ -169,10 +177,15 @@ public IBaseReference getIdentifiedReference( @Nonnull FhirToDhisTransformerCont } } - if ( containsSufficientIdentifier || context.getFhirRequest().isDhisFhirId() ) + if ( containsSufficientIdentifier || fhirResourceType.isSyncDhisId() || context.getFhirRequest().isDhisFhirId() ) { fhirReference = createReference( reference.getResource() == null ? reference.getReferenceElement() : reference.getResource().getIdElement() ); + if ( resetIdElement ) + { + fhirReference.setReference( null ); + } + identifiers.getSystemCodeValues().stream().filter( scv -> ( resourceSystem != null && resourceSystem.getSystem().equals( scv.getSystem() ) ) ) .forEach( scv -> addIdentifier( fhirReference, scv ) ); // may override the resource system identifier (has higher precedence) @@ -234,6 +247,13 @@ else if ( identifiedReference != null ) }, returnDescription = "The adapter reference for the specified reference or null if it cannot be resolved." ) public Reference getCanonicalAdapterReference( @Nullable IBaseDatatype canonical, @Nonnull Object fhirResourceType ) + { + final FhirToDhisTransformerContext context = getScriptVariable( ScriptVariable.CONTEXT.getVariableName(), FhirToDhisTransformerContext.class ); + + return getCanonicalAdapterReference( context, canonical, fhirResourceType ); + } + + public Reference getCanonicalAdapterReference( @Nonnull FhirToDhisTransformerContext context, @Nullable IBaseDatatype canonical, @Nonnull Object fhirResourceType ) { if ( canonical == null ) { @@ -274,7 +294,7 @@ public Reference getCanonicalAdapterReference( @Nullable IBaseDatatype canonical throw new TransformerDataException( "Unknown FHIR resource type in canonical URI: " + type ); } - return getAdapterReference( createReference( canonicalResourceType.getResourceTypeName(), id ), fhirResourceType ); + return getAdapterReference( context, createReference( canonicalResourceType.getResourceTypeName(), id ), fhirResourceType ); } @Nullable @@ -287,14 +307,30 @@ public Reference getCanonicalAdapterReference( @Nullable IBaseDatatype canonical returnDescription = "The adapter reference for the specified reference or null if it cannot be resolved." ) public Reference getAdapterReference( @Nullable IBaseReference reference, @Nonnull Object fhirResourceType ) { - final FhirToDhisTransformerContext context = getScriptVariable( - ScriptVariable.CONTEXT.getVariableName(), FhirToDhisTransformerContext.class ); + final FhirToDhisTransformerContext context = getScriptVariable( ScriptVariable.CONTEXT.getVariableName(), FhirToDhisTransformerContext.class ); + + return getAdapterReference( context, reference, fhirResourceType ); + } + + public Reference getAdapterReference( @Nonnull FhirToDhisTransformerContext context, @Nullable IBaseReference reference, @Nonnull Object fhirResourceType ) + { final IBaseReference identifiedReference = getIdentifiedReference( context, reference, fhirResourceType ); Reference adapterReference = null; if ( identifiedReference != null ) { - if ( identifiedReference.getReferenceElement().hasIdPart() && !identifiedReference.getReferenceElement().isLocal() && context.getFhirRequest().isDhisFhirId() ) + final FhirResourceType resourceType; + try + { + resourceType = NameUtils.toEnumValue( FhirResourceType.class, fhirResourceType ); + } + catch ( IllegalArgumentException e ) + { + throw new TransformerScriptException( "Invalid FHIR resource type: " + fhirResourceType, e ); + } + + if ( identifiedReference.getReferenceElement().hasIdPart() && !identifiedReference.getReferenceElement().isLocal() && + ( resourceType.isSyncDhisId() || context.getFhirRequest().isDhisFhirId() ) ) { final String dhisId = context.extractDhisId( identifiedReference.getReferenceElement().getIdPart() ); diff --git a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/model/ResourceSystem.java b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/model/ResourceSystem.java index f2be64bc..b0c94537 100644 --- a/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/model/ResourceSystem.java +++ b/fhir/src/main/java/org/dhis2/fhir/adapter/fhir/transform/fhir/model/ResourceSystem.java @@ -37,6 +37,8 @@ /** * Contains the system that is used for a specific FHIR resource type. + * + * @author volsch */ public class ResourceSystem implements Serializable { @@ -52,13 +54,16 @@ public class ResourceSystem implements Serializable private final String fhirDisplayName; - public ResourceSystem( @Nonnull FhirResourceType fhirResourceType, @Nonnull String system, @Nullable String codePrefix, @Nullable String defaultValue, @Nullable String fhirDisplayName ) + private final boolean fhirId; + + public ResourceSystem( @Nonnull FhirResourceType fhirResourceType, @Nonnull String system, @Nullable String codePrefix, @Nullable String defaultValue, @Nullable String fhirDisplayName, boolean fhirId ) { this.fhirResourceType = fhirResourceType; this.system = system; this.codePrefix = codePrefix; this.defaultValue = defaultValue; this.fhirDisplayName = fhirDisplayName; + this.fhirId = fhirId; } public ResourceSystem( @Nonnull FhirResourceType fhirResourceType, @Nonnull String system ) @@ -68,6 +73,7 @@ public ResourceSystem( @Nonnull FhirResourceType fhirResourceType, @Nonnull Stri this.codePrefix = null; this.defaultValue = null; this.fhirDisplayName = null; + this.fhirId = false; } @Nonnull @@ -100,14 +106,18 @@ public String getFhirDisplayName() return fhirDisplayName; } + public boolean isFhirId() + { + return fhirId; + } + @Override public boolean equals( Object o ) { if ( this == o ) return true; if ( o == null || getClass() != o.getClass() ) return false; ResourceSystem that = (ResourceSystem) o; - return fhirResourceType == that.fhirResourceType && - Objects.equals( system, that.system ); + return fhirResourceType == that.fhirResourceType && Objects.equals( system, that.system ); } @Override diff --git a/fhir/src/main/resources/db/migration/production/V1.1.0.43_0_0__FHIR_ID_DHIS_Code.sql b/fhir/src/main/resources/db/migration/production/V1.1.0.43_0_0__FHIR_ID_DHIS_Code.sql new file mode 100644 index 00000000..278944ba --- /dev/null +++ b/fhir/src/main/resources/db/migration/production/V1.1.0.43_0_0__FHIR_ID_DHIS_Code.sql @@ -0,0 +1,30 @@ +/* + * 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 PROGRAM_STAGE_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. + */ + +-- @formatter:off +ALTER TABLE fhir_client_system ADD fhir_id BOOLEAN DEFAULT FALSE NOT NULL; diff --git a/fhir/src/test/java/org/dhis2/fhir/adapter/fhir/metadata/repository/FhirClientSystemRepositoryRestDocsTest.java b/fhir/src/test/java/org/dhis2/fhir/adapter/fhir/metadata/repository/FhirClientSystemRepositoryRestDocsTest.java index aae11d33..155d6f56 100644 --- a/fhir/src/test/java/org/dhis2/fhir/adapter/fhir/metadata/repository/FhirClientSystemRepositoryRestDocsTest.java +++ b/fhir/src/test/java/org/dhis2/fhir/adapter/fhir/metadata/repository/FhirClientSystemRepositoryRestDocsTest.java @@ -90,7 +90,8 @@ public void createFhirClientSystem() throws Exception fields.withPath( "system" ).description( "The reference to the system URI that should be mapped to the FHIR client." ).type( JsonFieldType.STRING ), fields.withPath( "fhirResourceType" ).description( "The FHIR resource type to which the system URI should be mapped." ).type( JsonFieldType.STRING ), fields.withPath( "codePrefix" ).description( "The prefix that should be added to the codes when mapping them to DHIS2." ).type( JsonFieldType.STRING ).optional(), - fields.withPath( "defaultValue" ).description( "The default value that may be used when FHIR resource does not contain the corresponding value." ).type( JsonFieldType.STRING ).optional() + fields.withPath( "defaultValue" ).description( "The default value that may be used when FHIR resource does not contain the corresponding value." ).type( JsonFieldType.STRING ).optional(), + fields.withPath( "fhirId" ).description( "Specifies if the FHIR ID should be taken as identifier value is no identifier has been specified." ).type( JsonFieldType.BOOLEAN ).optional() ) ) ).andReturn().getResponse().getHeader( "Location" ); mockMvc @@ -121,6 +122,7 @@ public void readFhirClientSystem() throws Exception fields.withPath( "fhirResourceType" ).description( "The FHIR resource type to which the system URI should be mapped." ).type( JsonFieldType.STRING ), fields.withPath( "codePrefix" ).description( "The prefix that should be added to the codes when mapping them to DHIS2." ).type( JsonFieldType.STRING ).optional(), fields.withPath( "defaultValue" ).description( "The default value that may be used when FHIR resource does not contain the corresponding value." ).type( JsonFieldType.STRING ).optional(), + fields.withPath( "fhirId" ).description( "Specifies if the FHIR ID should be taken as identifier value is no identifier has been specified." ).type( JsonFieldType.BOOLEAN ).optional(), subsectionWithPath( "_links" ).description( "Links to other resources" ) ) ) ); }