@Test public void patientInstanceEverything() { Mockito.when( requestDetails.getServerBaseForRequest() ).thenReturn( "http: Mockito.when( requestDetails.getTenantId() ).thenReturn( "default" ); Mockito.when( observation.getIdElement() ).thenReturn( new IdType() ); Mockito.when( condition.getIdElement() ).thenReturn( new IdType() ); Mockito.when( immunization.getIdElement() ).thenReturn( new IdType() ); Mockito.when( encounter.getIdElement() ).thenReturn( new IdType() ); Mockito.when( diagnosticReport.getIdElement() ).thenReturn( new IdType() ); Mockito.when( medicationRequest.getIdElement() ).thenReturn( new IdType() ); final UUID fhirClientId = FhirClient.getIdByFhirVersion( FhirVersion.DSTU3 ); Mockito.doReturn( Optional.of( observationClientResource ) ).when( fhirClientResourceRepository ).findFirstCached( Mockito.eq( fhirClientId ), Mockito.eq( FhirResourceType.OBSERVATION ) ); Mockito.doReturn( Optional.of( conditionClientResource ) ).when( fhirClientResourceRepository ).findFirstCached( Mockito.eq( fhirClientId ), Mockito.eq( FhirResourceType.CONDITION ) ); Mockito.doReturn( Optional.of( immunizationClientResource ) ).when( fhirClientResourceRepository ).findFirstCached( Mockito.eq( fhirClientId ), Mockito.eq( FhirResourceType.IMMUNIZATION ) ); Mockito.doReturn( Optional.of( encounterClientResource ) ).when( fhirClientResourceRepository ).findFirstCached( Mockito.eq( fhirClientId ), Mockito.eq( FhirResourceType.ENCOUNTER ) ); Mockito.doReturn( Optional.of( diagnosticReportClientResource ) ).when( fhirClientResourceRepository ).findFirstCached( Mockito.eq( fhirClientId ), Mockito.eq( FhirResourceType.DIAGNOSTIC_REPORT ) ); Mockito.doReturn( Optional.of( medicationRequestClientResource ) ).when( fhirClientResourceRepository ).findFirstCached( Mockito.eq( fhirClientId ), Mockito.eq( FhirResourceType.MEDICATION_REQUEST ) ); Mockito.doReturn( fhirClient ).when( observationClientResource ).getFhirClient(); Mockito.doReturn( fhirClient ).when( conditionClientResource ).getFhirClient(); Mockito.doReturn( fhirClient ).when( immunizationClientResource ).getFhirClient(); Mockito.doReturn( fhirClient ).when( encounterClientResource ).getFhirClient(); Mockito.doReturn( fhirClient ).when( diagnosticReportClientResource ).getFhirClient(); Mockito.doReturn( fhirClient ).when( medicationRequestClientResource ).getFhirClient(); Mockito.doAnswer( invocation -> { final Map<String, List<String>> filter = invocation.getArgument( 5 ); Assert.assertEquals( filter.size(), 1 ); Assert.assertTrue( filter.containsKey( "patient" ) ); Assert.assertEquals( Collections.singletonList( "Patient/4711" ), filter.get( "patient" ) ); return observationBundleProvider; } ).when( dhisRepository ).search( Mockito.same( fhirClient ), Mockito.eq( FhirResourceType.OBSERVATION ), Mockito.isNull(), Mockito.eq( true ), Mockito.isNull(), Mockito.isNotNull(), Mockito.isNull() ); Mockito.doAnswer( invocation -> { final Map<String, List<String>> filter = invocation.getArgument( 5 ); Assert.assertEquals( filter.size(), 1 ); Assert.assertTrue( filter.containsKey( "patient" ) ); Assert.assertEquals( Collections.singletonList( "Patient/4711" ), filter.get( "patient" ) ); return conditionBundleProvider; } ).when( dhisRepository ).search( Mockito.same( fhirClient ), Mockito.eq( FhirResourceType.CONDITION ), Mockito.isNull(), Mockito.eq( true ), Mockito.isNull(), Mockito.isNotNull(), Mockito.isNull() ); Mockito.doAnswer( invocation -> { final Map<String, List<String>> filter = invocation.getArgument( 5 ); Assert.assertEquals( filter.size(), 1 ); Assert.assertTrue( filter.containsKey( "patient" ) ); Assert.assertEquals( Collections.singletonList( "Patient/4711" ), filter.get( "patient" ) ); return immunizationBundleProvider; } ).when( dhisRepository ).search( Mockito.same( fhirClient ), Mockito.eq( FhirResourceType.IMMUNIZATION ), Mockito.isNull(), Mockito.eq( true ), Mockito.isNull(), Mockito.isNotNull(), Mockito.isNull() ); Mockito.doAnswer( invocation -> { final Map<String, List<String>> filter = invocation.getArgument( 5 ); Assert.assertEquals( filter.size(), 1 ); Assert.assertTrue( filter.containsKey( "patient" ) ); Assert.assertEquals( Collections.singletonList( "Patient/4711" ), filter.get( "patient" ) ); return encounterBundleProvider; } ).when( dhisRepository ).search( Mockito.same( fhirClient ), Mockito.eq( FhirResourceType.ENCOUNTER ), Mockito.isNull(), Mockito.eq( true ), Mockito.isNull(), Mockito.isNotNull(), Mockito.isNull() ); Mockito.doAnswer( invocation -> { final Map<String, List<String>> filter = invocation.getArgument( 5 ); Assert.assertEquals( filter.size(), 1 ); Assert.assertTrue( filter.containsKey( "patient" ) ); Assert.assertEquals( Collections.singletonList( "Patient/4711" ), filter.get( "patient" ) ); return diagnosticReportBundleProvider; } ).when( dhisRepository ).search( Mockito.same( fhirClient ), Mockito.eq( FhirResourceType.DIAGNOSTIC_REPORT ), Mockito.isNull(), Mockito.eq( true ), Mockito.isNull(), Mockito.isNotNull(), Mockito.isNull() ); Mockito.doAnswer( invocation -> { final Map<String, List<String>> filter = invocation.getArgument( 5 ); Assert.assertEquals( filter.size(), 1 ); Assert.assertTrue( filter.containsKey( "patient" ) ); Assert.assertEquals( Collections.singletonList( "Patient/4711" ), filter.get( "patient" ) ); return medicationRequestBundleProvider; } ).when( dhisRepository ).search( Mockito.same( fhirClient ), Mockito.eq( FhirResourceType.MEDICATION_REQUEST ), Mockito.isNull(), Mockito.eq( true ), Mockito.isNull(), Mockito.isNotNull(), Mockito.isNull() ); Mockito.doReturn( Collections.singletonList( observation ) ).when( observationBundleProvider ).getResources( Mockito.eq( 0 ), Mockito.eq( Integer.MAX_VALUE ) ); Mockito.doReturn( Collections.singletonList( immunization ) ).when( immunizationBundleProvider ).getResources( Mockito.eq( 0 ), Mockito.eq( Integer.MAX_VALUE ) ); Mockito.doReturn( Collections.singletonList( condition ) ).when( conditionBundleProvider ).getResources( Mockito.eq( 0 ), Mockito.eq( Integer.MAX_VALUE ) ); Mockito.doReturn( Collections.singletonList( diagnosticReport ) ).when( diagnosticReportBundleProvider ).getResources( Mockito.eq( 0 ), Mockito.eq( Integer.MAX_VALUE ) ); Mockito.doReturn( Collections.singletonList( medicationRequest ) ).when( medicationRequestBundleProvider ).getResources( Mockito.eq( 0 ), Mockito.eq( Integer.MAX_VALUE ) ); Mockito.doReturn( Collections.singletonList( encounter ) ).when( encounterBundleProvider ).getResources( Mockito.eq( 0 ), Mockito.eq( Integer.MAX_VALUE ) ); final Bundle result = provider.patientInstanceEverything( requestDetails, new IdType( "4711" ) ); Assert.assertEquals( 6, result.getEntry().size() ); Assert.assertTrue( result.getEntry().stream().anyMatch( e -> e.getResource() == observation ) ); Assert.assertTrue( result.getEntry().stream().anyMatch( e -> e.getResource() == immunization ) ); Assert.assertTrue( result.getEntry().stream().anyMatch( e -> e.getResource() == condition ) ); Assert.assertTrue( result.getEntry().stream().anyMatch( e -> e.getResource() == diagnosticReport ) ); Assert.assertTrue( result.getEntry().stream().anyMatch( e -> e.getResource() == medicationRequest ) ); Assert.assertTrue( result.getEntry().stream().anyMatch( e -> e.getResource() == encounter ) ); }
@Nonnull @Operation( name = "$everything", idempotent = true ) public Bundle patientInstanceEverything( @Nonnull RequestDetails requestDetails, @IdParam IIdType patientId ) { validateUseCase( requestDetails ); final Bundle bundle = new Bundle(); patientInstanceEverything( patientId, ( fhirResourceType, resources ) -> resources.forEach( r -> bundle.addEntry().setResource( (Resource) r ) .setFullUrl( createFullUrl( requestDetails, fhirResourceType, r ) ) ) ); return bundle; }
Dstu3PatientResourceProvider extends AbstractPatientResourceProvider<Patient> { @Nonnull @Operation( name = "$everything", idempotent = true ) public Bundle patientInstanceEverything( @Nonnull RequestDetails requestDetails, @IdParam IIdType patientId ) { validateUseCase( requestDetails ); final Bundle bundle = new Bundle(); patientInstanceEverything( patientId, ( fhirResourceType, resources ) -> resources.forEach( r -> bundle.addEntry().setResource( (Resource) r ) .setFullUrl( createFullUrl( requestDetails, fhirResourceType, r ) ) ) ); return bundle; } }
Dstu3PatientResourceProvider extends AbstractPatientResourceProvider<Patient> { @Nonnull @Operation( name = "$everything", idempotent = true ) public Bundle patientInstanceEverything( @Nonnull RequestDetails requestDetails, @IdParam IIdType patientId ) { validateUseCase( requestDetails ); final Bundle bundle = new Bundle(); patientInstanceEverything( patientId, ( fhirResourceType, resources ) -> resources.forEach( r -> bundle.addEntry().setResource( (Resource) r ) .setFullUrl( createFullUrl( requestDetails, fhirResourceType, r ) ) ) ); return bundle; } Dstu3PatientResourceProvider( @Nonnull FhirClientResourceRepository fhirClientResourceRepository, @Nonnull FhirClientSystemRepository fhirClientSystemRepository,
        @Nonnull FhirRepository fhirRepository, @Nonnull DhisRepository dhisRepository ); }
Dstu3PatientResourceProvider extends AbstractPatientResourceProvider<Patient> { @Nonnull @Operation( name = "$everything", idempotent = true ) public Bundle patientInstanceEverything( @Nonnull RequestDetails requestDetails, @IdParam IIdType patientId ) { validateUseCase( requestDetails ); final Bundle bundle = new Bundle(); patientInstanceEverything( patientId, ( fhirResourceType, resources ) -> resources.forEach( r -> bundle.addEntry().setResource( (Resource) r ) .setFullUrl( createFullUrl( requestDetails, fhirResourceType, r ) ) ) ); return bundle; } Dstu3PatientResourceProvider( @Nonnull FhirClientResourceRepository fhirClientResourceRepository, @Nonnull FhirClientSystemRepository fhirClientSystemRepository,
        @Nonnull FhirRepository fhirRepository, @Nonnull DhisRepository dhisRepository ); @Nonnull @Override FhirVersion getFhirVersion(); @Nonnull @Operation( name = "$everything", idempotent = true ) Bundle patientInstanceEverything( @Nonnull RequestDetails requestDetails, @IdParam IIdType patientId ); @Search( allowUnknownParams = true ) @Nonnull IBundleProvider search( @Nonnull RequestDetails requestDetails, @Nullable @Count Integer count, @Nullable @OptionalParam( name = SP_LAST_UPDATED ) DateRangeParam lastUpdatedDateRange, @Nullable @RawParam Map<String, List<String>> filter ); }
Dstu3PatientResourceProvider extends AbstractPatientResourceProvider<Patient> { @Nonnull @Operation( name = "$everything", idempotent = true ) public Bundle patientInstanceEverything( @Nonnull RequestDetails requestDetails, @IdParam IIdType patientId ) { validateUseCase( requestDetails ); final Bundle bundle = new Bundle(); patientInstanceEverything( patientId, ( fhirResourceType, resources ) -> resources.forEach( r -> bundle.addEntry().setResource( (Resource) r ) .setFullUrl( createFullUrl( requestDetails, fhirResourceType, r ) ) ) ); return bundle; } Dstu3PatientResourceProvider( @Nonnull FhirClientResourceRepository fhirClientResourceRepository, @Nonnull FhirClientSystemRepository fhirClientSystemRepository,
        @Nonnull FhirRepository fhirRepository, @Nonnull DhisRepository dhisRepository ); @Nonnull @Override FhirVersion getFhirVersion(); @Nonnull @Operation( name = "$everything", idempotent = true ) Bundle patientInstanceEverything( @Nonnull RequestDetails requestDetails, @IdParam IIdType patientId ); @Search( allowUnknownParams = true ) @Nonnull IBundleProvider search( @Nonnull RequestDetails requestDetails, @Nullable @Count Integer count, @Nullable @OptionalParam( name = SP_LAST_UPDATED ) DateRangeParam lastUpdatedDateRange, @Nullable @RawParam Map<String, List<String>> filter );  }