diff --git a/dhis/src/main/java/org/dhis2/fhir/adapter/dhis/service/impl/AbstractDhisMetadataServiceImpl.java b/dhis/src/main/java/org/dhis2/fhir/adapter/dhis/service/impl/AbstractDhisMetadataServiceImpl.java index fc466c7b..102aab20 100644 --- a/dhis/src/main/java/org/dhis2/fhir/adapter/dhis/service/impl/AbstractDhisMetadataServiceImpl.java +++ b/dhis/src/main/java/org/dhis2/fhir/adapter/dhis/service/impl/AbstractDhisMetadataServiceImpl.java @@ -123,13 +123,12 @@ public Optional findMetadataRefreshedByReference( @Nonnull Reference referenc @HystrixCommand( ignoreExceptions = UnauthorizedException.class ) @Nonnull @Override - @CachePut( cacheResolver = "dhisMetadataCacheResolver", unless = "#result==null" ) public Optional findOneByReference( @Nonnull Reference reference ) { return findOneByReference( userRestTemplate, reference ); } - @HystrixCommand( ignoreExceptions = UnauthorizedException.class ) + @HystrixCommand( ignoreExceptions = { UnauthorizedException.class, DhisFindException.class } ) @Nonnull @Override public DhisResourceResult find( @Nonnull UriFilterApplier uriFilterApplier, int from, int max ) diff --git a/dhis/src/main/java/org/dhis2/fhir/adapter/dhis/tracker/program/EnrollmentService.java b/dhis/src/main/java/org/dhis2/fhir/adapter/dhis/tracker/program/EnrollmentService.java index fa3db68c..4c8f77fd 100644 --- a/dhis/src/main/java/org/dhis2/fhir/adapter/dhis/tracker/program/EnrollmentService.java +++ b/dhis/src/main/java/org/dhis2/fhir/adapter/dhis/tracker/program/EnrollmentService.java @@ -28,6 +28,8 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +import org.dhis2.fhir.adapter.dhis.model.DhisResourceResult; +import org.dhis2.fhir.adapter.dhis.model.UriFilterApplier; import org.dhis2.fhir.adapter.dhis.service.DhisService; import javax.annotation.Nonnull; @@ -55,4 +57,7 @@ public interface EnrollmentService extends DhisService Enrollment createOrUpdate( @Nonnull Enrollment enrollment ); boolean delete( @Nonnull String enrollmentId ); + + @Nonnull + DhisResourceResult find( @Nonnull UriFilterApplier uriFilterApplier, int from, int max ); } diff --git a/dhis/src/main/java/org/dhis2/fhir/adapter/dhis/tracker/program/impl/EnrollmentServiceImpl.java b/dhis/src/main/java/org/dhis2/fhir/adapter/dhis/tracker/program/impl/EnrollmentServiceImpl.java index ba8b1e07..b0d47089 100644 --- a/dhis/src/main/java/org/dhis2/fhir/adapter/dhis/tracker/program/impl/EnrollmentServiceImpl.java +++ b/dhis/src/main/java/org/dhis2/fhir/adapter/dhis/tracker/program/impl/EnrollmentServiceImpl.java @@ -33,24 +33,29 @@ import org.dhis2.fhir.adapter.auth.UnauthorizedException; import org.dhis2.fhir.adapter.cache.RequestCacheService; import org.dhis2.fhir.adapter.dhis.DhisConflictException; +import org.dhis2.fhir.adapter.dhis.DhisFindException; import org.dhis2.fhir.adapter.dhis.DhisImportUnsuccessfulException; import org.dhis2.fhir.adapter.dhis.local.LocalDhisRepositoryPersistCallback; import org.dhis2.fhir.adapter.dhis.local.LocalDhisRepositoryPersistResult; import org.dhis2.fhir.adapter.dhis.local.LocalDhisRepositoryPersistStatus; import org.dhis2.fhir.adapter.dhis.local.LocalDhisResourceRepositoryTemplate; import org.dhis2.fhir.adapter.dhis.model.DhisResourceComparator; +import org.dhis2.fhir.adapter.dhis.model.DhisResourceResult; import org.dhis2.fhir.adapter.dhis.model.DhisResourceType; import org.dhis2.fhir.adapter.dhis.model.ImportStatus; import org.dhis2.fhir.adapter.dhis.model.ImportSummaries; import org.dhis2.fhir.adapter.dhis.model.ImportSummariesWebMessage; import org.dhis2.fhir.adapter.dhis.model.ImportSummary; import org.dhis2.fhir.adapter.dhis.model.Status; +import org.dhis2.fhir.adapter.dhis.model.UriFilterApplier; import org.dhis2.fhir.adapter.dhis.tracker.program.Enrollment; import org.dhis2.fhir.adapter.dhis.tracker.program.EnrollmentService; import org.dhis2.fhir.adapter.dhis.tracker.program.EnrollmentStatus; import org.dhis2.fhir.adapter.dhis.tracker.program.Event; import org.dhis2.fhir.adapter.dhis.tracker.program.EventService; import org.dhis2.fhir.adapter.dhis.util.CodeGenerator; +import org.dhis2.fhir.adapter.dhis.util.DhisPagingQuery; +import org.dhis2.fhir.adapter.dhis.util.DhisPagingUtils; import org.dhis2.fhir.adapter.rest.RestTemplateUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; @@ -64,9 +69,11 @@ import org.springframework.stereotype.Service; import org.springframework.web.client.HttpClientErrorException; import org.springframework.web.client.RestTemplate; +import org.springframework.web.util.UriComponentsBuilder; import javax.annotation.Nonnull; import javax.annotation.Nullable; +import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.Comparator; @@ -125,6 +132,37 @@ public DhisResourceType getDhisResourceType() return DhisResourceType.ENROLLMENT; } + @HystrixCommand( ignoreExceptions = { UnauthorizedException.class, DhisFindException.class } ) + @Nonnull + @Override + public DhisResourceResult find( @Nonnull UriFilterApplier uriFilterApplier, int from, int max ) + { + final DhisPagingQuery pagingQuery = DhisPagingUtils.createPagingQuery( from, max ); + final List variables = new ArrayList<>(); + final String uri = uriFilterApplier.add( UriComponentsBuilder.newInstance(), variables ).path( "/enrollments.json" ) + .queryParam( "skipPaging", "false" ).queryParam( "page", pagingQuery.getPage() ).queryParam( "pageSize", pagingQuery.getPageSize() ) + .queryParam( "ouMode", uriFilterApplier.containsQueryParam( "ou" ) ? "SELECTED" : "ACCESSIBLE" ) + .queryParam( "fields", ":all" ).build().toString(); + final ResponseEntity result; + try + { + result = restTemplate.getForEntity( uri, DhisEnrollments.class, variables.toArray() ); + } + catch ( HttpClientErrorException e ) + { + if ( e.getStatusCode() == HttpStatus.BAD_REQUEST || e.getStatusCode() == HttpStatus.CONFLICT ) + { + throw new DhisFindException( e.getMessage(), e ); + } + throw e; + } + final DhisEnrollments enrollments = Objects.requireNonNull( result.getBody() ); + + return new DhisResourceResult<>( ( enrollments.getEnrollments().size() > pagingQuery.getResultOffset() ) ? + enrollments.getEnrollments().subList( pagingQuery.getResultOffset(), enrollments.getEnrollments().size() ) : Collections.emptyList(), + ( enrollments.getEnrollments().size() >= pagingQuery.getPageSize() ) ); + } + @HystrixCommand( ignoreExceptions = UnauthorizedException.class ) @Nonnull @Override diff --git a/dhis/src/main/java/org/dhis2/fhir/adapter/dhis/tracker/program/impl/EventServiceImpl.java b/dhis/src/main/java/org/dhis2/fhir/adapter/dhis/tracker/program/impl/EventServiceImpl.java index 4cf20c3a..437e279a 100644 --- a/dhis/src/main/java/org/dhis2/fhir/adapter/dhis/tracker/program/impl/EventServiceImpl.java +++ b/dhis/src/main/java/org/dhis2/fhir/adapter/dhis/tracker/program/impl/EventServiceImpl.java @@ -447,7 +447,7 @@ protected Event update( @Nonnull Event event ) return event; } - @HystrixCommand( ignoreExceptions = UnauthorizedException.class ) + @HystrixCommand( ignoreExceptions = { UnauthorizedException.class, DhisFindException.class } ) @Nonnull @Override public DhisResourceResult find( @Nonnull String programId, @Nonnull String programStageId, @Nonnull UriFilterApplier uriFilterApplier, int from, int max ) diff --git a/dhis/src/main/java/org/dhis2/fhir/adapter/dhis/tracker/trackedentity/impl/TrackedEntityServiceImpl.java b/dhis/src/main/java/org/dhis2/fhir/adapter/dhis/tracker/trackedentity/impl/TrackedEntityServiceImpl.java index a955f56c..0da19f9a 100644 --- a/dhis/src/main/java/org/dhis2/fhir/adapter/dhis/tracker/trackedentity/impl/TrackedEntityServiceImpl.java +++ b/dhis/src/main/java/org/dhis2/fhir/adapter/dhis/tracker/trackedentity/impl/TrackedEntityServiceImpl.java @@ -433,7 +433,7 @@ public boolean persistDeleteById( @Nonnull String id ) return _delete( id ); } - @HystrixCommand( ignoreExceptions = UnauthorizedException.class ) + @HystrixCommand( ignoreExceptions = { UnauthorizedException.class, DhisFindException.class } ) @Nonnull @Override public DhisResourceResult find( @Nonnull String trackedEntityTypeId, @Nonnull UriFilterApplier uriFilterApplier, int from, int max ) diff --git a/docs/fhir/profiles/TrackerProgramCarePlan.StructureDefinition.xml b/docs/fhir/profiles/TrackerProgramCarePlan.StructureDefinition.xml index 185560b2..c3f0c2ac 100644 --- a/docs/fhir/profiles/TrackerProgramCarePlan.StructureDefinition.xml +++ b/docs/fhir/profiles/TrackerProgramCarePlan.StructureDefinition.xml @@ -66,6 +66,7 @@