@Test public void addSubjectResourceType() { final TrackedEntityRule rule1 = new TrackedEntityRule(); rule1.setEvaluationOrder( 1 ); rule1.setFhirResourceType( FhirResourceType.RELATED_PERSON ); final TrackedEntityRule rule2 = new TrackedEntityRule(); rule2.setEvaluationOrder( 100 ); rule2.setFhirResourceType( FhirResourceType.PATIENT ); Mockito.doReturn( Optional.of( new WritableTrackedEntityType( "a1234567890", "Test", Collections.emptyList() ) ) ) .when( trackedEntityMetadataService ).findTypeByReference( Mockito.eq( new Reference( "a1234567890", ReferenceType.ID ) ) ); Mockito.doReturn( Arrays.asList( rule1, rule2 ) ).when( trackedEntityRuleRepository ).findByTypeRefs( Mockito.eq( new HashSet<>( Arrays.asList( new Reference( "a1234567890", ReferenceType.ID ), new Reference( "Test", ReferenceType.NAME ) ) ) ) ); final WritableProgram program = new WritableProgram(); program.setName( "Test Program" ); program.setDescription( "Test Description" ); program.setWithoutRegistration( false ); program.setTrackedEntityTypeId( "a1234567890" ); program.setStages( new ArrayList<>() ); Assert.assertEquals( FhirResourceType.PATIENT, ProgramTrackedEntityTypeUtils.getTrackedEntityFhirResourceType( trackedEntityMetadataService, trackedEntityRuleRepository, program ) ); }
@Nullable public static FhirResourceType getTrackedEntityFhirResourceType( @Nonnull TrackedEntityMetadataService trackedEntityMetadataService, @Nonnull TrackedEntityRuleRepository trackedEntityRuleRepository, @Nonnull Program program ) { return getTrackedEntityRule( trackedEntityMetadataService, trackedEntityRuleRepository, program ).map( AbstractRule::getFhirResourceType ).orElse( null ); }
ProgramTrackedEntityTypeUtils { @Nullable public static FhirResourceType getTrackedEntityFhirResourceType( @Nonnull TrackedEntityMetadataService trackedEntityMetadataService, @Nonnull TrackedEntityRuleRepository trackedEntityRuleRepository, @Nonnull Program program ) { return getTrackedEntityRule( trackedEntityMetadataService, trackedEntityRuleRepository, program ).map( AbstractRule::getFhirResourceType ).orElse( null ); } }
ProgramTrackedEntityTypeUtils { @Nullable public static FhirResourceType getTrackedEntityFhirResourceType( @Nonnull TrackedEntityMetadataService trackedEntityMetadataService, @Nonnull TrackedEntityRuleRepository trackedEntityRuleRepository, @Nonnull Program program ) { return getTrackedEntityRule( trackedEntityMetadataService, trackedEntityRuleRepository, program ).map( AbstractRule::getFhirResourceType ).orElse( null ); } private  ProgramTrackedEntityTypeUtils(); }
ProgramTrackedEntityTypeUtils { @Nullable public static FhirResourceType getTrackedEntityFhirResourceType( @Nonnull TrackedEntityMetadataService trackedEntityMetadataService, @Nonnull TrackedEntityRuleRepository trackedEntityRuleRepository, @Nonnull Program program ) { return getTrackedEntityRule( trackedEntityMetadataService, trackedEntityRuleRepository, program ).map( AbstractRule::getFhirResourceType ).orElse( null ); } private  ProgramTrackedEntityTypeUtils(); @Nonnull static Optional<TrackedEntityRule> getTrackedEntityRule(
        @Nonnull TrackedEntityMetadataService trackedEntityMetadataService,
        @Nonnull TrackedEntityRuleRepository trackedEntityRuleRepository,
        @Nonnull Program program ); @Nullable static FhirResourceType getTrackedEntityFhirResourceType(
        @Nonnull TrackedEntityMetadataService trackedEntityMetadataService,
        @Nonnull TrackedEntityRuleRepository trackedEntityRuleRepository,
        @Nonnull Program program ); }
ProgramTrackedEntityTypeUtils { @Nullable public static FhirResourceType getTrackedEntityFhirResourceType( @Nonnull TrackedEntityMetadataService trackedEntityMetadataService, @Nonnull TrackedEntityRuleRepository trackedEntityRuleRepository, @Nonnull Program program ) { return getTrackedEntityRule( trackedEntityMetadataService, trackedEntityRuleRepository, program ).map( AbstractRule::getFhirResourceType ).orElse( null ); } private  ProgramTrackedEntityTypeUtils(); @Nonnull static Optional<TrackedEntityRule> getTrackedEntityRule(
        @Nonnull TrackedEntityMetadataService trackedEntityMetadataService,
        @Nonnull TrackedEntityRuleRepository trackedEntityRuleRepository,
        @Nonnull Program program ); @Nullable static FhirResourceType getTrackedEntityFhirResourceType(
        @Nonnull TrackedEntityMetadataService trackedEntityMetadataService,
        @Nonnull TrackedEntityRuleRepository trackedEntityRuleRepository,
        @Nonnull Program program );  }