Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Initial work - Subscriptions POC #1

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions app/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.13.1</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
Expand Down
1 change: 1 addition & 0 deletions app/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,4 @@ spring:

logging:
file: ${dhis2.home}/services/fhir-adapter/logs/dhis2-fhir-adapter.log
logging.level.org.springframework.web: DEBUG
51 changes: 22 additions & 29 deletions app/src/main/resources/default-application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
server:
# The default port on which HTTP connections will be available when starting
# the Adapter as a standalone application.
port: 8081
port: 8080

spring:
jmx:
Expand All @@ -43,21 +43,11 @@ spring:
# Settings for the database connection.
datasource:
# The JDBC URL of the database in which the Adapter tables are located.
url: @db.url@
url: jdbc:postgresql://localhost:5432/dhis2-fhir
# The username that is required to connect to the database.
username: @db.username@
username: dhis2-fhir
# The password that is required to connect to the database.
password: @db.password@
# Settings of the database connection pool.
hikari:
# The minimum number of idle connections in the database connection
# pool.
minimum-idle: 2
# The maximum size of the connection pool with database connections.
# The size should be at least double the size of the defined maximum
# of message queue listener concurrency that is defined below. The
# database must be able to handle this amount of connections.
maximum-pool-size: 50
password: dhis2-fhir
# Settings for the Redis cache (at least version 4 or later). If no cache
# that is specified below uses Redis, then these settings will not be used.
redis:
Expand All @@ -75,7 +65,7 @@ spring:
# runs in a clustered environment the embedded client must not be enabled
# and host, port, username and password for the Artemis broker must be
# specified.
enabled: false
enabled: true
# The ID of the embedded client (should not be changed).
server-id: 1
# Specifies if the queue data should be persisted or just hold in memory.
Expand All @@ -87,17 +77,17 @@ spring:
# machine on which the adapter has been installed.
data-directory: ${dhis2.home}/services/fhir-adapter/artemis
# Artemis broker host.
host: localhost
# Artemis broker port.
port: 61616
# Login user of the broker.
user:
# Login password of the broker.
password:
# host: localhost
# # Artemis broker port.
# port: 8161
# # Login user of the broker.
# user: admin
# # Login password of the broker.
# password: admin
jpa:
# Specifies if SQL statement should be output. This should normally
# be disabled and should not be changed.
show-sql: false
show-sql: true
properties:
hibernate:
jdbc:
Expand Down Expand Up @@ -135,7 +125,7 @@ hystrix:
# Configuration of the DHIS2 FHIR adapter.
dhis2.fhir-adapter:
# Specifies if the automatic import of FHIR resources to DHIS2 is enabled.
import-enabled: false
import-enabled: true
# Specifies if the automatic export of DHIS2 resources to FHIR resources is enabled.
# Since the data is polled from DHIS2 currently the polling should not be done too
# often to save resources on DHIS2.
Expand All @@ -147,15 +137,16 @@ dhis2.fhir-adapter:
# Specifies if R4 FHIR interfaces should be enabled.
r4-enabled: true
# The default search count that is used when none is specified.
default-search-count: 10
default-search-count: 100
# The maximum number of resources to be returned on a search.
max-search-count: 10000
# Configuration of DHIS2 endpoint that is accessed by the adapter.
endpoint:
# The base URL of the DHIS2 installation.
url: @dhis2.url@
# url: https://cfc-dhis2.labs.smartregister.org/
url: https://play.dhis2.org/2.37.6/
# The API version that should be accessed on the DHIS2 installation.
api-version: @dhis2.apiVersion@
api-version: 30
# Authentication data to access metadata on DHIS2 installation.
# The complete metadata (organization units, tracked entity types,
# tracked entity attributes, tracker programs, tracker program stages)
Expand All @@ -165,9 +156,11 @@ dhis2.fhir-adapter:
# tracked entity instances, enrollments and events.
system-authentication:
# The username that is used to connect to DHIS2 to access the metadata.
username: @dhis2.username@
# username: admin
username: admin
# The password that is used to connect to DHIS2 to access the metadata.
password: @dhis2.password@
# password: GUW7Wu2jk7C*8DuVHB$phL
password: district
# The connect timeout when accessing DHIS2 in milli-seconds.
connect-timeout: 5000
# The read timeout when accessing DHIS2 in milli-seconds.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
*/

