Skip to content

Commit

Permalink
Adds support for FHIR ID to DHIS2 Code mapping.
Browse files Browse the repository at this point in the history
  • Loading branch information
volsch committed Aug 13, 2019
1 parent d1967f6 commit 15d0535
Show file tree
Hide file tree
Showing 23 changed files with 179 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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" );

Expand All @@ -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<String, Object> variables = new HashMap<>();
variables.put( ScriptVariable.CONTEXT.getVariableName(), context );
Expand All @@ -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<String, Object> variables = new HashMap<>();
variables.put( ScriptVariable.CONTEXT.getVariableName(), context );
Expand All @@ -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<String, Object> variables = new HashMap<>();
variables.put( ScriptVariable.CONTEXT.getVariableName(), context );
Expand All @@ -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<String, Object> variables = new HashMap<>();
variables.put( ScriptVariable.CONTEXT.getVariableName(), context );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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" ) );
Expand Down Expand Up @@ -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" ) );
Expand Down Expand Up @@ -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" ) );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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();
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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" ) );
}

Expand Down Expand Up @@ -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()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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" ) );
Expand All @@ -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" ) );
Expand Down Expand Up @@ -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" ) );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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" ) );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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" ) );
Expand All @@ -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" ) );
Expand All @@ -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" ) );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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" );

Expand All @@ -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<String, Object> variables = new HashMap<>();
variables.put( ScriptVariable.CONTEXT.getVariableName(), context );
Expand All @@ -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<String, Object> variables = new HashMap<>();
variables.put( ScriptVariable.CONTEXT.getVariableName(), context );
Expand All @@ -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<String, Object> variables = new HashMap<>();
variables.put( ScriptVariable.CONTEXT.getVariableName(), context );
Expand All @@ -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<String, Object> variables = new HashMap<>();
variables.put( ScriptVariable.CONTEXT.getVariableName(), context );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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" ) );
Expand Down Expand Up @@ -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" ) );
Expand Down Expand Up @@ -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" ) );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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();
Expand All @@ -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();
Expand Down
Loading

0 comments on commit 15d0535

Please sign in to comment.