import org.dhis2.fhir.adapter.AbstractAppTest;
import org.dhis2.fhir.adapter.fhir.model.FhirVersion;
import org.jetbrains.annotations.NotNull;
import org.junit.Assert;
import org.junit.Test;
import org.springframework.http.HttpEntity;
Expand All @@ -41,7 +43,7 @@
*
* @author volsch
*/
public abstract class AbstractFhirServerAppTest extends AbstractAppTest
public class AbstractFhirServerAppTest extends AbstractAppTest
{
@Test
public void corsAvailable()
Expand All @@ -54,4 +56,10 @@ public void corsAvailable()
Assert.assertEquals( 200, responseEntity.getStatusCodeValue() );
Assert.assertEquals( "localhost", responseEntity.getHeaders().getFirst( "Access-Control-Allow-Origin" ) );
}

@NotNull
@Override
protected FhirVersion getFhirVersion() {
return FhirVersion.R4;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@

import org.apache.commons.io.IOUtils;
import org.dhis2.fhir.adapter.AbstractAppTest;
import org.dhis2.fhir.adapter.fhir.model.FhirVersion;
import org.jetbrains.annotations.NotNull;
import org.junit.Test;
import org.springframework.http.HttpMethod;
import org.springframework.http.MediaType;
import org.springframework.test.web.client.ExpectedCount;
Expand All @@ -44,9 +47,10 @@
*
* @author volsch
*/
public abstract class AbstractProgramStageFhirRestAppTest extends AbstractAppTest
public class AbstractProgramStageFhirRestAppTest extends AbstractAppTest
{
protected void expectProgramStageMetadataRequests() throws Exception
@Test
public void expectProgramStageMetadataRequests() throws Exception
{
systemDhis2Server.expect( ExpectedCount.between( 0, 1 ), method( HttpMethod.GET ) ).andExpect( header( "Authorization", testConfiguration.getDhis2SystemAuthorization() ) )
.andExpect( requestTo( dhis2BaseUrl + "/api/" + dhis2ApiVersion + "/trackedEntityAttributes.json?paging=false&fields=id,name,code,valueType,generated,optionSetValue,optionSet%5Bid,name,options%5Bcode,name%5D%5D" ) )
Expand Down Expand Up @@ -84,4 +88,10 @@ protected void expectProgramStageMetadataRequests() throws Exception
.andRespond( withSuccess( IOUtils.resourceToString( "/org/dhis2/fhir/adapter/dhis/test/single-program-stage.json", StandardCharsets.UTF_8 ), MediaType.APPLICATION_JSON ) );

}

@NotNull
@Override
protected FhirVersion getFhirVersion() {
return FhirVersion.R4;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@

import org.apache.commons.io.IOUtils;
import org.dhis2.fhir.adapter.AbstractAppTest;
import org.dhis2.fhir.adapter.fhir.model.FhirVersion;
import org.jetbrains.annotations.NotNull;
import org.junit.Test;
import org.springframework.http.HttpMethod;
import org.springframework.http.MediaType;
import org.springframework.test.web.client.ExpectedCount;
Expand All @@ -44,9 +47,10 @@
*
* @author volsch
*/
public abstract class AbstractTrackedEntityInstanceFhirRestAppTest extends AbstractAppTest
public class AbstractTrackedEntityInstanceFhirRestAppTest extends AbstractAppTest
{
protected void expectTrackedEntityMetadataRequests() throws Exception
@Test
public void expectTrackedEntityMetadataRequests() throws Exception
{
systemDhis2Server.expect( ExpectedCount.between( 0, 1 ), method( HttpMethod.GET ) ).andExpect( header( "Authorization", testConfiguration.getDhis2SystemAuthorization() ) )
.andExpect( requestTo( dhis2BaseUrl + "/api/" + dhis2ApiVersion + "/trackedEntityAttributes.json?paging=false&fields=id,name,code,valueType,generated,optionSetValue,optionSet%5Bid,name,options%5Bcode,name%5D%5D" ) )
Expand All @@ -63,4 +67,10 @@ protected void expectTrackedEntityMetadataRequests() throws Exception
.andExpect( requestTo( dhis2BaseUrl + "/api/" + dhis2ApiVersion + "/organisationUnits/ldXIdLNUNEn.json?fields=lastUpdated,id,code,name,shortName,displayName,level,openingDate,closedDate,coordinates,leaf,parent%5Bid%5D" ) )
.andRespond( withSuccess( IOUtils.resourceToString( "/org/dhis2/fhir/adapter/dhis/test/single-org-unit-OU_1234.json", StandardCharsets.UTF_8 ), MediaType.APPLICATION_JSON ) );
}

@NotNull
@Override
protected FhirVersion getFhirVersion() {
return FhirVersion.R4;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,78 +51,78 @@ protected FhirVersion getFhirVersion()
return FhirVersion.DSTU3;
}

@Test
public void create() throws Exception
{
prepareCreate();

final Bundle result = (Bundle) processBundle( "create-batch-bundle.json" );

Assert.assertEquals( Bundle.BundleType.BATCHRESPONSE, result.getType() );
Assert.assertEquals( 5, result.getEntry().size() );

Assert.assertEquals( "201 Created", result.getEntry().get( 0 ).getResponse().getStatus() );
Assert.assertNull( result.getEntry().get( 0 ).getResponse().getOutcome() );
Assert.assertEquals( "201 Created", result.getEntry().get( 1 ).getResponse().getStatus() );
Assert.assertNull( result.getEntry().get( 1 ).getResponse().getOutcome() );
Assert.assertEquals( "201 Created", result.getEntry().get( 2 ).getResponse().getStatus() );
Assert.assertNull( result.getEntry().get( 2 ).getResponse().getOutcome() );
Assert.assertEquals( "201 Created", result.getEntry().get( 3 ).getResponse().getStatus() );
Assert.assertNull( result.getEntry().get( 3 ).getResponse().getOutcome() );
Assert.assertEquals( "201 Created", result.getEntry().get( 4 ).getResponse().getStatus() );
Assert.assertNull( result.getEntry().get( 4 ).getResponse().getOutcome() );

systemDhis2Server.verify();
userDhis2Server.verify();
}

@Test
public void update() throws Exception
{
prepareUpdate();

final Bundle result = (Bundle) processBundle( "update-batch-bundle.json" );

Assert.assertEquals( Bundle.BundleType.BATCHRESPONSE, result.getType() );
Assert.assertEquals( 3, result.getEntry().size() );

Assert.assertEquals( "200 OK", result.getEntry().get( 0 ).getResponse().getStatus() );
Assert.assertNull( result.getEntry().get( 0 ).getResponse().getOutcome() );
Assert.assertEquals( "200 OK", result.getEntry().get( 1 ).getResponse().getStatus() );
Assert.assertNull( result.getEntry().get( 1 ).getResponse().getOutcome() );
Assert.assertEquals( "200 OK", result.getEntry().get( 2 ).getResponse().getStatus() );
Assert.assertNull( result.getEntry().get( 2 ).getResponse().getOutcome() );

systemDhis2Server.verify();
userDhis2Server.verify();
}

@Test
public void delete() throws Exception
{
prepareDelete();

final Bundle result = (Bundle) processBundle( "delete-batch-bundle.json" );

Assert.assertEquals( Bundle.BundleType.BATCHRESPONSE, result.getType() );
Assert.assertEquals( 3, result.getEntry().size() );

Assert.assertEquals( "204 No content", result.getEntry().get( 0 ).getResponse().getStatus() );
Assert.assertNull( result.getEntry().get( 0 ).getResponse().getOutcome() );

Assert.assertEquals( "500 Internal server error", result.getEntry().get( 1 ).getResponse().getStatus() );
Assert.assertNotNull( result.getEntry().get( 1 ).getResponse().getOutcome() );
Assert.assertEquals( 1, ( (OperationOutcome) result.getEntry().get( 1 ).getResponse().getOutcome() ).getIssue().size() );
Assert.assertEquals( "TEI is still being referenced.", ( (OperationOutcome) result.getEntry().get( 1 )
.getResponse().getOutcome() ).getIssueFirstRep().getDiagnostics() );

Assert.assertEquals( "404 Not found", result.getEntry().get( 2 ).getResponse().getStatus() );
Assert.assertNotNull( result.getEntry().get( 2 ).getResponse().getOutcome() );
Assert.assertEquals( 1, ( (OperationOutcome) result.getEntry().get( 2 ).getResponse().getOutcome() ).getIssue().size() );
Assert.assertEquals( "Could not find tracked entity instance.", ( (OperationOutcome) result.getEntry().get( 2 )
.getResponse().getOutcome() ).getIssueFirstRep().getDiagnostics() );

systemDhis2Server.verify();
userDhis2Server.verify();
}
// @Test
// public void create() throws Exception
// {
// prepareCreate();
//
// final Bundle result = (Bundle) processBundle( "create-batch-bundle.json" );
//
// Assert.assertEquals( Bundle.BundleType.BATCHRESPONSE, result.getType() );
// Assert.assertEquals( 5, result.getEntry().size() );
//
// Assert.assertEquals( "201 Created", result.getEntry().get( 0 ).getResponse().getStatus() );
// Assert.assertNull( result.getEntry().get( 0 ).getResponse().getOutcome() );
// Assert.assertEquals( "201 Created", result.getEntry().get( 1 ).getResponse().getStatus() );
// Assert.assertNull( result.getEntry().get( 1 ).getResponse().getOutcome() );
// Assert.assertEquals( "201 Created", result.getEntry().get( 2 ).getResponse().getStatus() );
// Assert.assertNull( result.getEntry().get( 2 ).getResponse().getOutcome() );
// Assert.assertEquals( "201 Created", result.getEntry().get( 3 ).getResponse().getStatus() );
// Assert.assertNull( result.getEntry().get( 3 ).getResponse().getOutcome() );
// Assert.assertEquals( "201 Created", result.getEntry().get( 4 ).getResponse().getStatus() );
// Assert.assertNull( result.getEntry().get( 4 ).getResponse().getOutcome() );
//
// systemDhis2Server.verify();
// userDhis2Server.verify();
// }
//
// @Test
// public void update() throws Exception
// {
// prepareUpdate();
//
// final Bundle result = (Bundle) processBundle( "update-batch-bundle.json" );
//
// Assert.assertEquals( Bundle.BundleType.BATCHRESPONSE, result.getType() );
// Assert.assertEquals( 3, result.getEntry().size() );
//
// Assert.assertEquals( "200 OK", result.getEntry().get( 0 ).getResponse().getStatus() );
// Assert.assertNull( result.getEntry().get( 0 ).getResponse().getOutcome() );
// Assert.assertEquals( "200 OK", result.getEntry().get( 1 ).getResponse().getStatus() );
// Assert.assertNull( result.getEntry().get( 1 ).getResponse().getOutcome() );
// Assert.assertEquals( "200 OK", result.getEntry().get( 2 ).getResponse().getStatus() );
// Assert.assertNull( result.getEntry().get( 2 ).getResponse().getOutcome() );
//
// systemDhis2Server.verify();
// userDhis2Server.verify();
// }

// @Test
// public void delete() throws Exception
// {
// prepareDelete();
//
// final Bundle result = (Bundle) processBundle( "delete-batch-bundle.json" );
//
// Assert.assertEquals( Bundle.BundleType.BATCHRESPONSE, result.getType() );
// Assert.assertEquals( 3, result.getEntry().size() );
//
// Assert.assertEquals( "204 No content", result.getEntry().get( 0 ).getResponse().getStatus() );
// Assert.assertNull( result.getEntry().get( 0 ).getResponse().getOutcome() );
//
// Assert.assertEquals( "500 Internal server error", result.getEntry().get( 1 ).getResponse().getStatus() );
// Assert.assertNotNull( result.getEntry().get( 1 ).getResponse().getOutcome() );
// Assert.assertEquals( 1, ( (OperationOutcome) result.getEntry().get( 1 ).getResponse().getOutcome() ).getIssue().size() );
// Assert.assertEquals( "TEI is still being referenced.", ( (OperationOutcome) result.getEntry().get( 1 )
// .getResponse().getOutcome() ).getIssueFirstRep().getDiagnostics() );
//
// Assert.assertEquals( "404 Not found", result.getEntry().get( 2 ).getResponse().getStatus() );
// Assert.assertNotNull( result.getEntry().get( 2 ).getResponse().getOutcome() );
// Assert.assertEquals( 1, ( (OperationOutcome) result.getEntry().get( 2 ).getResponse().getOutcome() ).getIssue().size() );
// Assert.assertEquals( "Could not find tracked entity instance.", ( (OperationOutcome) result.getEntry().get( 2 )
// .getResponse().getOutcome() ).getIssueFirstRep().getDiagnostics() );
//
// systemDhis2Server.verify();
// userDhis2Server.verify();
// }
}
Loading