target
stringlengths
20
113k
src_fm
stringlengths
11
86.3k
src_fm_fc
stringlengths
21
86.4k
src_fm_fc_co
stringlengths
30
86.4k
src_fm_fc_ms
stringlengths
42
86.8k
src_fm_fc_ms_ff
stringlengths
43
86.8k
@Test(expected = NullPointerException.class) public void sharedPoolStrategyNullPool() { SchedulingStrategies.createParallelSharedStrategy( new Logger(), null ); }
public static SchedulingStrategy createParallelSharedStrategy( ConsoleLogger logger, ExecutorService threadPool ) { if ( threadPool == null ) { throw new NullPointerException( "null threadPool in #createParallelSharedStrategy" ); } return new SharedThreadPoolStrategy( logger, threadPool ); }
SchedulingStrategies { public static SchedulingStrategy createParallelSharedStrategy( ConsoleLogger logger, ExecutorService threadPool ) { if ( threadPool == null ) { throw new NullPointerException( "null threadPool in #createParallelSharedStrategy" ); } return new SharedThreadPoolStrategy( logger, threadPool ); } }
SchedulingStrategies { public static SchedulingStrategy createParallelSharedStrategy( ConsoleLogger logger, ExecutorService threadPool ) { if ( threadPool == null ) { throw new NullPointerException( "null threadPool in #createParallelSharedStrategy" ); } return new SharedThreadPoolStrategy( logger, threadPool ); } }
SchedulingStrategies { public static SchedulingStrategy createParallelSharedStrategy( ConsoleLogger logger, ExecutorService threadPool ) { if ( threadPool == null ) { throw new NullPointerException( "null threadPool in #createParallelSharedStrategy" ); } return new SharedThreadPoolStrategy( logger, threadPool ); } static SchedulingStrategy createInvokerStrategy( ConsoleLogger logger ); static SchedulingStrategy createParallelStrategy( ConsoleLogger logger, int nThreads ); static SchedulingStrategy createParallelStrategyUnbounded( ConsoleLogger logger ); static SchedulingStrategy createParallelSharedStrategy( ConsoleLogger logger, ExecutorService threadPool ); }
SchedulingStrategies { public static SchedulingStrategy createParallelSharedStrategy( ConsoleLogger logger, ExecutorService threadPool ) { if ( threadPool == null ) { throw new NullPointerException( "null threadPool in #createParallelSharedStrategy" ); } return new SharedThreadPoolStrategy( logger, threadPool ); } static SchedulingStrategy createInvokerStrategy( ConsoleLogger logger ); static SchedulingStrategy createParallelStrategy( ConsoleLogger logger, int nThreads ); static SchedulingStrategy createParallelStrategyUnbounded( ConsoleLogger logger ); static SchedulingStrategy createParallelSharedStrategy( ConsoleLogger logger, ExecutorService threadPool ); }
@Test public void sharedPoolStrategy() throws InterruptedException { ExecutorService sharedPool = Executors.newCachedThreadPool( DAEMON_THREAD_FACTORY ); SchedulingStrategy strategy1 = SchedulingStrategies.createParallelSharedStrategy( new Logger(), sharedPool ); assertTrue( strategy1.hasSharedThreadPool() ); assertTrue( strategy1.canSchedule() ); SchedulingStrategy strategy2 = SchedulingStrategies.createParallelSharedStrategy( new Logger(), sharedPool ); assertTrue( strategy2.hasSharedThreadPool() ); assertTrue( strategy2.canSchedule() ); Task task1 = new Task(); Task task2 = new Task(); Task task3 = new Task(); Task task4 = new Task(); strategy1.schedule( task1 ); strategy2.schedule( task2 ); strategy1.schedule( task3 ); strategy2.schedule( task4 ); assertTrue( strategy1.canSchedule() ); assertTrue( strategy2.canSchedule() ); assertTrue( strategy1.finished() ); assertFalse( strategy1.canSchedule() ); assertTrue( strategy2.finished() ); assertFalse( strategy2.canSchedule() ); assertTrue( task1.result ); assertTrue( task2.result ); assertTrue( task3.result ); assertTrue( task4.result ); }
public static SchedulingStrategy createParallelSharedStrategy( ConsoleLogger logger, ExecutorService threadPool ) { if ( threadPool == null ) { throw new NullPointerException( "null threadPool in #createParallelSharedStrategy" ); } return new SharedThreadPoolStrategy( logger, threadPool ); }
SchedulingStrategies { public static SchedulingStrategy createParallelSharedStrategy( ConsoleLogger logger, ExecutorService threadPool ) { if ( threadPool == null ) { throw new NullPointerException( "null threadPool in #createParallelSharedStrategy" ); } return new SharedThreadPoolStrategy( logger, threadPool ); } }
SchedulingStrategies { public static SchedulingStrategy createParallelSharedStrategy( ConsoleLogger logger, ExecutorService threadPool ) { if ( threadPool == null ) { throw new NullPointerException( "null threadPool in #createParallelSharedStrategy" ); } return new SharedThreadPoolStrategy( logger, threadPool ); } }
SchedulingStrategies { public static SchedulingStrategy createParallelSharedStrategy( ConsoleLogger logger, ExecutorService threadPool ) { if ( threadPool == null ) { throw new NullPointerException( "null threadPool in #createParallelSharedStrategy" ); } return new SharedThreadPoolStrategy( logger, threadPool ); } static SchedulingStrategy createInvokerStrategy( ConsoleLogger logger ); static SchedulingStrategy createParallelStrategy( ConsoleLogger logger, int nThreads ); static SchedulingStrategy createParallelStrategyUnbounded( ConsoleLogger logger ); static SchedulingStrategy createParallelSharedStrategy( ConsoleLogger logger, ExecutorService threadPool ); }
SchedulingStrategies { public static SchedulingStrategy createParallelSharedStrategy( ConsoleLogger logger, ExecutorService threadPool ) { if ( threadPool == null ) { throw new NullPointerException( "null threadPool in #createParallelSharedStrategy" ); } return new SharedThreadPoolStrategy( logger, threadPool ); } static SchedulingStrategy createInvokerStrategy( ConsoleLogger logger ); static SchedulingStrategy createParallelStrategy( ConsoleLogger logger, int nThreads ); static SchedulingStrategy createParallelStrategyUnbounded( ConsoleLogger logger ); static SchedulingStrategy createParallelSharedStrategy( ConsoleLogger logger, ExecutorService threadPool ); }
@Test public void infinitePoolStrategy() throws InterruptedException { SchedulingStrategy strategy = SchedulingStrategies.createParallelStrategyUnbounded( new Logger() ); assertFalse( strategy.hasSharedThreadPool() ); assertTrue( strategy.canSchedule() ); Task task1 = new Task(); Task task2 = new Task(); strategy.schedule( task1 ); strategy.schedule( task2 ); assertTrue( strategy.canSchedule() ); assertTrue( strategy.finished() ); assertFalse( strategy.canSchedule() ); assertTrue( task1.result ); assertTrue( task2.result ); }
public static SchedulingStrategy createParallelStrategyUnbounded( ConsoleLogger logger ) { return new NonSharedThreadPoolStrategy( logger, Executors.newCachedThreadPool( DAEMON_THREAD_FACTORY ) ); }
SchedulingStrategies { public static SchedulingStrategy createParallelStrategyUnbounded( ConsoleLogger logger ) { return new NonSharedThreadPoolStrategy( logger, Executors.newCachedThreadPool( DAEMON_THREAD_FACTORY ) ); } }
SchedulingStrategies { public static SchedulingStrategy createParallelStrategyUnbounded( ConsoleLogger logger ) { return new NonSharedThreadPoolStrategy( logger, Executors.newCachedThreadPool( DAEMON_THREAD_FACTORY ) ); } }
SchedulingStrategies { public static SchedulingStrategy createParallelStrategyUnbounded( ConsoleLogger logger ) { return new NonSharedThreadPoolStrategy( logger, Executors.newCachedThreadPool( DAEMON_THREAD_FACTORY ) ); } static SchedulingStrategy createInvokerStrategy( ConsoleLogger logger ); static SchedulingStrategy createParallelStrategy( ConsoleLogger logger, int nThreads ); static SchedulingStrategy createParallelStrategyUnbounded( ConsoleLogger logger ); static SchedulingStrategy createParallelSharedStrategy( ConsoleLogger logger, ExecutorService threadPool ); }
SchedulingStrategies { public static SchedulingStrategy createParallelStrategyUnbounded( ConsoleLogger logger ) { return new NonSharedThreadPoolStrategy( logger, Executors.newCachedThreadPool( DAEMON_THREAD_FACTORY ) ); } static SchedulingStrategy createInvokerStrategy( ConsoleLogger logger ); static SchedulingStrategy createParallelStrategy( ConsoleLogger logger, int nThreads ); static SchedulingStrategy createParallelStrategyUnbounded( ConsoleLogger logger ); static SchedulingStrategy createParallelSharedStrategy( ConsoleLogger logger, ExecutorService threadPool ); }
@Test public void unknownParallel() throws TestSetFailedException { Map<String, String> properties = new HashMap<String, String>(); exception.expect( TestSetFailedException.class ); resolveConcurrency( new JUnitCoreParameters( properties ), null ); }
static Concurrency resolveConcurrency( JUnitCoreParameters params, RunnerCounter counts ) throws TestSetFailedException { if ( !params.isParallelismSelected() ) { throw new TestSetFailedException( "Unspecified parameter '" + JUnitCoreParameters.PARALLEL_KEY + "'." ); } if ( !params.isUseUnlimitedThreads() && !hasThreadCount( params ) && !hasThreadCounts( params ) ) { throw new TestSetFailedException( "Unspecified thread-count(s). " + "See the parameters " + JUnitCoreParameters.USEUNLIMITEDTHREADS_KEY + ", " + JUnitCoreParameters.THREADCOUNT_KEY + ", " + JUnitCoreParameters.THREADCOUNTSUITES_KEY + ", " + JUnitCoreParameters.THREADCOUNTCLASSES_KEY + ", " + JUnitCoreParameters.THREADCOUNTMETHODS_KEY + "." ); } if ( params.isUseUnlimitedThreads() ) { return concurrencyForUnlimitedThreads( params ); } else if ( hasThreadCount( params ) ) { if ( hasThreadCounts( params ) ) { return isLeafUnspecified( params ) ? concurrencyFromAllThreadCountsButUnspecifiedLeafCount( params, counts ) : concurrencyFromAllThreadCounts( params ); } else { return estimateConcurrency( params, counts ); } } else { return concurrencyFromThreadCounts( params ); } }
ParallelComputerUtil { static Concurrency resolveConcurrency( JUnitCoreParameters params, RunnerCounter counts ) throws TestSetFailedException { if ( !params.isParallelismSelected() ) { throw new TestSetFailedException( "Unspecified parameter '" + JUnitCoreParameters.PARALLEL_KEY + "'." ); } if ( !params.isUseUnlimitedThreads() && !hasThreadCount( params ) && !hasThreadCounts( params ) ) { throw new TestSetFailedException( "Unspecified thread-count(s). " + "See the parameters " + JUnitCoreParameters.USEUNLIMITEDTHREADS_KEY + ", " + JUnitCoreParameters.THREADCOUNT_KEY + ", " + JUnitCoreParameters.THREADCOUNTSUITES_KEY + ", " + JUnitCoreParameters.THREADCOUNTCLASSES_KEY + ", " + JUnitCoreParameters.THREADCOUNTMETHODS_KEY + "." ); } if ( params.isUseUnlimitedThreads() ) { return concurrencyForUnlimitedThreads( params ); } else if ( hasThreadCount( params ) ) { if ( hasThreadCounts( params ) ) { return isLeafUnspecified( params ) ? concurrencyFromAllThreadCountsButUnspecifiedLeafCount( params, counts ) : concurrencyFromAllThreadCounts( params ); } else { return estimateConcurrency( params, counts ); } } else { return concurrencyFromThreadCounts( params ); } } }
ParallelComputerUtil { static Concurrency resolveConcurrency( JUnitCoreParameters params, RunnerCounter counts ) throws TestSetFailedException { if ( !params.isParallelismSelected() ) { throw new TestSetFailedException( "Unspecified parameter '" + JUnitCoreParameters.PARALLEL_KEY + "'." ); } if ( !params.isUseUnlimitedThreads() && !hasThreadCount( params ) && !hasThreadCounts( params ) ) { throw new TestSetFailedException( "Unspecified thread-count(s). " + "See the parameters " + JUnitCoreParameters.USEUNLIMITEDTHREADS_KEY + ", " + JUnitCoreParameters.THREADCOUNT_KEY + ", " + JUnitCoreParameters.THREADCOUNTSUITES_KEY + ", " + JUnitCoreParameters.THREADCOUNTCLASSES_KEY + ", " + JUnitCoreParameters.THREADCOUNTMETHODS_KEY + "." ); } if ( params.isUseUnlimitedThreads() ) { return concurrencyForUnlimitedThreads( params ); } else if ( hasThreadCount( params ) ) { if ( hasThreadCounts( params ) ) { return isLeafUnspecified( params ) ? concurrencyFromAllThreadCountsButUnspecifiedLeafCount( params, counts ) : concurrencyFromAllThreadCounts( params ); } else { return estimateConcurrency( params, counts ); } } else { return concurrencyFromThreadCounts( params ); } } private ParallelComputerUtil(); }
ParallelComputerUtil { static Concurrency resolveConcurrency( JUnitCoreParameters params, RunnerCounter counts ) throws TestSetFailedException { if ( !params.isParallelismSelected() ) { throw new TestSetFailedException( "Unspecified parameter '" + JUnitCoreParameters.PARALLEL_KEY + "'." ); } if ( !params.isUseUnlimitedThreads() && !hasThreadCount( params ) && !hasThreadCounts( params ) ) { throw new TestSetFailedException( "Unspecified thread-count(s). " + "See the parameters " + JUnitCoreParameters.USEUNLIMITEDTHREADS_KEY + ", " + JUnitCoreParameters.THREADCOUNT_KEY + ", " + JUnitCoreParameters.THREADCOUNTSUITES_KEY + ", " + JUnitCoreParameters.THREADCOUNTCLASSES_KEY + ", " + JUnitCoreParameters.THREADCOUNTMETHODS_KEY + "." ); } if ( params.isUseUnlimitedThreads() ) { return concurrencyForUnlimitedThreads( params ); } else if ( hasThreadCount( params ) ) { if ( hasThreadCounts( params ) ) { return isLeafUnspecified( params ) ? concurrencyFromAllThreadCountsButUnspecifiedLeafCount( params, counts ) : concurrencyFromAllThreadCounts( params ); } else { return estimateConcurrency( params, counts ); } } else { return concurrencyFromThreadCounts( params ); } } private ParallelComputerUtil(); }
ParallelComputerUtil { static Concurrency resolveConcurrency( JUnitCoreParameters params, RunnerCounter counts ) throws TestSetFailedException { if ( !params.isParallelismSelected() ) { throw new TestSetFailedException( "Unspecified parameter '" + JUnitCoreParameters.PARALLEL_KEY + "'." ); } if ( !params.isUseUnlimitedThreads() && !hasThreadCount( params ) && !hasThreadCounts( params ) ) { throw new TestSetFailedException( "Unspecified thread-count(s). " + "See the parameters " + JUnitCoreParameters.USEUNLIMITEDTHREADS_KEY + ", " + JUnitCoreParameters.THREADCOUNT_KEY + ", " + JUnitCoreParameters.THREADCOUNTSUITES_KEY + ", " + JUnitCoreParameters.THREADCOUNTCLASSES_KEY + ", " + JUnitCoreParameters.THREADCOUNTMETHODS_KEY + "." ); } if ( params.isUseUnlimitedThreads() ) { return concurrencyForUnlimitedThreads( params ); } else if ( hasThreadCount( params ) ) { if ( hasThreadCounts( params ) ) { return isLeafUnspecified( params ) ? concurrencyFromAllThreadCountsButUnspecifiedLeafCount( params, counts ) : concurrencyFromAllThreadCounts( params ); } else { return estimateConcurrency( params, counts ); } } else { return concurrencyFromThreadCounts( params ); } } private ParallelComputerUtil(); }
@Test public void stripRepeatedTypeVarsOfOuterClasses() { assertThat( new ClassName("java.util.Map<K, V>.Entry<K, V>").get(), is("java.util.Map.Entry<K, V>")); assertThat( new ClassName("java.util.Foo<K extends java.util.Bar<K>>.Entry<K extends java.util.Bar<K>>").get(), is("java.util.Foo.Entry<K extends java.util.Bar<K>>")); }
public String get() { return this.fullClassNameWithGenerics; }
ClassName { public String get() { return this.fullClassNameWithGenerics; } }
ClassName { public String get() { return this.fullClassNameWithGenerics; } ClassName(String fullClassNameWithGenerics); }
ClassName { public String get() { return this.fullClassNameWithGenerics; } ClassName(String fullClassNameWithGenerics); String get(); String toString(); String getSimpleName(); String getPackageName(); List<String> getGenericsWithoutBounds(); List<String> getGenericsWithBounds(); String getGenericPart(); String getGenericPartWithoutBrackets(); String getWithoutGenericPart(); }
ClassName { public String get() { return this.fullClassNameWithGenerics; } ClassName(String fullClassNameWithGenerics); String get(); String toString(); String getSimpleName(); String getPackageName(); List<String> getGenericsWithoutBounds(); List<String> getGenericsWithBounds(); String getGenericPart(); String getGenericPartWithoutBrackets(); String getWithoutGenericPart(); }
@Test public void assertDirectAlertActionTest() throws Exception { Action action = new Action("", "", "createAlert", null, "", false, null); actionRouter.directAlertAction(action); Assert.assertNotNull(actionRouter); }
public void directAlertAction(Action action) { AlertActionRoute[] alertActionRoutes = AlertActionRoute.values(); for (AlertActionRoute alertActionRoute : alertActionRoutes) { if (alertActionRoute.identifier().equals(action.type())) { alertActionRoute.direct(action); return; } } logWarn("Unknown type in Alert action: " + action); }
ActionRouter { public void directAlertAction(Action action) { AlertActionRoute[] alertActionRoutes = AlertActionRoute.values(); for (AlertActionRoute alertActionRoute : alertActionRoutes) { if (alertActionRoute.identifier().equals(action.type())) { alertActionRoute.direct(action); return; } } logWarn("Unknown type in Alert action: " + action); } }
ActionRouter { public void directAlertAction(Action action) { AlertActionRoute[] alertActionRoutes = AlertActionRoute.values(); for (AlertActionRoute alertActionRoute : alertActionRoutes) { if (alertActionRoute.identifier().equals(action.type())) { alertActionRoute.direct(action); return; } } logWarn("Unknown type in Alert action: " + action); } }
ActionRouter { public void directAlertAction(Action action) { AlertActionRoute[] alertActionRoutes = AlertActionRoute.values(); for (AlertActionRoute alertActionRoute : alertActionRoutes) { if (alertActionRoute.identifier().equals(action.type())) { alertActionRoute.direct(action); return; } } logWarn("Unknown type in Alert action: " + action); } void directAlertAction(Action action); void directMotherAction(Action action); }
ActionRouter { public void directAlertAction(Action action) { AlertActionRoute[] alertActionRoutes = AlertActionRoute.values(); for (AlertActionRoute alertActionRoute : alertActionRoutes) { if (alertActionRoute.identifier().equals(action.type())) { alertActionRoute.direct(action); return; } } logWarn("Unknown type in Alert action: " + action); } void directAlertAction(Action action); void directMotherAction(Action action); }
@Test @Config(sdk = Build.VERSION_CODES.LOLLIPOP_MR1) public void testCryptographicHelperGenerateKeyInvokesLegacyGenerateKeyMethod() { cryptographicHelper.generateKey(SAMPLE_KEY_ALIAS); Mockito.verify(androidLegacyCryptography).generateKey(SAMPLE_KEY_ALIAS); }
public void generateKey(String keyAlias) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) { legacyCryptography.generateKey(keyAlias); } else { mCryptography.generateKey(keyAlias); } }
CryptographicHelper { public void generateKey(String keyAlias) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) { legacyCryptography.generateKey(keyAlias); } else { mCryptography.generateKey(keyAlias); } } }
CryptographicHelper { public void generateKey(String keyAlias) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) { legacyCryptography.generateKey(keyAlias); } else { mCryptography.generateKey(keyAlias); } } }
CryptographicHelper { public void generateKey(String keyAlias) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) { legacyCryptography.generateKey(keyAlias); } else { mCryptography.generateKey(keyAlias); } } static CryptographicHelper getInstance(Context context_); static byte[] encrypt(byte[] data, String keyAlias); static byte[] decrypt(byte[] data, String keyAlias); void generateKey(String keyAlias); Key getKey(String keyAlias); void deleteKey(String keyAlias); void setLegacyCryptography(AndroidLegacyCryptography legacyCryptography); void setMCryptography(AndroidMCryptography androidMCryptography); }
CryptographicHelper { public void generateKey(String keyAlias) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) { legacyCryptography.generateKey(keyAlias); } else { mCryptography.generateKey(keyAlias); } } static CryptographicHelper getInstance(Context context_); static byte[] encrypt(byte[] data, String keyAlias); static byte[] decrypt(byte[] data, String keyAlias); void generateKey(String keyAlias); Key getKey(String keyAlias); void deleteKey(String keyAlias); void setLegacyCryptography(AndroidLegacyCryptography legacyCryptography); void setMCryptography(AndroidMCryptography androidMCryptography); }
@Test public void testCryptographicHelperGetKeyInvokesAndroidMGetKeyMethod() { cryptographicHelper.getKey(SAMPLE_KEY_ALIAS); Mockito.verify(androidMCryptography).getKey(SAMPLE_KEY_ALIAS); }
public Key getKey(String keyAlias) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) { return legacyCryptography.getKey(keyAlias); } else { return mCryptography.getKey(keyAlias); } }
CryptographicHelper { public Key getKey(String keyAlias) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) { return legacyCryptography.getKey(keyAlias); } else { return mCryptography.getKey(keyAlias); } } }
CryptographicHelper { public Key getKey(String keyAlias) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) { return legacyCryptography.getKey(keyAlias); } else { return mCryptography.getKey(keyAlias); } } }
CryptographicHelper { public Key getKey(String keyAlias) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) { return legacyCryptography.getKey(keyAlias); } else { return mCryptography.getKey(keyAlias); } } static CryptographicHelper getInstance(Context context_); static byte[] encrypt(byte[] data, String keyAlias); static byte[] decrypt(byte[] data, String keyAlias); void generateKey(String keyAlias); Key getKey(String keyAlias); void deleteKey(String keyAlias); void setLegacyCryptography(AndroidLegacyCryptography legacyCryptography); void setMCryptography(AndroidMCryptography androidMCryptography); }
CryptographicHelper { public Key getKey(String keyAlias) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) { return legacyCryptography.getKey(keyAlias); } else { return mCryptography.getKey(keyAlias); } } static CryptographicHelper getInstance(Context context_); static byte[] encrypt(byte[] data, String keyAlias); static byte[] decrypt(byte[] data, String keyAlias); void generateKey(String keyAlias); Key getKey(String keyAlias); void deleteKey(String keyAlias); void setLegacyCryptography(AndroidLegacyCryptography legacyCryptography); void setMCryptography(AndroidMCryptography androidMCryptography); }
@Test @Config(sdk = Build.VERSION_CODES.LOLLIPOP_MR1) public void testCryptographicHelperGetKeyInvokesLegacyGetKeyMethod() { cryptographicHelper.getKey(SAMPLE_KEY_ALIAS); Mockito.verify(androidLegacyCryptography).getKey(SAMPLE_KEY_ALIAS); }
public Key getKey(String keyAlias) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) { return legacyCryptography.getKey(keyAlias); } else { return mCryptography.getKey(keyAlias); } }
CryptographicHelper { public Key getKey(String keyAlias) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) { return legacyCryptography.getKey(keyAlias); } else { return mCryptography.getKey(keyAlias); } } }
CryptographicHelper { public Key getKey(String keyAlias) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) { return legacyCryptography.getKey(keyAlias); } else { return mCryptography.getKey(keyAlias); } } }
CryptographicHelper { public Key getKey(String keyAlias) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) { return legacyCryptography.getKey(keyAlias); } else { return mCryptography.getKey(keyAlias); } } static CryptographicHelper getInstance(Context context_); static byte[] encrypt(byte[] data, String keyAlias); static byte[] decrypt(byte[] data, String keyAlias); void generateKey(String keyAlias); Key getKey(String keyAlias); void deleteKey(String keyAlias); void setLegacyCryptography(AndroidLegacyCryptography legacyCryptography); void setMCryptography(AndroidMCryptography androidMCryptography); }
CryptographicHelper { public Key getKey(String keyAlias) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) { return legacyCryptography.getKey(keyAlias); } else { return mCryptography.getKey(keyAlias); } } static CryptographicHelper getInstance(Context context_); static byte[] encrypt(byte[] data, String keyAlias); static byte[] decrypt(byte[] data, String keyAlias); void generateKey(String keyAlias); Key getKey(String keyAlias); void deleteKey(String keyAlias); void setLegacyCryptography(AndroidLegacyCryptography legacyCryptography); void setMCryptography(AndroidMCryptography androidMCryptography); }
@Test public void testCryptographicHelperDeleteKeyInvokesAndroidMGetKeyMethod() { cryptographicHelper.deleteKey(SAMPLE_KEY_ALIAS); Mockito.verify(androidMCryptography).deleteKey(SAMPLE_KEY_ALIAS); }
public void deleteKey(String keyAlias) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) { legacyCryptography.deleteKey(keyAlias); } else { mCryptography.deleteKey(keyAlias); } }
CryptographicHelper { public void deleteKey(String keyAlias) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) { legacyCryptography.deleteKey(keyAlias); } else { mCryptography.deleteKey(keyAlias); } } }
CryptographicHelper { public void deleteKey(String keyAlias) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) { legacyCryptography.deleteKey(keyAlias); } else { mCryptography.deleteKey(keyAlias); } } }
CryptographicHelper { public void deleteKey(String keyAlias) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) { legacyCryptography.deleteKey(keyAlias); } else { mCryptography.deleteKey(keyAlias); } } static CryptographicHelper getInstance(Context context_); static byte[] encrypt(byte[] data, String keyAlias); static byte[] decrypt(byte[] data, String keyAlias); void generateKey(String keyAlias); Key getKey(String keyAlias); void deleteKey(String keyAlias); void setLegacyCryptography(AndroidLegacyCryptography legacyCryptography); void setMCryptography(AndroidMCryptography androidMCryptography); }
CryptographicHelper { public void deleteKey(String keyAlias) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) { legacyCryptography.deleteKey(keyAlias); } else { mCryptography.deleteKey(keyAlias); } } static CryptographicHelper getInstance(Context context_); static byte[] encrypt(byte[] data, String keyAlias); static byte[] decrypt(byte[] data, String keyAlias); void generateKey(String keyAlias); Key getKey(String keyAlias); void deleteKey(String keyAlias); void setLegacyCryptography(AndroidLegacyCryptography legacyCryptography); void setMCryptography(AndroidMCryptography androidMCryptography); }
@Test @Config(sdk = Build.VERSION_CODES.LOLLIPOP_MR1) public void testCryptographicHelperDeleteKeyInvokesLegacyGetKeyMethod() { cryptographicHelper.deleteKey(SAMPLE_KEY_ALIAS); Mockito.verify(androidLegacyCryptography).deleteKey(SAMPLE_KEY_ALIAS); }
public void deleteKey(String keyAlias) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) { legacyCryptography.deleteKey(keyAlias); } else { mCryptography.deleteKey(keyAlias); } }
CryptographicHelper { public void deleteKey(String keyAlias) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) { legacyCryptography.deleteKey(keyAlias); } else { mCryptography.deleteKey(keyAlias); } } }
CryptographicHelper { public void deleteKey(String keyAlias) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) { legacyCryptography.deleteKey(keyAlias); } else { mCryptography.deleteKey(keyAlias); } } }
CryptographicHelper { public void deleteKey(String keyAlias) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) { legacyCryptography.deleteKey(keyAlias); } else { mCryptography.deleteKey(keyAlias); } } static CryptographicHelper getInstance(Context context_); static byte[] encrypt(byte[] data, String keyAlias); static byte[] decrypt(byte[] data, String keyAlias); void generateKey(String keyAlias); Key getKey(String keyAlias); void deleteKey(String keyAlias); void setLegacyCryptography(AndroidLegacyCryptography legacyCryptography); void setMCryptography(AndroidMCryptography androidMCryptography); }
CryptographicHelper { public void deleteKey(String keyAlias) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) { legacyCryptography.deleteKey(keyAlias); } else { mCryptography.deleteKey(keyAlias); } } static CryptographicHelper getInstance(Context context_); static byte[] encrypt(byte[] data, String keyAlias); static byte[] decrypt(byte[] data, String keyAlias); void generateKey(String keyAlias); Key getKey(String keyAlias); void deleteKey(String keyAlias); void setLegacyCryptography(AndroidLegacyCryptography legacyCryptography); void setMCryptography(AndroidMCryptography androidMCryptography); }
@Test public void testAndroidMCryptographyClassInitsCorrectly() { Assert.assertNotNull(androidMCryptography); Assert.assertNotNull(androidMCryptography.secureRandom); Assert.assertNotNull(androidMCryptography.getAESMode()); Assert.assertEquals(AndroidMCryptography.AES_MODE, androidMCryptography.getAESMode()); }
@Override public String getAESMode() { return AES_MODE; }
AndroidMCryptography extends BaseCryptography implements ICryptography { @Override public String getAESMode() { return AES_MODE; } }
AndroidMCryptography extends BaseCryptography implements ICryptography { @Override public String getAESMode() { return AES_MODE; } AndroidMCryptography(Context context); }
AndroidMCryptography extends BaseCryptography implements ICryptography { @Override public String getAESMode() { return AES_MODE; } AndroidMCryptography(Context context); @RequiresApi(api = Build.VERSION_CODES.KITKAT) @Override byte[] encrypt(byte[] input, String keyAlias); @Override String getAESMode(); void generateInitializationVector(); @RequiresApi(api = Build.VERSION_CODES.KITKAT) @Override byte[] decrypt(byte[] encrypted, String keyAlias); @Override Key getKey(String keyAlias); @TargetApi(Build.VERSION_CODES.M) @Override void generateKey(String keyAlias); }
AndroidMCryptography extends BaseCryptography implements ICryptography { @Override public String getAESMode() { return AES_MODE; } AndroidMCryptography(Context context); @RequiresApi(api = Build.VERSION_CODES.KITKAT) @Override byte[] encrypt(byte[] input, String keyAlias); @Override String getAESMode(); void generateInitializationVector(); @RequiresApi(api = Build.VERSION_CODES.KITKAT) @Override byte[] decrypt(byte[] encrypted, String keyAlias); @Override Key getKey(String keyAlias); @TargetApi(Build.VERSION_CODES.M) @Override void generateKey(String keyAlias); static final String AES_MODE; }
@Test public void testAndroidLegacyCryptographyClassInitsCorrectly() { Assert.assertNotNull(androidLegacyCryptography); Assert.assertNotNull(androidLegacyCryptography.secureRandom); Assert.assertNotNull(androidLegacyCryptography.getAESMode()); Assert.assertEquals(AndroidLegacyCryptography.AES_MODE, androidLegacyCryptography.getAESMode()); }
@Override public String getAESMode() { return AES_MODE; }
AndroidLegacyCryptography extends BaseCryptography implements ICryptography { @Override public String getAESMode() { return AES_MODE; } }
AndroidLegacyCryptography extends BaseCryptography implements ICryptography { @Override public String getAESMode() { return AES_MODE; } AndroidLegacyCryptography(Context context); }
AndroidLegacyCryptography extends BaseCryptography implements ICryptography { @Override public String getAESMode() { return AES_MODE; } AndroidLegacyCryptography(Context context); @Override String getAESMode(); @Override byte[] encrypt(byte[] input, String keyAlias); @Override byte[] decrypt(byte[] encrypted, String keyAlias); @Override Key getKey(String keyAlias); @Override void generateKey(String keyAlias); String generateAESKey(String encryptedAESKeyKey, String rsaPrivateKeyAlias); void generateRSAKeys(String rsaKeyAlias); }
AndroidLegacyCryptography extends BaseCryptography implements ICryptography { @Override public String getAESMode() { return AES_MODE; } AndroidLegacyCryptography(Context context); @Override String getAESMode(); @Override byte[] encrypt(byte[] input, String keyAlias); @Override byte[] decrypt(byte[] encrypted, String keyAlias); @Override Key getKey(String keyAlias); @Override void generateKey(String keyAlias); String generateAESKey(String encryptedAESKeyKey, String rsaPrivateKeyAlias); void generateRSAKeys(String rsaKeyAlias); static final String AES_MODE; }
@Test public void testGetInflatesLayoutCorrectly() { Mockito.doReturn(viewGroup).when(viewStub).inflate(); ViewStubInflater viewStubInflater = new ViewStubInflater(viewStub); Assert.assertNotNull(viewStubInflater); Assert.assertEquals(viewGroup, viewStubInflater.get()); }
public ViewGroup get() { if (!isInflated()) { this.inflatedLayout = (ViewGroup) stub.inflate(); } return this.inflatedLayout; }
ViewStubInflater { public ViewGroup get() { if (!isInflated()) { this.inflatedLayout = (ViewGroup) stub.inflate(); } return this.inflatedLayout; } }
ViewStubInflater { public ViewGroup get() { if (!isInflated()) { this.inflatedLayout = (ViewGroup) stub.inflate(); } return this.inflatedLayout; } ViewStubInflater(ViewStub stub); }
ViewStubInflater { public ViewGroup get() { if (!isInflated()) { this.inflatedLayout = (ViewGroup) stub.inflate(); } return this.inflatedLayout; } ViewStubInflater(ViewStub stub); ViewGroup get(); void setVisibility(int visibility); }
ViewStubInflater { public ViewGroup get() { if (!isInflated()) { this.inflatedLayout = (ViewGroup) stub.inflate(); } return this.inflatedLayout; } ViewStubInflater(ViewStub stub); ViewGroup get(); void setVisibility(int visibility); }
@Test public void testSetVisiblityInvokesInflatedLayoutWithCorrectParams() { Mockito.doReturn(viewGroup).when(viewStub).inflate(); ViewStubInflater viewStubInflater = Mockito.spy(new ViewStubInflater(viewStub)); viewStubInflater.setVisibility(View.GONE); Mockito.verify(viewStubInflater).setVisibility(View.GONE); viewStubInflater.setVisibility(View.VISIBLE); Mockito.verify(viewStubInflater).setVisibility(View.VISIBLE); viewStubInflater.setVisibility(View.INVISIBLE); Mockito.verify(viewStubInflater).setVisibility(View.INVISIBLE); }
public void setVisibility(int visibility) { if (isInflated()) { inflatedLayout.setVisibility(visibility); } }
ViewStubInflater { public void setVisibility(int visibility) { if (isInflated()) { inflatedLayout.setVisibility(visibility); } } }
ViewStubInflater { public void setVisibility(int visibility) { if (isInflated()) { inflatedLayout.setVisibility(visibility); } } ViewStubInflater(ViewStub stub); }
ViewStubInflater { public void setVisibility(int visibility) { if (isInflated()) { inflatedLayout.setVisibility(visibility); } } ViewStubInflater(ViewStub stub); ViewGroup get(); void setVisibility(int visibility); }
ViewStubInflater { public void setVisibility(int visibility) { if (isInflated()) { inflatedLayout.setVisibility(visibility); } } ViewStubInflater(ViewStub stub); ViewGroup get(); void setVisibility(int visibility); }
@Test public void testGetReturnsCorrectDrawableForFemaleGender() { Drawable maleInfant = RuntimeEnvironment.application.getDrawable(R.drawable.child_boy_infant); Drawable femaleInfant = RuntimeEnvironment.application.getDrawable(R.drawable.child_girl_infant); ChildRegisterProfilePhotoLoader childRegisterProfilePhotoLoader = new ChildRegisterProfilePhotoLoader(maleInfant, femaleInfant); Assert.assertNotNull(childRegisterProfilePhotoLoader); Mockito.doReturn("female").when(smartRegisterClient).gender(); Assert.assertEquals(femaleInfant, childRegisterProfilePhotoLoader.get(smartRegisterClient)); }
public Drawable get(SmartRegisterClient client) { return FEMALE_GENDER.equalsIgnoreCase(((ChildSmartRegisterClient) client).gender()) ? femaleInfantDrawable : maleInfantDrawable; }
ChildRegisterProfilePhotoLoader implements ProfilePhotoLoader { public Drawable get(SmartRegisterClient client) { return FEMALE_GENDER.equalsIgnoreCase(((ChildSmartRegisterClient) client).gender()) ? femaleInfantDrawable : maleInfantDrawable; } }
ChildRegisterProfilePhotoLoader implements ProfilePhotoLoader { public Drawable get(SmartRegisterClient client) { return FEMALE_GENDER.equalsIgnoreCase(((ChildSmartRegisterClient) client).gender()) ? femaleInfantDrawable : maleInfantDrawable; } ChildRegisterProfilePhotoLoader(Drawable maleInfantDrawable, Drawable femaleInfantDrawable); }
ChildRegisterProfilePhotoLoader implements ProfilePhotoLoader { public Drawable get(SmartRegisterClient client) { return FEMALE_GENDER.equalsIgnoreCase(((ChildSmartRegisterClient) client).gender()) ? femaleInfantDrawable : maleInfantDrawable; } ChildRegisterProfilePhotoLoader(Drawable maleInfantDrawable, Drawable femaleInfantDrawable); Drawable get(SmartRegisterClient client); }
ChildRegisterProfilePhotoLoader implements ProfilePhotoLoader { public Drawable get(SmartRegisterClient client) { return FEMALE_GENDER.equalsIgnoreCase(((ChildSmartRegisterClient) client).gender()) ? femaleInfantDrawable : maleInfantDrawable; } ChildRegisterProfilePhotoLoader(Drawable maleInfantDrawable, Drawable femaleInfantDrawable); Drawable get(SmartRegisterClient client); }
@Test public void testSectionFieldsShouldGetCorrectSectionMap() throws JSONException { Map<String, String> sectionsMap = JsonFormUtils.sectionFields(new JSONObject(SINGLE_STEP_WITH_SECTIONS)); assertEquals("gps", sectionsMap.get("gps")); assertNotNull("scan_respiratory_specimen_barcode", sectionsMap.get("lbl_scan_respiratory_specimen_barcode")); assertNotNull("affix_respiratory_specimen_label", sectionsMap.get("lbl_affix_respiratory_specimen_label")); }
public static Map<String, String> sectionFields(JSONObject jsonForm) { try { JSONObject step1 = jsonForm.has(STEP1) ? jsonForm.getJSONObject(STEP1) : null; if (step1 == null) { return null; } JSONArray sections = step1.has(SECTIONS) ? step1.getJSONArray(SECTIONS) : null; if (sections == null) { return null; } Map<String, String> result = new HashMap<>(); for (int i = 0; i < sections.length(); i++) { JSONObject sectionsJSONObject = sections.getJSONObject(i); if (sectionsJSONObject.has(FIELDS)) { JSONArray fieldsArray = sectionsJSONObject.getJSONArray(FIELDS); for (int j = 0; j < fieldsArray.length(); j++) { JSONObject fieldJsonObject = fieldsArray.getJSONObject(j); String key = fieldJsonObject.getString(KEY); String value = fieldJsonObject.getString(VALUE); result.put(key, value); } } } return result; } catch (JSONException e) { Timber.e(e); return null; } }
JsonFormUtils { public static Map<String, String> sectionFields(JSONObject jsonForm) { try { JSONObject step1 = jsonForm.has(STEP1) ? jsonForm.getJSONObject(STEP1) : null; if (step1 == null) { return null; } JSONArray sections = step1.has(SECTIONS) ? step1.getJSONArray(SECTIONS) : null; if (sections == null) { return null; } Map<String, String> result = new HashMap<>(); for (int i = 0; i < sections.length(); i++) { JSONObject sectionsJSONObject = sections.getJSONObject(i); if (sectionsJSONObject.has(FIELDS)) { JSONArray fieldsArray = sectionsJSONObject.getJSONArray(FIELDS); for (int j = 0; j < fieldsArray.length(); j++) { JSONObject fieldJsonObject = fieldsArray.getJSONObject(j); String key = fieldJsonObject.getString(KEY); String value = fieldJsonObject.getString(VALUE); result.put(key, value); } } } return result; } catch (JSONException e) { Timber.e(e); return null; } } }
JsonFormUtils { public static Map<String, String> sectionFields(JSONObject jsonForm) { try { JSONObject step1 = jsonForm.has(STEP1) ? jsonForm.getJSONObject(STEP1) : null; if (step1 == null) { return null; } JSONArray sections = step1.has(SECTIONS) ? step1.getJSONArray(SECTIONS) : null; if (sections == null) { return null; } Map<String, String> result = new HashMap<>(); for (int i = 0; i < sections.length(); i++) { JSONObject sectionsJSONObject = sections.getJSONObject(i); if (sectionsJSONObject.has(FIELDS)) { JSONArray fieldsArray = sectionsJSONObject.getJSONArray(FIELDS); for (int j = 0; j < fieldsArray.length(); j++) { JSONObject fieldJsonObject = fieldsArray.getJSONObject(j); String key = fieldJsonObject.getString(KEY); String value = fieldJsonObject.getString(VALUE); result.put(key, value); } } } return result; } catch (JSONException e) { Timber.e(e); return null; } } }
JsonFormUtils { public static Map<String, String> sectionFields(JSONObject jsonForm) { try { JSONObject step1 = jsonForm.has(STEP1) ? jsonForm.getJSONObject(STEP1) : null; if (step1 == null) { return null; } JSONArray sections = step1.has(SECTIONS) ? step1.getJSONArray(SECTIONS) : null; if (sections == null) { return null; } Map<String, String> result = new HashMap<>(); for (int i = 0; i < sections.length(); i++) { JSONObject sectionsJSONObject = sections.getJSONObject(i); if (sectionsJSONObject.has(FIELDS)) { JSONArray fieldsArray = sectionsJSONObject.getJSONArray(FIELDS); for (int j = 0; j < fieldsArray.length(); j++) { JSONObject fieldJsonObject = fieldsArray.getJSONObject(j); String key = fieldJsonObject.getString(KEY); String value = fieldJsonObject.getString(VALUE); result.put(key, value); } } } return result; } catch (JSONException e) { Timber.e(e); return null; } } static Client createBaseClient(JSONArray fields, FormTag formTag, String entityId); static Event createEvent(JSONArray fields, JSONObject metadata, FormTag formTag, String entityId, String encounterType, String bindType); static void addObservation(Event e, JSONObject jsonObject); static Map<String, String> extractIdentifiers(JSONArray fields); static Map<String, Object> extractAttributes(JSONArray fields); static Map<String, Address> extractAddresses(JSONArray fields); static void fillIdentifiers(Map<String, String> pids, JSONObject jsonObject); static void fillAttributes(Map<String, Object> pattributes, JSONObject jsonObject); static void fillAddressFields(JSONObject jsonObject, Map<String, Address> addresses); static Map<String, String> extractIdentifiers(JSONArray fields, String bindType); static Map<String, Object> extractAttributes(JSONArray fields, String bindType); static Map<String, Address> extractAddresses(JSONArray fields, String bindType); static String getSubFormFieldValue(JSONArray jsonArray, FormEntityConstants.Person person, String bindType); static void fillSubFormIdentifiers(Map<String, String> pids, JSONObject jsonObject, String bindType); static void fillSubFormAttributes(Map<String, Object> pattributes, JSONObject jsonObject, String bindType); static void fillSubFormAddressFields(JSONObject jsonObject, Map<String, Address> addresses, String bindType); static JSONArray getSingleStepFormfields(JSONObject jsonForm); static JSONArray fields(JSONObject jsonForm); static JSONArray getMultiStepFormFields(JSONObject jsonForm); static Map<String, String> sectionFields(JSONObject jsonForm); static JSONObject toJSONObject(String jsonString); static String getFieldValue(JSONArray jsonArray, FormEntityConstants.Person person); static String getFieldValue(JSONArray jsonArray, FormEntityConstants.Encounter encounter); static String getFieldValue(String jsonString, String key); @Nullable static JSONObject getFieldJSONObject(JSONArray jsonArray, String key); @Nullable static String value(JSONArray jsonArray, String entity, String entityId); @Nullable static String getFieldValue(JSONArray jsonArray, String key); @Nullable static JSONObject getJSONObject(JSONArray jsonArray, int index); @Nullable static JSONArray getJSONArray(JSONObject jsonObject, String field); static JSONObject getJSONObject(JSONObject jsonObject, String field); static String getString(JSONObject jsonObject, String field); static String getString(String jsonString, String field); static Long getLong(JSONObject jsonObject, String field); static Date formatDate(String dateString, boolean startOfToday); static String generateRandomUUIDString(); static void addToJSONObject(JSONObject jsonObject, String key, String value); static String formatDate(String date); static JSONObject merge(JSONObject original, JSONObject updated); static String[] getNames(JSONObject jo); static String convertToOpenMRSDate(String value); static boolean isBlankJsonArray(JSONArray jsonArray); static boolean isBlankJsonObject(JSONObject jsonObject); }
JsonFormUtils { public static Map<String, String> sectionFields(JSONObject jsonForm) { try { JSONObject step1 = jsonForm.has(STEP1) ? jsonForm.getJSONObject(STEP1) : null; if (step1 == null) { return null; } JSONArray sections = step1.has(SECTIONS) ? step1.getJSONArray(SECTIONS) : null; if (sections == null) { return null; } Map<String, String> result = new HashMap<>(); for (int i = 0; i < sections.length(); i++) { JSONObject sectionsJSONObject = sections.getJSONObject(i); if (sectionsJSONObject.has(FIELDS)) { JSONArray fieldsArray = sectionsJSONObject.getJSONArray(FIELDS); for (int j = 0; j < fieldsArray.length(); j++) { JSONObject fieldJsonObject = fieldsArray.getJSONObject(j); String key = fieldJsonObject.getString(KEY); String value = fieldJsonObject.getString(VALUE); result.put(key, value); } } } return result; } catch (JSONException e) { Timber.e(e); return null; } } static Client createBaseClient(JSONArray fields, FormTag formTag, String entityId); static Event createEvent(JSONArray fields, JSONObject metadata, FormTag formTag, String entityId, String encounterType, String bindType); static void addObservation(Event e, JSONObject jsonObject); static Map<String, String> extractIdentifiers(JSONArray fields); static Map<String, Object> extractAttributes(JSONArray fields); static Map<String, Address> extractAddresses(JSONArray fields); static void fillIdentifiers(Map<String, String> pids, JSONObject jsonObject); static void fillAttributes(Map<String, Object> pattributes, JSONObject jsonObject); static void fillAddressFields(JSONObject jsonObject, Map<String, Address> addresses); static Map<String, String> extractIdentifiers(JSONArray fields, String bindType); static Map<String, Object> extractAttributes(JSONArray fields, String bindType); static Map<String, Address> extractAddresses(JSONArray fields, String bindType); static String getSubFormFieldValue(JSONArray jsonArray, FormEntityConstants.Person person, String bindType); static void fillSubFormIdentifiers(Map<String, String> pids, JSONObject jsonObject, String bindType); static void fillSubFormAttributes(Map<String, Object> pattributes, JSONObject jsonObject, String bindType); static void fillSubFormAddressFields(JSONObject jsonObject, Map<String, Address> addresses, String bindType); static JSONArray getSingleStepFormfields(JSONObject jsonForm); static JSONArray fields(JSONObject jsonForm); static JSONArray getMultiStepFormFields(JSONObject jsonForm); static Map<String, String> sectionFields(JSONObject jsonForm); static JSONObject toJSONObject(String jsonString); static String getFieldValue(JSONArray jsonArray, FormEntityConstants.Person person); static String getFieldValue(JSONArray jsonArray, FormEntityConstants.Encounter encounter); static String getFieldValue(String jsonString, String key); @Nullable static JSONObject getFieldJSONObject(JSONArray jsonArray, String key); @Nullable static String value(JSONArray jsonArray, String entity, String entityId); @Nullable static String getFieldValue(JSONArray jsonArray, String key); @Nullable static JSONObject getJSONObject(JSONArray jsonArray, int index); @Nullable static JSONArray getJSONArray(JSONObject jsonObject, String field); static JSONObject getJSONObject(JSONObject jsonObject, String field); static String getString(JSONObject jsonObject, String field); static String getString(String jsonString, String field); static Long getLong(JSONObject jsonObject, String field); static Date formatDate(String dateString, boolean startOfToday); static String generateRandomUUIDString(); static void addToJSONObject(JSONObject jsonObject, String key, String value); static String formatDate(String date); static JSONObject merge(JSONObject original, JSONObject updated); static String[] getNames(JSONObject jo); static String convertToOpenMRSDate(String value); static boolean isBlankJsonArray(JSONArray jsonArray); static boolean isBlankJsonObject(JSONObject jsonObject); static final String TAG; static final String OPENMRS_ENTITY; static final String OPENMRS_ENTITY_ID; static final String OPENMRS_ENTITY_PARENT; static final String OPENMRS_CHOICE_IDS; static final String OPENMRS_DATA_TYPE; static final String PERSON_ATTRIBUTE; static final String PERSON_INDENTIFIER; static final String PERSON_ADDRESS; static final String SIMPRINTS_GUID; static final String FINGERPRINT_KEY; static final String FINGERPRINT_OPTION; static final String FINGERPRINT_OPTION_REGISTER; static final String CONCEPT; static final String VALUE; static final String VALUES; static final String FIELDS; static final String KEY; static final String ENTITY_ID; static final String STEP1; static final String SECTIONS; static final String attributes; static final String ENCOUNTER; static final String ENCOUNTER_LOCATION; static final String SAVE_OBS_AS_ARRAY; static final String SAVE_ALL_CHECKBOX_OBS_AS_ARRAY; static final SimpleDateFormat dd_MM_yyyy; static Gson gson; }
@Test public void testGetReturnsCorrectDrawableForMaleGender() { Drawable maleInfant = RuntimeEnvironment.application.getDrawable(R.drawable.child_boy_infant); Drawable femaleInfant = RuntimeEnvironment.application.getDrawable(R.drawable.child_girl_infant); ChildRegisterProfilePhotoLoader childRegisterProfilePhotoLoader = new ChildRegisterProfilePhotoLoader(maleInfant, femaleInfant); Assert.assertNotNull(childRegisterProfilePhotoLoader); Mockito.doReturn("male").when(smartRegisterClient).gender(); Assert.assertEquals(maleInfant, childRegisterProfilePhotoLoader.get(smartRegisterClient)); }
public Drawable get(SmartRegisterClient client) { return FEMALE_GENDER.equalsIgnoreCase(((ChildSmartRegisterClient) client).gender()) ? femaleInfantDrawable : maleInfantDrawable; }
ChildRegisterProfilePhotoLoader implements ProfilePhotoLoader { public Drawable get(SmartRegisterClient client) { return FEMALE_GENDER.equalsIgnoreCase(((ChildSmartRegisterClient) client).gender()) ? femaleInfantDrawable : maleInfantDrawable; } }
ChildRegisterProfilePhotoLoader implements ProfilePhotoLoader { public Drawable get(SmartRegisterClient client) { return FEMALE_GENDER.equalsIgnoreCase(((ChildSmartRegisterClient) client).gender()) ? femaleInfantDrawable : maleInfantDrawable; } ChildRegisterProfilePhotoLoader(Drawable maleInfantDrawable, Drawable femaleInfantDrawable); }
ChildRegisterProfilePhotoLoader implements ProfilePhotoLoader { public Drawable get(SmartRegisterClient client) { return FEMALE_GENDER.equalsIgnoreCase(((ChildSmartRegisterClient) client).gender()) ? femaleInfantDrawable : maleInfantDrawable; } ChildRegisterProfilePhotoLoader(Drawable maleInfantDrawable, Drawable femaleInfantDrawable); Drawable get(SmartRegisterClient client); }
ChildRegisterProfilePhotoLoader implements ProfilePhotoLoader { public Drawable get(SmartRegisterClient client) { return FEMALE_GENDER.equalsIgnoreCase(((ChildSmartRegisterClient) client).gender()) ? femaleInfantDrawable : maleInfantDrawable; } ChildRegisterProfilePhotoLoader(Drawable maleInfantDrawable, Drawable femaleInfantDrawable); Drawable get(SmartRegisterClient client); }
@Test public void testOnClickInvokesStartFormActivityWithCorrectParams() { String testMetadata = "{\"fieldOverrides\": \"metadata-override-values\"}"; Mockito.doNothing().when(activity).startFormActivity(TEST_FORM_NAME, TEST_BASE_ENTITY_ID, testMetadata); OnClickFormLauncher onClickFormLauncher = new OnClickFormLauncher(activity, TEST_FORM_NAME, TEST_BASE_ENTITY_ID, testMetadata); Assert.assertNotNull(onClickFormLauncher); onClickFormLauncher.onClick(view); Mockito.verify(activity).startFormActivity(TEST_FORM_NAME, TEST_BASE_ENTITY_ID, testMetadata); }
@Override public void onClick(View view) { activity.startFormActivity(formName, entityId, metaData); }
OnClickFormLauncher implements View.OnClickListener { @Override public void onClick(View view) { activity.startFormActivity(formName, entityId, metaData); } }
OnClickFormLauncher implements View.OnClickListener { @Override public void onClick(View view) { activity.startFormActivity(formName, entityId, metaData); } OnClickFormLauncher(SecuredActivity activity, String formName, String entityId); OnClickFormLauncher(SecuredActivity activity, String formName, String entityId, String metaData); }
OnClickFormLauncher implements View.OnClickListener { @Override public void onClick(View view) { activity.startFormActivity(formName, entityId, metaData); } OnClickFormLauncher(SecuredActivity activity, String formName, String entityId); OnClickFormLauncher(SecuredActivity activity, String formName, String entityId, String metaData); @Override void onClick(View view); }
OnClickFormLauncher implements View.OnClickListener { @Override public void onClick(View view) { activity.startFormActivity(formName, entityId, metaData); } OnClickFormLauncher(SecuredActivity activity, String formName, String entityId); OnClickFormLauncher(SecuredActivity activity, String formName, String entityId, String metaData); @Override void onClick(View view); }
@Test public void testOnClickInvokesStartFormActivityWithCorrectParamsNoMetadata() { Mockito.doNothing().when(activity).startFormActivity(TEST_FORM_NAME, TEST_BASE_ENTITY_ID, ""); OnClickFormLauncher onClickFormLauncher = new OnClickFormLauncher(activity, TEST_FORM_NAME, TEST_BASE_ENTITY_ID); Assert.assertNotNull(onClickFormLauncher); onClickFormLauncher.onClick(view); Mockito.verify(activity).startFormActivity(TEST_FORM_NAME, TEST_BASE_ENTITY_ID, (String) null); }
@Override public void onClick(View view) { activity.startFormActivity(formName, entityId, metaData); }
OnClickFormLauncher implements View.OnClickListener { @Override public void onClick(View view) { activity.startFormActivity(formName, entityId, metaData); } }
OnClickFormLauncher implements View.OnClickListener { @Override public void onClick(View view) { activity.startFormActivity(formName, entityId, metaData); } OnClickFormLauncher(SecuredActivity activity, String formName, String entityId); OnClickFormLauncher(SecuredActivity activity, String formName, String entityId, String metaData); }
OnClickFormLauncher implements View.OnClickListener { @Override public void onClick(View view) { activity.startFormActivity(formName, entityId, metaData); } OnClickFormLauncher(SecuredActivity activity, String formName, String entityId); OnClickFormLauncher(SecuredActivity activity, String formName, String entityId, String metaData); @Override void onClick(View view); }
OnClickFormLauncher implements View.OnClickListener { @Override public void onClick(View view) { activity.startFormActivity(formName, entityId, metaData); } OnClickFormLauncher(SecuredActivity activity, String formName, String entityId); OnClickFormLauncher(SecuredActivity activity, String formName, String entityId, String metaData); @Override void onClick(View view); }
@Test public void testOnClickInvokesStartFormActivityWithCorrectMapMetadataParams() { Map<String, String> testMetadata = new HashMap<>(); testMetadata.put("first_name", "john"); testMetadata.put("last_name", "doe"); Mockito.doNothing().when(activity).startFormActivity(TEST_FORM_NAME, TEST_BASE_ENTITY_ID, testMetadata); OnClickFormLauncher onClickFormLauncher = new OnClickFormLauncher(activity, TEST_FORM_NAME, TEST_BASE_ENTITY_ID, testMetadata.toString()); Assert.assertNotNull(onClickFormLauncher); onClickFormLauncher.onClick(view); Mockito.verify(activity, Mockito.times(1)).startFormActivity(TEST_FORM_NAME, TEST_BASE_ENTITY_ID, testMetadata.toString()); }
@Override public void onClick(View view) { activity.startFormActivity(formName, entityId, metaData); }
OnClickFormLauncher implements View.OnClickListener { @Override public void onClick(View view) { activity.startFormActivity(formName, entityId, metaData); } }
OnClickFormLauncher implements View.OnClickListener { @Override public void onClick(View view) { activity.startFormActivity(formName, entityId, metaData); } OnClickFormLauncher(SecuredActivity activity, String formName, String entityId); OnClickFormLauncher(SecuredActivity activity, String formName, String entityId, String metaData); }
OnClickFormLauncher implements View.OnClickListener { @Override public void onClick(View view) { activity.startFormActivity(formName, entityId, metaData); } OnClickFormLauncher(SecuredActivity activity, String formName, String entityId); OnClickFormLauncher(SecuredActivity activity, String formName, String entityId, String metaData); @Override void onClick(View view); }
OnClickFormLauncher implements View.OnClickListener { @Override public void onClick(View view) { activity.startFormActivity(formName, entityId, metaData); } OnClickFormLauncher(SecuredActivity activity, String formName, String entityId); OnClickFormLauncher(SecuredActivity activity, String formName, String entityId, String metaData); @Override void onClick(View view); }
@Test public void testOnClickInvokesStartFormActivityWithEmptyMapMetadataParams() { Map<String, String> testMetadata = new HashMap<>(); Mockito.doNothing().when(activity).startFormActivity(TEST_FORM_NAME, TEST_BASE_ENTITY_ID, testMetadata); OnClickFormLauncher onClickFormLauncher = new OnClickFormLauncher(activity, TEST_FORM_NAME, TEST_BASE_ENTITY_ID, testMetadata.toString()); Assert.assertNotNull(onClickFormLauncher); onClickFormLauncher.onClick(view); Mockito.verify(activity, Mockito.times(1)).startFormActivity(TEST_FORM_NAME, TEST_BASE_ENTITY_ID, testMetadata.toString()); }
@Override public void onClick(View view) { activity.startFormActivity(formName, entityId, metaData); }
OnClickFormLauncher implements View.OnClickListener { @Override public void onClick(View view) { activity.startFormActivity(formName, entityId, metaData); } }
OnClickFormLauncher implements View.OnClickListener { @Override public void onClick(View view) { activity.startFormActivity(formName, entityId, metaData); } OnClickFormLauncher(SecuredActivity activity, String formName, String entityId); OnClickFormLauncher(SecuredActivity activity, String formName, String entityId, String metaData); }
OnClickFormLauncher implements View.OnClickListener { @Override public void onClick(View view) { activity.startFormActivity(formName, entityId, metaData); } OnClickFormLauncher(SecuredActivity activity, String formName, String entityId); OnClickFormLauncher(SecuredActivity activity, String formName, String entityId, String metaData); @Override void onClick(View view); }
OnClickFormLauncher implements View.OnClickListener { @Override public void onClick(View view) { activity.startFormActivity(formName, entityId, metaData); } OnClickFormLauncher(SecuredActivity activity, String formName, String entityId); OnClickFormLauncher(SecuredActivity activity, String formName, String entityId, String metaData); @Override void onClick(View view); }
@Test public void testOnCreateInitializesFragmentFields() { securedFragment.onCreate(bundle); Listener<Boolean> logoutListener = ReflectionHelpers.getField(securedFragment, "logoutListener"); FormController formController = ReflectionHelpers.getField(securedFragment, "formController"); ANMController anmController = ReflectionHelpers.getField(securedFragment, "anmController"); NavigationController navigationController = ReflectionHelpers.getField(securedFragment, "navigationController"); Assert.assertNotNull(logoutListener); Assert.assertNotNull(formController); Assert.assertNotNull(anmController); Assert.assertNotNull(navigationController); }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); logoutListener = data -> { if (getActivity() != null && !getActivity().isFinishing()) { getActivity().finish(); } }; Event.ON_LOGOUT.addListener(logoutListener); if (context().IsUserLoggedOut()) { DrishtiApplication application = (DrishtiApplication) this.getActivity() .getApplication(); application.logoutCurrentUser(); return; } if (getActivity() instanceof SecuredActivity) { formController = new FormController((SecuredActivity) getActivity()); } anmController = context().anmController(); navigationController = new NavigationController(getActivity(), anmController); onCreation(); }
SecuredFragment extends Fragment { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); logoutListener = data -> { if (getActivity() != null && !getActivity().isFinishing()) { getActivity().finish(); } }; Event.ON_LOGOUT.addListener(logoutListener); if (context().IsUserLoggedOut()) { DrishtiApplication application = (DrishtiApplication) this.getActivity() .getApplication(); application.logoutCurrentUser(); return; } if (getActivity() instanceof SecuredActivity) { formController = new FormController((SecuredActivity) getActivity()); } anmController = context().anmController(); navigationController = new NavigationController(getActivity(), anmController); onCreation(); } }
SecuredFragment extends Fragment { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); logoutListener = data -> { if (getActivity() != null && !getActivity().isFinishing()) { getActivity().finish(); } }; Event.ON_LOGOUT.addListener(logoutListener); if (context().IsUserLoggedOut()) { DrishtiApplication application = (DrishtiApplication) this.getActivity() .getApplication(); application.logoutCurrentUser(); return; } if (getActivity() instanceof SecuredActivity) { formController = new FormController((SecuredActivity) getActivity()); } anmController = context().anmController(); navigationController = new NavigationController(getActivity(), anmController); onCreation(); } }
SecuredFragment extends Fragment { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); logoutListener = data -> { if (getActivity() != null && !getActivity().isFinishing()) { getActivity().finish(); } }; Event.ON_LOGOUT.addListener(logoutListener); if (context().IsUserLoggedOut()) { DrishtiApplication application = (DrishtiApplication) this.getActivity() .getApplication(); application.logoutCurrentUser(); return; } if (getActivity() instanceof SecuredActivity) { formController = new FormController((SecuredActivity) getActivity()); } anmController = context().anmController(); navigationController = new NavigationController(getActivity(), anmController); onCreation(); } @Override void onCreate(Bundle savedInstanceState); @Override void onResume(); @Override void onPause(); @Override boolean onOptionsItemSelected(MenuItem item); void logoutUser(); void startFormActivity(String formName, String entityId, String metaData); void startMicroFormActivity(String formName, String entityId, String metaData); boolean isPaused(); }
SecuredFragment extends Fragment { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); logoutListener = data -> { if (getActivity() != null && !getActivity().isFinishing()) { getActivity().finish(); } }; Event.ON_LOGOUT.addListener(logoutListener); if (context().IsUserLoggedOut()) { DrishtiApplication application = (DrishtiApplication) this.getActivity() .getApplication(); application.logoutCurrentUser(); return; } if (getActivity() instanceof SecuredActivity) { formController = new FormController((SecuredActivity) getActivity()); } anmController = context().anmController(); navigationController = new NavigationController(getActivity(), anmController); onCreation(); } @Override void onCreate(Bundle savedInstanceState); @Override void onResume(); @Override void onPause(); @Override boolean onOptionsItemSelected(MenuItem item); void logoutUser(); void startFormActivity(String formName, String entityId, String metaData); void startMicroFormActivity(String formName, String entityId, String metaData); boolean isPaused(); }
@Test public void assertOnResumeLogsOutCurrentUserIfContextIsUserLoggedOutIsTrue() { Mockito.doReturn(true).when(context).IsUserLoggedOut(); securedFragment.onResume(); Mockito.verify(application).logoutCurrentUser(); }
@Override public void onResume() { super.onResume(); if (context().IsUserLoggedOut()) { DrishtiApplication application = (DrishtiApplication) this.getActivity() .getApplication(); application.logoutCurrentUser(); return; } onResumption(); isPaused = false; }
SecuredFragment extends Fragment { @Override public void onResume() { super.onResume(); if (context().IsUserLoggedOut()) { DrishtiApplication application = (DrishtiApplication) this.getActivity() .getApplication(); application.logoutCurrentUser(); return; } onResumption(); isPaused = false; } }
SecuredFragment extends Fragment { @Override public void onResume() { super.onResume(); if (context().IsUserLoggedOut()) { DrishtiApplication application = (DrishtiApplication) this.getActivity() .getApplication(); application.logoutCurrentUser(); return; } onResumption(); isPaused = false; } }
SecuredFragment extends Fragment { @Override public void onResume() { super.onResume(); if (context().IsUserLoggedOut()) { DrishtiApplication application = (DrishtiApplication) this.getActivity() .getApplication(); application.logoutCurrentUser(); return; } onResumption(); isPaused = false; } @Override void onCreate(Bundle savedInstanceState); @Override void onResume(); @Override void onPause(); @Override boolean onOptionsItemSelected(MenuItem item); void logoutUser(); void startFormActivity(String formName, String entityId, String metaData); void startMicroFormActivity(String formName, String entityId, String metaData); boolean isPaused(); }
SecuredFragment extends Fragment { @Override public void onResume() { super.onResume(); if (context().IsUserLoggedOut()) { DrishtiApplication application = (DrishtiApplication) this.getActivity() .getApplication(); application.logoutCurrentUser(); return; } onResumption(); isPaused = false; } @Override void onCreate(Bundle savedInstanceState); @Override void onResume(); @Override void onPause(); @Override boolean onOptionsItemSelected(MenuItem item); void logoutUser(); void startFormActivity(String formName, String entityId, String metaData); void startMicroFormActivity(String formName, String entityId, String metaData); boolean isPaused(); }
@Test public void assertOnPauseSetsOnPausedFlagToTrue() { ReflectionHelpers.setField(securedFragment, "isPaused", false); boolean onPauseFlag = ReflectionHelpers.getField(securedFragment, "isPaused"); Assert.assertFalse(onPauseFlag); securedFragment.onPause(); onPauseFlag = ReflectionHelpers.getField(securedFragment, "isPaused"); Assert.assertTrue(onPauseFlag); }
@Override public void onPause() { super.onPause(); isPaused = true; }
SecuredFragment extends Fragment { @Override public void onPause() { super.onPause(); isPaused = true; } }
SecuredFragment extends Fragment { @Override public void onPause() { super.onPause(); isPaused = true; } }
SecuredFragment extends Fragment { @Override public void onPause() { super.onPause(); isPaused = true; } @Override void onCreate(Bundle savedInstanceState); @Override void onResume(); @Override void onPause(); @Override boolean onOptionsItemSelected(MenuItem item); void logoutUser(); void startFormActivity(String formName, String entityId, String metaData); void startMicroFormActivity(String formName, String entityId, String metaData); boolean isPaused(); }
SecuredFragment extends Fragment { @Override public void onPause() { super.onPause(); isPaused = true; } @Override void onCreate(Bundle savedInstanceState); @Override void onResume(); @Override void onPause(); @Override boolean onOptionsItemSelected(MenuItem item); void logoutUser(); void startFormActivity(String formName, String entityId, String metaData); void startMicroFormActivity(String formName, String entityId, String metaData); boolean isPaused(); }
@Test public void assertLogoutUserInvokesUserserviceLogoutMethod() { Mockito.doNothing().when(securedFragment).startActivity(ArgumentMatchers.any(Intent.class)); Mockito.doNothing().when(userService).logout(); securedFragment.logoutUser(); Mockito.verify(userService).logout(); }
public void logoutUser() { context().userService().logout(); }
SecuredFragment extends Fragment { public void logoutUser() { context().userService().logout(); } }
SecuredFragment extends Fragment { public void logoutUser() { context().userService().logout(); } }
SecuredFragment extends Fragment { public void logoutUser() { context().userService().logout(); } @Override void onCreate(Bundle savedInstanceState); @Override void onResume(); @Override void onPause(); @Override boolean onOptionsItemSelected(MenuItem item); void logoutUser(); void startFormActivity(String formName, String entityId, String metaData); void startMicroFormActivity(String formName, String entityId, String metaData); boolean isPaused(); }
SecuredFragment extends Fragment { public void logoutUser() { context().userService().logout(); } @Override void onCreate(Bundle savedInstanceState); @Override void onResume(); @Override void onPause(); @Override boolean onOptionsItemSelected(MenuItem item); void logoutUser(); void startFormActivity(String formName, String entityId, String metaData); void startMicroFormActivity(String formName, String entityId, String metaData); boolean isPaused(); }
@Test public void testFillSubFormIdentifiersShouldAddCorrectIdentifiers() throws JSONException { JSONObject jsonObject = new JSONObject(); jsonObject.put(ENTITY_ID, "entity_id"); jsonObject.put(VALUE, "value"); jsonObject.put(OPENMRS_ENTITY, PERSON_INDENTIFIER); jsonObject.put(OPENMRS_ENTITY_ID, "openmrs_entity_id"); Map<String, String> pids = new HashMap<>(); JsonFormUtils.fillSubFormIdentifiers(pids, jsonObject, "entity_id"); assertEquals(1, pids.size()); assertEquals("value", pids.get(OPENMRS_ENTITY_ID)); }
public static void fillSubFormIdentifiers(Map<String, String> pids, JSONObject jsonObject, String bindType) { String value = getString(jsonObject, VALUE); if (StringUtils.isBlank(value)) { return; } String bind = getString(jsonObject, ENTITY_ID); if (bind == null || !bind.equals(bindType)) { return; } String entity = PERSON_INDENTIFIER; String entityVal = getString(jsonObject, OPENMRS_ENTITY); if (entityVal != null && entityVal.equals(entity)) { String entityIdVal = getString(jsonObject, OPENMRS_ENTITY_ID); pids.put(entityIdVal, value); } }
JsonFormUtils { public static void fillSubFormIdentifiers(Map<String, String> pids, JSONObject jsonObject, String bindType) { String value = getString(jsonObject, VALUE); if (StringUtils.isBlank(value)) { return; } String bind = getString(jsonObject, ENTITY_ID); if (bind == null || !bind.equals(bindType)) { return; } String entity = PERSON_INDENTIFIER; String entityVal = getString(jsonObject, OPENMRS_ENTITY); if (entityVal != null && entityVal.equals(entity)) { String entityIdVal = getString(jsonObject, OPENMRS_ENTITY_ID); pids.put(entityIdVal, value); } } }
JsonFormUtils { public static void fillSubFormIdentifiers(Map<String, String> pids, JSONObject jsonObject, String bindType) { String value = getString(jsonObject, VALUE); if (StringUtils.isBlank(value)) { return; } String bind = getString(jsonObject, ENTITY_ID); if (bind == null || !bind.equals(bindType)) { return; } String entity = PERSON_INDENTIFIER; String entityVal = getString(jsonObject, OPENMRS_ENTITY); if (entityVal != null && entityVal.equals(entity)) { String entityIdVal = getString(jsonObject, OPENMRS_ENTITY_ID); pids.put(entityIdVal, value); } } }
JsonFormUtils { public static void fillSubFormIdentifiers(Map<String, String> pids, JSONObject jsonObject, String bindType) { String value = getString(jsonObject, VALUE); if (StringUtils.isBlank(value)) { return; } String bind = getString(jsonObject, ENTITY_ID); if (bind == null || !bind.equals(bindType)) { return; } String entity = PERSON_INDENTIFIER; String entityVal = getString(jsonObject, OPENMRS_ENTITY); if (entityVal != null && entityVal.equals(entity)) { String entityIdVal = getString(jsonObject, OPENMRS_ENTITY_ID); pids.put(entityIdVal, value); } } static Client createBaseClient(JSONArray fields, FormTag formTag, String entityId); static Event createEvent(JSONArray fields, JSONObject metadata, FormTag formTag, String entityId, String encounterType, String bindType); static void addObservation(Event e, JSONObject jsonObject); static Map<String, String> extractIdentifiers(JSONArray fields); static Map<String, Object> extractAttributes(JSONArray fields); static Map<String, Address> extractAddresses(JSONArray fields); static void fillIdentifiers(Map<String, String> pids, JSONObject jsonObject); static void fillAttributes(Map<String, Object> pattributes, JSONObject jsonObject); static void fillAddressFields(JSONObject jsonObject, Map<String, Address> addresses); static Map<String, String> extractIdentifiers(JSONArray fields, String bindType); static Map<String, Object> extractAttributes(JSONArray fields, String bindType); static Map<String, Address> extractAddresses(JSONArray fields, String bindType); static String getSubFormFieldValue(JSONArray jsonArray, FormEntityConstants.Person person, String bindType); static void fillSubFormIdentifiers(Map<String, String> pids, JSONObject jsonObject, String bindType); static void fillSubFormAttributes(Map<String, Object> pattributes, JSONObject jsonObject, String bindType); static void fillSubFormAddressFields(JSONObject jsonObject, Map<String, Address> addresses, String bindType); static JSONArray getSingleStepFormfields(JSONObject jsonForm); static JSONArray fields(JSONObject jsonForm); static JSONArray getMultiStepFormFields(JSONObject jsonForm); static Map<String, String> sectionFields(JSONObject jsonForm); static JSONObject toJSONObject(String jsonString); static String getFieldValue(JSONArray jsonArray, FormEntityConstants.Person person); static String getFieldValue(JSONArray jsonArray, FormEntityConstants.Encounter encounter); static String getFieldValue(String jsonString, String key); @Nullable static JSONObject getFieldJSONObject(JSONArray jsonArray, String key); @Nullable static String value(JSONArray jsonArray, String entity, String entityId); @Nullable static String getFieldValue(JSONArray jsonArray, String key); @Nullable static JSONObject getJSONObject(JSONArray jsonArray, int index); @Nullable static JSONArray getJSONArray(JSONObject jsonObject, String field); static JSONObject getJSONObject(JSONObject jsonObject, String field); static String getString(JSONObject jsonObject, String field); static String getString(String jsonString, String field); static Long getLong(JSONObject jsonObject, String field); static Date formatDate(String dateString, boolean startOfToday); static String generateRandomUUIDString(); static void addToJSONObject(JSONObject jsonObject, String key, String value); static String formatDate(String date); static JSONObject merge(JSONObject original, JSONObject updated); static String[] getNames(JSONObject jo); static String convertToOpenMRSDate(String value); static boolean isBlankJsonArray(JSONArray jsonArray); static boolean isBlankJsonObject(JSONObject jsonObject); }
JsonFormUtils { public static void fillSubFormIdentifiers(Map<String, String> pids, JSONObject jsonObject, String bindType) { String value = getString(jsonObject, VALUE); if (StringUtils.isBlank(value)) { return; } String bind = getString(jsonObject, ENTITY_ID); if (bind == null || !bind.equals(bindType)) { return; } String entity = PERSON_INDENTIFIER; String entityVal = getString(jsonObject, OPENMRS_ENTITY); if (entityVal != null && entityVal.equals(entity)) { String entityIdVal = getString(jsonObject, OPENMRS_ENTITY_ID); pids.put(entityIdVal, value); } } static Client createBaseClient(JSONArray fields, FormTag formTag, String entityId); static Event createEvent(JSONArray fields, JSONObject metadata, FormTag formTag, String entityId, String encounterType, String bindType); static void addObservation(Event e, JSONObject jsonObject); static Map<String, String> extractIdentifiers(JSONArray fields); static Map<String, Object> extractAttributes(JSONArray fields); static Map<String, Address> extractAddresses(JSONArray fields); static void fillIdentifiers(Map<String, String> pids, JSONObject jsonObject); static void fillAttributes(Map<String, Object> pattributes, JSONObject jsonObject); static void fillAddressFields(JSONObject jsonObject, Map<String, Address> addresses); static Map<String, String> extractIdentifiers(JSONArray fields, String bindType); static Map<String, Object> extractAttributes(JSONArray fields, String bindType); static Map<String, Address> extractAddresses(JSONArray fields, String bindType); static String getSubFormFieldValue(JSONArray jsonArray, FormEntityConstants.Person person, String bindType); static void fillSubFormIdentifiers(Map<String, String> pids, JSONObject jsonObject, String bindType); static void fillSubFormAttributes(Map<String, Object> pattributes, JSONObject jsonObject, String bindType); static void fillSubFormAddressFields(JSONObject jsonObject, Map<String, Address> addresses, String bindType); static JSONArray getSingleStepFormfields(JSONObject jsonForm); static JSONArray fields(JSONObject jsonForm); static JSONArray getMultiStepFormFields(JSONObject jsonForm); static Map<String, String> sectionFields(JSONObject jsonForm); static JSONObject toJSONObject(String jsonString); static String getFieldValue(JSONArray jsonArray, FormEntityConstants.Person person); static String getFieldValue(JSONArray jsonArray, FormEntityConstants.Encounter encounter); static String getFieldValue(String jsonString, String key); @Nullable static JSONObject getFieldJSONObject(JSONArray jsonArray, String key); @Nullable static String value(JSONArray jsonArray, String entity, String entityId); @Nullable static String getFieldValue(JSONArray jsonArray, String key); @Nullable static JSONObject getJSONObject(JSONArray jsonArray, int index); @Nullable static JSONArray getJSONArray(JSONObject jsonObject, String field); static JSONObject getJSONObject(JSONObject jsonObject, String field); static String getString(JSONObject jsonObject, String field); static String getString(String jsonString, String field); static Long getLong(JSONObject jsonObject, String field); static Date formatDate(String dateString, boolean startOfToday); static String generateRandomUUIDString(); static void addToJSONObject(JSONObject jsonObject, String key, String value); static String formatDate(String date); static JSONObject merge(JSONObject original, JSONObject updated); static String[] getNames(JSONObject jo); static String convertToOpenMRSDate(String value); static boolean isBlankJsonArray(JSONArray jsonArray); static boolean isBlankJsonObject(JSONObject jsonObject); static final String TAG; static final String OPENMRS_ENTITY; static final String OPENMRS_ENTITY_ID; static final String OPENMRS_ENTITY_PARENT; static final String OPENMRS_CHOICE_IDS; static final String OPENMRS_DATA_TYPE; static final String PERSON_ATTRIBUTE; static final String PERSON_INDENTIFIER; static final String PERSON_ADDRESS; static final String SIMPRINTS_GUID; static final String FINGERPRINT_KEY; static final String FINGERPRINT_OPTION; static final String FINGERPRINT_OPTION_REGISTER; static final String CONCEPT; static final String VALUE; static final String VALUES; static final String FIELDS; static final String KEY; static final String ENTITY_ID; static final String STEP1; static final String SECTIONS; static final String attributes; static final String ENCOUNTER; static final String ENCOUNTER_LOCATION; static final String SAVE_OBS_AS_ARRAY; static final String SAVE_ALL_CHECKBOX_OBS_AS_ARRAY; static final SimpleDateFormat dd_MM_yyyy; static Gson gson; }
@Test public void assertStartFormActivityInvokesNavigationToFormActivity() { Mockito.doNothing().when(securedFragment).startActivityForResult(ArgumentMatchers.any(Intent.class), ArgumentMatchers.anyInt()); securedFragment.startFormActivity(TEST_FORM_NAME, TEST_BASE_ENTITY_ID, null); Mockito.verify(securedFragment).startActivityForResult(intentArgumentCaptor.capture(), integerArgumentCaptor.capture()); Intent capturedIntent = intentArgumentCaptor.getValue(); Assert.assertNotNull(capturedIntent); Assert.assertEquals("org.smartregister.view.activity.FormActivity", capturedIntent.getComponent().getClassName()); Integer capturedInteger = integerArgumentCaptor.getValue(); Assert.assertNotNull(capturedInteger); Assert.assertEquals(AllConstants.FORM_SUCCESSFULLY_SUBMITTED_RESULT_CODE, capturedInteger.intValue()); }
public void startFormActivity(String formName, String entityId, String metaData) { launchForm(formName, entityId, metaData, FormActivity.class); }
SecuredFragment extends Fragment { public void startFormActivity(String formName, String entityId, String metaData) { launchForm(formName, entityId, metaData, FormActivity.class); } }
SecuredFragment extends Fragment { public void startFormActivity(String formName, String entityId, String metaData) { launchForm(formName, entityId, metaData, FormActivity.class); } }
SecuredFragment extends Fragment { public void startFormActivity(String formName, String entityId, String metaData) { launchForm(formName, entityId, metaData, FormActivity.class); } @Override void onCreate(Bundle savedInstanceState); @Override void onResume(); @Override void onPause(); @Override boolean onOptionsItemSelected(MenuItem item); void logoutUser(); void startFormActivity(String formName, String entityId, String metaData); void startMicroFormActivity(String formName, String entityId, String metaData); boolean isPaused(); }
SecuredFragment extends Fragment { public void startFormActivity(String formName, String entityId, String metaData) { launchForm(formName, entityId, metaData, FormActivity.class); } @Override void onCreate(Bundle savedInstanceState); @Override void onResume(); @Override void onPause(); @Override boolean onOptionsItemSelected(MenuItem item); void logoutUser(); void startFormActivity(String formName, String entityId, String metaData); void startMicroFormActivity(String formName, String entityId, String metaData); boolean isPaused(); }
@Test public void assertStartMicroFormActivityInvokesNavigationToMicroFormActivity() { Mockito.doNothing().when(securedFragment).startActivityForResult(ArgumentMatchers.any(Intent.class), ArgumentMatchers.anyInt()); securedFragment.startMicroFormActivity(TEST_FORM_NAME, TEST_BASE_ENTITY_ID, null); Mockito.verify(securedFragment).startActivityForResult(intentArgumentCaptor.capture(), integerArgumentCaptor.capture()); Intent capturedIntent = intentArgumentCaptor.getValue(); Assert.assertNotNull(capturedIntent); Assert.assertEquals("org.smartregister.view.activity.MicroFormActivity", capturedIntent.getComponent().getClassName()); Integer capturedInteger = integerArgumentCaptor.getValue(); Assert.assertNotNull(capturedInteger); Assert.assertEquals(AllConstants.FORM_SUCCESSFULLY_SUBMITTED_RESULT_CODE, capturedInteger.intValue()); }
public void startMicroFormActivity(String formName, String entityId, String metaData) { launchForm(formName, entityId, metaData, MicroFormActivity.class); }
SecuredFragment extends Fragment { public void startMicroFormActivity(String formName, String entityId, String metaData) { launchForm(formName, entityId, metaData, MicroFormActivity.class); } }
SecuredFragment extends Fragment { public void startMicroFormActivity(String formName, String entityId, String metaData) { launchForm(formName, entityId, metaData, MicroFormActivity.class); } }
SecuredFragment extends Fragment { public void startMicroFormActivity(String formName, String entityId, String metaData) { launchForm(formName, entityId, metaData, MicroFormActivity.class); } @Override void onCreate(Bundle savedInstanceState); @Override void onResume(); @Override void onPause(); @Override boolean onOptionsItemSelected(MenuItem item); void logoutUser(); void startFormActivity(String formName, String entityId, String metaData); void startMicroFormActivity(String formName, String entityId, String metaData); boolean isPaused(); }
SecuredFragment extends Fragment { public void startMicroFormActivity(String formName, String entityId, String metaData) { launchForm(formName, entityId, metaData, MicroFormActivity.class); } @Override void onCreate(Bundle savedInstanceState); @Override void onResume(); @Override void onPause(); @Override boolean onOptionsItemSelected(MenuItem item); void logoutUser(); void startFormActivity(String formName, String entityId, String metaData); void startMicroFormActivity(String formName, String entityId, String metaData); boolean isPaused(); }
@Test public void testAddFieldOverridesIfExistAddsFieldOverrideParamsToRequestIntent() { String testMetadata = "{\"fieldOverrides\": \"metadata-override-values\"}"; Mockito.doNothing().when(securedFragment).startActivityForResult(ArgumentMatchers.any(Intent.class), ArgumentMatchers.anyInt()); securedFragment.startFormActivity(TEST_FORM_NAME, TEST_BASE_ENTITY_ID, testMetadata); Mockito.verify(securedFragment).startActivityForResult(intentArgumentCaptor.capture(), integerArgumentCaptor.capture()); Intent capturedIntent = intentArgumentCaptor.getValue(); Assert.assertNotNull(capturedIntent); Assert.assertEquals("metadata-override-values", capturedIntent.getStringExtra(AllConstants.FIELD_OVERRIDES_PARAM)); }
public void startFormActivity(String formName, String entityId, String metaData) { launchForm(formName, entityId, metaData, FormActivity.class); }
SecuredFragment extends Fragment { public void startFormActivity(String formName, String entityId, String metaData) { launchForm(formName, entityId, metaData, FormActivity.class); } }
SecuredFragment extends Fragment { public void startFormActivity(String formName, String entityId, String metaData) { launchForm(formName, entityId, metaData, FormActivity.class); } }
SecuredFragment extends Fragment { public void startFormActivity(String formName, String entityId, String metaData) { launchForm(formName, entityId, metaData, FormActivity.class); } @Override void onCreate(Bundle savedInstanceState); @Override void onResume(); @Override void onPause(); @Override boolean onOptionsItemSelected(MenuItem item); void logoutUser(); void startFormActivity(String formName, String entityId, String metaData); void startMicroFormActivity(String formName, String entityId, String metaData); boolean isPaused(); }
SecuredFragment extends Fragment { public void startFormActivity(String formName, String entityId, String metaData) { launchForm(formName, entityId, metaData, FormActivity.class); } @Override void onCreate(Bundle savedInstanceState); @Override void onResume(); @Override void onPause(); @Override boolean onOptionsItemSelected(MenuItem item); void logoutUser(); void startFormActivity(String formName, String entityId, String metaData); void startMicroFormActivity(String formName, String entityId, String metaData); boolean isPaused(); }
@Test public void assertOnCreateViewInflatesCorrectLayout() { libraryFragment.onCreateView(inflater, container, null); Assert.assertNotNull(libraryFragment); Mockito.verify(inflater).inflate(R.layout.fragment_library, container, false); }
@Nullable @Override public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { return inflater.inflate(R.layout.fragment_library, container, false); }
LibraryFragment extends Fragment implements LibraryContract.View { @Nullable @Override public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { return inflater.inflate(R.layout.fragment_library, container, false); } }
LibraryFragment extends Fragment implements LibraryContract.View { @Nullable @Override public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { return inflater.inflate(R.layout.fragment_library, container, false); } }
LibraryFragment extends Fragment implements LibraryContract.View { @Nullable @Override public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { return inflater.inflate(R.layout.fragment_library, container, false); } @Nullable @Override View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState); }
LibraryFragment extends Fragment implements LibraryContract.View { @Nullable @Override public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { return inflater.inflate(R.layout.fragment_library, container, false); } @Nullable @Override View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState); }
@Test public void testOnViewCreatedAddsOnTouchListenerHandlerToView() { Mockito.when(context.IsUserLoggedOut()).thenReturn(false); Mockito.doReturn(context).when(baseProfileFragment).context(); baseProfileFragment.onViewCreated(view, bundle); Mockito.verify(view).setOnTouchListener(baseProfileFragmentArgumentCaptor.capture()); Fragment baseProfileFragment = baseProfileFragmentArgumentCaptor.getValue(); Assert.assertNotNull(baseProfileFragment); Assert.assertTrue(baseProfileFragment instanceof BaseProfileFragment); }
@Override public void onViewCreated(View view, Bundle savedInstanceState) { super.onCreate(savedInstanceState); gestureDetector = new GestureDetectorCompat(this.getActivity(), new ProfileFragmentsSwipeListener()); view.setOnTouchListener(this); }
BaseProfileFragment extends SecuredFragment implements View.OnTouchListener { @Override public void onViewCreated(View view, Bundle savedInstanceState) { super.onCreate(savedInstanceState); gestureDetector = new GestureDetectorCompat(this.getActivity(), new ProfileFragmentsSwipeListener()); view.setOnTouchListener(this); } }
BaseProfileFragment extends SecuredFragment implements View.OnTouchListener { @Override public void onViewCreated(View view, Bundle savedInstanceState) { super.onCreate(savedInstanceState); gestureDetector = new GestureDetectorCompat(this.getActivity(), new ProfileFragmentsSwipeListener()); view.setOnTouchListener(this); } }
BaseProfileFragment extends SecuredFragment implements View.OnTouchListener { @Override public void onViewCreated(View view, Bundle savedInstanceState) { super.onCreate(savedInstanceState); gestureDetector = new GestureDetectorCompat(this.getActivity(), new ProfileFragmentsSwipeListener()); view.setOnTouchListener(this); } @Override void onViewCreated(View view, Bundle savedInstanceState); @Override boolean onTouch(View view, MotionEvent event); }
BaseProfileFragment extends SecuredFragment implements View.OnTouchListener { @Override public void onViewCreated(View view, Bundle savedInstanceState) { super.onCreate(savedInstanceState); gestureDetector = new GestureDetectorCompat(this.getActivity(), new ProfileFragmentsSwipeListener()); view.setOnTouchListener(this); } @Override void onViewCreated(View view, Bundle savedInstanceState); @Override boolean onTouch(View view, MotionEvent event); }
@Test public void testOnViewCreatedInstantiatesValidGestureDetectorField() { Mockito.when(context.IsUserLoggedOut()).thenReturn(false); Mockito.doReturn(context).when(baseProfileFragment).context(); GestureDetectorCompat gestureDetector = ReflectionHelpers.getField(baseProfileFragment, "gestureDetector"); Assert.assertNull(gestureDetector); baseProfileFragment.onViewCreated(view, bundle); gestureDetector = ReflectionHelpers.getField(baseProfileFragment, "gestureDetector"); Assert.assertNotNull(gestureDetector); }
@Override public void onViewCreated(View view, Bundle savedInstanceState) { super.onCreate(savedInstanceState); gestureDetector = new GestureDetectorCompat(this.getActivity(), new ProfileFragmentsSwipeListener()); view.setOnTouchListener(this); }
BaseProfileFragment extends SecuredFragment implements View.OnTouchListener { @Override public void onViewCreated(View view, Bundle savedInstanceState) { super.onCreate(savedInstanceState); gestureDetector = new GestureDetectorCompat(this.getActivity(), new ProfileFragmentsSwipeListener()); view.setOnTouchListener(this); } }
BaseProfileFragment extends SecuredFragment implements View.OnTouchListener { @Override public void onViewCreated(View view, Bundle savedInstanceState) { super.onCreate(savedInstanceState); gestureDetector = new GestureDetectorCompat(this.getActivity(), new ProfileFragmentsSwipeListener()); view.setOnTouchListener(this); } }
BaseProfileFragment extends SecuredFragment implements View.OnTouchListener { @Override public void onViewCreated(View view, Bundle savedInstanceState) { super.onCreate(savedInstanceState); gestureDetector = new GestureDetectorCompat(this.getActivity(), new ProfileFragmentsSwipeListener()); view.setOnTouchListener(this); } @Override void onViewCreated(View view, Bundle savedInstanceState); @Override boolean onTouch(View view, MotionEvent event); }
BaseProfileFragment extends SecuredFragment implements View.OnTouchListener { @Override public void onViewCreated(View view, Bundle savedInstanceState) { super.onCreate(savedInstanceState); gestureDetector = new GestureDetectorCompat(this.getActivity(), new ProfileFragmentsSwipeListener()); view.setOnTouchListener(this); } @Override void onViewCreated(View view, Bundle savedInstanceState); @Override boolean onTouch(View view, MotionEvent event); }
@Test public void testOnTouchAssignsMotionEventHandler() { ReflectionHelpers.setField(baseProfileFragment, "gestureDetector", gestureDetector); baseProfileFragment.onTouch(view, motionEvent); Mockito.verify(gestureDetector).onTouchEvent(motionEvent); }
@Override public boolean onTouch(View view, MotionEvent event) { return gestureDetector.onTouchEvent(event); }
BaseProfileFragment extends SecuredFragment implements View.OnTouchListener { @Override public boolean onTouch(View view, MotionEvent event) { return gestureDetector.onTouchEvent(event); } }
BaseProfileFragment extends SecuredFragment implements View.OnTouchListener { @Override public boolean onTouch(View view, MotionEvent event) { return gestureDetector.onTouchEvent(event); } }
BaseProfileFragment extends SecuredFragment implements View.OnTouchListener { @Override public boolean onTouch(View view, MotionEvent event) { return gestureDetector.onTouchEvent(event); } @Override void onViewCreated(View view, Bundle savedInstanceState); @Override boolean onTouch(View view, MotionEvent event); }
BaseProfileFragment extends SecuredFragment implements View.OnTouchListener { @Override public boolean onTouch(View view, MotionEvent event) { return gestureDetector.onTouchEvent(event); } @Override void onViewCreated(View view, Bundle savedInstanceState); @Override boolean onTouch(View view, MotionEvent event); }
@Test public void testOnFlingProcessorReturnsTrueIfXTranlationGreatherThanSwipeOffMaxPath() { Mockito.doReturn(500f).when(motionEvent1).getX(); Mockito.doReturn(100f).when(motionEvent2).getX(); Boolean result = baseProfileFragment.onFlingProcessor(motionEvent1, motionEvent2, 1.0f); Assert.assertNotNull(result); Assert.assertTrue(result); }
@VisibleForTesting protected boolean onFlingProcessor(MotionEvent event, MotionEvent event2, float velocityY) { final int SWIPE_MIN_DISTANCE = 120; final int SWIPE_MAX_OFF_PATH = 300; final int SWIPE_THRESHOLD_VELOCITY = 200; try { if (Math.abs(event.getX() - event2.getX()) > SWIPE_MAX_OFF_PATH) { return true; } if (event.getY() - event2.getY() > SWIPE_MIN_DISTANCE && Math.abs(velocityY) > SWIPE_THRESHOLD_VELOCITY) { ((BaseProfileActivity) getActivity()).getProfileAppBarLayout().setExpanded(false, true); } else if (event2.getY() - event.getY() > SWIPE_MIN_DISTANCE && Math.abs(velocityY) > SWIPE_THRESHOLD_VELOCITY) { ((BaseProfileActivity) getActivity()).getProfileAppBarLayout().setExpanded(true, true); } } catch (Exception e) { } return false; }
BaseProfileFragment extends SecuredFragment implements View.OnTouchListener { @VisibleForTesting protected boolean onFlingProcessor(MotionEvent event, MotionEvent event2, float velocityY) { final int SWIPE_MIN_DISTANCE = 120; final int SWIPE_MAX_OFF_PATH = 300; final int SWIPE_THRESHOLD_VELOCITY = 200; try { if (Math.abs(event.getX() - event2.getX()) > SWIPE_MAX_OFF_PATH) { return true; } if (event.getY() - event2.getY() > SWIPE_MIN_DISTANCE && Math.abs(velocityY) > SWIPE_THRESHOLD_VELOCITY) { ((BaseProfileActivity) getActivity()).getProfileAppBarLayout().setExpanded(false, true); } else if (event2.getY() - event.getY() > SWIPE_MIN_DISTANCE && Math.abs(velocityY) > SWIPE_THRESHOLD_VELOCITY) { ((BaseProfileActivity) getActivity()).getProfileAppBarLayout().setExpanded(true, true); } } catch (Exception e) { } return false; } }
BaseProfileFragment extends SecuredFragment implements View.OnTouchListener { @VisibleForTesting protected boolean onFlingProcessor(MotionEvent event, MotionEvent event2, float velocityY) { final int SWIPE_MIN_DISTANCE = 120; final int SWIPE_MAX_OFF_PATH = 300; final int SWIPE_THRESHOLD_VELOCITY = 200; try { if (Math.abs(event.getX() - event2.getX()) > SWIPE_MAX_OFF_PATH) { return true; } if (event.getY() - event2.getY() > SWIPE_MIN_DISTANCE && Math.abs(velocityY) > SWIPE_THRESHOLD_VELOCITY) { ((BaseProfileActivity) getActivity()).getProfileAppBarLayout().setExpanded(false, true); } else if (event2.getY() - event.getY() > SWIPE_MIN_DISTANCE && Math.abs(velocityY) > SWIPE_THRESHOLD_VELOCITY) { ((BaseProfileActivity) getActivity()).getProfileAppBarLayout().setExpanded(true, true); } } catch (Exception e) { } return false; } }
BaseProfileFragment extends SecuredFragment implements View.OnTouchListener { @VisibleForTesting protected boolean onFlingProcessor(MotionEvent event, MotionEvent event2, float velocityY) { final int SWIPE_MIN_DISTANCE = 120; final int SWIPE_MAX_OFF_PATH = 300; final int SWIPE_THRESHOLD_VELOCITY = 200; try { if (Math.abs(event.getX() - event2.getX()) > SWIPE_MAX_OFF_PATH) { return true; } if (event.getY() - event2.getY() > SWIPE_MIN_DISTANCE && Math.abs(velocityY) > SWIPE_THRESHOLD_VELOCITY) { ((BaseProfileActivity) getActivity()).getProfileAppBarLayout().setExpanded(false, true); } else if (event2.getY() - event.getY() > SWIPE_MIN_DISTANCE && Math.abs(velocityY) > SWIPE_THRESHOLD_VELOCITY) { ((BaseProfileActivity) getActivity()).getProfileAppBarLayout().setExpanded(true, true); } } catch (Exception e) { } return false; } @Override void onViewCreated(View view, Bundle savedInstanceState); @Override boolean onTouch(View view, MotionEvent event); }
BaseProfileFragment extends SecuredFragment implements View.OnTouchListener { @VisibleForTesting protected boolean onFlingProcessor(MotionEvent event, MotionEvent event2, float velocityY) { final int SWIPE_MIN_DISTANCE = 120; final int SWIPE_MAX_OFF_PATH = 300; final int SWIPE_THRESHOLD_VELOCITY = 200; try { if (Math.abs(event.getX() - event2.getX()) > SWIPE_MAX_OFF_PATH) { return true; } if (event.getY() - event2.getY() > SWIPE_MIN_DISTANCE && Math.abs(velocityY) > SWIPE_THRESHOLD_VELOCITY) { ((BaseProfileActivity) getActivity()).getProfileAppBarLayout().setExpanded(false, true); } else if (event2.getY() - event.getY() > SWIPE_MIN_DISTANCE && Math.abs(velocityY) > SWIPE_THRESHOLD_VELOCITY) { ((BaseProfileActivity) getActivity()).getProfileAppBarLayout().setExpanded(true, true); } } catch (Exception e) { } return false; } @Override void onViewCreated(View view, Bundle savedInstanceState); @Override boolean onTouch(View view, MotionEvent event); }
@Test public void testOnFlingProcessorReturnsFalseIfXTranlationLessThanSwipeOffMaxPath() { Mockito.doReturn(400f).when(motionEvent1).getX(); Mockito.doReturn(300f).when(motionEvent2).getX(); Boolean result = baseProfileFragment.onFlingProcessor(motionEvent1, motionEvent2, 1.0f); Assert.assertNotNull(result); Assert.assertFalse(result); }
@VisibleForTesting protected boolean onFlingProcessor(MotionEvent event, MotionEvent event2, float velocityY) { final int SWIPE_MIN_DISTANCE = 120; final int SWIPE_MAX_OFF_PATH = 300; final int SWIPE_THRESHOLD_VELOCITY = 200; try { if (Math.abs(event.getX() - event2.getX()) > SWIPE_MAX_OFF_PATH) { return true; } if (event.getY() - event2.getY() > SWIPE_MIN_DISTANCE && Math.abs(velocityY) > SWIPE_THRESHOLD_VELOCITY) { ((BaseProfileActivity) getActivity()).getProfileAppBarLayout().setExpanded(false, true); } else if (event2.getY() - event.getY() > SWIPE_MIN_DISTANCE && Math.abs(velocityY) > SWIPE_THRESHOLD_VELOCITY) { ((BaseProfileActivity) getActivity()).getProfileAppBarLayout().setExpanded(true, true); } } catch (Exception e) { } return false; }
BaseProfileFragment extends SecuredFragment implements View.OnTouchListener { @VisibleForTesting protected boolean onFlingProcessor(MotionEvent event, MotionEvent event2, float velocityY) { final int SWIPE_MIN_DISTANCE = 120; final int SWIPE_MAX_OFF_PATH = 300; final int SWIPE_THRESHOLD_VELOCITY = 200; try { if (Math.abs(event.getX() - event2.getX()) > SWIPE_MAX_OFF_PATH) { return true; } if (event.getY() - event2.getY() > SWIPE_MIN_DISTANCE && Math.abs(velocityY) > SWIPE_THRESHOLD_VELOCITY) { ((BaseProfileActivity) getActivity()).getProfileAppBarLayout().setExpanded(false, true); } else if (event2.getY() - event.getY() > SWIPE_MIN_DISTANCE && Math.abs(velocityY) > SWIPE_THRESHOLD_VELOCITY) { ((BaseProfileActivity) getActivity()).getProfileAppBarLayout().setExpanded(true, true); } } catch (Exception e) { } return false; } }
BaseProfileFragment extends SecuredFragment implements View.OnTouchListener { @VisibleForTesting protected boolean onFlingProcessor(MotionEvent event, MotionEvent event2, float velocityY) { final int SWIPE_MIN_DISTANCE = 120; final int SWIPE_MAX_OFF_PATH = 300; final int SWIPE_THRESHOLD_VELOCITY = 200; try { if (Math.abs(event.getX() - event2.getX()) > SWIPE_MAX_OFF_PATH) { return true; } if (event.getY() - event2.getY() > SWIPE_MIN_DISTANCE && Math.abs(velocityY) > SWIPE_THRESHOLD_VELOCITY) { ((BaseProfileActivity) getActivity()).getProfileAppBarLayout().setExpanded(false, true); } else if (event2.getY() - event.getY() > SWIPE_MIN_DISTANCE && Math.abs(velocityY) > SWIPE_THRESHOLD_VELOCITY) { ((BaseProfileActivity) getActivity()).getProfileAppBarLayout().setExpanded(true, true); } } catch (Exception e) { } return false; } }
BaseProfileFragment extends SecuredFragment implements View.OnTouchListener { @VisibleForTesting protected boolean onFlingProcessor(MotionEvent event, MotionEvent event2, float velocityY) { final int SWIPE_MIN_DISTANCE = 120; final int SWIPE_MAX_OFF_PATH = 300; final int SWIPE_THRESHOLD_VELOCITY = 200; try { if (Math.abs(event.getX() - event2.getX()) > SWIPE_MAX_OFF_PATH) { return true; } if (event.getY() - event2.getY() > SWIPE_MIN_DISTANCE && Math.abs(velocityY) > SWIPE_THRESHOLD_VELOCITY) { ((BaseProfileActivity) getActivity()).getProfileAppBarLayout().setExpanded(false, true); } else if (event2.getY() - event.getY() > SWIPE_MIN_DISTANCE && Math.abs(velocityY) > SWIPE_THRESHOLD_VELOCITY) { ((BaseProfileActivity) getActivity()).getProfileAppBarLayout().setExpanded(true, true); } } catch (Exception e) { } return false; } @Override void onViewCreated(View view, Bundle savedInstanceState); @Override boolean onTouch(View view, MotionEvent event); }
BaseProfileFragment extends SecuredFragment implements View.OnTouchListener { @VisibleForTesting protected boolean onFlingProcessor(MotionEvent event, MotionEvent event2, float velocityY) { final int SWIPE_MIN_DISTANCE = 120; final int SWIPE_MAX_OFF_PATH = 300; final int SWIPE_THRESHOLD_VELOCITY = 200; try { if (Math.abs(event.getX() - event2.getX()) > SWIPE_MAX_OFF_PATH) { return true; } if (event.getY() - event2.getY() > SWIPE_MIN_DISTANCE && Math.abs(velocityY) > SWIPE_THRESHOLD_VELOCITY) { ((BaseProfileActivity) getActivity()).getProfileAppBarLayout().setExpanded(false, true); } else if (event2.getY() - event.getY() > SWIPE_MIN_DISTANCE && Math.abs(velocityY) > SWIPE_THRESHOLD_VELOCITY) { ((BaseProfileActivity) getActivity()).getProfileAppBarLayout().setExpanded(true, true); } } catch (Exception e) { } return false; } @Override void onViewCreated(View view, Bundle savedInstanceState); @Override boolean onTouch(View view, MotionEvent event); }
@Test public void testOnFlingProcessorSetsAppBarLayoutExpandedToTrueWhenYTranlationGreaterThanSwipeOffMinPath() { Mockito.doReturn(200f).when(motionEvent1).getY(); Mockito.doReturn(50f).when(motionEvent2).getY(); Mockito.doReturn(baseProfileActivity).when(baseProfileFragment).getActivity(); Mockito.doReturn(appBarLayout).when(baseProfileActivity).getProfileAppBarLayout(); Boolean result = baseProfileFragment.onFlingProcessor(motionEvent1, motionEvent2, 250.0f); Assert.assertNotNull(result); Assert.assertFalse(result); Mockito.verify(appBarLayout).setExpanded(appBarLayoutExpandedArgumentCaptor.capture(), appBarLayoutAnimateArgumentCaptor.capture()); Boolean isExpanded = appBarLayoutExpandedArgumentCaptor.getValue(); Assert.assertNotNull(isExpanded); Assert.assertFalse(isExpanded); }
@VisibleForTesting protected boolean onFlingProcessor(MotionEvent event, MotionEvent event2, float velocityY) { final int SWIPE_MIN_DISTANCE = 120; final int SWIPE_MAX_OFF_PATH = 300; final int SWIPE_THRESHOLD_VELOCITY = 200; try { if (Math.abs(event.getX() - event2.getX()) > SWIPE_MAX_OFF_PATH) { return true; } if (event.getY() - event2.getY() > SWIPE_MIN_DISTANCE && Math.abs(velocityY) > SWIPE_THRESHOLD_VELOCITY) { ((BaseProfileActivity) getActivity()).getProfileAppBarLayout().setExpanded(false, true); } else if (event2.getY() - event.getY() > SWIPE_MIN_DISTANCE && Math.abs(velocityY) > SWIPE_THRESHOLD_VELOCITY) { ((BaseProfileActivity) getActivity()).getProfileAppBarLayout().setExpanded(true, true); } } catch (Exception e) { } return false; }
BaseProfileFragment extends SecuredFragment implements View.OnTouchListener { @VisibleForTesting protected boolean onFlingProcessor(MotionEvent event, MotionEvent event2, float velocityY) { final int SWIPE_MIN_DISTANCE = 120; final int SWIPE_MAX_OFF_PATH = 300; final int SWIPE_THRESHOLD_VELOCITY = 200; try { if (Math.abs(event.getX() - event2.getX()) > SWIPE_MAX_OFF_PATH) { return true; } if (event.getY() - event2.getY() > SWIPE_MIN_DISTANCE && Math.abs(velocityY) > SWIPE_THRESHOLD_VELOCITY) { ((BaseProfileActivity) getActivity()).getProfileAppBarLayout().setExpanded(false, true); } else if (event2.getY() - event.getY() > SWIPE_MIN_DISTANCE && Math.abs(velocityY) > SWIPE_THRESHOLD_VELOCITY) { ((BaseProfileActivity) getActivity()).getProfileAppBarLayout().setExpanded(true, true); } } catch (Exception e) { } return false; } }
BaseProfileFragment extends SecuredFragment implements View.OnTouchListener { @VisibleForTesting protected boolean onFlingProcessor(MotionEvent event, MotionEvent event2, float velocityY) { final int SWIPE_MIN_DISTANCE = 120; final int SWIPE_MAX_OFF_PATH = 300; final int SWIPE_THRESHOLD_VELOCITY = 200; try { if (Math.abs(event.getX() - event2.getX()) > SWIPE_MAX_OFF_PATH) { return true; } if (event.getY() - event2.getY() > SWIPE_MIN_DISTANCE && Math.abs(velocityY) > SWIPE_THRESHOLD_VELOCITY) { ((BaseProfileActivity) getActivity()).getProfileAppBarLayout().setExpanded(false, true); } else if (event2.getY() - event.getY() > SWIPE_MIN_DISTANCE && Math.abs(velocityY) > SWIPE_THRESHOLD_VELOCITY) { ((BaseProfileActivity) getActivity()).getProfileAppBarLayout().setExpanded(true, true); } } catch (Exception e) { } return false; } }
BaseProfileFragment extends SecuredFragment implements View.OnTouchListener { @VisibleForTesting protected boolean onFlingProcessor(MotionEvent event, MotionEvent event2, float velocityY) { final int SWIPE_MIN_DISTANCE = 120; final int SWIPE_MAX_OFF_PATH = 300; final int SWIPE_THRESHOLD_VELOCITY = 200; try { if (Math.abs(event.getX() - event2.getX()) > SWIPE_MAX_OFF_PATH) { return true; } if (event.getY() - event2.getY() > SWIPE_MIN_DISTANCE && Math.abs(velocityY) > SWIPE_THRESHOLD_VELOCITY) { ((BaseProfileActivity) getActivity()).getProfileAppBarLayout().setExpanded(false, true); } else if (event2.getY() - event.getY() > SWIPE_MIN_DISTANCE && Math.abs(velocityY) > SWIPE_THRESHOLD_VELOCITY) { ((BaseProfileActivity) getActivity()).getProfileAppBarLayout().setExpanded(true, true); } } catch (Exception e) { } return false; } @Override void onViewCreated(View view, Bundle savedInstanceState); @Override boolean onTouch(View view, MotionEvent event); }
BaseProfileFragment extends SecuredFragment implements View.OnTouchListener { @VisibleForTesting protected boolean onFlingProcessor(MotionEvent event, MotionEvent event2, float velocityY) { final int SWIPE_MIN_DISTANCE = 120; final int SWIPE_MAX_OFF_PATH = 300; final int SWIPE_THRESHOLD_VELOCITY = 200; try { if (Math.abs(event.getX() - event2.getX()) > SWIPE_MAX_OFF_PATH) { return true; } if (event.getY() - event2.getY() > SWIPE_MIN_DISTANCE && Math.abs(velocityY) > SWIPE_THRESHOLD_VELOCITY) { ((BaseProfileActivity) getActivity()).getProfileAppBarLayout().setExpanded(false, true); } else if (event2.getY() - event.getY() > SWIPE_MIN_DISTANCE && Math.abs(velocityY) > SWIPE_THRESHOLD_VELOCITY) { ((BaseProfileActivity) getActivity()).getProfileAppBarLayout().setExpanded(true, true); } } catch (Exception e) { } return false; } @Override void onViewCreated(View view, Bundle savedInstanceState); @Override boolean onTouch(View view, MotionEvent event); }
@Test public void testFillSubFormAttributesShouldFillCorrectAttributes() throws JSONException { JSONObject jsonObject = new JSONObject(); jsonObject.put(ENTITY_ID, "entity_id"); jsonObject.put(VALUE, "value"); jsonObject.put(OPENMRS_ENTITY, PERSON_ATTRIBUTE); jsonObject.put(OPENMRS_ENTITY_ID, "openmrs_entity_id"); Map<String, Object> patientAttributes = new HashMap<>(); JsonFormUtils.fillSubFormAttributes(patientAttributes, jsonObject, "entity_id"); assertEquals(1, patientAttributes.size()); assertEquals("value", patientAttributes.get(OPENMRS_ENTITY_ID)); }
public static void fillSubFormAttributes(Map<String, Object> pattributes, JSONObject jsonObject, String bindType) { String value = getString(jsonObject, VALUE); if (StringUtils.isBlank(value)) { return; } String bind = getString(jsonObject, ENTITY_ID); if (bind == null || !bind.equals(bindType)) { return; } String entity = PERSON_ATTRIBUTE; String entityVal = getString(jsonObject, OPENMRS_ENTITY); if (entityVal != null && entityVal.equals(entity)) { String entityIdVal = getString(jsonObject, OPENMRS_ENTITY_ID); pattributes.put(entityIdVal, value); } }
JsonFormUtils { public static void fillSubFormAttributes(Map<String, Object> pattributes, JSONObject jsonObject, String bindType) { String value = getString(jsonObject, VALUE); if (StringUtils.isBlank(value)) { return; } String bind = getString(jsonObject, ENTITY_ID); if (bind == null || !bind.equals(bindType)) { return; } String entity = PERSON_ATTRIBUTE; String entityVal = getString(jsonObject, OPENMRS_ENTITY); if (entityVal != null && entityVal.equals(entity)) { String entityIdVal = getString(jsonObject, OPENMRS_ENTITY_ID); pattributes.put(entityIdVal, value); } } }
JsonFormUtils { public static void fillSubFormAttributes(Map<String, Object> pattributes, JSONObject jsonObject, String bindType) { String value = getString(jsonObject, VALUE); if (StringUtils.isBlank(value)) { return; } String bind = getString(jsonObject, ENTITY_ID); if (bind == null || !bind.equals(bindType)) { return; } String entity = PERSON_ATTRIBUTE; String entityVal = getString(jsonObject, OPENMRS_ENTITY); if (entityVal != null && entityVal.equals(entity)) { String entityIdVal = getString(jsonObject, OPENMRS_ENTITY_ID); pattributes.put(entityIdVal, value); } } }
JsonFormUtils { public static void fillSubFormAttributes(Map<String, Object> pattributes, JSONObject jsonObject, String bindType) { String value = getString(jsonObject, VALUE); if (StringUtils.isBlank(value)) { return; } String bind = getString(jsonObject, ENTITY_ID); if (bind == null || !bind.equals(bindType)) { return; } String entity = PERSON_ATTRIBUTE; String entityVal = getString(jsonObject, OPENMRS_ENTITY); if (entityVal != null && entityVal.equals(entity)) { String entityIdVal = getString(jsonObject, OPENMRS_ENTITY_ID); pattributes.put(entityIdVal, value); } } static Client createBaseClient(JSONArray fields, FormTag formTag, String entityId); static Event createEvent(JSONArray fields, JSONObject metadata, FormTag formTag, String entityId, String encounterType, String bindType); static void addObservation(Event e, JSONObject jsonObject); static Map<String, String> extractIdentifiers(JSONArray fields); static Map<String, Object> extractAttributes(JSONArray fields); static Map<String, Address> extractAddresses(JSONArray fields); static void fillIdentifiers(Map<String, String> pids, JSONObject jsonObject); static void fillAttributes(Map<String, Object> pattributes, JSONObject jsonObject); static void fillAddressFields(JSONObject jsonObject, Map<String, Address> addresses); static Map<String, String> extractIdentifiers(JSONArray fields, String bindType); static Map<String, Object> extractAttributes(JSONArray fields, String bindType); static Map<String, Address> extractAddresses(JSONArray fields, String bindType); static String getSubFormFieldValue(JSONArray jsonArray, FormEntityConstants.Person person, String bindType); static void fillSubFormIdentifiers(Map<String, String> pids, JSONObject jsonObject, String bindType); static void fillSubFormAttributes(Map<String, Object> pattributes, JSONObject jsonObject, String bindType); static void fillSubFormAddressFields(JSONObject jsonObject, Map<String, Address> addresses, String bindType); static JSONArray getSingleStepFormfields(JSONObject jsonForm); static JSONArray fields(JSONObject jsonForm); static JSONArray getMultiStepFormFields(JSONObject jsonForm); static Map<String, String> sectionFields(JSONObject jsonForm); static JSONObject toJSONObject(String jsonString); static String getFieldValue(JSONArray jsonArray, FormEntityConstants.Person person); static String getFieldValue(JSONArray jsonArray, FormEntityConstants.Encounter encounter); static String getFieldValue(String jsonString, String key); @Nullable static JSONObject getFieldJSONObject(JSONArray jsonArray, String key); @Nullable static String value(JSONArray jsonArray, String entity, String entityId); @Nullable static String getFieldValue(JSONArray jsonArray, String key); @Nullable static JSONObject getJSONObject(JSONArray jsonArray, int index); @Nullable static JSONArray getJSONArray(JSONObject jsonObject, String field); static JSONObject getJSONObject(JSONObject jsonObject, String field); static String getString(JSONObject jsonObject, String field); static String getString(String jsonString, String field); static Long getLong(JSONObject jsonObject, String field); static Date formatDate(String dateString, boolean startOfToday); static String generateRandomUUIDString(); static void addToJSONObject(JSONObject jsonObject, String key, String value); static String formatDate(String date); static JSONObject merge(JSONObject original, JSONObject updated); static String[] getNames(JSONObject jo); static String convertToOpenMRSDate(String value); static boolean isBlankJsonArray(JSONArray jsonArray); static boolean isBlankJsonObject(JSONObject jsonObject); }
JsonFormUtils { public static void fillSubFormAttributes(Map<String, Object> pattributes, JSONObject jsonObject, String bindType) { String value = getString(jsonObject, VALUE); if (StringUtils.isBlank(value)) { return; } String bind = getString(jsonObject, ENTITY_ID); if (bind == null || !bind.equals(bindType)) { return; } String entity = PERSON_ATTRIBUTE; String entityVal = getString(jsonObject, OPENMRS_ENTITY); if (entityVal != null && entityVal.equals(entity)) { String entityIdVal = getString(jsonObject, OPENMRS_ENTITY_ID); pattributes.put(entityIdVal, value); } } static Client createBaseClient(JSONArray fields, FormTag formTag, String entityId); static Event createEvent(JSONArray fields, JSONObject metadata, FormTag formTag, String entityId, String encounterType, String bindType); static void addObservation(Event e, JSONObject jsonObject); static Map<String, String> extractIdentifiers(JSONArray fields); static Map<String, Object> extractAttributes(JSONArray fields); static Map<String, Address> extractAddresses(JSONArray fields); static void fillIdentifiers(Map<String, String> pids, JSONObject jsonObject); static void fillAttributes(Map<String, Object> pattributes, JSONObject jsonObject); static void fillAddressFields(JSONObject jsonObject, Map<String, Address> addresses); static Map<String, String> extractIdentifiers(JSONArray fields, String bindType); static Map<String, Object> extractAttributes(JSONArray fields, String bindType); static Map<String, Address> extractAddresses(JSONArray fields, String bindType); static String getSubFormFieldValue(JSONArray jsonArray, FormEntityConstants.Person person, String bindType); static void fillSubFormIdentifiers(Map<String, String> pids, JSONObject jsonObject, String bindType); static void fillSubFormAttributes(Map<String, Object> pattributes, JSONObject jsonObject, String bindType); static void fillSubFormAddressFields(JSONObject jsonObject, Map<String, Address> addresses, String bindType); static JSONArray getSingleStepFormfields(JSONObject jsonForm); static JSONArray fields(JSONObject jsonForm); static JSONArray getMultiStepFormFields(JSONObject jsonForm); static Map<String, String> sectionFields(JSONObject jsonForm); static JSONObject toJSONObject(String jsonString); static String getFieldValue(JSONArray jsonArray, FormEntityConstants.Person person); static String getFieldValue(JSONArray jsonArray, FormEntityConstants.Encounter encounter); static String getFieldValue(String jsonString, String key); @Nullable static JSONObject getFieldJSONObject(JSONArray jsonArray, String key); @Nullable static String value(JSONArray jsonArray, String entity, String entityId); @Nullable static String getFieldValue(JSONArray jsonArray, String key); @Nullable static JSONObject getJSONObject(JSONArray jsonArray, int index); @Nullable static JSONArray getJSONArray(JSONObject jsonObject, String field); static JSONObject getJSONObject(JSONObject jsonObject, String field); static String getString(JSONObject jsonObject, String field); static String getString(String jsonString, String field); static Long getLong(JSONObject jsonObject, String field); static Date formatDate(String dateString, boolean startOfToday); static String generateRandomUUIDString(); static void addToJSONObject(JSONObject jsonObject, String key, String value); static String formatDate(String date); static JSONObject merge(JSONObject original, JSONObject updated); static String[] getNames(JSONObject jo); static String convertToOpenMRSDate(String value); static boolean isBlankJsonArray(JSONArray jsonArray); static boolean isBlankJsonObject(JSONObject jsonObject); static final String TAG; static final String OPENMRS_ENTITY; static final String OPENMRS_ENTITY_ID; static final String OPENMRS_ENTITY_PARENT; static final String OPENMRS_CHOICE_IDS; static final String OPENMRS_DATA_TYPE; static final String PERSON_ATTRIBUTE; static final String PERSON_INDENTIFIER; static final String PERSON_ADDRESS; static final String SIMPRINTS_GUID; static final String FINGERPRINT_KEY; static final String FINGERPRINT_OPTION; static final String FINGERPRINT_OPTION_REGISTER; static final String CONCEPT; static final String VALUE; static final String VALUES; static final String FIELDS; static final String KEY; static final String ENTITY_ID; static final String STEP1; static final String SECTIONS; static final String attributes; static final String ENCOUNTER; static final String ENCOUNTER_LOCATION; static final String SAVE_OBS_AS_ARRAY; static final String SAVE_ALL_CHECKBOX_OBS_AS_ARRAY; static final SimpleDateFormat dd_MM_yyyy; static Gson gson; }
@Test public void testOnFlingProcessorSetsAppBarLayoutExpandedToFalseWhenYTranlationLessThanSwipeOffMinPath() { Mockito.doReturn(100f).when(motionEvent1).getY(); Mockito.doReturn(550f).when(motionEvent2).getY(); Mockito.doReturn(baseProfileActivity).when(baseProfileFragment).getActivity(); Mockito.doReturn(appBarLayout).when(baseProfileActivity).getProfileAppBarLayout(); Boolean result = baseProfileFragment.onFlingProcessor(motionEvent1, motionEvent2, 350.0f); Assert.assertNotNull(result); Assert.assertFalse(result); Mockito.verify(appBarLayout).setExpanded(appBarLayoutExpandedArgumentCaptor.capture(), appBarLayoutAnimateArgumentCaptor.capture()); Boolean isExpanded = appBarLayoutExpandedArgumentCaptor.getValue(); Assert.assertNotNull(isExpanded); Assert.assertTrue(isExpanded); }
@VisibleForTesting protected boolean onFlingProcessor(MotionEvent event, MotionEvent event2, float velocityY) { final int SWIPE_MIN_DISTANCE = 120; final int SWIPE_MAX_OFF_PATH = 300; final int SWIPE_THRESHOLD_VELOCITY = 200; try { if (Math.abs(event.getX() - event2.getX()) > SWIPE_MAX_OFF_PATH) { return true; } if (event.getY() - event2.getY() > SWIPE_MIN_DISTANCE && Math.abs(velocityY) > SWIPE_THRESHOLD_VELOCITY) { ((BaseProfileActivity) getActivity()).getProfileAppBarLayout().setExpanded(false, true); } else if (event2.getY() - event.getY() > SWIPE_MIN_DISTANCE && Math.abs(velocityY) > SWIPE_THRESHOLD_VELOCITY) { ((BaseProfileActivity) getActivity()).getProfileAppBarLayout().setExpanded(true, true); } } catch (Exception e) { } return false; }
BaseProfileFragment extends SecuredFragment implements View.OnTouchListener { @VisibleForTesting protected boolean onFlingProcessor(MotionEvent event, MotionEvent event2, float velocityY) { final int SWIPE_MIN_DISTANCE = 120; final int SWIPE_MAX_OFF_PATH = 300; final int SWIPE_THRESHOLD_VELOCITY = 200; try { if (Math.abs(event.getX() - event2.getX()) > SWIPE_MAX_OFF_PATH) { return true; } if (event.getY() - event2.getY() > SWIPE_MIN_DISTANCE && Math.abs(velocityY) > SWIPE_THRESHOLD_VELOCITY) { ((BaseProfileActivity) getActivity()).getProfileAppBarLayout().setExpanded(false, true); } else if (event2.getY() - event.getY() > SWIPE_MIN_DISTANCE && Math.abs(velocityY) > SWIPE_THRESHOLD_VELOCITY) { ((BaseProfileActivity) getActivity()).getProfileAppBarLayout().setExpanded(true, true); } } catch (Exception e) { } return false; } }
BaseProfileFragment extends SecuredFragment implements View.OnTouchListener { @VisibleForTesting protected boolean onFlingProcessor(MotionEvent event, MotionEvent event2, float velocityY) { final int SWIPE_MIN_DISTANCE = 120; final int SWIPE_MAX_OFF_PATH = 300; final int SWIPE_THRESHOLD_VELOCITY = 200; try { if (Math.abs(event.getX() - event2.getX()) > SWIPE_MAX_OFF_PATH) { return true; } if (event.getY() - event2.getY() > SWIPE_MIN_DISTANCE && Math.abs(velocityY) > SWIPE_THRESHOLD_VELOCITY) { ((BaseProfileActivity) getActivity()).getProfileAppBarLayout().setExpanded(false, true); } else if (event2.getY() - event.getY() > SWIPE_MIN_DISTANCE && Math.abs(velocityY) > SWIPE_THRESHOLD_VELOCITY) { ((BaseProfileActivity) getActivity()).getProfileAppBarLayout().setExpanded(true, true); } } catch (Exception e) { } return false; } }
BaseProfileFragment extends SecuredFragment implements View.OnTouchListener { @VisibleForTesting protected boolean onFlingProcessor(MotionEvent event, MotionEvent event2, float velocityY) { final int SWIPE_MIN_DISTANCE = 120; final int SWIPE_MAX_OFF_PATH = 300; final int SWIPE_THRESHOLD_VELOCITY = 200; try { if (Math.abs(event.getX() - event2.getX()) > SWIPE_MAX_OFF_PATH) { return true; } if (event.getY() - event2.getY() > SWIPE_MIN_DISTANCE && Math.abs(velocityY) > SWIPE_THRESHOLD_VELOCITY) { ((BaseProfileActivity) getActivity()).getProfileAppBarLayout().setExpanded(false, true); } else if (event2.getY() - event.getY() > SWIPE_MIN_DISTANCE && Math.abs(velocityY) > SWIPE_THRESHOLD_VELOCITY) { ((BaseProfileActivity) getActivity()).getProfileAppBarLayout().setExpanded(true, true); } } catch (Exception e) { } return false; } @Override void onViewCreated(View view, Bundle savedInstanceState); @Override boolean onTouch(View view, MotionEvent event); }
BaseProfileFragment extends SecuredFragment implements View.OnTouchListener { @VisibleForTesting protected boolean onFlingProcessor(MotionEvent event, MotionEvent event2, float velocityY) { final int SWIPE_MIN_DISTANCE = 120; final int SWIPE_MAX_OFF_PATH = 300; final int SWIPE_THRESHOLD_VELOCITY = 200; try { if (Math.abs(event.getX() - event2.getX()) > SWIPE_MAX_OFF_PATH) { return true; } if (event.getY() - event2.getY() > SWIPE_MIN_DISTANCE && Math.abs(velocityY) > SWIPE_THRESHOLD_VELOCITY) { ((BaseProfileActivity) getActivity()).getProfileAppBarLayout().setExpanded(false, true); } else if (event2.getY() - event.getY() > SWIPE_MIN_DISTANCE && Math.abs(velocityY) > SWIPE_THRESHOLD_VELOCITY) { ((BaseProfileActivity) getActivity()).getProfileAppBarLayout().setExpanded(true, true); } } catch (Exception e) { } return false; } @Override void onViewCreated(View view, Bundle savedInstanceState); @Override boolean onTouch(View view, MotionEvent event); }
@Test public void assertGetNavBarOptionsProviderNotNull() { SecuredNativeSmartRegisterActivity.NavBarOptionsProvider provider = baseRegisterFragment.getNavBarOptionsProvider(); Assert.assertNotNull(provider); }
@Override protected SecuredNativeSmartRegisterActivity.NavBarOptionsProvider getNavBarOptionsProvider() { return new SecuredNativeSmartRegisterActivity.NavBarOptionsProvider() { @Override public DialogOption[] filterOptions() { return new DialogOption[]{}; } @Override public DialogOption[] serviceModeOptions() { return new DialogOption[]{ }; } @Override public DialogOption[] sortingOptions() { return new DialogOption[]{ }; } @Override public String searchHint() { return context().getStringResource(R.string.search_hint); } }; }
BaseRegisterFragment extends RecyclerViewFragment implements BaseRegisterFragmentContract.View, SyncStatusBroadcastReceiver.SyncStatusListener { @Override protected SecuredNativeSmartRegisterActivity.NavBarOptionsProvider getNavBarOptionsProvider() { return new SecuredNativeSmartRegisterActivity.NavBarOptionsProvider() { @Override public DialogOption[] filterOptions() { return new DialogOption[]{}; } @Override public DialogOption[] serviceModeOptions() { return new DialogOption[]{ }; } @Override public DialogOption[] sortingOptions() { return new DialogOption[]{ }; } @Override public String searchHint() { return context().getStringResource(R.string.search_hint); } }; } }
BaseRegisterFragment extends RecyclerViewFragment implements BaseRegisterFragmentContract.View, SyncStatusBroadcastReceiver.SyncStatusListener { @Override protected SecuredNativeSmartRegisterActivity.NavBarOptionsProvider getNavBarOptionsProvider() { return new SecuredNativeSmartRegisterActivity.NavBarOptionsProvider() { @Override public DialogOption[] filterOptions() { return new DialogOption[]{}; } @Override public DialogOption[] serviceModeOptions() { return new DialogOption[]{ }; } @Override public DialogOption[] sortingOptions() { return new DialogOption[]{ }; } @Override public String searchHint() { return context().getStringResource(R.string.search_hint); } }; } }
BaseRegisterFragment extends RecyclerViewFragment implements BaseRegisterFragmentContract.View, SyncStatusBroadcastReceiver.SyncStatusListener { @Override protected SecuredNativeSmartRegisterActivity.NavBarOptionsProvider getNavBarOptionsProvider() { return new SecuredNativeSmartRegisterActivity.NavBarOptionsProvider() { @Override public DialogOption[] filterOptions() { return new DialogOption[]{}; } @Override public DialogOption[] serviceModeOptions() { return new DialogOption[]{ }; } @Override public DialogOption[] sortingOptions() { return new DialogOption[]{ }; } @Override public String searchHint() { return context().getStringResource(R.string.search_hint); } }; } @Nullable @Override View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState); @Override void updateSearchBarHint(String searchBarText); void setSearchTerm(String searchText); void onQRCodeSucessfullyScanned(String qrCode); abstract void setUniqueID(String qrCode); abstract void setAdvancedSearchFormData(HashMap<String, String> advancedSearchFormData); @Override void setupViews(View view); @Override void setTotalPatients(); @Override void initializeQueryParams(String tableName, String countSelect, String mainSelect); void filter(String filterString, String joinTableString, String mainConditionString, boolean qrCode); @Override void updateFilterAndFilterStatus(String filterText, String sortText); boolean onBackPressed(); @Override void onSyncInProgress(FetchStatus fetchStatus); @Override void onSyncStart(); @Override void onSyncComplete(FetchStatus fetchStatus); @Override void onResume(); @Override void onPause(); }
BaseRegisterFragment extends RecyclerViewFragment implements BaseRegisterFragmentContract.View, SyncStatusBroadcastReceiver.SyncStatusListener { @Override protected SecuredNativeSmartRegisterActivity.NavBarOptionsProvider getNavBarOptionsProvider() { return new SecuredNativeSmartRegisterActivity.NavBarOptionsProvider() { @Override public DialogOption[] filterOptions() { return new DialogOption[]{}; } @Override public DialogOption[] serviceModeOptions() { return new DialogOption[]{ }; } @Override public DialogOption[] sortingOptions() { return new DialogOption[]{ }; } @Override public String searchHint() { return context().getStringResource(R.string.search_hint); } }; } @Nullable @Override View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState); @Override void updateSearchBarHint(String searchBarText); void setSearchTerm(String searchText); void onQRCodeSucessfullyScanned(String qrCode); abstract void setUniqueID(String qrCode); abstract void setAdvancedSearchFormData(HashMap<String, String> advancedSearchFormData); @Override void setupViews(View view); @Override void setTotalPatients(); @Override void initializeQueryParams(String tableName, String countSelect, String mainSelect); void filter(String filterString, String joinTableString, String mainConditionString, boolean qrCode); @Override void updateFilterAndFilterStatus(String filterText, String sortText); boolean onBackPressed(); @Override void onSyncInProgress(FetchStatus fetchStatus); @Override void onSyncStart(); @Override void onSyncComplete(FetchStatus fetchStatus); @Override void onResume(); @Override void onPause(); static String TOOLBAR_TITLE; }
@Test public void assertGetNavBarOptionsProviderReturnsCorrectValueFormSearchHint() { SecuredNativeSmartRegisterActivity.NavBarOptionsProvider provider = baseRegisterFragment.getNavBarOptionsProvider(); Mockito.doReturn(opensrpContext).when(baseRegisterFragment).context(); Mockito.doReturn(RuntimeEnvironment.application.getResources().getString(R.string.search_hint)).when(opensrpContext).getStringResource(R.string.search_hint); String hint = RuntimeEnvironment.application.getResources().getString(R.string.search_hint); Assert.assertEquals(hint, provider.searchHint()); }
@Override protected SecuredNativeSmartRegisterActivity.NavBarOptionsProvider getNavBarOptionsProvider() { return new SecuredNativeSmartRegisterActivity.NavBarOptionsProvider() { @Override public DialogOption[] filterOptions() { return new DialogOption[]{}; } @Override public DialogOption[] serviceModeOptions() { return new DialogOption[]{ }; } @Override public DialogOption[] sortingOptions() { return new DialogOption[]{ }; } @Override public String searchHint() { return context().getStringResource(R.string.search_hint); } }; }
BaseRegisterFragment extends RecyclerViewFragment implements BaseRegisterFragmentContract.View, SyncStatusBroadcastReceiver.SyncStatusListener { @Override protected SecuredNativeSmartRegisterActivity.NavBarOptionsProvider getNavBarOptionsProvider() { return new SecuredNativeSmartRegisterActivity.NavBarOptionsProvider() { @Override public DialogOption[] filterOptions() { return new DialogOption[]{}; } @Override public DialogOption[] serviceModeOptions() { return new DialogOption[]{ }; } @Override public DialogOption[] sortingOptions() { return new DialogOption[]{ }; } @Override public String searchHint() { return context().getStringResource(R.string.search_hint); } }; } }
BaseRegisterFragment extends RecyclerViewFragment implements BaseRegisterFragmentContract.View, SyncStatusBroadcastReceiver.SyncStatusListener { @Override protected SecuredNativeSmartRegisterActivity.NavBarOptionsProvider getNavBarOptionsProvider() { return new SecuredNativeSmartRegisterActivity.NavBarOptionsProvider() { @Override public DialogOption[] filterOptions() { return new DialogOption[]{}; } @Override public DialogOption[] serviceModeOptions() { return new DialogOption[]{ }; } @Override public DialogOption[] sortingOptions() { return new DialogOption[]{ }; } @Override public String searchHint() { return context().getStringResource(R.string.search_hint); } }; } }
BaseRegisterFragment extends RecyclerViewFragment implements BaseRegisterFragmentContract.View, SyncStatusBroadcastReceiver.SyncStatusListener { @Override protected SecuredNativeSmartRegisterActivity.NavBarOptionsProvider getNavBarOptionsProvider() { return new SecuredNativeSmartRegisterActivity.NavBarOptionsProvider() { @Override public DialogOption[] filterOptions() { return new DialogOption[]{}; } @Override public DialogOption[] serviceModeOptions() { return new DialogOption[]{ }; } @Override public DialogOption[] sortingOptions() { return new DialogOption[]{ }; } @Override public String searchHint() { return context().getStringResource(R.string.search_hint); } }; } @Nullable @Override View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState); @Override void updateSearchBarHint(String searchBarText); void setSearchTerm(String searchText); void onQRCodeSucessfullyScanned(String qrCode); abstract void setUniqueID(String qrCode); abstract void setAdvancedSearchFormData(HashMap<String, String> advancedSearchFormData); @Override void setupViews(View view); @Override void setTotalPatients(); @Override void initializeQueryParams(String tableName, String countSelect, String mainSelect); void filter(String filterString, String joinTableString, String mainConditionString, boolean qrCode); @Override void updateFilterAndFilterStatus(String filterText, String sortText); boolean onBackPressed(); @Override void onSyncInProgress(FetchStatus fetchStatus); @Override void onSyncStart(); @Override void onSyncComplete(FetchStatus fetchStatus); @Override void onResume(); @Override void onPause(); }
BaseRegisterFragment extends RecyclerViewFragment implements BaseRegisterFragmentContract.View, SyncStatusBroadcastReceiver.SyncStatusListener { @Override protected SecuredNativeSmartRegisterActivity.NavBarOptionsProvider getNavBarOptionsProvider() { return new SecuredNativeSmartRegisterActivity.NavBarOptionsProvider() { @Override public DialogOption[] filterOptions() { return new DialogOption[]{}; } @Override public DialogOption[] serviceModeOptions() { return new DialogOption[]{ }; } @Override public DialogOption[] sortingOptions() { return new DialogOption[]{ }; } @Override public String searchHint() { return context().getStringResource(R.string.search_hint); } }; } @Nullable @Override View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState); @Override void updateSearchBarHint(String searchBarText); void setSearchTerm(String searchText); void onQRCodeSucessfullyScanned(String qrCode); abstract void setUniqueID(String qrCode); abstract void setAdvancedSearchFormData(HashMap<String, String> advancedSearchFormData); @Override void setupViews(View view); @Override void setTotalPatients(); @Override void initializeQueryParams(String tableName, String countSelect, String mainSelect); void filter(String filterString, String joinTableString, String mainConditionString, boolean qrCode); @Override void updateFilterAndFilterStatus(String filterText, String sortText); boolean onBackPressed(); @Override void onSyncInProgress(FetchStatus fetchStatus); @Override void onSyncStart(); @Override void onSyncComplete(FetchStatus fetchStatus); @Override void onResume(); @Override void onPause(); static String TOOLBAR_TITLE; }
@Test public void testOnCreateViewInitsToolbarConfigurationCorrectly() { View parentLayout = LayoutInflater.from(RuntimeEnvironment.application.getApplicationContext()).inflate(R.layout.fragment_base_register, null, false); Mockito.doReturn(parentLayout).when(layoutInflater).inflate(R.layout.fragment_base_register, container, false); Toolbar toolbar = parentLayout.findViewById(R.id.register_toolbar); AppCompatActivity activitySpy = Mockito.spy(activity); Mockito.doReturn(activitySpy).when(baseRegisterFragment).getActivity(); Mockito.doReturn(actionBar).when(activitySpy).getSupportActionBar(); baseRegisterFragment.onCreateView(layoutInflater, container, bundle); Mockito.verify(activitySpy).setSupportActionBar(toolbar); Mockito.verify(actionBar).setTitle(TEST_RANDOM_STRING); Mockito.verify(actionBar).setDisplayHomeAsUpEnabled(false); Mockito.verify(actionBar).setLogo(R.drawable.round_white_background); Mockito.verify(actionBar).setDisplayUseLogoEnabled(false); Mockito.verify(actionBar).setDisplayShowTitleEnabled(false); }
@Nullable @Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { View view = inflater.inflate(getLayout(), container, false); rootView = view; setUpActionBar(); setupViews(view); return view; }
BaseRegisterFragment extends RecyclerViewFragment implements BaseRegisterFragmentContract.View, SyncStatusBroadcastReceiver.SyncStatusListener { @Nullable @Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { View view = inflater.inflate(getLayout(), container, false); rootView = view; setUpActionBar(); setupViews(view); return view; } }
BaseRegisterFragment extends RecyclerViewFragment implements BaseRegisterFragmentContract.View, SyncStatusBroadcastReceiver.SyncStatusListener { @Nullable @Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { View view = inflater.inflate(getLayout(), container, false); rootView = view; setUpActionBar(); setupViews(view); return view; } }
BaseRegisterFragment extends RecyclerViewFragment implements BaseRegisterFragmentContract.View, SyncStatusBroadcastReceiver.SyncStatusListener { @Nullable @Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { View view = inflater.inflate(getLayout(), container, false); rootView = view; setUpActionBar(); setupViews(view); return view; } @Nullable @Override View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState); @Override void updateSearchBarHint(String searchBarText); void setSearchTerm(String searchText); void onQRCodeSucessfullyScanned(String qrCode); abstract void setUniqueID(String qrCode); abstract void setAdvancedSearchFormData(HashMap<String, String> advancedSearchFormData); @Override void setupViews(View view); @Override void setTotalPatients(); @Override void initializeQueryParams(String tableName, String countSelect, String mainSelect); void filter(String filterString, String joinTableString, String mainConditionString, boolean qrCode); @Override void updateFilterAndFilterStatus(String filterText, String sortText); boolean onBackPressed(); @Override void onSyncInProgress(FetchStatus fetchStatus); @Override void onSyncStart(); @Override void onSyncComplete(FetchStatus fetchStatus); @Override void onResume(); @Override void onPause(); }
BaseRegisterFragment extends RecyclerViewFragment implements BaseRegisterFragmentContract.View, SyncStatusBroadcastReceiver.SyncStatusListener { @Nullable @Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { View view = inflater.inflate(getLayout(), container, false); rootView = view; setUpActionBar(); setupViews(view); return view; } @Nullable @Override View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState); @Override void updateSearchBarHint(String searchBarText); void setSearchTerm(String searchText); void onQRCodeSucessfullyScanned(String qrCode); abstract void setUniqueID(String qrCode); abstract void setAdvancedSearchFormData(HashMap<String, String> advancedSearchFormData); @Override void setupViews(View view); @Override void setTotalPatients(); @Override void initializeQueryParams(String tableName, String countSelect, String mainSelect); void filter(String filterString, String joinTableString, String mainConditionString, boolean qrCode); @Override void updateFilterAndFilterStatus(String filterText, String sortText); boolean onBackPressed(); @Override void onSyncInProgress(FetchStatus fetchStatus); @Override void onSyncStart(); @Override void onSyncComplete(FetchStatus fetchStatus); @Override void onResume(); @Override void onPause(); static String TOOLBAR_TITLE; }
@Test public void assertGetLayoutReturnsCorrectLayout() { Assert.assertEquals(R.layout.fragment_base_register, baseRegisterFragment.getLayout()); }
@LayoutRes protected int getLayout() { return R.layout.fragment_base_register; }
BaseRegisterFragment extends RecyclerViewFragment implements BaseRegisterFragmentContract.View, SyncStatusBroadcastReceiver.SyncStatusListener { @LayoutRes protected int getLayout() { return R.layout.fragment_base_register; } }
BaseRegisterFragment extends RecyclerViewFragment implements BaseRegisterFragmentContract.View, SyncStatusBroadcastReceiver.SyncStatusListener { @LayoutRes protected int getLayout() { return R.layout.fragment_base_register; } }
BaseRegisterFragment extends RecyclerViewFragment implements BaseRegisterFragmentContract.View, SyncStatusBroadcastReceiver.SyncStatusListener { @LayoutRes protected int getLayout() { return R.layout.fragment_base_register; } @Nullable @Override View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState); @Override void updateSearchBarHint(String searchBarText); void setSearchTerm(String searchText); void onQRCodeSucessfullyScanned(String qrCode); abstract void setUniqueID(String qrCode); abstract void setAdvancedSearchFormData(HashMap<String, String> advancedSearchFormData); @Override void setupViews(View view); @Override void setTotalPatients(); @Override void initializeQueryParams(String tableName, String countSelect, String mainSelect); void filter(String filterString, String joinTableString, String mainConditionString, boolean qrCode); @Override void updateFilterAndFilterStatus(String filterText, String sortText); boolean onBackPressed(); @Override void onSyncInProgress(FetchStatus fetchStatus); @Override void onSyncStart(); @Override void onSyncComplete(FetchStatus fetchStatus); @Override void onResume(); @Override void onPause(); }
BaseRegisterFragment extends RecyclerViewFragment implements BaseRegisterFragmentContract.View, SyncStatusBroadcastReceiver.SyncStatusListener { @LayoutRes protected int getLayout() { return R.layout.fragment_base_register; } @Nullable @Override View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState); @Override void updateSearchBarHint(String searchBarText); void setSearchTerm(String searchText); void onQRCodeSucessfullyScanned(String qrCode); abstract void setUniqueID(String qrCode); abstract void setAdvancedSearchFormData(HashMap<String, String> advancedSearchFormData); @Override void setupViews(View view); @Override void setTotalPatients(); @Override void initializeQueryParams(String tableName, String countSelect, String mainSelect); void filter(String filterString, String joinTableString, String mainConditionString, boolean qrCode); @Override void updateFilterAndFilterStatus(String filterText, String sortText); boolean onBackPressed(); @Override void onSyncInProgress(FetchStatus fetchStatus); @Override void onSyncStart(); @Override void onSyncComplete(FetchStatus fetchStatus); @Override void onResume(); @Override void onPause(); static String TOOLBAR_TITLE; }
@Test public void assertUpdateSearchViewAddsCorrectListenersToSearchView() { Mockito.doReturn(searchView).when(baseRegisterFragment).getSearchView(); ReflectionHelpers.setField(baseRegisterFragment, "textWatcher", textWatcher); ReflectionHelpers.setField(baseRegisterFragment, "hideKeyboard", hideKeyboard); baseRegisterFragment.updateSearchView(); Mockito.verify(searchView).removeTextChangedListener(textWatcher); Mockito.verify(searchView).addTextChangedListener(textWatcher); Mockito.verify(searchView).setOnKeyListener(hideKeyboard); }
protected void updateSearchView() { if (getSearchView() != null) { getSearchView().removeTextChangedListener(textWatcher); getSearchView().addTextChangedListener(textWatcher); getSearchView().setOnKeyListener(hideKeyboard); } }
BaseRegisterFragment extends RecyclerViewFragment implements BaseRegisterFragmentContract.View, SyncStatusBroadcastReceiver.SyncStatusListener { protected void updateSearchView() { if (getSearchView() != null) { getSearchView().removeTextChangedListener(textWatcher); getSearchView().addTextChangedListener(textWatcher); getSearchView().setOnKeyListener(hideKeyboard); } } }
BaseRegisterFragment extends RecyclerViewFragment implements BaseRegisterFragmentContract.View, SyncStatusBroadcastReceiver.SyncStatusListener { protected void updateSearchView() { if (getSearchView() != null) { getSearchView().removeTextChangedListener(textWatcher); getSearchView().addTextChangedListener(textWatcher); getSearchView().setOnKeyListener(hideKeyboard); } } }
BaseRegisterFragment extends RecyclerViewFragment implements BaseRegisterFragmentContract.View, SyncStatusBroadcastReceiver.SyncStatusListener { protected void updateSearchView() { if (getSearchView() != null) { getSearchView().removeTextChangedListener(textWatcher); getSearchView().addTextChangedListener(textWatcher); getSearchView().setOnKeyListener(hideKeyboard); } } @Nullable @Override View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState); @Override void updateSearchBarHint(String searchBarText); void setSearchTerm(String searchText); void onQRCodeSucessfullyScanned(String qrCode); abstract void setUniqueID(String qrCode); abstract void setAdvancedSearchFormData(HashMap<String, String> advancedSearchFormData); @Override void setupViews(View view); @Override void setTotalPatients(); @Override void initializeQueryParams(String tableName, String countSelect, String mainSelect); void filter(String filterString, String joinTableString, String mainConditionString, boolean qrCode); @Override void updateFilterAndFilterStatus(String filterText, String sortText); boolean onBackPressed(); @Override void onSyncInProgress(FetchStatus fetchStatus); @Override void onSyncStart(); @Override void onSyncComplete(FetchStatus fetchStatus); @Override void onResume(); @Override void onPause(); }
BaseRegisterFragment extends RecyclerViewFragment implements BaseRegisterFragmentContract.View, SyncStatusBroadcastReceiver.SyncStatusListener { protected void updateSearchView() { if (getSearchView() != null) { getSearchView().removeTextChangedListener(textWatcher); getSearchView().addTextChangedListener(textWatcher); getSearchView().setOnKeyListener(hideKeyboard); } } @Nullable @Override View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState); @Override void updateSearchBarHint(String searchBarText); void setSearchTerm(String searchText); void onQRCodeSucessfullyScanned(String qrCode); abstract void setUniqueID(String qrCode); abstract void setAdvancedSearchFormData(HashMap<String, String> advancedSearchFormData); @Override void setupViews(View view); @Override void setTotalPatients(); @Override void initializeQueryParams(String tableName, String countSelect, String mainSelect); void filter(String filterString, String joinTableString, String mainConditionString, boolean qrCode); @Override void updateFilterAndFilterStatus(String filterText, String sortText); boolean onBackPressed(); @Override void onSyncInProgress(FetchStatus fetchStatus); @Override void onSyncStart(); @Override void onSyncComplete(FetchStatus fetchStatus); @Override void onResume(); @Override void onPause(); static String TOOLBAR_TITLE; }
@Test public void assertUpdateSearchBarHintSetsCorrectValue() { Mockito.doReturn(searchView).when(baseRegisterFragment).getSearchView(); baseRegisterFragment.updateSearchBarHint(TEST_RANDOM_STRING); Mockito.verify(searchView).setHint(TEST_RANDOM_STRING); }
@Override public void updateSearchBarHint(String searchBarText) { if (getSearchView() != null) { getSearchView().setHint(searchBarText); } }
BaseRegisterFragment extends RecyclerViewFragment implements BaseRegisterFragmentContract.View, SyncStatusBroadcastReceiver.SyncStatusListener { @Override public void updateSearchBarHint(String searchBarText) { if (getSearchView() != null) { getSearchView().setHint(searchBarText); } } }
BaseRegisterFragment extends RecyclerViewFragment implements BaseRegisterFragmentContract.View, SyncStatusBroadcastReceiver.SyncStatusListener { @Override public void updateSearchBarHint(String searchBarText) { if (getSearchView() != null) { getSearchView().setHint(searchBarText); } } }
BaseRegisterFragment extends RecyclerViewFragment implements BaseRegisterFragmentContract.View, SyncStatusBroadcastReceiver.SyncStatusListener { @Override public void updateSearchBarHint(String searchBarText) { if (getSearchView() != null) { getSearchView().setHint(searchBarText); } } @Nullable @Override View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState); @Override void updateSearchBarHint(String searchBarText); void setSearchTerm(String searchText); void onQRCodeSucessfullyScanned(String qrCode); abstract void setUniqueID(String qrCode); abstract void setAdvancedSearchFormData(HashMap<String, String> advancedSearchFormData); @Override void setupViews(View view); @Override void setTotalPatients(); @Override void initializeQueryParams(String tableName, String countSelect, String mainSelect); void filter(String filterString, String joinTableString, String mainConditionString, boolean qrCode); @Override void updateFilterAndFilterStatus(String filterText, String sortText); boolean onBackPressed(); @Override void onSyncInProgress(FetchStatus fetchStatus); @Override void onSyncStart(); @Override void onSyncComplete(FetchStatus fetchStatus); @Override void onResume(); @Override void onPause(); }
BaseRegisterFragment extends RecyclerViewFragment implements BaseRegisterFragmentContract.View, SyncStatusBroadcastReceiver.SyncStatusListener { @Override public void updateSearchBarHint(String searchBarText) { if (getSearchView() != null) { getSearchView().setHint(searchBarText); } } @Nullable @Override View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState); @Override void updateSearchBarHint(String searchBarText); void setSearchTerm(String searchText); void onQRCodeSucessfullyScanned(String qrCode); abstract void setUniqueID(String qrCode); abstract void setAdvancedSearchFormData(HashMap<String, String> advancedSearchFormData); @Override void setupViews(View view); @Override void setTotalPatients(); @Override void initializeQueryParams(String tableName, String countSelect, String mainSelect); void filter(String filterString, String joinTableString, String mainConditionString, boolean qrCode); @Override void updateFilterAndFilterStatus(String filterText, String sortText); boolean onBackPressed(); @Override void onSyncInProgress(FetchStatus fetchStatus); @Override void onSyncStart(); @Override void onSyncComplete(FetchStatus fetchStatus); @Override void onResume(); @Override void onPause(); static String TOOLBAR_TITLE; }
@Test public void setSearchTermInitsCorrectValue() { Mockito.doReturn(searchView).when(baseRegisterFragment).getSearchView(); baseRegisterFragment.setSearchTerm(TEST_RANDOM_STRING); Mockito.verify(searchView).setText(TEST_RANDOM_STRING); }
public void setSearchTerm(String searchText) { if (getSearchView() != null) { getSearchView().setText(searchText); } }
BaseRegisterFragment extends RecyclerViewFragment implements BaseRegisterFragmentContract.View, SyncStatusBroadcastReceiver.SyncStatusListener { public void setSearchTerm(String searchText) { if (getSearchView() != null) { getSearchView().setText(searchText); } } }
BaseRegisterFragment extends RecyclerViewFragment implements BaseRegisterFragmentContract.View, SyncStatusBroadcastReceiver.SyncStatusListener { public void setSearchTerm(String searchText) { if (getSearchView() != null) { getSearchView().setText(searchText); } } }
BaseRegisterFragment extends RecyclerViewFragment implements BaseRegisterFragmentContract.View, SyncStatusBroadcastReceiver.SyncStatusListener { public void setSearchTerm(String searchText) { if (getSearchView() != null) { getSearchView().setText(searchText); } } @Nullable @Override View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState); @Override void updateSearchBarHint(String searchBarText); void setSearchTerm(String searchText); void onQRCodeSucessfullyScanned(String qrCode); abstract void setUniqueID(String qrCode); abstract void setAdvancedSearchFormData(HashMap<String, String> advancedSearchFormData); @Override void setupViews(View view); @Override void setTotalPatients(); @Override void initializeQueryParams(String tableName, String countSelect, String mainSelect); void filter(String filterString, String joinTableString, String mainConditionString, boolean qrCode); @Override void updateFilterAndFilterStatus(String filterText, String sortText); boolean onBackPressed(); @Override void onSyncInProgress(FetchStatus fetchStatus); @Override void onSyncStart(); @Override void onSyncComplete(FetchStatus fetchStatus); @Override void onResume(); @Override void onPause(); }
BaseRegisterFragment extends RecyclerViewFragment implements BaseRegisterFragmentContract.View, SyncStatusBroadcastReceiver.SyncStatusListener { public void setSearchTerm(String searchText) { if (getSearchView() != null) { getSearchView().setText(searchText); } } @Nullable @Override View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState); @Override void updateSearchBarHint(String searchBarText); void setSearchTerm(String searchText); void onQRCodeSucessfullyScanned(String qrCode); abstract void setUniqueID(String qrCode); abstract void setAdvancedSearchFormData(HashMap<String, String> advancedSearchFormData); @Override void setupViews(View view); @Override void setTotalPatients(); @Override void initializeQueryParams(String tableName, String countSelect, String mainSelect); void filter(String filterString, String joinTableString, String mainConditionString, boolean qrCode); @Override void updateFilterAndFilterStatus(String filterText, String sortText); boolean onBackPressed(); @Override void onSyncInProgress(FetchStatus fetchStatus); @Override void onSyncStart(); @Override void onSyncComplete(FetchStatus fetchStatus); @Override void onResume(); @Override void onPause(); static String TOOLBAR_TITLE; }
@Test public void testSetTotalPatientsSetsCorrectHeaderTextForDisplay() { Mockito.doReturn(activity).when(baseRegisterFragment).getActivity(); Mockito.doReturn(5).when(clientAdapter).getTotalcount(); baseRegisterFragment.setTotalPatients(); Mockito.verify(headerTextDisplay).setText(stringArgumentCaptor.capture()); String capturedHeaderText = stringArgumentCaptor.getValue(); Assert.assertEquals("5 Clients", capturedHeaderText); Mockito.doReturn(1).when(clientAdapter).getTotalcount(); baseRegisterFragment.setTotalPatients(); Mockito.verify(headerTextDisplay, Mockito.times(2)).setText(stringArgumentCaptor.capture()); capturedHeaderText = stringArgumentCaptor.getValue(); Assert.assertEquals("1 Client", capturedHeaderText); }
@Override public void setTotalPatients() { if (headerTextDisplay != null) { headerTextDisplay.setText(clientAdapter.getTotalcount() > 1 ? String.format(getActivity().getString(R.string.clients), clientAdapter.getTotalcount()) : String.format(getActivity().getString(R.string.client), clientAdapter.getTotalcount())); filterRelativeLayout.setVisibility(View.GONE); } }
BaseRegisterFragment extends RecyclerViewFragment implements BaseRegisterFragmentContract.View, SyncStatusBroadcastReceiver.SyncStatusListener { @Override public void setTotalPatients() { if (headerTextDisplay != null) { headerTextDisplay.setText(clientAdapter.getTotalcount() > 1 ? String.format(getActivity().getString(R.string.clients), clientAdapter.getTotalcount()) : String.format(getActivity().getString(R.string.client), clientAdapter.getTotalcount())); filterRelativeLayout.setVisibility(View.GONE); } } }
BaseRegisterFragment extends RecyclerViewFragment implements BaseRegisterFragmentContract.View, SyncStatusBroadcastReceiver.SyncStatusListener { @Override public void setTotalPatients() { if (headerTextDisplay != null) { headerTextDisplay.setText(clientAdapter.getTotalcount() > 1 ? String.format(getActivity().getString(R.string.clients), clientAdapter.getTotalcount()) : String.format(getActivity().getString(R.string.client), clientAdapter.getTotalcount())); filterRelativeLayout.setVisibility(View.GONE); } } }
BaseRegisterFragment extends RecyclerViewFragment implements BaseRegisterFragmentContract.View, SyncStatusBroadcastReceiver.SyncStatusListener { @Override public void setTotalPatients() { if (headerTextDisplay != null) { headerTextDisplay.setText(clientAdapter.getTotalcount() > 1 ? String.format(getActivity().getString(R.string.clients), clientAdapter.getTotalcount()) : String.format(getActivity().getString(R.string.client), clientAdapter.getTotalcount())); filterRelativeLayout.setVisibility(View.GONE); } } @Nullable @Override View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState); @Override void updateSearchBarHint(String searchBarText); void setSearchTerm(String searchText); void onQRCodeSucessfullyScanned(String qrCode); abstract void setUniqueID(String qrCode); abstract void setAdvancedSearchFormData(HashMap<String, String> advancedSearchFormData); @Override void setupViews(View view); @Override void setTotalPatients(); @Override void initializeQueryParams(String tableName, String countSelect, String mainSelect); void filter(String filterString, String joinTableString, String mainConditionString, boolean qrCode); @Override void updateFilterAndFilterStatus(String filterText, String sortText); boolean onBackPressed(); @Override void onSyncInProgress(FetchStatus fetchStatus); @Override void onSyncStart(); @Override void onSyncComplete(FetchStatus fetchStatus); @Override void onResume(); @Override void onPause(); }
BaseRegisterFragment extends RecyclerViewFragment implements BaseRegisterFragmentContract.View, SyncStatusBroadcastReceiver.SyncStatusListener { @Override public void setTotalPatients() { if (headerTextDisplay != null) { headerTextDisplay.setText(clientAdapter.getTotalcount() > 1 ? String.format(getActivity().getString(R.string.clients), clientAdapter.getTotalcount()) : String.format(getActivity().getString(R.string.client), clientAdapter.getTotalcount())); filterRelativeLayout.setVisibility(View.GONE); } } @Nullable @Override View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState); @Override void updateSearchBarHint(String searchBarText); void setSearchTerm(String searchText); void onQRCodeSucessfullyScanned(String qrCode); abstract void setUniqueID(String qrCode); abstract void setAdvancedSearchFormData(HashMap<String, String> advancedSearchFormData); @Override void setupViews(View view); @Override void setTotalPatients(); @Override void initializeQueryParams(String tableName, String countSelect, String mainSelect); void filter(String filterString, String joinTableString, String mainConditionString, boolean qrCode); @Override void updateFilterAndFilterStatus(String filterText, String sortText); boolean onBackPressed(); @Override void onSyncInProgress(FetchStatus fetchStatus); @Override void onSyncStart(); @Override void onSyncComplete(FetchStatus fetchStatus); @Override void onResume(); @Override void onPause(); static String TOOLBAR_TITLE; }
@Test public void testSetTotalPatientsHidesFilterRelativeLayoutView() { Mockito.doReturn(activity).when(baseRegisterFragment).getActivity(); Mockito.doReturn(5).when(clientAdapter).getTotalcount(); baseRegisterFragment.setTotalPatients(); Mockito.verify(filterRelativeLayout).setVisibility(intArgumentCaptor.capture()); int visibility = intArgumentCaptor.getValue(); Assert.assertEquals(View.GONE, visibility); }
@Override public void setTotalPatients() { if (headerTextDisplay != null) { headerTextDisplay.setText(clientAdapter.getTotalcount() > 1 ? String.format(getActivity().getString(R.string.clients), clientAdapter.getTotalcount()) : String.format(getActivity().getString(R.string.client), clientAdapter.getTotalcount())); filterRelativeLayout.setVisibility(View.GONE); } }
BaseRegisterFragment extends RecyclerViewFragment implements BaseRegisterFragmentContract.View, SyncStatusBroadcastReceiver.SyncStatusListener { @Override public void setTotalPatients() { if (headerTextDisplay != null) { headerTextDisplay.setText(clientAdapter.getTotalcount() > 1 ? String.format(getActivity().getString(R.string.clients), clientAdapter.getTotalcount()) : String.format(getActivity().getString(R.string.client), clientAdapter.getTotalcount())); filterRelativeLayout.setVisibility(View.GONE); } } }
BaseRegisterFragment extends RecyclerViewFragment implements BaseRegisterFragmentContract.View, SyncStatusBroadcastReceiver.SyncStatusListener { @Override public void setTotalPatients() { if (headerTextDisplay != null) { headerTextDisplay.setText(clientAdapter.getTotalcount() > 1 ? String.format(getActivity().getString(R.string.clients), clientAdapter.getTotalcount()) : String.format(getActivity().getString(R.string.client), clientAdapter.getTotalcount())); filterRelativeLayout.setVisibility(View.GONE); } } }
BaseRegisterFragment extends RecyclerViewFragment implements BaseRegisterFragmentContract.View, SyncStatusBroadcastReceiver.SyncStatusListener { @Override public void setTotalPatients() { if (headerTextDisplay != null) { headerTextDisplay.setText(clientAdapter.getTotalcount() > 1 ? String.format(getActivity().getString(R.string.clients), clientAdapter.getTotalcount()) : String.format(getActivity().getString(R.string.client), clientAdapter.getTotalcount())); filterRelativeLayout.setVisibility(View.GONE); } } @Nullable @Override View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState); @Override void updateSearchBarHint(String searchBarText); void setSearchTerm(String searchText); void onQRCodeSucessfullyScanned(String qrCode); abstract void setUniqueID(String qrCode); abstract void setAdvancedSearchFormData(HashMap<String, String> advancedSearchFormData); @Override void setupViews(View view); @Override void setTotalPatients(); @Override void initializeQueryParams(String tableName, String countSelect, String mainSelect); void filter(String filterString, String joinTableString, String mainConditionString, boolean qrCode); @Override void updateFilterAndFilterStatus(String filterText, String sortText); boolean onBackPressed(); @Override void onSyncInProgress(FetchStatus fetchStatus); @Override void onSyncStart(); @Override void onSyncComplete(FetchStatus fetchStatus); @Override void onResume(); @Override void onPause(); }
BaseRegisterFragment extends RecyclerViewFragment implements BaseRegisterFragmentContract.View, SyncStatusBroadcastReceiver.SyncStatusListener { @Override public void setTotalPatients() { if (headerTextDisplay != null) { headerTextDisplay.setText(clientAdapter.getTotalcount() > 1 ? String.format(getActivity().getString(R.string.clients), clientAdapter.getTotalcount()) : String.format(getActivity().getString(R.string.client), clientAdapter.getTotalcount())); filterRelativeLayout.setVisibility(View.GONE); } } @Nullable @Override View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState); @Override void updateSearchBarHint(String searchBarText); void setSearchTerm(String searchText); void onQRCodeSucessfullyScanned(String qrCode); abstract void setUniqueID(String qrCode); abstract void setAdvancedSearchFormData(HashMap<String, String> advancedSearchFormData); @Override void setupViews(View view); @Override void setTotalPatients(); @Override void initializeQueryParams(String tableName, String countSelect, String mainSelect); void filter(String filterString, String joinTableString, String mainConditionString, boolean qrCode); @Override void updateFilterAndFilterStatus(String filterText, String sortText); boolean onBackPressed(); @Override void onSyncInProgress(FetchStatus fetchStatus); @Override void onSyncStart(); @Override void onSyncComplete(FetchStatus fetchStatus); @Override void onResume(); @Override void onPause(); static String TOOLBAR_TITLE; }
@Test public void testGetSubFormFieldValueShouldGetCorrectValue() throws JSONException { JSONArray jsonArray = new JSONArray(STEP_1_FIELDS); String value = JsonFormUtils.getSubFormFieldValue(jsonArray, FormEntityConstants.Person.first_name, "entity_id"); assertEquals("primary", value); }
public static String getSubFormFieldValue(JSONArray jsonArray, FormEntityConstants.Person person, String bindType) { if (isBlankJsonArray(jsonArray)) { return null; } if (person == null) { return null; } for (int i = 0; i < jsonArray.length(); i++) { JSONObject jsonObject = getJSONObject(jsonArray, i); String bind = getString(jsonObject, ENTITY_ID); if (bind == null || !bind.equals(bindType)) { continue; } String entityVal = getString(jsonObject, OPENMRS_ENTITY); String entityIdVal = getString(jsonObject, OPENMRS_ENTITY_ID); if (entityVal != null && entityVal.equals(person.entity()) && entityIdVal != null && entityIdVal.equals(person.name())) { return getString(jsonObject, VALUE); } } return null; }
JsonFormUtils { public static String getSubFormFieldValue(JSONArray jsonArray, FormEntityConstants.Person person, String bindType) { if (isBlankJsonArray(jsonArray)) { return null; } if (person == null) { return null; } for (int i = 0; i < jsonArray.length(); i++) { JSONObject jsonObject = getJSONObject(jsonArray, i); String bind = getString(jsonObject, ENTITY_ID); if (bind == null || !bind.equals(bindType)) { continue; } String entityVal = getString(jsonObject, OPENMRS_ENTITY); String entityIdVal = getString(jsonObject, OPENMRS_ENTITY_ID); if (entityVal != null && entityVal.equals(person.entity()) && entityIdVal != null && entityIdVal.equals(person.name())) { return getString(jsonObject, VALUE); } } return null; } }
JsonFormUtils { public static String getSubFormFieldValue(JSONArray jsonArray, FormEntityConstants.Person person, String bindType) { if (isBlankJsonArray(jsonArray)) { return null; } if (person == null) { return null; } for (int i = 0; i < jsonArray.length(); i++) { JSONObject jsonObject = getJSONObject(jsonArray, i); String bind = getString(jsonObject, ENTITY_ID); if (bind == null || !bind.equals(bindType)) { continue; } String entityVal = getString(jsonObject, OPENMRS_ENTITY); String entityIdVal = getString(jsonObject, OPENMRS_ENTITY_ID); if (entityVal != null && entityVal.equals(person.entity()) && entityIdVal != null && entityIdVal.equals(person.name())) { return getString(jsonObject, VALUE); } } return null; } }
JsonFormUtils { public static String getSubFormFieldValue(JSONArray jsonArray, FormEntityConstants.Person person, String bindType) { if (isBlankJsonArray(jsonArray)) { return null; } if (person == null) { return null; } for (int i = 0; i < jsonArray.length(); i++) { JSONObject jsonObject = getJSONObject(jsonArray, i); String bind = getString(jsonObject, ENTITY_ID); if (bind == null || !bind.equals(bindType)) { continue; } String entityVal = getString(jsonObject, OPENMRS_ENTITY); String entityIdVal = getString(jsonObject, OPENMRS_ENTITY_ID); if (entityVal != null && entityVal.equals(person.entity()) && entityIdVal != null && entityIdVal.equals(person.name())) { return getString(jsonObject, VALUE); } } return null; } static Client createBaseClient(JSONArray fields, FormTag formTag, String entityId); static Event createEvent(JSONArray fields, JSONObject metadata, FormTag formTag, String entityId, String encounterType, String bindType); static void addObservation(Event e, JSONObject jsonObject); static Map<String, String> extractIdentifiers(JSONArray fields); static Map<String, Object> extractAttributes(JSONArray fields); static Map<String, Address> extractAddresses(JSONArray fields); static void fillIdentifiers(Map<String, String> pids, JSONObject jsonObject); static void fillAttributes(Map<String, Object> pattributes, JSONObject jsonObject); static void fillAddressFields(JSONObject jsonObject, Map<String, Address> addresses); static Map<String, String> extractIdentifiers(JSONArray fields, String bindType); static Map<String, Object> extractAttributes(JSONArray fields, String bindType); static Map<String, Address> extractAddresses(JSONArray fields, String bindType); static String getSubFormFieldValue(JSONArray jsonArray, FormEntityConstants.Person person, String bindType); static void fillSubFormIdentifiers(Map<String, String> pids, JSONObject jsonObject, String bindType); static void fillSubFormAttributes(Map<String, Object> pattributes, JSONObject jsonObject, String bindType); static void fillSubFormAddressFields(JSONObject jsonObject, Map<String, Address> addresses, String bindType); static JSONArray getSingleStepFormfields(JSONObject jsonForm); static JSONArray fields(JSONObject jsonForm); static JSONArray getMultiStepFormFields(JSONObject jsonForm); static Map<String, String> sectionFields(JSONObject jsonForm); static JSONObject toJSONObject(String jsonString); static String getFieldValue(JSONArray jsonArray, FormEntityConstants.Person person); static String getFieldValue(JSONArray jsonArray, FormEntityConstants.Encounter encounter); static String getFieldValue(String jsonString, String key); @Nullable static JSONObject getFieldJSONObject(JSONArray jsonArray, String key); @Nullable static String value(JSONArray jsonArray, String entity, String entityId); @Nullable static String getFieldValue(JSONArray jsonArray, String key); @Nullable static JSONObject getJSONObject(JSONArray jsonArray, int index); @Nullable static JSONArray getJSONArray(JSONObject jsonObject, String field); static JSONObject getJSONObject(JSONObject jsonObject, String field); static String getString(JSONObject jsonObject, String field); static String getString(String jsonString, String field); static Long getLong(JSONObject jsonObject, String field); static Date formatDate(String dateString, boolean startOfToday); static String generateRandomUUIDString(); static void addToJSONObject(JSONObject jsonObject, String key, String value); static String formatDate(String date); static JSONObject merge(JSONObject original, JSONObject updated); static String[] getNames(JSONObject jo); static String convertToOpenMRSDate(String value); static boolean isBlankJsonArray(JSONArray jsonArray); static boolean isBlankJsonObject(JSONObject jsonObject); }
JsonFormUtils { public static String getSubFormFieldValue(JSONArray jsonArray, FormEntityConstants.Person person, String bindType) { if (isBlankJsonArray(jsonArray)) { return null; } if (person == null) { return null; } for (int i = 0; i < jsonArray.length(); i++) { JSONObject jsonObject = getJSONObject(jsonArray, i); String bind = getString(jsonObject, ENTITY_ID); if (bind == null || !bind.equals(bindType)) { continue; } String entityVal = getString(jsonObject, OPENMRS_ENTITY); String entityIdVal = getString(jsonObject, OPENMRS_ENTITY_ID); if (entityVal != null && entityVal.equals(person.entity()) && entityIdVal != null && entityIdVal.equals(person.name())) { return getString(jsonObject, VALUE); } } return null; } static Client createBaseClient(JSONArray fields, FormTag formTag, String entityId); static Event createEvent(JSONArray fields, JSONObject metadata, FormTag formTag, String entityId, String encounterType, String bindType); static void addObservation(Event e, JSONObject jsonObject); static Map<String, String> extractIdentifiers(JSONArray fields); static Map<String, Object> extractAttributes(JSONArray fields); static Map<String, Address> extractAddresses(JSONArray fields); static void fillIdentifiers(Map<String, String> pids, JSONObject jsonObject); static void fillAttributes(Map<String, Object> pattributes, JSONObject jsonObject); static void fillAddressFields(JSONObject jsonObject, Map<String, Address> addresses); static Map<String, String> extractIdentifiers(JSONArray fields, String bindType); static Map<String, Object> extractAttributes(JSONArray fields, String bindType); static Map<String, Address> extractAddresses(JSONArray fields, String bindType); static String getSubFormFieldValue(JSONArray jsonArray, FormEntityConstants.Person person, String bindType); static void fillSubFormIdentifiers(Map<String, String> pids, JSONObject jsonObject, String bindType); static void fillSubFormAttributes(Map<String, Object> pattributes, JSONObject jsonObject, String bindType); static void fillSubFormAddressFields(JSONObject jsonObject, Map<String, Address> addresses, String bindType); static JSONArray getSingleStepFormfields(JSONObject jsonForm); static JSONArray fields(JSONObject jsonForm); static JSONArray getMultiStepFormFields(JSONObject jsonForm); static Map<String, String> sectionFields(JSONObject jsonForm); static JSONObject toJSONObject(String jsonString); static String getFieldValue(JSONArray jsonArray, FormEntityConstants.Person person); static String getFieldValue(JSONArray jsonArray, FormEntityConstants.Encounter encounter); static String getFieldValue(String jsonString, String key); @Nullable static JSONObject getFieldJSONObject(JSONArray jsonArray, String key); @Nullable static String value(JSONArray jsonArray, String entity, String entityId); @Nullable static String getFieldValue(JSONArray jsonArray, String key); @Nullable static JSONObject getJSONObject(JSONArray jsonArray, int index); @Nullable static JSONArray getJSONArray(JSONObject jsonObject, String field); static JSONObject getJSONObject(JSONObject jsonObject, String field); static String getString(JSONObject jsonObject, String field); static String getString(String jsonString, String field); static Long getLong(JSONObject jsonObject, String field); static Date formatDate(String dateString, boolean startOfToday); static String generateRandomUUIDString(); static void addToJSONObject(JSONObject jsonObject, String key, String value); static String formatDate(String date); static JSONObject merge(JSONObject original, JSONObject updated); static String[] getNames(JSONObject jo); static String convertToOpenMRSDate(String value); static boolean isBlankJsonArray(JSONArray jsonArray); static boolean isBlankJsonObject(JSONObject jsonObject); static final String TAG; static final String OPENMRS_ENTITY; static final String OPENMRS_ENTITY_ID; static final String OPENMRS_ENTITY_PARENT; static final String OPENMRS_CHOICE_IDS; static final String OPENMRS_DATA_TYPE; static final String PERSON_ATTRIBUTE; static final String PERSON_INDENTIFIER; static final String PERSON_ADDRESS; static final String SIMPRINTS_GUID; static final String FINGERPRINT_KEY; static final String FINGERPRINT_OPTION; static final String FINGERPRINT_OPTION_REGISTER; static final String CONCEPT; static final String VALUE; static final String VALUES; static final String FIELDS; static final String KEY; static final String ENTITY_ID; static final String STEP1; static final String SECTIONS; static final String attributes; static final String ENCOUNTER; static final String ENCOUNTER_LOCATION; static final String SAVE_OBS_AS_ARRAY; static final String SAVE_ALL_CHECKBOX_OBS_AS_ARRAY; static final SimpleDateFormat dd_MM_yyyy; static Gson gson; }
@Test public void assertClientsProviderSetToNull() { Assert.assertNull(baseRegisterFragment.clientsProvider()); }
@Override protected SmartRegisterClientsProvider clientsProvider() { return null; }
BaseRegisterFragment extends RecyclerViewFragment implements BaseRegisterFragmentContract.View, SyncStatusBroadcastReceiver.SyncStatusListener { @Override protected SmartRegisterClientsProvider clientsProvider() { return null; } }
BaseRegisterFragment extends RecyclerViewFragment implements BaseRegisterFragmentContract.View, SyncStatusBroadcastReceiver.SyncStatusListener { @Override protected SmartRegisterClientsProvider clientsProvider() { return null; } }
BaseRegisterFragment extends RecyclerViewFragment implements BaseRegisterFragmentContract.View, SyncStatusBroadcastReceiver.SyncStatusListener { @Override protected SmartRegisterClientsProvider clientsProvider() { return null; } @Nullable @Override View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState); @Override void updateSearchBarHint(String searchBarText); void setSearchTerm(String searchText); void onQRCodeSucessfullyScanned(String qrCode); abstract void setUniqueID(String qrCode); abstract void setAdvancedSearchFormData(HashMap<String, String> advancedSearchFormData); @Override void setupViews(View view); @Override void setTotalPatients(); @Override void initializeQueryParams(String tableName, String countSelect, String mainSelect); void filter(String filterString, String joinTableString, String mainConditionString, boolean qrCode); @Override void updateFilterAndFilterStatus(String filterText, String sortText); boolean onBackPressed(); @Override void onSyncInProgress(FetchStatus fetchStatus); @Override void onSyncStart(); @Override void onSyncComplete(FetchStatus fetchStatus); @Override void onResume(); @Override void onPause(); }
BaseRegisterFragment extends RecyclerViewFragment implements BaseRegisterFragmentContract.View, SyncStatusBroadcastReceiver.SyncStatusListener { @Override protected SmartRegisterClientsProvider clientsProvider() { return null; } @Nullable @Override View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState); @Override void updateSearchBarHint(String searchBarText); void setSearchTerm(String searchText); void onQRCodeSucessfullyScanned(String qrCode); abstract void setUniqueID(String qrCode); abstract void setAdvancedSearchFormData(HashMap<String, String> advancedSearchFormData); @Override void setupViews(View view); @Override void setTotalPatients(); @Override void initializeQueryParams(String tableName, String countSelect, String mainSelect); void filter(String filterString, String joinTableString, String mainConditionString, boolean qrCode); @Override void updateFilterAndFilterStatus(String filterText, String sortText); boolean onBackPressed(); @Override void onSyncInProgress(FetchStatus fetchStatus); @Override void onSyncStart(); @Override void onSyncComplete(FetchStatus fetchStatus); @Override void onResume(); @Override void onPause(); static String TOOLBAR_TITLE; }
@Test public void testOnCreationInvokesPresenterStartSyncForRemoteLogin() { Mockito.doReturn(activity).when(baseRegisterFragment).getActivity(); Intent intent = new Intent(); intent.putExtra(AllConstants.INTENT_KEY.IS_REMOTE_LOGIN, true); activity.setIntent(intent); baseRegisterFragment.onCreation(); Mockito.verify(presenter).startSync(); }
@Override protected void onCreation() { initializePresenter(); Bundle extras = getActivity().getIntent().getExtras(); if (extras != null) { boolean isRemote = extras.getBoolean(AllConstants.INTENT_KEY.IS_REMOTE_LOGIN); if (isRemote) { presenter.startSync(); } } }
BaseRegisterFragment extends RecyclerViewFragment implements BaseRegisterFragmentContract.View, SyncStatusBroadcastReceiver.SyncStatusListener { @Override protected void onCreation() { initializePresenter(); Bundle extras = getActivity().getIntent().getExtras(); if (extras != null) { boolean isRemote = extras.getBoolean(AllConstants.INTENT_KEY.IS_REMOTE_LOGIN); if (isRemote) { presenter.startSync(); } } } }
BaseRegisterFragment extends RecyclerViewFragment implements BaseRegisterFragmentContract.View, SyncStatusBroadcastReceiver.SyncStatusListener { @Override protected void onCreation() { initializePresenter(); Bundle extras = getActivity().getIntent().getExtras(); if (extras != null) { boolean isRemote = extras.getBoolean(AllConstants.INTENT_KEY.IS_REMOTE_LOGIN); if (isRemote) { presenter.startSync(); } } } }
BaseRegisterFragment extends RecyclerViewFragment implements BaseRegisterFragmentContract.View, SyncStatusBroadcastReceiver.SyncStatusListener { @Override protected void onCreation() { initializePresenter(); Bundle extras = getActivity().getIntent().getExtras(); if (extras != null) { boolean isRemote = extras.getBoolean(AllConstants.INTENT_KEY.IS_REMOTE_LOGIN); if (isRemote) { presenter.startSync(); } } } @Nullable @Override View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState); @Override void updateSearchBarHint(String searchBarText); void setSearchTerm(String searchText); void onQRCodeSucessfullyScanned(String qrCode); abstract void setUniqueID(String qrCode); abstract void setAdvancedSearchFormData(HashMap<String, String> advancedSearchFormData); @Override void setupViews(View view); @Override void setTotalPatients(); @Override void initializeQueryParams(String tableName, String countSelect, String mainSelect); void filter(String filterString, String joinTableString, String mainConditionString, boolean qrCode); @Override void updateFilterAndFilterStatus(String filterText, String sortText); boolean onBackPressed(); @Override void onSyncInProgress(FetchStatus fetchStatus); @Override void onSyncStart(); @Override void onSyncComplete(FetchStatus fetchStatus); @Override void onResume(); @Override void onPause(); }
BaseRegisterFragment extends RecyclerViewFragment implements BaseRegisterFragmentContract.View, SyncStatusBroadcastReceiver.SyncStatusListener { @Override protected void onCreation() { initializePresenter(); Bundle extras = getActivity().getIntent().getExtras(); if (extras != null) { boolean isRemote = extras.getBoolean(AllConstants.INTENT_KEY.IS_REMOTE_LOGIN); if (isRemote) { presenter.startSync(); } } } @Nullable @Override View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState); @Override void updateSearchBarHint(String searchBarText); void setSearchTerm(String searchText); void onQRCodeSucessfullyScanned(String qrCode); abstract void setUniqueID(String qrCode); abstract void setAdvancedSearchFormData(HashMap<String, String> advancedSearchFormData); @Override void setupViews(View view); @Override void setTotalPatients(); @Override void initializeQueryParams(String tableName, String countSelect, String mainSelect); void filter(String filterString, String joinTableString, String mainConditionString, boolean qrCode); @Override void updateFilterAndFilterStatus(String filterText, String sortText); boolean onBackPressed(); @Override void onSyncInProgress(FetchStatus fetchStatus); @Override void onSyncStart(); @Override void onSyncComplete(FetchStatus fetchStatus); @Override void onResume(); @Override void onPause(); static String TOOLBAR_TITLE; }
@Test public void assertOnBackPressedReturnsFalse() { Assert.assertFalse(baseRegisterFragment.onBackPressed()); }
public boolean onBackPressed() { return false; }
BaseRegisterFragment extends RecyclerViewFragment implements BaseRegisterFragmentContract.View, SyncStatusBroadcastReceiver.SyncStatusListener { public boolean onBackPressed() { return false; } }
BaseRegisterFragment extends RecyclerViewFragment implements BaseRegisterFragmentContract.View, SyncStatusBroadcastReceiver.SyncStatusListener { public boolean onBackPressed() { return false; } }
BaseRegisterFragment extends RecyclerViewFragment implements BaseRegisterFragmentContract.View, SyncStatusBroadcastReceiver.SyncStatusListener { public boolean onBackPressed() { return false; } @Nullable @Override View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState); @Override void updateSearchBarHint(String searchBarText); void setSearchTerm(String searchText); void onQRCodeSucessfullyScanned(String qrCode); abstract void setUniqueID(String qrCode); abstract void setAdvancedSearchFormData(HashMap<String, String> advancedSearchFormData); @Override void setupViews(View view); @Override void setTotalPatients(); @Override void initializeQueryParams(String tableName, String countSelect, String mainSelect); void filter(String filterString, String joinTableString, String mainConditionString, boolean qrCode); @Override void updateFilterAndFilterStatus(String filterText, String sortText); boolean onBackPressed(); @Override void onSyncInProgress(FetchStatus fetchStatus); @Override void onSyncStart(); @Override void onSyncComplete(FetchStatus fetchStatus); @Override void onResume(); @Override void onPause(); }
BaseRegisterFragment extends RecyclerViewFragment implements BaseRegisterFragmentContract.View, SyncStatusBroadcastReceiver.SyncStatusListener { public boolean onBackPressed() { return false; } @Nullable @Override View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState); @Override void updateSearchBarHint(String searchBarText); void setSearchTerm(String searchText); void onQRCodeSucessfullyScanned(String qrCode); abstract void setUniqueID(String qrCode); abstract void setAdvancedSearchFormData(HashMap<String, String> advancedSearchFormData); @Override void setupViews(View view); @Override void setTotalPatients(); @Override void initializeQueryParams(String tableName, String countSelect, String mainSelect); void filter(String filterString, String joinTableString, String mainConditionString, boolean qrCode); @Override void updateFilterAndFilterStatus(String filterText, String sortText); boolean onBackPressed(); @Override void onSyncInProgress(FetchStatus fetchStatus); @Override void onSyncStart(); @Override void onSyncComplete(FetchStatus fetchStatus); @Override void onResume(); @Override void onPause(); static String TOOLBAR_TITLE; }
@Test public void testUpdateFilterAndFilterStatus() { View parentLayout = LayoutInflater.from(RuntimeEnvironment.application.getApplicationContext()).inflate(R.layout.fragment_base_register, null, false); Mockito.doReturn(parentLayout).when(layoutInflater).inflate(R.layout.fragment_base_register, container, false); TextView headerTextDisplay = parentLayout.findViewById(R.id.header_text_display); TextView filterStatus = parentLayout.findViewById(R.id.filter_status); RelativeLayout filterRelativeLayout = parentLayout.findViewById(R.id.filter_display_view); ReflectionHelpers.setField(baseRegisterFragment, "headerTextDisplay", headerTextDisplay); ReflectionHelpers.setField(baseRegisterFragment, "filterRelativeLayout", filterRelativeLayout); ReflectionHelpers.setField(baseRegisterFragment, "filterStatus", filterStatus); Mockito.doReturn(5).when(clientAdapter).getTotalcount(); baseRegisterFragment.updateFilterAndFilterStatus("benji", "ASC"); Assert.assertEquals("benji", headerTextDisplay.getText().toString()); Assert.assertEquals("5 patients ASC", filterStatus.getText().toString()); }
@Override public void updateFilterAndFilterStatus(String filterText, String sortText) { if (headerTextDisplay != null) { headerTextDisplay.setText(Html.fromHtml(filterText)); filterRelativeLayout.setVisibility(View.VISIBLE); } if (filterStatus != null) { filterStatus.setText(Html.fromHtml(clientAdapter.getTotalcount() + " patients " + sortText)); } }
BaseRegisterFragment extends RecyclerViewFragment implements BaseRegisterFragmentContract.View, SyncStatusBroadcastReceiver.SyncStatusListener { @Override public void updateFilterAndFilterStatus(String filterText, String sortText) { if (headerTextDisplay != null) { headerTextDisplay.setText(Html.fromHtml(filterText)); filterRelativeLayout.setVisibility(View.VISIBLE); } if (filterStatus != null) { filterStatus.setText(Html.fromHtml(clientAdapter.getTotalcount() + " patients " + sortText)); } } }
BaseRegisterFragment extends RecyclerViewFragment implements BaseRegisterFragmentContract.View, SyncStatusBroadcastReceiver.SyncStatusListener { @Override public void updateFilterAndFilterStatus(String filterText, String sortText) { if (headerTextDisplay != null) { headerTextDisplay.setText(Html.fromHtml(filterText)); filterRelativeLayout.setVisibility(View.VISIBLE); } if (filterStatus != null) { filterStatus.setText(Html.fromHtml(clientAdapter.getTotalcount() + " patients " + sortText)); } } }
BaseRegisterFragment extends RecyclerViewFragment implements BaseRegisterFragmentContract.View, SyncStatusBroadcastReceiver.SyncStatusListener { @Override public void updateFilterAndFilterStatus(String filterText, String sortText) { if (headerTextDisplay != null) { headerTextDisplay.setText(Html.fromHtml(filterText)); filterRelativeLayout.setVisibility(View.VISIBLE); } if (filterStatus != null) { filterStatus.setText(Html.fromHtml(clientAdapter.getTotalcount() + " patients " + sortText)); } } @Nullable @Override View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState); @Override void updateSearchBarHint(String searchBarText); void setSearchTerm(String searchText); void onQRCodeSucessfullyScanned(String qrCode); abstract void setUniqueID(String qrCode); abstract void setAdvancedSearchFormData(HashMap<String, String> advancedSearchFormData); @Override void setupViews(View view); @Override void setTotalPatients(); @Override void initializeQueryParams(String tableName, String countSelect, String mainSelect); void filter(String filterString, String joinTableString, String mainConditionString, boolean qrCode); @Override void updateFilterAndFilterStatus(String filterText, String sortText); boolean onBackPressed(); @Override void onSyncInProgress(FetchStatus fetchStatus); @Override void onSyncStart(); @Override void onSyncComplete(FetchStatus fetchStatus); @Override void onResume(); @Override void onPause(); }
BaseRegisterFragment extends RecyclerViewFragment implements BaseRegisterFragmentContract.View, SyncStatusBroadcastReceiver.SyncStatusListener { @Override public void updateFilterAndFilterStatus(String filterText, String sortText) { if (headerTextDisplay != null) { headerTextDisplay.setText(Html.fromHtml(filterText)); filterRelativeLayout.setVisibility(View.VISIBLE); } if (filterStatus != null) { filterStatus.setText(Html.fromHtml(clientAdapter.getTotalcount() + " patients " + sortText)); } } @Nullable @Override View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState); @Override void updateSearchBarHint(String searchBarText); void setSearchTerm(String searchText); void onQRCodeSucessfullyScanned(String qrCode); abstract void setUniqueID(String qrCode); abstract void setAdvancedSearchFormData(HashMap<String, String> advancedSearchFormData); @Override void setupViews(View view); @Override void setTotalPatients(); @Override void initializeQueryParams(String tableName, String countSelect, String mainSelect); void filter(String filterString, String joinTableString, String mainConditionString, boolean qrCode); @Override void updateFilterAndFilterStatus(String filterText, String sortText); boolean onBackPressed(); @Override void onSyncInProgress(FetchStatus fetchStatus); @Override void onSyncStart(); @Override void onSyncComplete(FetchStatus fetchStatus); @Override void onResume(); @Override void onPause(); static String TOOLBAR_TITLE; }
@Test @Ignore public void testOnCreateViewReturnsCorrectLayoutView() { View layoutView = meFragment.onCreateView(layoutInflater, viewGroup, bundle); Assert.assertNotNull(layoutView); Mockito.verify(layoutInflater).inflate(R.layout.fragment_me, viewGroup, false); }
@Nullable @Override public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { return inflater.inflate(R.layout.fragment_me, container, false); }
MeFragment extends Fragment implements MeContract.View { @Nullable @Override public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { return inflater.inflate(R.layout.fragment_me, container, false); } }
MeFragment extends Fragment implements MeContract.View { @Nullable @Override public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { return inflater.inflate(R.layout.fragment_me, container, false); } }
MeFragment extends Fragment implements MeContract.View { @Nullable @Override public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { return inflater.inflate(R.layout.fragment_me, container, false); } @Override void onCreate(Bundle savedInstanceState); @Nullable @Override View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState); @Override void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState); @Override void onStart(); @Override void onResume(); @Override void updateInitialsText(String userInitials); @Override void updateNameText(String name); }
MeFragment extends Fragment implements MeContract.View { @Nullable @Override public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { return inflater.inflate(R.layout.fragment_me, container, false); } @Override void onCreate(Bundle savedInstanceState); @Nullable @Override View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState); @Override void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState); @Override void onStart(); @Override void onResume(); @Override void updateInitialsText(String userInitials); @Override void updateNameText(String name); }
@Test public void testSetupSearchView() { View parent = LayoutInflater.from(RuntimeEnvironment.application).inflate(R.layout.smart_register_activity, null, false); View parentSpy = Mockito.spy(parent); Mockito.doReturn(searchView).when(parentSpy).findViewById(R.id.edt_search); Mockito.doReturn(searchCancelButton).when(parentSpy).findViewById(R.id.btn_search_cancel); securedNativeSmartRegisterFragment.setupSearchView(parentSpy); Assert.assertNotNull(securedNativeSmartRegisterFragment.getSearchView()); Assert.assertNotNull(securedNativeSmartRegisterFragment.getSearchCancelView()); Mockito.verify(parentSpy).findViewById(R.id.edt_search); Mockito.verify(parentSpy).findViewById(R.id.btn_search_cancel); Mockito.verify(searchView).addTextChangedListener(ArgumentMatchers.any(TextWatcher.class)); Mockito.verify(searchCancelButton).setOnClickListener(ArgumentMatchers.any(SecuredNativeSmartRegisterFragment.SearchCancelHandler.class)); }
public void setupSearchView(View view) { searchView = view.findViewById(R.id.edt_search); searchView.setHint(getNavBarOptionsProvider().searchHint()); searchView.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) { } @Override public void onTextChanged(CharSequence cs, int start, int before, int count) { currentSearchFilter = new ECSearchOption(cs.toString()); clientsAdapter.refreshList(currentVillageFilter, currentServiceModeOption, currentSearchFilter, currentSortOption); searchCancelView.setVisibility(isEmpty(cs) ? INVISIBLE : VISIBLE); } @Override public void afterTextChanged(Editable editable) { } }); searchCancelView = view.findViewById(R.id.btn_search_cancel); searchCancelView.setOnClickListener(searchCancelHandler); }
SecuredNativeSmartRegisterFragment extends SecuredFragment { public void setupSearchView(View view) { searchView = view.findViewById(R.id.edt_search); searchView.setHint(getNavBarOptionsProvider().searchHint()); searchView.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) { } @Override public void onTextChanged(CharSequence cs, int start, int before, int count) { currentSearchFilter = new ECSearchOption(cs.toString()); clientsAdapter.refreshList(currentVillageFilter, currentServiceModeOption, currentSearchFilter, currentSortOption); searchCancelView.setVisibility(isEmpty(cs) ? INVISIBLE : VISIBLE); } @Override public void afterTextChanged(Editable editable) { } }); searchCancelView = view.findViewById(R.id.btn_search_cancel); searchCancelView.setOnClickListener(searchCancelHandler); } }
SecuredNativeSmartRegisterFragment extends SecuredFragment { public void setupSearchView(View view) { searchView = view.findViewById(R.id.edt_search); searchView.setHint(getNavBarOptionsProvider().searchHint()); searchView.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) { } @Override public void onTextChanged(CharSequence cs, int start, int before, int count) { currentSearchFilter = new ECSearchOption(cs.toString()); clientsAdapter.refreshList(currentVillageFilter, currentServiceModeOption, currentSearchFilter, currentSortOption); searchCancelView.setVisibility(isEmpty(cs) ? INVISIBLE : VISIBLE); } @Override public void afterTextChanged(Editable editable) { } }); searchCancelView = view.findViewById(R.id.btn_search_cancel); searchCancelView.setOnClickListener(searchCancelHandler); } }
SecuredNativeSmartRegisterFragment extends SecuredFragment { public void setupSearchView(View view) { searchView = view.findViewById(R.id.edt_search); searchView.setHint(getNavBarOptionsProvider().searchHint()); searchView.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) { } @Override public void onTextChanged(CharSequence cs, int start, int before, int count) { currentSearchFilter = new ECSearchOption(cs.toString()); clientsAdapter.refreshList(currentVillageFilter, currentServiceModeOption, currentSearchFilter, currentSortOption); searchCancelView.setVisibility(isEmpty(cs) ? INVISIBLE : VISIBLE); } @Override public void afterTextChanged(Editable editable) { } }); searchCancelView = view.findViewById(R.id.btn_search_cancel); searchCancelView.setOnClickListener(searchCancelHandler); } EditText getSearchView(); View getSearchCancelView(); FilterOption getCurrentVillageFilter(); FilterOption getCurrentSearchFilter(); void setCurrentSearchFilter(FilterOption currentSearchFilter); SortOption getCurrentSortOption(); ServiceModeOption getCurrentServiceModeOption(); SmartRegisterPaginatedAdapter getClientsAdapter(); void setClientsAdapter(SmartRegisterPaginatedAdapter clientsAdapter); @Override View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState); void refreshListView(); void setupSearchView(View view); void onSortSelection(SortOption sortBy); void onFilterSelection(FilterOption filter); void gotoNextPage(); void goBackToPreviousPage(); boolean isRefreshList(); void setRefreshList(boolean refreshList); }
SecuredNativeSmartRegisterFragment extends SecuredFragment { public void setupSearchView(View view) { searchView = view.findViewById(R.id.edt_search); searchView.setHint(getNavBarOptionsProvider().searchHint()); searchView.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) { } @Override public void onTextChanged(CharSequence cs, int start, int before, int count) { currentSearchFilter = new ECSearchOption(cs.toString()); clientsAdapter.refreshList(currentVillageFilter, currentServiceModeOption, currentSearchFilter, currentSortOption); searchCancelView.setVisibility(isEmpty(cs) ? INVISIBLE : VISIBLE); } @Override public void afterTextChanged(Editable editable) { } }); searchCancelView = view.findViewById(R.id.btn_search_cancel); searchCancelView.setOnClickListener(searchCancelHandler); } EditText getSearchView(); View getSearchCancelView(); FilterOption getCurrentVillageFilter(); FilterOption getCurrentSearchFilter(); void setCurrentSearchFilter(FilterOption currentSearchFilter); SortOption getCurrentSortOption(); ServiceModeOption getCurrentServiceModeOption(); SmartRegisterPaginatedAdapter getClientsAdapter(); void setClientsAdapter(SmartRegisterPaginatedAdapter clientsAdapter); @Override View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState); void refreshListView(); void setupSearchView(View view); void onSortSelection(SortOption sortBy); void onFilterSelection(FilterOption filter); void gotoNextPage(); void goBackToPreviousPage(); boolean isRefreshList(); void setRefreshList(boolean refreshList); static final String DIALOG_TAG; static final List<? extends DialogOption> DEFAULT_FILTER_OPTIONS; public ListView clientsView; public ProgressBar clientsProgressView; public TextView serviceModeView; public TextView appliedVillageFilterView; public TextView appliedSortView; public EditText searchView; public View searchCancelView; public TextView titleLabelView; public View mView; }
@Test public void testServiceModeViewSetsServiceModeViewWithCorrectCompoundDrawableValues() { Whitebox.setInternalState(securedNativeSmartRegisterFragment, "serviceModeView", serviceModeView); securedNativeSmartRegisterFragment.setServiceModeViewDrawableRight(drawable); Mockito.verify(serviceModeView).setCompoundDrawables(null, null, drawable, null); }
protected void setServiceModeViewDrawableRight(Drawable drawable) { serviceModeView.setCompoundDrawables(null, null, drawable, null); }
SecuredNativeSmartRegisterFragment extends SecuredFragment { protected void setServiceModeViewDrawableRight(Drawable drawable) { serviceModeView.setCompoundDrawables(null, null, drawable, null); } }
SecuredNativeSmartRegisterFragment extends SecuredFragment { protected void setServiceModeViewDrawableRight(Drawable drawable) { serviceModeView.setCompoundDrawables(null, null, drawable, null); } }
SecuredNativeSmartRegisterFragment extends SecuredFragment { protected void setServiceModeViewDrawableRight(Drawable drawable) { serviceModeView.setCompoundDrawables(null, null, drawable, null); } EditText getSearchView(); View getSearchCancelView(); FilterOption getCurrentVillageFilter(); FilterOption getCurrentSearchFilter(); void setCurrentSearchFilter(FilterOption currentSearchFilter); SortOption getCurrentSortOption(); ServiceModeOption getCurrentServiceModeOption(); SmartRegisterPaginatedAdapter getClientsAdapter(); void setClientsAdapter(SmartRegisterPaginatedAdapter clientsAdapter); @Override View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState); void refreshListView(); void setupSearchView(View view); void onSortSelection(SortOption sortBy); void onFilterSelection(FilterOption filter); void gotoNextPage(); void goBackToPreviousPage(); boolean isRefreshList(); void setRefreshList(boolean refreshList); }
SecuredNativeSmartRegisterFragment extends SecuredFragment { protected void setServiceModeViewDrawableRight(Drawable drawable) { serviceModeView.setCompoundDrawables(null, null, drawable, null); } EditText getSearchView(); View getSearchCancelView(); FilterOption getCurrentVillageFilter(); FilterOption getCurrentSearchFilter(); void setCurrentSearchFilter(FilterOption currentSearchFilter); SortOption getCurrentSortOption(); ServiceModeOption getCurrentServiceModeOption(); SmartRegisterPaginatedAdapter getClientsAdapter(); void setClientsAdapter(SmartRegisterPaginatedAdapter clientsAdapter); @Override View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState); void refreshListView(); void setupSearchView(View view); void onSortSelection(SortOption sortBy); void onFilterSelection(FilterOption filter); void gotoNextPage(); void goBackToPreviousPage(); boolean isRefreshList(); void setRefreshList(boolean refreshList); static final String DIALOG_TAG; static final List<? extends DialogOption> DEFAULT_FILTER_OPTIONS; public ListView clientsView; public ProgressBar clientsProgressView; public TextView serviceModeView; public TextView appliedVillageFilterView; public TextView appliedSortView; public EditText searchView; public View searchCancelView; public TextView titleLabelView; public View mView; }
@Test public void refreshListView() { Mockito.doNothing().when(securedNativeSmartRegisterFragment).onResumption(); securedNativeSmartRegisterFragment.refreshListView(); Mockito.verify(securedNativeSmartRegisterFragment).setRefreshList(true); Mockito.verify(securedNativeSmartRegisterFragment).onResumption(); Mockito.verify(securedNativeSmartRegisterFragment).setRefreshList(false); }
public void refreshListView() { this.setRefreshList(true); this.onResumption(); this.setRefreshList(false); }
SecuredNativeSmartRegisterFragment extends SecuredFragment { public void refreshListView() { this.setRefreshList(true); this.onResumption(); this.setRefreshList(false); } }
SecuredNativeSmartRegisterFragment extends SecuredFragment { public void refreshListView() { this.setRefreshList(true); this.onResumption(); this.setRefreshList(false); } }
SecuredNativeSmartRegisterFragment extends SecuredFragment { public void refreshListView() { this.setRefreshList(true); this.onResumption(); this.setRefreshList(false); } EditText getSearchView(); View getSearchCancelView(); FilterOption getCurrentVillageFilter(); FilterOption getCurrentSearchFilter(); void setCurrentSearchFilter(FilterOption currentSearchFilter); SortOption getCurrentSortOption(); ServiceModeOption getCurrentServiceModeOption(); SmartRegisterPaginatedAdapter getClientsAdapter(); void setClientsAdapter(SmartRegisterPaginatedAdapter clientsAdapter); @Override View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState); void refreshListView(); void setupSearchView(View view); void onSortSelection(SortOption sortBy); void onFilterSelection(FilterOption filter); void gotoNextPage(); void goBackToPreviousPage(); boolean isRefreshList(); void setRefreshList(boolean refreshList); }
SecuredNativeSmartRegisterFragment extends SecuredFragment { public void refreshListView() { this.setRefreshList(true); this.onResumption(); this.setRefreshList(false); } EditText getSearchView(); View getSearchCancelView(); FilterOption getCurrentVillageFilter(); FilterOption getCurrentSearchFilter(); void setCurrentSearchFilter(FilterOption currentSearchFilter); SortOption getCurrentSortOption(); ServiceModeOption getCurrentServiceModeOption(); SmartRegisterPaginatedAdapter getClientsAdapter(); void setClientsAdapter(SmartRegisterPaginatedAdapter clientsAdapter); @Override View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState); void refreshListView(); void setupSearchView(View view); void onSortSelection(SortOption sortBy); void onFilterSelection(FilterOption filter); void gotoNextPage(); void goBackToPreviousPage(); boolean isRefreshList(); void setRefreshList(boolean refreshList); static final String DIALOG_TAG; static final List<? extends DialogOption> DEFAULT_FILTER_OPTIONS; public ListView clientsView; public ProgressBar clientsProgressView; public TextView serviceModeView; public TextView appliedVillageFilterView; public TextView appliedSortView; public EditText searchView; public View searchCancelView; public TextView titleLabelView; public View mView; }
@Test public void testSetLoadingStateCalledTwiceHidesViewAfterBeingCalledTwice() { ProgressBar progressBar = Mockito.mock(ProgressBar.class); Whitebox.setInternalState(baseListFragment, "progressBar", progressBar); AtomicInteger incompleteRequests = new AtomicInteger(0); Whitebox.setInternalState(baseListFragment, "incompleteRequests", incompleteRequests); baseListFragment.setLoadingState(true); Assert.assertEquals(incompleteRequests.get(), 1); baseListFragment.setLoadingState(true); Assert.assertEquals(incompleteRequests.get(), 2); baseListFragment.setLoadingState(false); Assert.assertEquals(incompleteRequests.get(), 1); Mockito.verify(progressBar, Mockito.times(3)).setVisibility(View.VISIBLE); baseListFragment.setLoadingState(false); Assert.assertEquals(incompleteRequests.get(), 0); Mockito.verify(progressBar, Mockito.times(1)).setVisibility(View.INVISIBLE); }
@Override public void setLoadingState(boolean loadingState) { int result = loadingState ? incompleteRequests.incrementAndGet() : incompleteRequests.decrementAndGet(); progressBar.setVisibility(result > 0 ? View.VISIBLE : View.INVISIBLE); }
BaseListFragment extends Fragment implements ListContract.View<T> { @Override public void setLoadingState(boolean loadingState) { int result = loadingState ? incompleteRequests.incrementAndGet() : incompleteRequests.decrementAndGet(); progressBar.setVisibility(result > 0 ? View.VISIBLE : View.INVISIBLE); } }
BaseListFragment extends Fragment implements ListContract.View<T> { @Override public void setLoadingState(boolean loadingState) { int result = loadingState ? incompleteRequests.incrementAndGet() : incompleteRequests.decrementAndGet(); progressBar.setVisibility(result > 0 ? View.VISIBLE : View.INVISIBLE); } }
BaseListFragment extends Fragment implements ListContract.View<T> { @Override public void setLoadingState(boolean loadingState) { int result = loadingState ? incompleteRequests.incrementAndGet() : incompleteRequests.decrementAndGet(); progressBar.setVisibility(result > 0 ? View.VISIBLE : View.INVISIBLE); } @Override View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState); @Override void bindLayout(); @Override boolean hasDivider(); @Override void renderData(List<T> identifiables); @Override void refreshView(); @Override void setLoadingState(boolean loadingState); @Override abstract void onListItemClicked(T t, int layoutID); @NonNull @Override abstract ListContract.Adapter<T> adapter(); @NonNull @Override ListContract.Presenter<T> loadPresenter(); }
BaseListFragment extends Fragment implements ListContract.View<T> { @Override public void setLoadingState(boolean loadingState) { int result = loadingState ? incompleteRequests.incrementAndGet() : incompleteRequests.decrementAndGet(); progressBar.setVisibility(result > 0 ? View.VISIBLE : View.INVISIBLE); } @Override View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState); @Override void bindLayout(); @Override boolean hasDivider(); @Override void renderData(List<T> identifiables); @Override void refreshView(); @Override void setLoadingState(boolean loadingState); @Override abstract void onListItemClicked(T t, int layoutID); @NonNull @Override abstract ListContract.Adapter<T> adapter(); @NonNull @Override ListContract.Presenter<T> loadPresenter(); }
@Test public void testLoadPresenterAssignsPresenter() { Assert.assertNull(Whitebox.getInternalState(baseListFragment, "presenter")); ListContract.Presenter presenter = baseListFragment.loadPresenter(); Assert.assertNotNull(Whitebox.getInternalState(baseListFragment, "presenter")); Assert.assertEquals(presenter, Whitebox.getInternalState(baseListFragment, "presenter")); }
@NonNull @Override public ListContract.Presenter<T> loadPresenter() { if (presenter == null) { presenter = new ListPresenter<T>() .with(this); } return presenter; }
BaseListFragment extends Fragment implements ListContract.View<T> { @NonNull @Override public ListContract.Presenter<T> loadPresenter() { if (presenter == null) { presenter = new ListPresenter<T>() .with(this); } return presenter; } }
BaseListFragment extends Fragment implements ListContract.View<T> { @NonNull @Override public ListContract.Presenter<T> loadPresenter() { if (presenter == null) { presenter = new ListPresenter<T>() .with(this); } return presenter; } }
BaseListFragment extends Fragment implements ListContract.View<T> { @NonNull @Override public ListContract.Presenter<T> loadPresenter() { if (presenter == null) { presenter = new ListPresenter<T>() .with(this); } return presenter; } @Override View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState); @Override void bindLayout(); @Override boolean hasDivider(); @Override void renderData(List<T> identifiables); @Override void refreshView(); @Override void setLoadingState(boolean loadingState); @Override abstract void onListItemClicked(T t, int layoutID); @NonNull @Override abstract ListContract.Adapter<T> adapter(); @NonNull @Override ListContract.Presenter<T> loadPresenter(); }
BaseListFragment extends Fragment implements ListContract.View<T> { @NonNull @Override public ListContract.Presenter<T> loadPresenter() { if (presenter == null) { presenter = new ListPresenter<T>() .with(this); } return presenter; } @Override View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState); @Override void bindLayout(); @Override boolean hasDivider(); @Override void renderData(List<T> identifiables); @Override void refreshView(); @Override void setLoadingState(boolean loadingState); @Override abstract void onListItemClicked(T t, int layoutID); @NonNull @Override abstract ListContract.Adapter<T> adapter(); @NonNull @Override ListContract.Presenter<T> loadPresenter(); }
@Test public void testGetPaginationViewInflatesCorrectLayout() { Mockito.doReturn(layoutInflater).when(activity).getLayoutInflater(); Mockito.doReturn(paginationView).when(layoutInflater).inflate(R.layout.smart_register_pagination, null); ViewHelper.getPaginationView(activity); Mockito.verify(layoutInflater).inflate(R.layout.smart_register_pagination, null); }
public static ViewGroup getPaginationView(Activity context) { return (ViewGroup) context.getLayoutInflater() .inflate(R.layout.smart_register_pagination, null); }
ViewHelper { public static ViewGroup getPaginationView(Activity context) { return (ViewGroup) context.getLayoutInflater() .inflate(R.layout.smart_register_pagination, null); } }
ViewHelper { public static ViewGroup getPaginationView(Activity context) { return (ViewGroup) context.getLayoutInflater() .inflate(R.layout.smart_register_pagination, null); } }
ViewHelper { public static ViewGroup getPaginationView(Activity context) { return (ViewGroup) context.getLayoutInflater() .inflate(R.layout.smart_register_pagination, null); } static PaginationHolder addPaginationCore(View.OnClickListener onClickListener, ListView clientsView); static ViewGroup getPaginationView(Activity context); }
ViewHelper { public static ViewGroup getPaginationView(Activity context) { return (ViewGroup) context.getLayoutInflater() .inflate(R.layout.smart_register_pagination, null); } static PaginationHolder addPaginationCore(View.OnClickListener onClickListener, ListView clientsView); static ViewGroup getPaginationView(Activity context); }
@Test public void shouldMapECToFPClient() throws Exception { Map<String, String> details = EasyMap.create("wifeAge", "22") .put("currentMethod", "condom") .put("familyPlanningMethodChangeDate", "2013-01-02") .put("sideEffects", "sideEffects 1") .put("numberOfPregnancies", "2") .put("parity", "2") .put("numberOfLivingChildren", "1") .put("numberOfStillBirths", "1") .put("numberOfAbortions", "0") .put("isHighPriority", Boolean.toString(false)) .put("isYoungestChildUnderTwo", "yes") .put("youngestChildAge", "3") .put("complicationDate", "2011-05-05") .put("caste", "sc") .put("economicStatus", "bpl") .put("fpFollowupDate", "2013-03-04") .put("iudPlace", "iudPlace") .put("iudPerson", "iudPerson") .put("numberOfCondomsSupplied", "numberOfCondomsSupplied") .put("numberOfCentchromanPillsDelivered", "numberOfCentchromanPillsDelivered") .put("numberOfOCPDelivered", "numberOfOCPDelivered") .put("condomSideEffect", "condom side effect") .put("iudSidEffect", "iud side effect") .put("ocpSideEffect", "ocp side effect") .put("sterilizationSideEffect", "sterilization side effect") .put("injectableSideEffect", "injectable side effect") .put("otherSideEffect", "other side effect") .put("highPriorityReason", "high priority reason") .map(); EligibleCouple ec = new EligibleCouple("EC Case 1", "Woman A", "Husband A", "EC Number 1", "Bherya", "Bherya SC", details) .withPhotoPath("new photo path"); Mockito.when(allEligibleCouples.all()).thenReturn(Arrays.asList(ec)); FPClient expectedFPClient = new FPClient("EC Case 1", "Woman A", "Husband A", "Bherya", "EC Number 1") .withAge("22") .withFPMethod("condom") .withFamilyPlanningMethodChangeDate("2013-01-02") .withComplicationDate("2011-05-05") .withIUDPlace("iudPlace") .withIUDPerson("iudPerson") .withNumberOfCondomsSupplied("numberOfCondomsSupplied") .withNumberOfCentchromanPillsDelivered("numberOfCentchromanPillsDelivered") .withNumberOfOCPDelivered("numberOfOCPDelivered").withFPMethodFollowupDate("2013-03-04") .withCaste("sc") .withEconomicStatus("bpl") .withNumberOfPregnancies("2") .withParity("2") .withNumberOfLivingChildren("1") .withNumberOfStillBirths("1") .withNumberOfAbortions("0") .withIsYoungestChildUnderTwo(true) .withYoungestChildAge("3") .withIsHighPriority(false) .withPhotoPath("new photo path") .withCondomSideEffect("condom side effect") .withIUDSidEffect("iud side effect") .withOCPSideEffect("ocp side effect") .withSterilizationSideEffect("sterilization side effect") .withInjectableSideEffect("injectable side effect") .withOtherSideEffect("other side effect") .withHighPriorityReason("high priority reason") .withAlerts(Collections.<AlertDTO>emptyList()); FPClients actualClients = controller.getClients(); Assert.assertEquals(Arrays.asList(expectedFPClient), actualClients); }
public FPClients getClients() { return fpClientsCache.get(FP_CLIENTS_LIST, new CacheableData<FPClients>() { @Override public FPClients fetch() { List<EligibleCouple> ecs = allEligibleCouples.all(); FPClients fpClients = new FPClients(); for (EligibleCouple ec : ecs) { if (allBeneficiaries.isPregnant(ec.caseId())) { continue; } String photoPath = isBlank(ec.photoPath()) ? DEFAULT_WOMAN_IMAGE_PLACEHOLDER_PATH : ec.photoPath(); List<AlertDTO> alerts = getFPAlertsForEC(ec.caseId()); FPClient fpClient = new FPClient(ec.caseId(), ec.wifeName(), ec.husbandName(), ec.village(), ec.ecNumber()).withAge(ec.age()) .withFPMethod(ec.getDetail("currentMethod")) .withFamilyPlanningMethodChangeDate( ec.getDetail("familyPlanningMethodChangeDate")) .withComplicationDate(ec.getDetail("complicationDate")) .withIUDPlace(ec.getDetail("iudPlace")) .withIUDPerson(ec.getDetail("iudPerson")) .withNumberOfCondomsSupplied(ec.getDetail("numberOfCondomsSupplied")) .withNumberOfCentchromanPillsDelivered( ec.getDetail("numberOfCentchromanPillsDelivered")) .withNumberOfOCPDelivered(ec.getDetail("numberOfOCPDelivered")) .withFPMethodFollowupDate(ec.getDetail("fpFollowupDate")) .withCaste(ec.getDetail("caste")) .withEconomicStatus(ec.getDetail("economicStatus")) .withNumberOfPregnancies(ec.getDetail("numberOfPregnancies")) .withParity(ec.getDetail("parity")) .withNumberOfLivingChildren(ec.getDetail("numberOfLivingChildren")) .withNumberOfStillBirths(ec.getDetail("numberOfStillBirths")) .withNumberOfAbortions(ec.getDetail("numberOfAbortions")) .withIsYoungestChildUnderTwo(ec.isYoungestChildUnderTwo()) .withYoungestChildAge(ec.getDetail("youngestChildAge")) .withIsHighPriority(ec.isHighPriority()).withPhotoPath(photoPath) .withAlerts(alerts) .withCondomSideEffect(ec.getDetail("condomSideEffect")) .withIUDSidEffect(ec.getDetail("iudSidEffect")) .withOCPSideEffect(ec.getDetail("ocpSideEffect")) .withInjectableSideEffect(ec.getDetail("injectableSideEffect")) .withSterilizationSideEffect(ec.getDetail("sterilizationSideEffect")) .withOtherSideEffect(ec.getDetail("otherSideEffect")) .withHighPriorityReason(ec.getDetail("highPriorityReason")) .preprocess(); fpClients.add(fpClient); } return fpClients; } }); }
FPSmartRegisterController { public FPClients getClients() { return fpClientsCache.get(FP_CLIENTS_LIST, new CacheableData<FPClients>() { @Override public FPClients fetch() { List<EligibleCouple> ecs = allEligibleCouples.all(); FPClients fpClients = new FPClients(); for (EligibleCouple ec : ecs) { if (allBeneficiaries.isPregnant(ec.caseId())) { continue; } String photoPath = isBlank(ec.photoPath()) ? DEFAULT_WOMAN_IMAGE_PLACEHOLDER_PATH : ec.photoPath(); List<AlertDTO> alerts = getFPAlertsForEC(ec.caseId()); FPClient fpClient = new FPClient(ec.caseId(), ec.wifeName(), ec.husbandName(), ec.village(), ec.ecNumber()).withAge(ec.age()) .withFPMethod(ec.getDetail("currentMethod")) .withFamilyPlanningMethodChangeDate( ec.getDetail("familyPlanningMethodChangeDate")) .withComplicationDate(ec.getDetail("complicationDate")) .withIUDPlace(ec.getDetail("iudPlace")) .withIUDPerson(ec.getDetail("iudPerson")) .withNumberOfCondomsSupplied(ec.getDetail("numberOfCondomsSupplied")) .withNumberOfCentchromanPillsDelivered( ec.getDetail("numberOfCentchromanPillsDelivered")) .withNumberOfOCPDelivered(ec.getDetail("numberOfOCPDelivered")) .withFPMethodFollowupDate(ec.getDetail("fpFollowupDate")) .withCaste(ec.getDetail("caste")) .withEconomicStatus(ec.getDetail("economicStatus")) .withNumberOfPregnancies(ec.getDetail("numberOfPregnancies")) .withParity(ec.getDetail("parity")) .withNumberOfLivingChildren(ec.getDetail("numberOfLivingChildren")) .withNumberOfStillBirths(ec.getDetail("numberOfStillBirths")) .withNumberOfAbortions(ec.getDetail("numberOfAbortions")) .withIsYoungestChildUnderTwo(ec.isYoungestChildUnderTwo()) .withYoungestChildAge(ec.getDetail("youngestChildAge")) .withIsHighPriority(ec.isHighPriority()).withPhotoPath(photoPath) .withAlerts(alerts) .withCondomSideEffect(ec.getDetail("condomSideEffect")) .withIUDSidEffect(ec.getDetail("iudSidEffect")) .withOCPSideEffect(ec.getDetail("ocpSideEffect")) .withInjectableSideEffect(ec.getDetail("injectableSideEffect")) .withSterilizationSideEffect(ec.getDetail("sterilizationSideEffect")) .withOtherSideEffect(ec.getDetail("otherSideEffect")) .withHighPriorityReason(ec.getDetail("highPriorityReason")) .preprocess(); fpClients.add(fpClient); } return fpClients; } }); } }
FPSmartRegisterController { public FPClients getClients() { return fpClientsCache.get(FP_CLIENTS_LIST, new CacheableData<FPClients>() { @Override public FPClients fetch() { List<EligibleCouple> ecs = allEligibleCouples.all(); FPClients fpClients = new FPClients(); for (EligibleCouple ec : ecs) { if (allBeneficiaries.isPregnant(ec.caseId())) { continue; } String photoPath = isBlank(ec.photoPath()) ? DEFAULT_WOMAN_IMAGE_PLACEHOLDER_PATH : ec.photoPath(); List<AlertDTO> alerts = getFPAlertsForEC(ec.caseId()); FPClient fpClient = new FPClient(ec.caseId(), ec.wifeName(), ec.husbandName(), ec.village(), ec.ecNumber()).withAge(ec.age()) .withFPMethod(ec.getDetail("currentMethod")) .withFamilyPlanningMethodChangeDate( ec.getDetail("familyPlanningMethodChangeDate")) .withComplicationDate(ec.getDetail("complicationDate")) .withIUDPlace(ec.getDetail("iudPlace")) .withIUDPerson(ec.getDetail("iudPerson")) .withNumberOfCondomsSupplied(ec.getDetail("numberOfCondomsSupplied")) .withNumberOfCentchromanPillsDelivered( ec.getDetail("numberOfCentchromanPillsDelivered")) .withNumberOfOCPDelivered(ec.getDetail("numberOfOCPDelivered")) .withFPMethodFollowupDate(ec.getDetail("fpFollowupDate")) .withCaste(ec.getDetail("caste")) .withEconomicStatus(ec.getDetail("economicStatus")) .withNumberOfPregnancies(ec.getDetail("numberOfPregnancies")) .withParity(ec.getDetail("parity")) .withNumberOfLivingChildren(ec.getDetail("numberOfLivingChildren")) .withNumberOfStillBirths(ec.getDetail("numberOfStillBirths")) .withNumberOfAbortions(ec.getDetail("numberOfAbortions")) .withIsYoungestChildUnderTwo(ec.isYoungestChildUnderTwo()) .withYoungestChildAge(ec.getDetail("youngestChildAge")) .withIsHighPriority(ec.isHighPriority()).withPhotoPath(photoPath) .withAlerts(alerts) .withCondomSideEffect(ec.getDetail("condomSideEffect")) .withIUDSidEffect(ec.getDetail("iudSidEffect")) .withOCPSideEffect(ec.getDetail("ocpSideEffect")) .withInjectableSideEffect(ec.getDetail("injectableSideEffect")) .withSterilizationSideEffect(ec.getDetail("sterilizationSideEffect")) .withOtherSideEffect(ec.getDetail("otherSideEffect")) .withHighPriorityReason(ec.getDetail("highPriorityReason")) .preprocess(); fpClients.add(fpClient); } return fpClients; } }); } FPSmartRegisterController(AllEligibleCouples allEligibleCouples, AllBeneficiaries allBeneficiaries, AlertService alertService, Cache<String> cache, Cache<FPClients> fpClientsCache); }
FPSmartRegisterController { public FPClients getClients() { return fpClientsCache.get(FP_CLIENTS_LIST, new CacheableData<FPClients>() { @Override public FPClients fetch() { List<EligibleCouple> ecs = allEligibleCouples.all(); FPClients fpClients = new FPClients(); for (EligibleCouple ec : ecs) { if (allBeneficiaries.isPregnant(ec.caseId())) { continue; } String photoPath = isBlank(ec.photoPath()) ? DEFAULT_WOMAN_IMAGE_PLACEHOLDER_PATH : ec.photoPath(); List<AlertDTO> alerts = getFPAlertsForEC(ec.caseId()); FPClient fpClient = new FPClient(ec.caseId(), ec.wifeName(), ec.husbandName(), ec.village(), ec.ecNumber()).withAge(ec.age()) .withFPMethod(ec.getDetail("currentMethod")) .withFamilyPlanningMethodChangeDate( ec.getDetail("familyPlanningMethodChangeDate")) .withComplicationDate(ec.getDetail("complicationDate")) .withIUDPlace(ec.getDetail("iudPlace")) .withIUDPerson(ec.getDetail("iudPerson")) .withNumberOfCondomsSupplied(ec.getDetail("numberOfCondomsSupplied")) .withNumberOfCentchromanPillsDelivered( ec.getDetail("numberOfCentchromanPillsDelivered")) .withNumberOfOCPDelivered(ec.getDetail("numberOfOCPDelivered")) .withFPMethodFollowupDate(ec.getDetail("fpFollowupDate")) .withCaste(ec.getDetail("caste")) .withEconomicStatus(ec.getDetail("economicStatus")) .withNumberOfPregnancies(ec.getDetail("numberOfPregnancies")) .withParity(ec.getDetail("parity")) .withNumberOfLivingChildren(ec.getDetail("numberOfLivingChildren")) .withNumberOfStillBirths(ec.getDetail("numberOfStillBirths")) .withNumberOfAbortions(ec.getDetail("numberOfAbortions")) .withIsYoungestChildUnderTwo(ec.isYoungestChildUnderTwo()) .withYoungestChildAge(ec.getDetail("youngestChildAge")) .withIsHighPriority(ec.isHighPriority()).withPhotoPath(photoPath) .withAlerts(alerts) .withCondomSideEffect(ec.getDetail("condomSideEffect")) .withIUDSidEffect(ec.getDetail("iudSidEffect")) .withOCPSideEffect(ec.getDetail("ocpSideEffect")) .withInjectableSideEffect(ec.getDetail("injectableSideEffect")) .withSterilizationSideEffect(ec.getDetail("sterilizationSideEffect")) .withOtherSideEffect(ec.getDetail("otherSideEffect")) .withHighPriorityReason(ec.getDetail("highPriorityReason")) .preprocess(); fpClients.add(fpClient); } return fpClients; } }); } FPSmartRegisterController(AllEligibleCouples allEligibleCouples, AllBeneficiaries allBeneficiaries, AlertService alertService, Cache<String> cache, Cache<FPClients> fpClientsCache); FPClients getClients(); }
FPSmartRegisterController { public FPClients getClients() { return fpClientsCache.get(FP_CLIENTS_LIST, new CacheableData<FPClients>() { @Override public FPClients fetch() { List<EligibleCouple> ecs = allEligibleCouples.all(); FPClients fpClients = new FPClients(); for (EligibleCouple ec : ecs) { if (allBeneficiaries.isPregnant(ec.caseId())) { continue; } String photoPath = isBlank(ec.photoPath()) ? DEFAULT_WOMAN_IMAGE_PLACEHOLDER_PATH : ec.photoPath(); List<AlertDTO> alerts = getFPAlertsForEC(ec.caseId()); FPClient fpClient = new FPClient(ec.caseId(), ec.wifeName(), ec.husbandName(), ec.village(), ec.ecNumber()).withAge(ec.age()) .withFPMethod(ec.getDetail("currentMethod")) .withFamilyPlanningMethodChangeDate( ec.getDetail("familyPlanningMethodChangeDate")) .withComplicationDate(ec.getDetail("complicationDate")) .withIUDPlace(ec.getDetail("iudPlace")) .withIUDPerson(ec.getDetail("iudPerson")) .withNumberOfCondomsSupplied(ec.getDetail("numberOfCondomsSupplied")) .withNumberOfCentchromanPillsDelivered( ec.getDetail("numberOfCentchromanPillsDelivered")) .withNumberOfOCPDelivered(ec.getDetail("numberOfOCPDelivered")) .withFPMethodFollowupDate(ec.getDetail("fpFollowupDate")) .withCaste(ec.getDetail("caste")) .withEconomicStatus(ec.getDetail("economicStatus")) .withNumberOfPregnancies(ec.getDetail("numberOfPregnancies")) .withParity(ec.getDetail("parity")) .withNumberOfLivingChildren(ec.getDetail("numberOfLivingChildren")) .withNumberOfStillBirths(ec.getDetail("numberOfStillBirths")) .withNumberOfAbortions(ec.getDetail("numberOfAbortions")) .withIsYoungestChildUnderTwo(ec.isYoungestChildUnderTwo()) .withYoungestChildAge(ec.getDetail("youngestChildAge")) .withIsHighPriority(ec.isHighPriority()).withPhotoPath(photoPath) .withAlerts(alerts) .withCondomSideEffect(ec.getDetail("condomSideEffect")) .withIUDSidEffect(ec.getDetail("iudSidEffect")) .withOCPSideEffect(ec.getDetail("ocpSideEffect")) .withInjectableSideEffect(ec.getDetail("injectableSideEffect")) .withSterilizationSideEffect(ec.getDetail("sterilizationSideEffect")) .withOtherSideEffect(ec.getDetail("otherSideEffect")) .withHighPriorityReason(ec.getDetail("highPriorityReason")) .preprocess(); fpClients.add(fpClient); } return fpClients; } }); } FPSmartRegisterController(AllEligibleCouples allEligibleCouples, AllBeneficiaries allBeneficiaries, AlertService alertService, Cache<String> cache, Cache<FPClients> fpClientsCache); FPClients getClients(); static final String OCP_REFILL_ALERT_NAME; static final String CONDOM_REFILL_ALERT_NAME; static final String DMPA_INJECTABLE_REFILL_ALERT_NAME; static final String FEMALE_STERILIZATION_FOLLOWUP_1_ALERT_NAME; static final String FEMALE_STERILIZATION_FOLLOWUP_2_ALERT_NAME; static final String FEMALE_STERILIZATION_FOLLOWUP_3_ALERT_NAME; static final String MALE_STERILIZATION_FOLLOWUP_1_ALERT_NAME; static final String MALE_STERILIZATION_FOLLOWUP_2_ALERT_NAME; static final String IUD_FOLLOWUP_1_ALERT_NAME; static final String IUD_FOLLOWUP_2_ALERT_NAME; static final String FP_FOLLOWUP_ALERT_NAME; static final String FP_REFERRAL_FOLLOWUP_ALERT_NAME; }
@Test public void shouldCreateFPClientsWithOCPRefillAlert() throws Exception { EligibleCouple ec = new EligibleCouple("entity id 1", "Woman C", "Husband C", "EC Number 3", "Bherya", "Bherya SC", emptyDetails); Alert ocpRefillAlert = new Alert("entity id 1", "OCP Refill", "OCP Refill", AlertStatus.normal, "2013-01-01", "2013-02-01"); Mockito.when(allEligibleCouples.all()).thenReturn(Arrays.asList(ec)); Mockito.when(alertService.findByEntityIdAndAlertNames("entity id 1", EC_ALERTS)).thenReturn(Arrays.asList(ocpRefillAlert)); FPClients actualClients = controller.getClients(); Mockito.verify(alertService).findByEntityIdAndAlertNames("entity id 1", EC_ALERTS); AlertDTO expectedAlertDto = new AlertDTO("OCP Refill", "normal", "2013-01-01"); FPClient expectedEC = createFPClient("entity id 1", "Woman C", "Husband C", "Bherya", "EC Number 3").withAlerts(Arrays.asList(expectedAlertDto)).withNumberOfAbortions("0").withNumberOfPregnancies("0").withNumberOfStillBirths("0").withNumberOfLivingChildren("0").withParity("0"); Assert.assertEquals(Arrays.asList(expectedEC), actualClients); }
public FPClients getClients() { return fpClientsCache.get(FP_CLIENTS_LIST, new CacheableData<FPClients>() { @Override public FPClients fetch() { List<EligibleCouple> ecs = allEligibleCouples.all(); FPClients fpClients = new FPClients(); for (EligibleCouple ec : ecs) { if (allBeneficiaries.isPregnant(ec.caseId())) { continue; } String photoPath = isBlank(ec.photoPath()) ? DEFAULT_WOMAN_IMAGE_PLACEHOLDER_PATH : ec.photoPath(); List<AlertDTO> alerts = getFPAlertsForEC(ec.caseId()); FPClient fpClient = new FPClient(ec.caseId(), ec.wifeName(), ec.husbandName(), ec.village(), ec.ecNumber()).withAge(ec.age()) .withFPMethod(ec.getDetail("currentMethod")) .withFamilyPlanningMethodChangeDate( ec.getDetail("familyPlanningMethodChangeDate")) .withComplicationDate(ec.getDetail("complicationDate")) .withIUDPlace(ec.getDetail("iudPlace")) .withIUDPerson(ec.getDetail("iudPerson")) .withNumberOfCondomsSupplied(ec.getDetail("numberOfCondomsSupplied")) .withNumberOfCentchromanPillsDelivered( ec.getDetail("numberOfCentchromanPillsDelivered")) .withNumberOfOCPDelivered(ec.getDetail("numberOfOCPDelivered")) .withFPMethodFollowupDate(ec.getDetail("fpFollowupDate")) .withCaste(ec.getDetail("caste")) .withEconomicStatus(ec.getDetail("economicStatus")) .withNumberOfPregnancies(ec.getDetail("numberOfPregnancies")) .withParity(ec.getDetail("parity")) .withNumberOfLivingChildren(ec.getDetail("numberOfLivingChildren")) .withNumberOfStillBirths(ec.getDetail("numberOfStillBirths")) .withNumberOfAbortions(ec.getDetail("numberOfAbortions")) .withIsYoungestChildUnderTwo(ec.isYoungestChildUnderTwo()) .withYoungestChildAge(ec.getDetail("youngestChildAge")) .withIsHighPriority(ec.isHighPriority()).withPhotoPath(photoPath) .withAlerts(alerts) .withCondomSideEffect(ec.getDetail("condomSideEffect")) .withIUDSidEffect(ec.getDetail("iudSidEffect")) .withOCPSideEffect(ec.getDetail("ocpSideEffect")) .withInjectableSideEffect(ec.getDetail("injectableSideEffect")) .withSterilizationSideEffect(ec.getDetail("sterilizationSideEffect")) .withOtherSideEffect(ec.getDetail("otherSideEffect")) .withHighPriorityReason(ec.getDetail("highPriorityReason")) .preprocess(); fpClients.add(fpClient); } return fpClients; } }); }
FPSmartRegisterController { public FPClients getClients() { return fpClientsCache.get(FP_CLIENTS_LIST, new CacheableData<FPClients>() { @Override public FPClients fetch() { List<EligibleCouple> ecs = allEligibleCouples.all(); FPClients fpClients = new FPClients(); for (EligibleCouple ec : ecs) { if (allBeneficiaries.isPregnant(ec.caseId())) { continue; } String photoPath = isBlank(ec.photoPath()) ? DEFAULT_WOMAN_IMAGE_PLACEHOLDER_PATH : ec.photoPath(); List<AlertDTO> alerts = getFPAlertsForEC(ec.caseId()); FPClient fpClient = new FPClient(ec.caseId(), ec.wifeName(), ec.husbandName(), ec.village(), ec.ecNumber()).withAge(ec.age()) .withFPMethod(ec.getDetail("currentMethod")) .withFamilyPlanningMethodChangeDate( ec.getDetail("familyPlanningMethodChangeDate")) .withComplicationDate(ec.getDetail("complicationDate")) .withIUDPlace(ec.getDetail("iudPlace")) .withIUDPerson(ec.getDetail("iudPerson")) .withNumberOfCondomsSupplied(ec.getDetail("numberOfCondomsSupplied")) .withNumberOfCentchromanPillsDelivered( ec.getDetail("numberOfCentchromanPillsDelivered")) .withNumberOfOCPDelivered(ec.getDetail("numberOfOCPDelivered")) .withFPMethodFollowupDate(ec.getDetail("fpFollowupDate")) .withCaste(ec.getDetail("caste")) .withEconomicStatus(ec.getDetail("economicStatus")) .withNumberOfPregnancies(ec.getDetail("numberOfPregnancies")) .withParity(ec.getDetail("parity")) .withNumberOfLivingChildren(ec.getDetail("numberOfLivingChildren")) .withNumberOfStillBirths(ec.getDetail("numberOfStillBirths")) .withNumberOfAbortions(ec.getDetail("numberOfAbortions")) .withIsYoungestChildUnderTwo(ec.isYoungestChildUnderTwo()) .withYoungestChildAge(ec.getDetail("youngestChildAge")) .withIsHighPriority(ec.isHighPriority()).withPhotoPath(photoPath) .withAlerts(alerts) .withCondomSideEffect(ec.getDetail("condomSideEffect")) .withIUDSidEffect(ec.getDetail("iudSidEffect")) .withOCPSideEffect(ec.getDetail("ocpSideEffect")) .withInjectableSideEffect(ec.getDetail("injectableSideEffect")) .withSterilizationSideEffect(ec.getDetail("sterilizationSideEffect")) .withOtherSideEffect(ec.getDetail("otherSideEffect")) .withHighPriorityReason(ec.getDetail("highPriorityReason")) .preprocess(); fpClients.add(fpClient); } return fpClients; } }); } }
FPSmartRegisterController { public FPClients getClients() { return fpClientsCache.get(FP_CLIENTS_LIST, new CacheableData<FPClients>() { @Override public FPClients fetch() { List<EligibleCouple> ecs = allEligibleCouples.all(); FPClients fpClients = new FPClients(); for (EligibleCouple ec : ecs) { if (allBeneficiaries.isPregnant(ec.caseId())) { continue; } String photoPath = isBlank(ec.photoPath()) ? DEFAULT_WOMAN_IMAGE_PLACEHOLDER_PATH : ec.photoPath(); List<AlertDTO> alerts = getFPAlertsForEC(ec.caseId()); FPClient fpClient = new FPClient(ec.caseId(), ec.wifeName(), ec.husbandName(), ec.village(), ec.ecNumber()).withAge(ec.age()) .withFPMethod(ec.getDetail("currentMethod")) .withFamilyPlanningMethodChangeDate( ec.getDetail("familyPlanningMethodChangeDate")) .withComplicationDate(ec.getDetail("complicationDate")) .withIUDPlace(ec.getDetail("iudPlace")) .withIUDPerson(ec.getDetail("iudPerson")) .withNumberOfCondomsSupplied(ec.getDetail("numberOfCondomsSupplied")) .withNumberOfCentchromanPillsDelivered( ec.getDetail("numberOfCentchromanPillsDelivered")) .withNumberOfOCPDelivered(ec.getDetail("numberOfOCPDelivered")) .withFPMethodFollowupDate(ec.getDetail("fpFollowupDate")) .withCaste(ec.getDetail("caste")) .withEconomicStatus(ec.getDetail("economicStatus")) .withNumberOfPregnancies(ec.getDetail("numberOfPregnancies")) .withParity(ec.getDetail("parity")) .withNumberOfLivingChildren(ec.getDetail("numberOfLivingChildren")) .withNumberOfStillBirths(ec.getDetail("numberOfStillBirths")) .withNumberOfAbortions(ec.getDetail("numberOfAbortions")) .withIsYoungestChildUnderTwo(ec.isYoungestChildUnderTwo()) .withYoungestChildAge(ec.getDetail("youngestChildAge")) .withIsHighPriority(ec.isHighPriority()).withPhotoPath(photoPath) .withAlerts(alerts) .withCondomSideEffect(ec.getDetail("condomSideEffect")) .withIUDSidEffect(ec.getDetail("iudSidEffect")) .withOCPSideEffect(ec.getDetail("ocpSideEffect")) .withInjectableSideEffect(ec.getDetail("injectableSideEffect")) .withSterilizationSideEffect(ec.getDetail("sterilizationSideEffect")) .withOtherSideEffect(ec.getDetail("otherSideEffect")) .withHighPriorityReason(ec.getDetail("highPriorityReason")) .preprocess(); fpClients.add(fpClient); } return fpClients; } }); } FPSmartRegisterController(AllEligibleCouples allEligibleCouples, AllBeneficiaries allBeneficiaries, AlertService alertService, Cache<String> cache, Cache<FPClients> fpClientsCache); }
FPSmartRegisterController { public FPClients getClients() { return fpClientsCache.get(FP_CLIENTS_LIST, new CacheableData<FPClients>() { @Override public FPClients fetch() { List<EligibleCouple> ecs = allEligibleCouples.all(); FPClients fpClients = new FPClients(); for (EligibleCouple ec : ecs) { if (allBeneficiaries.isPregnant(ec.caseId())) { continue; } String photoPath = isBlank(ec.photoPath()) ? DEFAULT_WOMAN_IMAGE_PLACEHOLDER_PATH : ec.photoPath(); List<AlertDTO> alerts = getFPAlertsForEC(ec.caseId()); FPClient fpClient = new FPClient(ec.caseId(), ec.wifeName(), ec.husbandName(), ec.village(), ec.ecNumber()).withAge(ec.age()) .withFPMethod(ec.getDetail("currentMethod")) .withFamilyPlanningMethodChangeDate( ec.getDetail("familyPlanningMethodChangeDate")) .withComplicationDate(ec.getDetail("complicationDate")) .withIUDPlace(ec.getDetail("iudPlace")) .withIUDPerson(ec.getDetail("iudPerson")) .withNumberOfCondomsSupplied(ec.getDetail("numberOfCondomsSupplied")) .withNumberOfCentchromanPillsDelivered( ec.getDetail("numberOfCentchromanPillsDelivered")) .withNumberOfOCPDelivered(ec.getDetail("numberOfOCPDelivered")) .withFPMethodFollowupDate(ec.getDetail("fpFollowupDate")) .withCaste(ec.getDetail("caste")) .withEconomicStatus(ec.getDetail("economicStatus")) .withNumberOfPregnancies(ec.getDetail("numberOfPregnancies")) .withParity(ec.getDetail("parity")) .withNumberOfLivingChildren(ec.getDetail("numberOfLivingChildren")) .withNumberOfStillBirths(ec.getDetail("numberOfStillBirths")) .withNumberOfAbortions(ec.getDetail("numberOfAbortions")) .withIsYoungestChildUnderTwo(ec.isYoungestChildUnderTwo()) .withYoungestChildAge(ec.getDetail("youngestChildAge")) .withIsHighPriority(ec.isHighPriority()).withPhotoPath(photoPath) .withAlerts(alerts) .withCondomSideEffect(ec.getDetail("condomSideEffect")) .withIUDSidEffect(ec.getDetail("iudSidEffect")) .withOCPSideEffect(ec.getDetail("ocpSideEffect")) .withInjectableSideEffect(ec.getDetail("injectableSideEffect")) .withSterilizationSideEffect(ec.getDetail("sterilizationSideEffect")) .withOtherSideEffect(ec.getDetail("otherSideEffect")) .withHighPriorityReason(ec.getDetail("highPriorityReason")) .preprocess(); fpClients.add(fpClient); } return fpClients; } }); } FPSmartRegisterController(AllEligibleCouples allEligibleCouples, AllBeneficiaries allBeneficiaries, AlertService alertService, Cache<String> cache, Cache<FPClients> fpClientsCache); FPClients getClients(); }
FPSmartRegisterController { public FPClients getClients() { return fpClientsCache.get(FP_CLIENTS_LIST, new CacheableData<FPClients>() { @Override public FPClients fetch() { List<EligibleCouple> ecs = allEligibleCouples.all(); FPClients fpClients = new FPClients(); for (EligibleCouple ec : ecs) { if (allBeneficiaries.isPregnant(ec.caseId())) { continue; } String photoPath = isBlank(ec.photoPath()) ? DEFAULT_WOMAN_IMAGE_PLACEHOLDER_PATH : ec.photoPath(); List<AlertDTO> alerts = getFPAlertsForEC(ec.caseId()); FPClient fpClient = new FPClient(ec.caseId(), ec.wifeName(), ec.husbandName(), ec.village(), ec.ecNumber()).withAge(ec.age()) .withFPMethod(ec.getDetail("currentMethod")) .withFamilyPlanningMethodChangeDate( ec.getDetail("familyPlanningMethodChangeDate")) .withComplicationDate(ec.getDetail("complicationDate")) .withIUDPlace(ec.getDetail("iudPlace")) .withIUDPerson(ec.getDetail("iudPerson")) .withNumberOfCondomsSupplied(ec.getDetail("numberOfCondomsSupplied")) .withNumberOfCentchromanPillsDelivered( ec.getDetail("numberOfCentchromanPillsDelivered")) .withNumberOfOCPDelivered(ec.getDetail("numberOfOCPDelivered")) .withFPMethodFollowupDate(ec.getDetail("fpFollowupDate")) .withCaste(ec.getDetail("caste")) .withEconomicStatus(ec.getDetail("economicStatus")) .withNumberOfPregnancies(ec.getDetail("numberOfPregnancies")) .withParity(ec.getDetail("parity")) .withNumberOfLivingChildren(ec.getDetail("numberOfLivingChildren")) .withNumberOfStillBirths(ec.getDetail("numberOfStillBirths")) .withNumberOfAbortions(ec.getDetail("numberOfAbortions")) .withIsYoungestChildUnderTwo(ec.isYoungestChildUnderTwo()) .withYoungestChildAge(ec.getDetail("youngestChildAge")) .withIsHighPriority(ec.isHighPriority()).withPhotoPath(photoPath) .withAlerts(alerts) .withCondomSideEffect(ec.getDetail("condomSideEffect")) .withIUDSidEffect(ec.getDetail("iudSidEffect")) .withOCPSideEffect(ec.getDetail("ocpSideEffect")) .withInjectableSideEffect(ec.getDetail("injectableSideEffect")) .withSterilizationSideEffect(ec.getDetail("sterilizationSideEffect")) .withOtherSideEffect(ec.getDetail("otherSideEffect")) .withHighPriorityReason(ec.getDetail("highPriorityReason")) .preprocess(); fpClients.add(fpClient); } return fpClients; } }); } FPSmartRegisterController(AllEligibleCouples allEligibleCouples, AllBeneficiaries allBeneficiaries, AlertService alertService, Cache<String> cache, Cache<FPClients> fpClientsCache); FPClients getClients(); static final String OCP_REFILL_ALERT_NAME; static final String CONDOM_REFILL_ALERT_NAME; static final String DMPA_INJECTABLE_REFILL_ALERT_NAME; static final String FEMALE_STERILIZATION_FOLLOWUP_1_ALERT_NAME; static final String FEMALE_STERILIZATION_FOLLOWUP_2_ALERT_NAME; static final String FEMALE_STERILIZATION_FOLLOWUP_3_ALERT_NAME; static final String MALE_STERILIZATION_FOLLOWUP_1_ALERT_NAME; static final String MALE_STERILIZATION_FOLLOWUP_2_ALERT_NAME; static final String IUD_FOLLOWUP_1_ALERT_NAME; static final String IUD_FOLLOWUP_2_ALERT_NAME; static final String FP_FOLLOWUP_ALERT_NAME; static final String FP_REFERRAL_FOLLOWUP_ALERT_NAME; }
@Test public void shouldCreateFPClientsWithRefillFollowUps() throws Exception { EligibleCouple ec = new EligibleCouple("entity id 1", "Woman C", "Husband C", "EC Number 3", "Bherya", "Bherya SC", EasyMap.create("currentMethod", "condom").map()); Alert condomRefillAlert = new Alert("entity id 1", "Condom Refill", "Condom Refill", AlertStatus.urgent, "2013-01-01", "2013-02-01"); Mockito.when(allEligibleCouples.all()).thenReturn(Arrays.asList(ec)); Mockito.when(alertService.findByEntityIdAndAlertNames("entity id 1", EC_ALERTS)).thenReturn(Arrays.asList(condomRefillAlert)); Mockito.when(context.getStringResource(R.string.str_refill)).thenReturn("refill"); CoreLibrary.reset(context); FPClients clients = controller.getClients(); Mockito.verify(alertService).findByEntityIdAndAlertNames("entity id 1", EC_ALERTS); AlertDTO expectedAlertDto = new AlertDTO("Condom Refill", "urgent", "2013-01-01"); FPClient expectedEC = createFPClient("entity id 1", "Woman C", "Husband C", "Bherya", "EC Number 3") .withAlerts(Arrays.asList(expectedAlertDto)) .withNumberOfAbortions("0") .withNumberOfPregnancies("0") .withNumberOfStillBirths("0") .withNumberOfLivingChildren("0") .withParity("0") .withFPMethod("condom") .withRefillFollowUps(new RefillFollowUps("Condom Refill", expectedAlertDto, "refill")); Assert.assertEquals(Arrays.asList(expectedEC), clients); }
public FPClients getClients() { return fpClientsCache.get(FP_CLIENTS_LIST, new CacheableData<FPClients>() { @Override public FPClients fetch() { List<EligibleCouple> ecs = allEligibleCouples.all(); FPClients fpClients = new FPClients(); for (EligibleCouple ec : ecs) { if (allBeneficiaries.isPregnant(ec.caseId())) { continue; } String photoPath = isBlank(ec.photoPath()) ? DEFAULT_WOMAN_IMAGE_PLACEHOLDER_PATH : ec.photoPath(); List<AlertDTO> alerts = getFPAlertsForEC(ec.caseId()); FPClient fpClient = new FPClient(ec.caseId(), ec.wifeName(), ec.husbandName(), ec.village(), ec.ecNumber()).withAge(ec.age()) .withFPMethod(ec.getDetail("currentMethod")) .withFamilyPlanningMethodChangeDate( ec.getDetail("familyPlanningMethodChangeDate")) .withComplicationDate(ec.getDetail("complicationDate")) .withIUDPlace(ec.getDetail("iudPlace")) .withIUDPerson(ec.getDetail("iudPerson")) .withNumberOfCondomsSupplied(ec.getDetail("numberOfCondomsSupplied")) .withNumberOfCentchromanPillsDelivered( ec.getDetail("numberOfCentchromanPillsDelivered")) .withNumberOfOCPDelivered(ec.getDetail("numberOfOCPDelivered")) .withFPMethodFollowupDate(ec.getDetail("fpFollowupDate")) .withCaste(ec.getDetail("caste")) .withEconomicStatus(ec.getDetail("economicStatus")) .withNumberOfPregnancies(ec.getDetail("numberOfPregnancies")) .withParity(ec.getDetail("parity")) .withNumberOfLivingChildren(ec.getDetail("numberOfLivingChildren")) .withNumberOfStillBirths(ec.getDetail("numberOfStillBirths")) .withNumberOfAbortions(ec.getDetail("numberOfAbortions")) .withIsYoungestChildUnderTwo(ec.isYoungestChildUnderTwo()) .withYoungestChildAge(ec.getDetail("youngestChildAge")) .withIsHighPriority(ec.isHighPriority()).withPhotoPath(photoPath) .withAlerts(alerts) .withCondomSideEffect(ec.getDetail("condomSideEffect")) .withIUDSidEffect(ec.getDetail("iudSidEffect")) .withOCPSideEffect(ec.getDetail("ocpSideEffect")) .withInjectableSideEffect(ec.getDetail("injectableSideEffect")) .withSterilizationSideEffect(ec.getDetail("sterilizationSideEffect")) .withOtherSideEffect(ec.getDetail("otherSideEffect")) .withHighPriorityReason(ec.getDetail("highPriorityReason")) .preprocess(); fpClients.add(fpClient); } return fpClients; } }); }
FPSmartRegisterController { public FPClients getClients() { return fpClientsCache.get(FP_CLIENTS_LIST, new CacheableData<FPClients>() { @Override public FPClients fetch() { List<EligibleCouple> ecs = allEligibleCouples.all(); FPClients fpClients = new FPClients(); for (EligibleCouple ec : ecs) { if (allBeneficiaries.isPregnant(ec.caseId())) { continue; } String photoPath = isBlank(ec.photoPath()) ? DEFAULT_WOMAN_IMAGE_PLACEHOLDER_PATH : ec.photoPath(); List<AlertDTO> alerts = getFPAlertsForEC(ec.caseId()); FPClient fpClient = new FPClient(ec.caseId(), ec.wifeName(), ec.husbandName(), ec.village(), ec.ecNumber()).withAge(ec.age()) .withFPMethod(ec.getDetail("currentMethod")) .withFamilyPlanningMethodChangeDate( ec.getDetail("familyPlanningMethodChangeDate")) .withComplicationDate(ec.getDetail("complicationDate")) .withIUDPlace(ec.getDetail("iudPlace")) .withIUDPerson(ec.getDetail("iudPerson")) .withNumberOfCondomsSupplied(ec.getDetail("numberOfCondomsSupplied")) .withNumberOfCentchromanPillsDelivered( ec.getDetail("numberOfCentchromanPillsDelivered")) .withNumberOfOCPDelivered(ec.getDetail("numberOfOCPDelivered")) .withFPMethodFollowupDate(ec.getDetail("fpFollowupDate")) .withCaste(ec.getDetail("caste")) .withEconomicStatus(ec.getDetail("economicStatus")) .withNumberOfPregnancies(ec.getDetail("numberOfPregnancies")) .withParity(ec.getDetail("parity")) .withNumberOfLivingChildren(ec.getDetail("numberOfLivingChildren")) .withNumberOfStillBirths(ec.getDetail("numberOfStillBirths")) .withNumberOfAbortions(ec.getDetail("numberOfAbortions")) .withIsYoungestChildUnderTwo(ec.isYoungestChildUnderTwo()) .withYoungestChildAge(ec.getDetail("youngestChildAge")) .withIsHighPriority(ec.isHighPriority()).withPhotoPath(photoPath) .withAlerts(alerts) .withCondomSideEffect(ec.getDetail("condomSideEffect")) .withIUDSidEffect(ec.getDetail("iudSidEffect")) .withOCPSideEffect(ec.getDetail("ocpSideEffect")) .withInjectableSideEffect(ec.getDetail("injectableSideEffect")) .withSterilizationSideEffect(ec.getDetail("sterilizationSideEffect")) .withOtherSideEffect(ec.getDetail("otherSideEffect")) .withHighPriorityReason(ec.getDetail("highPriorityReason")) .preprocess(); fpClients.add(fpClient); } return fpClients; } }); } }
FPSmartRegisterController { public FPClients getClients() { return fpClientsCache.get(FP_CLIENTS_LIST, new CacheableData<FPClients>() { @Override public FPClients fetch() { List<EligibleCouple> ecs = allEligibleCouples.all(); FPClients fpClients = new FPClients(); for (EligibleCouple ec : ecs) { if (allBeneficiaries.isPregnant(ec.caseId())) { continue; } String photoPath = isBlank(ec.photoPath()) ? DEFAULT_WOMAN_IMAGE_PLACEHOLDER_PATH : ec.photoPath(); List<AlertDTO> alerts = getFPAlertsForEC(ec.caseId()); FPClient fpClient = new FPClient(ec.caseId(), ec.wifeName(), ec.husbandName(), ec.village(), ec.ecNumber()).withAge(ec.age()) .withFPMethod(ec.getDetail("currentMethod")) .withFamilyPlanningMethodChangeDate( ec.getDetail("familyPlanningMethodChangeDate")) .withComplicationDate(ec.getDetail("complicationDate")) .withIUDPlace(ec.getDetail("iudPlace")) .withIUDPerson(ec.getDetail("iudPerson")) .withNumberOfCondomsSupplied(ec.getDetail("numberOfCondomsSupplied")) .withNumberOfCentchromanPillsDelivered( ec.getDetail("numberOfCentchromanPillsDelivered")) .withNumberOfOCPDelivered(ec.getDetail("numberOfOCPDelivered")) .withFPMethodFollowupDate(ec.getDetail("fpFollowupDate")) .withCaste(ec.getDetail("caste")) .withEconomicStatus(ec.getDetail("economicStatus")) .withNumberOfPregnancies(ec.getDetail("numberOfPregnancies")) .withParity(ec.getDetail("parity")) .withNumberOfLivingChildren(ec.getDetail("numberOfLivingChildren")) .withNumberOfStillBirths(ec.getDetail("numberOfStillBirths")) .withNumberOfAbortions(ec.getDetail("numberOfAbortions")) .withIsYoungestChildUnderTwo(ec.isYoungestChildUnderTwo()) .withYoungestChildAge(ec.getDetail("youngestChildAge")) .withIsHighPriority(ec.isHighPriority()).withPhotoPath(photoPath) .withAlerts(alerts) .withCondomSideEffect(ec.getDetail("condomSideEffect")) .withIUDSidEffect(ec.getDetail("iudSidEffect")) .withOCPSideEffect(ec.getDetail("ocpSideEffect")) .withInjectableSideEffect(ec.getDetail("injectableSideEffect")) .withSterilizationSideEffect(ec.getDetail("sterilizationSideEffect")) .withOtherSideEffect(ec.getDetail("otherSideEffect")) .withHighPriorityReason(ec.getDetail("highPriorityReason")) .preprocess(); fpClients.add(fpClient); } return fpClients; } }); } FPSmartRegisterController(AllEligibleCouples allEligibleCouples, AllBeneficiaries allBeneficiaries, AlertService alertService, Cache<String> cache, Cache<FPClients> fpClientsCache); }
FPSmartRegisterController { public FPClients getClients() { return fpClientsCache.get(FP_CLIENTS_LIST, new CacheableData<FPClients>() { @Override public FPClients fetch() { List<EligibleCouple> ecs = allEligibleCouples.all(); FPClients fpClients = new FPClients(); for (EligibleCouple ec : ecs) { if (allBeneficiaries.isPregnant(ec.caseId())) { continue; } String photoPath = isBlank(ec.photoPath()) ? DEFAULT_WOMAN_IMAGE_PLACEHOLDER_PATH : ec.photoPath(); List<AlertDTO> alerts = getFPAlertsForEC(ec.caseId()); FPClient fpClient = new FPClient(ec.caseId(), ec.wifeName(), ec.husbandName(), ec.village(), ec.ecNumber()).withAge(ec.age()) .withFPMethod(ec.getDetail("currentMethod")) .withFamilyPlanningMethodChangeDate( ec.getDetail("familyPlanningMethodChangeDate")) .withComplicationDate(ec.getDetail("complicationDate")) .withIUDPlace(ec.getDetail("iudPlace")) .withIUDPerson(ec.getDetail("iudPerson")) .withNumberOfCondomsSupplied(ec.getDetail("numberOfCondomsSupplied")) .withNumberOfCentchromanPillsDelivered( ec.getDetail("numberOfCentchromanPillsDelivered")) .withNumberOfOCPDelivered(ec.getDetail("numberOfOCPDelivered")) .withFPMethodFollowupDate(ec.getDetail("fpFollowupDate")) .withCaste(ec.getDetail("caste")) .withEconomicStatus(ec.getDetail("economicStatus")) .withNumberOfPregnancies(ec.getDetail("numberOfPregnancies")) .withParity(ec.getDetail("parity")) .withNumberOfLivingChildren(ec.getDetail("numberOfLivingChildren")) .withNumberOfStillBirths(ec.getDetail("numberOfStillBirths")) .withNumberOfAbortions(ec.getDetail("numberOfAbortions")) .withIsYoungestChildUnderTwo(ec.isYoungestChildUnderTwo()) .withYoungestChildAge(ec.getDetail("youngestChildAge")) .withIsHighPriority(ec.isHighPriority()).withPhotoPath(photoPath) .withAlerts(alerts) .withCondomSideEffect(ec.getDetail("condomSideEffect")) .withIUDSidEffect(ec.getDetail("iudSidEffect")) .withOCPSideEffect(ec.getDetail("ocpSideEffect")) .withInjectableSideEffect(ec.getDetail("injectableSideEffect")) .withSterilizationSideEffect(ec.getDetail("sterilizationSideEffect")) .withOtherSideEffect(ec.getDetail("otherSideEffect")) .withHighPriorityReason(ec.getDetail("highPriorityReason")) .preprocess(); fpClients.add(fpClient); } return fpClients; } }); } FPSmartRegisterController(AllEligibleCouples allEligibleCouples, AllBeneficiaries allBeneficiaries, AlertService alertService, Cache<String> cache, Cache<FPClients> fpClientsCache); FPClients getClients(); }
FPSmartRegisterController { public FPClients getClients() { return fpClientsCache.get(FP_CLIENTS_LIST, new CacheableData<FPClients>() { @Override public FPClients fetch() { List<EligibleCouple> ecs = allEligibleCouples.all(); FPClients fpClients = new FPClients(); for (EligibleCouple ec : ecs) { if (allBeneficiaries.isPregnant(ec.caseId())) { continue; } String photoPath = isBlank(ec.photoPath()) ? DEFAULT_WOMAN_IMAGE_PLACEHOLDER_PATH : ec.photoPath(); List<AlertDTO> alerts = getFPAlertsForEC(ec.caseId()); FPClient fpClient = new FPClient(ec.caseId(), ec.wifeName(), ec.husbandName(), ec.village(), ec.ecNumber()).withAge(ec.age()) .withFPMethod(ec.getDetail("currentMethod")) .withFamilyPlanningMethodChangeDate( ec.getDetail("familyPlanningMethodChangeDate")) .withComplicationDate(ec.getDetail("complicationDate")) .withIUDPlace(ec.getDetail("iudPlace")) .withIUDPerson(ec.getDetail("iudPerson")) .withNumberOfCondomsSupplied(ec.getDetail("numberOfCondomsSupplied")) .withNumberOfCentchromanPillsDelivered( ec.getDetail("numberOfCentchromanPillsDelivered")) .withNumberOfOCPDelivered(ec.getDetail("numberOfOCPDelivered")) .withFPMethodFollowupDate(ec.getDetail("fpFollowupDate")) .withCaste(ec.getDetail("caste")) .withEconomicStatus(ec.getDetail("economicStatus")) .withNumberOfPregnancies(ec.getDetail("numberOfPregnancies")) .withParity(ec.getDetail("parity")) .withNumberOfLivingChildren(ec.getDetail("numberOfLivingChildren")) .withNumberOfStillBirths(ec.getDetail("numberOfStillBirths")) .withNumberOfAbortions(ec.getDetail("numberOfAbortions")) .withIsYoungestChildUnderTwo(ec.isYoungestChildUnderTwo()) .withYoungestChildAge(ec.getDetail("youngestChildAge")) .withIsHighPriority(ec.isHighPriority()).withPhotoPath(photoPath) .withAlerts(alerts) .withCondomSideEffect(ec.getDetail("condomSideEffect")) .withIUDSidEffect(ec.getDetail("iudSidEffect")) .withOCPSideEffect(ec.getDetail("ocpSideEffect")) .withInjectableSideEffect(ec.getDetail("injectableSideEffect")) .withSterilizationSideEffect(ec.getDetail("sterilizationSideEffect")) .withOtherSideEffect(ec.getDetail("otherSideEffect")) .withHighPriorityReason(ec.getDetail("highPriorityReason")) .preprocess(); fpClients.add(fpClient); } return fpClients; } }); } FPSmartRegisterController(AllEligibleCouples allEligibleCouples, AllBeneficiaries allBeneficiaries, AlertService alertService, Cache<String> cache, Cache<FPClients> fpClientsCache); FPClients getClients(); static final String OCP_REFILL_ALERT_NAME; static final String CONDOM_REFILL_ALERT_NAME; static final String DMPA_INJECTABLE_REFILL_ALERT_NAME; static final String FEMALE_STERILIZATION_FOLLOWUP_1_ALERT_NAME; static final String FEMALE_STERILIZATION_FOLLOWUP_2_ALERT_NAME; static final String FEMALE_STERILIZATION_FOLLOWUP_3_ALERT_NAME; static final String MALE_STERILIZATION_FOLLOWUP_1_ALERT_NAME; static final String MALE_STERILIZATION_FOLLOWUP_2_ALERT_NAME; static final String IUD_FOLLOWUP_1_ALERT_NAME; static final String IUD_FOLLOWUP_2_ALERT_NAME; static final String FP_FOLLOWUP_ALERT_NAME; static final String FP_REFERRAL_FOLLOWUP_ALERT_NAME; }
@Test public void shouldNotIncludePregnantECsWhenFPClientsIsCreated() throws Exception { EligibleCouple ec = new EligibleCouple("entity id 1", "Woman C", "Husband C", "EC Number 3", "Bherya", "Bherya SC", emptyDetails); EligibleCouple pregnantEC = new EligibleCouple("entity id 2", "Woman D", "Husband D", "EC Number 4", "Bherya", "Bherya SC", emptyDetails); Mockito.when(allEligibleCouples.all()).thenReturn(Arrays.asList(ec, pregnantEC)); Mockito.when(allBeneficiaries.isPregnant("entity id 1")).thenReturn(false); Mockito.when(allBeneficiaries.isPregnant("entity id 2")).thenReturn(true); FPClients actualClients = controller.getClients(); Mockito.verify(allBeneficiaries).isPregnant("entity id 1"); Mockito.verify(allBeneficiaries).isPregnant("entity id 2"); FPClient expectedEC = createFPClient("entity id 1", "Woman C", "Husband C", "Bherya", "EC Number 3").withNumberOfAbortions("0").withNumberOfPregnancies("0").withNumberOfStillBirths("0").withNumberOfLivingChildren("0").withParity("0"); Assert.assertEquals(Arrays.asList(expectedEC), actualClients); }
public FPClients getClients() { return fpClientsCache.get(FP_CLIENTS_LIST, new CacheableData<FPClients>() { @Override public FPClients fetch() { List<EligibleCouple> ecs = allEligibleCouples.all(); FPClients fpClients = new FPClients(); for (EligibleCouple ec : ecs) { if (allBeneficiaries.isPregnant(ec.caseId())) { continue; } String photoPath = isBlank(ec.photoPath()) ? DEFAULT_WOMAN_IMAGE_PLACEHOLDER_PATH : ec.photoPath(); List<AlertDTO> alerts = getFPAlertsForEC(ec.caseId()); FPClient fpClient = new FPClient(ec.caseId(), ec.wifeName(), ec.husbandName(), ec.village(), ec.ecNumber()).withAge(ec.age()) .withFPMethod(ec.getDetail("currentMethod")) .withFamilyPlanningMethodChangeDate( ec.getDetail("familyPlanningMethodChangeDate")) .withComplicationDate(ec.getDetail("complicationDate")) .withIUDPlace(ec.getDetail("iudPlace")) .withIUDPerson(ec.getDetail("iudPerson")) .withNumberOfCondomsSupplied(ec.getDetail("numberOfCondomsSupplied")) .withNumberOfCentchromanPillsDelivered( ec.getDetail("numberOfCentchromanPillsDelivered")) .withNumberOfOCPDelivered(ec.getDetail("numberOfOCPDelivered")) .withFPMethodFollowupDate(ec.getDetail("fpFollowupDate")) .withCaste(ec.getDetail("caste")) .withEconomicStatus(ec.getDetail("economicStatus")) .withNumberOfPregnancies(ec.getDetail("numberOfPregnancies")) .withParity(ec.getDetail("parity")) .withNumberOfLivingChildren(ec.getDetail("numberOfLivingChildren")) .withNumberOfStillBirths(ec.getDetail("numberOfStillBirths")) .withNumberOfAbortions(ec.getDetail("numberOfAbortions")) .withIsYoungestChildUnderTwo(ec.isYoungestChildUnderTwo()) .withYoungestChildAge(ec.getDetail("youngestChildAge")) .withIsHighPriority(ec.isHighPriority()).withPhotoPath(photoPath) .withAlerts(alerts) .withCondomSideEffect(ec.getDetail("condomSideEffect")) .withIUDSidEffect(ec.getDetail("iudSidEffect")) .withOCPSideEffect(ec.getDetail("ocpSideEffect")) .withInjectableSideEffect(ec.getDetail("injectableSideEffect")) .withSterilizationSideEffect(ec.getDetail("sterilizationSideEffect")) .withOtherSideEffect(ec.getDetail("otherSideEffect")) .withHighPriorityReason(ec.getDetail("highPriorityReason")) .preprocess(); fpClients.add(fpClient); } return fpClients; } }); }
FPSmartRegisterController { public FPClients getClients() { return fpClientsCache.get(FP_CLIENTS_LIST, new CacheableData<FPClients>() { @Override public FPClients fetch() { List<EligibleCouple> ecs = allEligibleCouples.all(); FPClients fpClients = new FPClients(); for (EligibleCouple ec : ecs) { if (allBeneficiaries.isPregnant(ec.caseId())) { continue; } String photoPath = isBlank(ec.photoPath()) ? DEFAULT_WOMAN_IMAGE_PLACEHOLDER_PATH : ec.photoPath(); List<AlertDTO> alerts = getFPAlertsForEC(ec.caseId()); FPClient fpClient = new FPClient(ec.caseId(), ec.wifeName(), ec.husbandName(), ec.village(), ec.ecNumber()).withAge(ec.age()) .withFPMethod(ec.getDetail("currentMethod")) .withFamilyPlanningMethodChangeDate( ec.getDetail("familyPlanningMethodChangeDate")) .withComplicationDate(ec.getDetail("complicationDate")) .withIUDPlace(ec.getDetail("iudPlace")) .withIUDPerson(ec.getDetail("iudPerson")) .withNumberOfCondomsSupplied(ec.getDetail("numberOfCondomsSupplied")) .withNumberOfCentchromanPillsDelivered( ec.getDetail("numberOfCentchromanPillsDelivered")) .withNumberOfOCPDelivered(ec.getDetail("numberOfOCPDelivered")) .withFPMethodFollowupDate(ec.getDetail("fpFollowupDate")) .withCaste(ec.getDetail("caste")) .withEconomicStatus(ec.getDetail("economicStatus")) .withNumberOfPregnancies(ec.getDetail("numberOfPregnancies")) .withParity(ec.getDetail("parity")) .withNumberOfLivingChildren(ec.getDetail("numberOfLivingChildren")) .withNumberOfStillBirths(ec.getDetail("numberOfStillBirths")) .withNumberOfAbortions(ec.getDetail("numberOfAbortions")) .withIsYoungestChildUnderTwo(ec.isYoungestChildUnderTwo()) .withYoungestChildAge(ec.getDetail("youngestChildAge")) .withIsHighPriority(ec.isHighPriority()).withPhotoPath(photoPath) .withAlerts(alerts) .withCondomSideEffect(ec.getDetail("condomSideEffect")) .withIUDSidEffect(ec.getDetail("iudSidEffect")) .withOCPSideEffect(ec.getDetail("ocpSideEffect")) .withInjectableSideEffect(ec.getDetail("injectableSideEffect")) .withSterilizationSideEffect(ec.getDetail("sterilizationSideEffect")) .withOtherSideEffect(ec.getDetail("otherSideEffect")) .withHighPriorityReason(ec.getDetail("highPriorityReason")) .preprocess(); fpClients.add(fpClient); } return fpClients; } }); } }
FPSmartRegisterController { public FPClients getClients() { return fpClientsCache.get(FP_CLIENTS_LIST, new CacheableData<FPClients>() { @Override public FPClients fetch() { List<EligibleCouple> ecs = allEligibleCouples.all(); FPClients fpClients = new FPClients(); for (EligibleCouple ec : ecs) { if (allBeneficiaries.isPregnant(ec.caseId())) { continue; } String photoPath = isBlank(ec.photoPath()) ? DEFAULT_WOMAN_IMAGE_PLACEHOLDER_PATH : ec.photoPath(); List<AlertDTO> alerts = getFPAlertsForEC(ec.caseId()); FPClient fpClient = new FPClient(ec.caseId(), ec.wifeName(), ec.husbandName(), ec.village(), ec.ecNumber()).withAge(ec.age()) .withFPMethod(ec.getDetail("currentMethod")) .withFamilyPlanningMethodChangeDate( ec.getDetail("familyPlanningMethodChangeDate")) .withComplicationDate(ec.getDetail("complicationDate")) .withIUDPlace(ec.getDetail("iudPlace")) .withIUDPerson(ec.getDetail("iudPerson")) .withNumberOfCondomsSupplied(ec.getDetail("numberOfCondomsSupplied")) .withNumberOfCentchromanPillsDelivered( ec.getDetail("numberOfCentchromanPillsDelivered")) .withNumberOfOCPDelivered(ec.getDetail("numberOfOCPDelivered")) .withFPMethodFollowupDate(ec.getDetail("fpFollowupDate")) .withCaste(ec.getDetail("caste")) .withEconomicStatus(ec.getDetail("economicStatus")) .withNumberOfPregnancies(ec.getDetail("numberOfPregnancies")) .withParity(ec.getDetail("parity")) .withNumberOfLivingChildren(ec.getDetail("numberOfLivingChildren")) .withNumberOfStillBirths(ec.getDetail("numberOfStillBirths")) .withNumberOfAbortions(ec.getDetail("numberOfAbortions")) .withIsYoungestChildUnderTwo(ec.isYoungestChildUnderTwo()) .withYoungestChildAge(ec.getDetail("youngestChildAge")) .withIsHighPriority(ec.isHighPriority()).withPhotoPath(photoPath) .withAlerts(alerts) .withCondomSideEffect(ec.getDetail("condomSideEffect")) .withIUDSidEffect(ec.getDetail("iudSidEffect")) .withOCPSideEffect(ec.getDetail("ocpSideEffect")) .withInjectableSideEffect(ec.getDetail("injectableSideEffect")) .withSterilizationSideEffect(ec.getDetail("sterilizationSideEffect")) .withOtherSideEffect(ec.getDetail("otherSideEffect")) .withHighPriorityReason(ec.getDetail("highPriorityReason")) .preprocess(); fpClients.add(fpClient); } return fpClients; } }); } FPSmartRegisterController(AllEligibleCouples allEligibleCouples, AllBeneficiaries allBeneficiaries, AlertService alertService, Cache<String> cache, Cache<FPClients> fpClientsCache); }
FPSmartRegisterController { public FPClients getClients() { return fpClientsCache.get(FP_CLIENTS_LIST, new CacheableData<FPClients>() { @Override public FPClients fetch() { List<EligibleCouple> ecs = allEligibleCouples.all(); FPClients fpClients = new FPClients(); for (EligibleCouple ec : ecs) { if (allBeneficiaries.isPregnant(ec.caseId())) { continue; } String photoPath = isBlank(ec.photoPath()) ? DEFAULT_WOMAN_IMAGE_PLACEHOLDER_PATH : ec.photoPath(); List<AlertDTO> alerts = getFPAlertsForEC(ec.caseId()); FPClient fpClient = new FPClient(ec.caseId(), ec.wifeName(), ec.husbandName(), ec.village(), ec.ecNumber()).withAge(ec.age()) .withFPMethod(ec.getDetail("currentMethod")) .withFamilyPlanningMethodChangeDate( ec.getDetail("familyPlanningMethodChangeDate")) .withComplicationDate(ec.getDetail("complicationDate")) .withIUDPlace(ec.getDetail("iudPlace")) .withIUDPerson(ec.getDetail("iudPerson")) .withNumberOfCondomsSupplied(ec.getDetail("numberOfCondomsSupplied")) .withNumberOfCentchromanPillsDelivered( ec.getDetail("numberOfCentchromanPillsDelivered")) .withNumberOfOCPDelivered(ec.getDetail("numberOfOCPDelivered")) .withFPMethodFollowupDate(ec.getDetail("fpFollowupDate")) .withCaste(ec.getDetail("caste")) .withEconomicStatus(ec.getDetail("economicStatus")) .withNumberOfPregnancies(ec.getDetail("numberOfPregnancies")) .withParity(ec.getDetail("parity")) .withNumberOfLivingChildren(ec.getDetail("numberOfLivingChildren")) .withNumberOfStillBirths(ec.getDetail("numberOfStillBirths")) .withNumberOfAbortions(ec.getDetail("numberOfAbortions")) .withIsYoungestChildUnderTwo(ec.isYoungestChildUnderTwo()) .withYoungestChildAge(ec.getDetail("youngestChildAge")) .withIsHighPriority(ec.isHighPriority()).withPhotoPath(photoPath) .withAlerts(alerts) .withCondomSideEffect(ec.getDetail("condomSideEffect")) .withIUDSidEffect(ec.getDetail("iudSidEffect")) .withOCPSideEffect(ec.getDetail("ocpSideEffect")) .withInjectableSideEffect(ec.getDetail("injectableSideEffect")) .withSterilizationSideEffect(ec.getDetail("sterilizationSideEffect")) .withOtherSideEffect(ec.getDetail("otherSideEffect")) .withHighPriorityReason(ec.getDetail("highPriorityReason")) .preprocess(); fpClients.add(fpClient); } return fpClients; } }); } FPSmartRegisterController(AllEligibleCouples allEligibleCouples, AllBeneficiaries allBeneficiaries, AlertService alertService, Cache<String> cache, Cache<FPClients> fpClientsCache); FPClients getClients(); }
FPSmartRegisterController { public FPClients getClients() { return fpClientsCache.get(FP_CLIENTS_LIST, new CacheableData<FPClients>() { @Override public FPClients fetch() { List<EligibleCouple> ecs = allEligibleCouples.all(); FPClients fpClients = new FPClients(); for (EligibleCouple ec : ecs) { if (allBeneficiaries.isPregnant(ec.caseId())) { continue; } String photoPath = isBlank(ec.photoPath()) ? DEFAULT_WOMAN_IMAGE_PLACEHOLDER_PATH : ec.photoPath(); List<AlertDTO> alerts = getFPAlertsForEC(ec.caseId()); FPClient fpClient = new FPClient(ec.caseId(), ec.wifeName(), ec.husbandName(), ec.village(), ec.ecNumber()).withAge(ec.age()) .withFPMethod(ec.getDetail("currentMethod")) .withFamilyPlanningMethodChangeDate( ec.getDetail("familyPlanningMethodChangeDate")) .withComplicationDate(ec.getDetail("complicationDate")) .withIUDPlace(ec.getDetail("iudPlace")) .withIUDPerson(ec.getDetail("iudPerson")) .withNumberOfCondomsSupplied(ec.getDetail("numberOfCondomsSupplied")) .withNumberOfCentchromanPillsDelivered( ec.getDetail("numberOfCentchromanPillsDelivered")) .withNumberOfOCPDelivered(ec.getDetail("numberOfOCPDelivered")) .withFPMethodFollowupDate(ec.getDetail("fpFollowupDate")) .withCaste(ec.getDetail("caste")) .withEconomicStatus(ec.getDetail("economicStatus")) .withNumberOfPregnancies(ec.getDetail("numberOfPregnancies")) .withParity(ec.getDetail("parity")) .withNumberOfLivingChildren(ec.getDetail("numberOfLivingChildren")) .withNumberOfStillBirths(ec.getDetail("numberOfStillBirths")) .withNumberOfAbortions(ec.getDetail("numberOfAbortions")) .withIsYoungestChildUnderTwo(ec.isYoungestChildUnderTwo()) .withYoungestChildAge(ec.getDetail("youngestChildAge")) .withIsHighPriority(ec.isHighPriority()).withPhotoPath(photoPath) .withAlerts(alerts) .withCondomSideEffect(ec.getDetail("condomSideEffect")) .withIUDSidEffect(ec.getDetail("iudSidEffect")) .withOCPSideEffect(ec.getDetail("ocpSideEffect")) .withInjectableSideEffect(ec.getDetail("injectableSideEffect")) .withSterilizationSideEffect(ec.getDetail("sterilizationSideEffect")) .withOtherSideEffect(ec.getDetail("otherSideEffect")) .withHighPriorityReason(ec.getDetail("highPriorityReason")) .preprocess(); fpClients.add(fpClient); } return fpClients; } }); } FPSmartRegisterController(AllEligibleCouples allEligibleCouples, AllBeneficiaries allBeneficiaries, AlertService alertService, Cache<String> cache, Cache<FPClients> fpClientsCache); FPClients getClients(); static final String OCP_REFILL_ALERT_NAME; static final String CONDOM_REFILL_ALERT_NAME; static final String DMPA_INJECTABLE_REFILL_ALERT_NAME; static final String FEMALE_STERILIZATION_FOLLOWUP_1_ALERT_NAME; static final String FEMALE_STERILIZATION_FOLLOWUP_2_ALERT_NAME; static final String FEMALE_STERILIZATION_FOLLOWUP_3_ALERT_NAME; static final String MALE_STERILIZATION_FOLLOWUP_1_ALERT_NAME; static final String MALE_STERILIZATION_FOLLOWUP_2_ALERT_NAME; static final String IUD_FOLLOWUP_1_ALERT_NAME; static final String IUD_FOLLOWUP_2_ALERT_NAME; static final String FP_FOLLOWUP_ALERT_NAME; static final String FP_REFERRAL_FOLLOWUP_ALERT_NAME; }
@Test public void shouldSortANCsByWifeName() throws Exception { Map<String, String> details = EasyMap.mapOf("edd", "Tue, 25 Feb 2014 00:00:00 GMT"); EligibleCouple ec2 = new EligibleCouple("EC Case 2", "Woman B", "Husband B", "EC Number 2", "kavalu_hosur", "Bherya SC", emptyMap); EligibleCouple ec3 = new EligibleCouple("EC Case 3", "Woman C", "Husband C", "EC Number 3", "Bherya", "Bherya SC", emptyMap); EligibleCouple ec1 = new EligibleCouple("EC Case 1", "Woman A", "Husband A", "EC Number 1", "Bherya", null, emptyMap); Mother m1 = new Mother("Entity X", "EC Case 2", "thayi 1", "2013-05-25").withDetails(details); Mother m2 = new Mother("Entity Y", "EC Case 3", "thayi 2", "2013-05-25").withDetails(details); Mother m3 = new Mother("Entity Z", "EC Case 1", "thayi 3", "2013-05-25").withDetails(details); Map<String, Visits> serviceToVisitsMap = EasyMap.create("tt", new Visits()).put("pnc", new Visits()).put("ifa", new Visits()).put("delivery_plan", new Visits()).put("anc", new Visits()).put("hb", new Visits()).map(); ANCClient expectedClient1 = createANCClient("Entity Z", "Woman A", "Bherya", "thayi 3", "Tue, 25 Feb 2014 00:00:00 GMT", "2013-05-25").withECNumber("EC Number 1").withHusbandName("Husband A").withEntityIdToSavePhoto("EC Case 1").withServiceToVisitMap(serviceToVisitsMap).withHighRiskReason(""); ANCClient expectedClient2 = createANCClient("Entity X", "Woman B", "kavalu_hosur", "thayi 1", "Tue, 25 Feb 2014 00:00:00 GMT", "2013-05-25").withECNumber("EC Number 2").withHusbandName("Husband B").withEntityIdToSavePhoto("EC Case 2").withServiceToVisitMap(serviceToVisitsMap).withHighRiskReason(""); ANCClient expectedClient3 = createANCClient("Entity Y", "Woman C", "Bherya", "thayi 2", "Tue, 25 Feb 2014 00:00:00 GMT", "2013-05-25").withECNumber("EC Number 3").withHusbandName("Husband C").withEntityIdToSavePhoto("EC Case 3").withServiceToVisitMap(serviceToVisitsMap).withHighRiskReason(""); Mockito.when(allBeneficiaries.allANCsWithEC()).thenReturn(Arrays.asList(Pair.of(m1, ec2), Pair.of(m2, ec3), Pair.of(m3, ec1))); ANCClients actualClients = controller.getClients(); Assert.assertEquals(Arrays.asList(expectedClient1, expectedClient2, expectedClient3), actualClients); }
public ANCClients getClients() { return ancClientsCache.get(ANC_CLIENTS_LIST, new CacheableData<ANCClients>() { @Override public ANCClients fetch() { ANCClients ancClients = new ANCClients(); List<Pair<Mother, EligibleCouple>> ancsWithEcs = allBeneficiaries.allANCsWithEC(); for (Pair<Mother, EligibleCouple> ancWithEc : ancsWithEcs) { Mother anc = ancWithEc.getLeft(); EligibleCouple ec = ancWithEc.getRight(); String photoPath = isBlank(ec.photoPath()) ? DEFAULT_WOMAN_IMAGE_PLACEHOLDER_PATH : ec.photoPath(); List<ServiceProvidedDTO> servicesProvided = getServicesProvided(anc.caseId()); List<AlertDTO> alerts = getAlerts(anc.caseId()); ANCClient ancClient = new ANCClient(anc.caseId(), ec.village(), ec.wifeName(), anc.thayiCardNumber(), anc.getDetail(AllConstants.ANCRegistrationFields.EDD), anc.referenceDate()).withHusbandName(ec.husbandName()).withAge(ec.age()) .withECNumber(ec.ecNumber()).withANCNumber( anc.getDetail(AllConstants.ANCRegistrationFields.ANC_NUMBER)) .withIsHighPriority(ec.isHighPriority()) .withIsHighRisk(anc.isHighRisk()).withIsOutOfArea(ec.isOutOfArea()) .withHighRiskReason(anc.highRiskReason()) .withCaste(ec.getDetail(AllConstants.ECRegistrationFields.CASTE)) .withEconomicStatus( ec.getDetail(AllConstants.ECRegistrationFields.ECONOMIC_STATUS)) .withPhotoPath(photoPath).withEntityIdToSavePhoto(ec.caseId()) .withAlerts(alerts).withAshaPhoneNumber(anc.getDetail( AllConstants.ANCRegistrationFields.ASHA_PHONE_NUMBER)) .withServicesProvided(servicesProvided).withPreProcess(); ancClients.add(ancClient); } sortByName(ancClients); return ancClients; } }); }
ANCSmartRegisterController { public ANCClients getClients() { return ancClientsCache.get(ANC_CLIENTS_LIST, new CacheableData<ANCClients>() { @Override public ANCClients fetch() { ANCClients ancClients = new ANCClients(); List<Pair<Mother, EligibleCouple>> ancsWithEcs = allBeneficiaries.allANCsWithEC(); for (Pair<Mother, EligibleCouple> ancWithEc : ancsWithEcs) { Mother anc = ancWithEc.getLeft(); EligibleCouple ec = ancWithEc.getRight(); String photoPath = isBlank(ec.photoPath()) ? DEFAULT_WOMAN_IMAGE_PLACEHOLDER_PATH : ec.photoPath(); List<ServiceProvidedDTO> servicesProvided = getServicesProvided(anc.caseId()); List<AlertDTO> alerts = getAlerts(anc.caseId()); ANCClient ancClient = new ANCClient(anc.caseId(), ec.village(), ec.wifeName(), anc.thayiCardNumber(), anc.getDetail(AllConstants.ANCRegistrationFields.EDD), anc.referenceDate()).withHusbandName(ec.husbandName()).withAge(ec.age()) .withECNumber(ec.ecNumber()).withANCNumber( anc.getDetail(AllConstants.ANCRegistrationFields.ANC_NUMBER)) .withIsHighPriority(ec.isHighPriority()) .withIsHighRisk(anc.isHighRisk()).withIsOutOfArea(ec.isOutOfArea()) .withHighRiskReason(anc.highRiskReason()) .withCaste(ec.getDetail(AllConstants.ECRegistrationFields.CASTE)) .withEconomicStatus( ec.getDetail(AllConstants.ECRegistrationFields.ECONOMIC_STATUS)) .withPhotoPath(photoPath).withEntityIdToSavePhoto(ec.caseId()) .withAlerts(alerts).withAshaPhoneNumber(anc.getDetail( AllConstants.ANCRegistrationFields.ASHA_PHONE_NUMBER)) .withServicesProvided(servicesProvided).withPreProcess(); ancClients.add(ancClient); } sortByName(ancClients); return ancClients; } }); } }
ANCSmartRegisterController { public ANCClients getClients() { return ancClientsCache.get(ANC_CLIENTS_LIST, new CacheableData<ANCClients>() { @Override public ANCClients fetch() { ANCClients ancClients = new ANCClients(); List<Pair<Mother, EligibleCouple>> ancsWithEcs = allBeneficiaries.allANCsWithEC(); for (Pair<Mother, EligibleCouple> ancWithEc : ancsWithEcs) { Mother anc = ancWithEc.getLeft(); EligibleCouple ec = ancWithEc.getRight(); String photoPath = isBlank(ec.photoPath()) ? DEFAULT_WOMAN_IMAGE_PLACEHOLDER_PATH : ec.photoPath(); List<ServiceProvidedDTO> servicesProvided = getServicesProvided(anc.caseId()); List<AlertDTO> alerts = getAlerts(anc.caseId()); ANCClient ancClient = new ANCClient(anc.caseId(), ec.village(), ec.wifeName(), anc.thayiCardNumber(), anc.getDetail(AllConstants.ANCRegistrationFields.EDD), anc.referenceDate()).withHusbandName(ec.husbandName()).withAge(ec.age()) .withECNumber(ec.ecNumber()).withANCNumber( anc.getDetail(AllConstants.ANCRegistrationFields.ANC_NUMBER)) .withIsHighPriority(ec.isHighPriority()) .withIsHighRisk(anc.isHighRisk()).withIsOutOfArea(ec.isOutOfArea()) .withHighRiskReason(anc.highRiskReason()) .withCaste(ec.getDetail(AllConstants.ECRegistrationFields.CASTE)) .withEconomicStatus( ec.getDetail(AllConstants.ECRegistrationFields.ECONOMIC_STATUS)) .withPhotoPath(photoPath).withEntityIdToSavePhoto(ec.caseId()) .withAlerts(alerts).withAshaPhoneNumber(anc.getDetail( AllConstants.ANCRegistrationFields.ASHA_PHONE_NUMBER)) .withServicesProvided(servicesProvided).withPreProcess(); ancClients.add(ancClient); } sortByName(ancClients); return ancClients; } }); } ANCSmartRegisterController(ServiceProvidedService serviceProvidedService, AlertService alertService, AllBeneficiaries allBeneficiaries, Cache<String> cache, Cache<ANCClients> ancClientsCache); }
ANCSmartRegisterController { public ANCClients getClients() { return ancClientsCache.get(ANC_CLIENTS_LIST, new CacheableData<ANCClients>() { @Override public ANCClients fetch() { ANCClients ancClients = new ANCClients(); List<Pair<Mother, EligibleCouple>> ancsWithEcs = allBeneficiaries.allANCsWithEC(); for (Pair<Mother, EligibleCouple> ancWithEc : ancsWithEcs) { Mother anc = ancWithEc.getLeft(); EligibleCouple ec = ancWithEc.getRight(); String photoPath = isBlank(ec.photoPath()) ? DEFAULT_WOMAN_IMAGE_PLACEHOLDER_PATH : ec.photoPath(); List<ServiceProvidedDTO> servicesProvided = getServicesProvided(anc.caseId()); List<AlertDTO> alerts = getAlerts(anc.caseId()); ANCClient ancClient = new ANCClient(anc.caseId(), ec.village(), ec.wifeName(), anc.thayiCardNumber(), anc.getDetail(AllConstants.ANCRegistrationFields.EDD), anc.referenceDate()).withHusbandName(ec.husbandName()).withAge(ec.age()) .withECNumber(ec.ecNumber()).withANCNumber( anc.getDetail(AllConstants.ANCRegistrationFields.ANC_NUMBER)) .withIsHighPriority(ec.isHighPriority()) .withIsHighRisk(anc.isHighRisk()).withIsOutOfArea(ec.isOutOfArea()) .withHighRiskReason(anc.highRiskReason()) .withCaste(ec.getDetail(AllConstants.ECRegistrationFields.CASTE)) .withEconomicStatus( ec.getDetail(AllConstants.ECRegistrationFields.ECONOMIC_STATUS)) .withPhotoPath(photoPath).withEntityIdToSavePhoto(ec.caseId()) .withAlerts(alerts).withAshaPhoneNumber(anc.getDetail( AllConstants.ANCRegistrationFields.ASHA_PHONE_NUMBER)) .withServicesProvided(servicesProvided).withPreProcess(); ancClients.add(ancClient); } sortByName(ancClients); return ancClients; } }); } ANCSmartRegisterController(ServiceProvidedService serviceProvidedService, AlertService alertService, AllBeneficiaries allBeneficiaries, Cache<String> cache, Cache<ANCClients> ancClientsCache); ANCClients getClients(); }
ANCSmartRegisterController { public ANCClients getClients() { return ancClientsCache.get(ANC_CLIENTS_LIST, new CacheableData<ANCClients>() { @Override public ANCClients fetch() { ANCClients ancClients = new ANCClients(); List<Pair<Mother, EligibleCouple>> ancsWithEcs = allBeneficiaries.allANCsWithEC(); for (Pair<Mother, EligibleCouple> ancWithEc : ancsWithEcs) { Mother anc = ancWithEc.getLeft(); EligibleCouple ec = ancWithEc.getRight(); String photoPath = isBlank(ec.photoPath()) ? DEFAULT_WOMAN_IMAGE_PLACEHOLDER_PATH : ec.photoPath(); List<ServiceProvidedDTO> servicesProvided = getServicesProvided(anc.caseId()); List<AlertDTO> alerts = getAlerts(anc.caseId()); ANCClient ancClient = new ANCClient(anc.caseId(), ec.village(), ec.wifeName(), anc.thayiCardNumber(), anc.getDetail(AllConstants.ANCRegistrationFields.EDD), anc.referenceDate()).withHusbandName(ec.husbandName()).withAge(ec.age()) .withECNumber(ec.ecNumber()).withANCNumber( anc.getDetail(AllConstants.ANCRegistrationFields.ANC_NUMBER)) .withIsHighPriority(ec.isHighPriority()) .withIsHighRisk(anc.isHighRisk()).withIsOutOfArea(ec.isOutOfArea()) .withHighRiskReason(anc.highRiskReason()) .withCaste(ec.getDetail(AllConstants.ECRegistrationFields.CASTE)) .withEconomicStatus( ec.getDetail(AllConstants.ECRegistrationFields.ECONOMIC_STATUS)) .withPhotoPath(photoPath).withEntityIdToSavePhoto(ec.caseId()) .withAlerts(alerts).withAshaPhoneNumber(anc.getDetail( AllConstants.ANCRegistrationFields.ASHA_PHONE_NUMBER)) .withServicesProvided(servicesProvided).withPreProcess(); ancClients.add(ancClient); } sortByName(ancClients); return ancClients; } }); } ANCSmartRegisterController(ServiceProvidedService serviceProvidedService, AlertService alertService, AllBeneficiaries allBeneficiaries, Cache<String> cache, Cache<ANCClients> ancClientsCache); ANCClients getClients(); }
@Test public void shouldGetANCClientsListWithSortedANCsByWifeName() throws Exception { Map<String, String> details = EasyMap.mapOf("edd", "Tue, 25 Feb 2014 00:00:00 GMT"); EligibleCouple ec2 = new EligibleCouple("EC Case 2", "Woman B", "Husband B", "EC Number 2", "kavalu_hosur", "Bherya SC", emptyMap); EligibleCouple ec3 = new EligibleCouple("EC Case 3", "Woman C", "Husband C", "EC Number 3", "Bherya", "Bherya SC", emptyMap); EligibleCouple ec1 = new EligibleCouple("EC Case 1", "Woman A", "Husband A", "EC Number 1", "Bherya", null, emptyMap); Mother m1 = new Mother("Entity X", "EC Case 2", "thayi 1", "2013-05-25").withDetails(details); Mother m2 = new Mother("Entity Y", "EC Case 3", "thayi 2", "2013-05-25").withDetails(details); Mother m3 = new Mother("Entity Z", "EC Case 1", "thayi 3", "2013-05-25").withDetails(details); Map<String, Visits> serviceToVisitsMap = EasyMap.create("tt", new Visits()).put("pnc", new Visits()).put("ifa", new Visits()).put("delivery_plan", new Visits()).put("anc", new Visits()).put("hb", new Visits()).map(); ANCClient expectedClient1 = createANCClient("Entity Z", "Woman A", "Bherya", "thayi 3", "Tue, 25 Feb 2014 00:00:00 GMT", "2013-05-25").withECNumber("EC Number 1").withHusbandName("Husband A").withEntityIdToSavePhoto("EC Case 1").withServiceToVisitMap(serviceToVisitsMap).withHighRiskReason(""); ANCClient expectedClient2 = createANCClient("Entity X", "Woman B", "kavalu_hosur", "thayi 1", "Tue, 25 Feb 2014 00:00:00 GMT", "2013-05-25").withECNumber("EC Number 2").withHusbandName("Husband B").withEntityIdToSavePhoto("EC Case 2").withServiceToVisitMap(serviceToVisitsMap).withHighRiskReason(""); ANCClient expectedClient3 = createANCClient("Entity Y", "Woman C", "Bherya", "thayi 2", "Tue, 25 Feb 2014 00:00:00 GMT", "2013-05-25").withECNumber("EC Number 3").withHusbandName("Husband C").withEntityIdToSavePhoto("EC Case 3").withServiceToVisitMap(serviceToVisitsMap).withHighRiskReason(""); Mockito.when(allBeneficiaries.allANCsWithEC()).thenReturn(Arrays.asList(Pair.of(m1, ec2), Pair.of(m2, ec3), Pair.of(m3, ec1))); SmartRegisterClients actualClients = controller.getClients(); Assert.assertEquals(Arrays.asList(expectedClient1, expectedClient2, expectedClient3), actualClients); }
public ANCClients getClients() { return ancClientsCache.get(ANC_CLIENTS_LIST, new CacheableData<ANCClients>() { @Override public ANCClients fetch() { ANCClients ancClients = new ANCClients(); List<Pair<Mother, EligibleCouple>> ancsWithEcs = allBeneficiaries.allANCsWithEC(); for (Pair<Mother, EligibleCouple> ancWithEc : ancsWithEcs) { Mother anc = ancWithEc.getLeft(); EligibleCouple ec = ancWithEc.getRight(); String photoPath = isBlank(ec.photoPath()) ? DEFAULT_WOMAN_IMAGE_PLACEHOLDER_PATH : ec.photoPath(); List<ServiceProvidedDTO> servicesProvided = getServicesProvided(anc.caseId()); List<AlertDTO> alerts = getAlerts(anc.caseId()); ANCClient ancClient = new ANCClient(anc.caseId(), ec.village(), ec.wifeName(), anc.thayiCardNumber(), anc.getDetail(AllConstants.ANCRegistrationFields.EDD), anc.referenceDate()).withHusbandName(ec.husbandName()).withAge(ec.age()) .withECNumber(ec.ecNumber()).withANCNumber( anc.getDetail(AllConstants.ANCRegistrationFields.ANC_NUMBER)) .withIsHighPriority(ec.isHighPriority()) .withIsHighRisk(anc.isHighRisk()).withIsOutOfArea(ec.isOutOfArea()) .withHighRiskReason(anc.highRiskReason()) .withCaste(ec.getDetail(AllConstants.ECRegistrationFields.CASTE)) .withEconomicStatus( ec.getDetail(AllConstants.ECRegistrationFields.ECONOMIC_STATUS)) .withPhotoPath(photoPath).withEntityIdToSavePhoto(ec.caseId()) .withAlerts(alerts).withAshaPhoneNumber(anc.getDetail( AllConstants.ANCRegistrationFields.ASHA_PHONE_NUMBER)) .withServicesProvided(servicesProvided).withPreProcess(); ancClients.add(ancClient); } sortByName(ancClients); return ancClients; } }); }
ANCSmartRegisterController { public ANCClients getClients() { return ancClientsCache.get(ANC_CLIENTS_LIST, new CacheableData<ANCClients>() { @Override public ANCClients fetch() { ANCClients ancClients = new ANCClients(); List<Pair<Mother, EligibleCouple>> ancsWithEcs = allBeneficiaries.allANCsWithEC(); for (Pair<Mother, EligibleCouple> ancWithEc : ancsWithEcs) { Mother anc = ancWithEc.getLeft(); EligibleCouple ec = ancWithEc.getRight(); String photoPath = isBlank(ec.photoPath()) ? DEFAULT_WOMAN_IMAGE_PLACEHOLDER_PATH : ec.photoPath(); List<ServiceProvidedDTO> servicesProvided = getServicesProvided(anc.caseId()); List<AlertDTO> alerts = getAlerts(anc.caseId()); ANCClient ancClient = new ANCClient(anc.caseId(), ec.village(), ec.wifeName(), anc.thayiCardNumber(), anc.getDetail(AllConstants.ANCRegistrationFields.EDD), anc.referenceDate()).withHusbandName(ec.husbandName()).withAge(ec.age()) .withECNumber(ec.ecNumber()).withANCNumber( anc.getDetail(AllConstants.ANCRegistrationFields.ANC_NUMBER)) .withIsHighPriority(ec.isHighPriority()) .withIsHighRisk(anc.isHighRisk()).withIsOutOfArea(ec.isOutOfArea()) .withHighRiskReason(anc.highRiskReason()) .withCaste(ec.getDetail(AllConstants.ECRegistrationFields.CASTE)) .withEconomicStatus( ec.getDetail(AllConstants.ECRegistrationFields.ECONOMIC_STATUS)) .withPhotoPath(photoPath).withEntityIdToSavePhoto(ec.caseId()) .withAlerts(alerts).withAshaPhoneNumber(anc.getDetail( AllConstants.ANCRegistrationFields.ASHA_PHONE_NUMBER)) .withServicesProvided(servicesProvided).withPreProcess(); ancClients.add(ancClient); } sortByName(ancClients); return ancClients; } }); } }
ANCSmartRegisterController { public ANCClients getClients() { return ancClientsCache.get(ANC_CLIENTS_LIST, new CacheableData<ANCClients>() { @Override public ANCClients fetch() { ANCClients ancClients = new ANCClients(); List<Pair<Mother, EligibleCouple>> ancsWithEcs = allBeneficiaries.allANCsWithEC(); for (Pair<Mother, EligibleCouple> ancWithEc : ancsWithEcs) { Mother anc = ancWithEc.getLeft(); EligibleCouple ec = ancWithEc.getRight(); String photoPath = isBlank(ec.photoPath()) ? DEFAULT_WOMAN_IMAGE_PLACEHOLDER_PATH : ec.photoPath(); List<ServiceProvidedDTO> servicesProvided = getServicesProvided(anc.caseId()); List<AlertDTO> alerts = getAlerts(anc.caseId()); ANCClient ancClient = new ANCClient(anc.caseId(), ec.village(), ec.wifeName(), anc.thayiCardNumber(), anc.getDetail(AllConstants.ANCRegistrationFields.EDD), anc.referenceDate()).withHusbandName(ec.husbandName()).withAge(ec.age()) .withECNumber(ec.ecNumber()).withANCNumber( anc.getDetail(AllConstants.ANCRegistrationFields.ANC_NUMBER)) .withIsHighPriority(ec.isHighPriority()) .withIsHighRisk(anc.isHighRisk()).withIsOutOfArea(ec.isOutOfArea()) .withHighRiskReason(anc.highRiskReason()) .withCaste(ec.getDetail(AllConstants.ECRegistrationFields.CASTE)) .withEconomicStatus( ec.getDetail(AllConstants.ECRegistrationFields.ECONOMIC_STATUS)) .withPhotoPath(photoPath).withEntityIdToSavePhoto(ec.caseId()) .withAlerts(alerts).withAshaPhoneNumber(anc.getDetail( AllConstants.ANCRegistrationFields.ASHA_PHONE_NUMBER)) .withServicesProvided(servicesProvided).withPreProcess(); ancClients.add(ancClient); } sortByName(ancClients); return ancClients; } }); } ANCSmartRegisterController(ServiceProvidedService serviceProvidedService, AlertService alertService, AllBeneficiaries allBeneficiaries, Cache<String> cache, Cache<ANCClients> ancClientsCache); }
ANCSmartRegisterController { public ANCClients getClients() { return ancClientsCache.get(ANC_CLIENTS_LIST, new CacheableData<ANCClients>() { @Override public ANCClients fetch() { ANCClients ancClients = new ANCClients(); List<Pair<Mother, EligibleCouple>> ancsWithEcs = allBeneficiaries.allANCsWithEC(); for (Pair<Mother, EligibleCouple> ancWithEc : ancsWithEcs) { Mother anc = ancWithEc.getLeft(); EligibleCouple ec = ancWithEc.getRight(); String photoPath = isBlank(ec.photoPath()) ? DEFAULT_WOMAN_IMAGE_PLACEHOLDER_PATH : ec.photoPath(); List<ServiceProvidedDTO> servicesProvided = getServicesProvided(anc.caseId()); List<AlertDTO> alerts = getAlerts(anc.caseId()); ANCClient ancClient = new ANCClient(anc.caseId(), ec.village(), ec.wifeName(), anc.thayiCardNumber(), anc.getDetail(AllConstants.ANCRegistrationFields.EDD), anc.referenceDate()).withHusbandName(ec.husbandName()).withAge(ec.age()) .withECNumber(ec.ecNumber()).withANCNumber( anc.getDetail(AllConstants.ANCRegistrationFields.ANC_NUMBER)) .withIsHighPriority(ec.isHighPriority()) .withIsHighRisk(anc.isHighRisk()).withIsOutOfArea(ec.isOutOfArea()) .withHighRiskReason(anc.highRiskReason()) .withCaste(ec.getDetail(AllConstants.ECRegistrationFields.CASTE)) .withEconomicStatus( ec.getDetail(AllConstants.ECRegistrationFields.ECONOMIC_STATUS)) .withPhotoPath(photoPath).withEntityIdToSavePhoto(ec.caseId()) .withAlerts(alerts).withAshaPhoneNumber(anc.getDetail( AllConstants.ANCRegistrationFields.ASHA_PHONE_NUMBER)) .withServicesProvided(servicesProvided).withPreProcess(); ancClients.add(ancClient); } sortByName(ancClients); return ancClients; } }); } ANCSmartRegisterController(ServiceProvidedService serviceProvidedService, AlertService alertService, AllBeneficiaries allBeneficiaries, Cache<String> cache, Cache<ANCClients> ancClientsCache); ANCClients getClients(); }
ANCSmartRegisterController { public ANCClients getClients() { return ancClientsCache.get(ANC_CLIENTS_LIST, new CacheableData<ANCClients>() { @Override public ANCClients fetch() { ANCClients ancClients = new ANCClients(); List<Pair<Mother, EligibleCouple>> ancsWithEcs = allBeneficiaries.allANCsWithEC(); for (Pair<Mother, EligibleCouple> ancWithEc : ancsWithEcs) { Mother anc = ancWithEc.getLeft(); EligibleCouple ec = ancWithEc.getRight(); String photoPath = isBlank(ec.photoPath()) ? DEFAULT_WOMAN_IMAGE_PLACEHOLDER_PATH : ec.photoPath(); List<ServiceProvidedDTO> servicesProvided = getServicesProvided(anc.caseId()); List<AlertDTO> alerts = getAlerts(anc.caseId()); ANCClient ancClient = new ANCClient(anc.caseId(), ec.village(), ec.wifeName(), anc.thayiCardNumber(), anc.getDetail(AllConstants.ANCRegistrationFields.EDD), anc.referenceDate()).withHusbandName(ec.husbandName()).withAge(ec.age()) .withECNumber(ec.ecNumber()).withANCNumber( anc.getDetail(AllConstants.ANCRegistrationFields.ANC_NUMBER)) .withIsHighPriority(ec.isHighPriority()) .withIsHighRisk(anc.isHighRisk()).withIsOutOfArea(ec.isOutOfArea()) .withHighRiskReason(anc.highRiskReason()) .withCaste(ec.getDetail(AllConstants.ECRegistrationFields.CASTE)) .withEconomicStatus( ec.getDetail(AllConstants.ECRegistrationFields.ECONOMIC_STATUS)) .withPhotoPath(photoPath).withEntityIdToSavePhoto(ec.caseId()) .withAlerts(alerts).withAshaPhoneNumber(anc.getDetail( AllConstants.ANCRegistrationFields.ASHA_PHONE_NUMBER)) .withServicesProvided(servicesProvided).withPreProcess(); ancClients.add(ancClient); } sortByName(ancClients); return ancClients; } }); } ANCSmartRegisterController(ServiceProvidedService serviceProvidedService, AlertService alertService, AllBeneficiaries allBeneficiaries, Cache<String> cache, Cache<ANCClients> ancClientsCache); ANCClients getClients(); }
@Test public void shouldMapANCToANCClient() throws Exception { Map<String, String> details = EasyMap.create("edd", "Tue, 25 Feb 2014 00:00:00 GMT") .put("isHighRisk", "yes") .put("ancNumber", "ANC X") .put("highRiskReason", "Headache") .put("riskObservedDuringANC", "Headache") .put("ashaPhoneNumber", "Asha phone number 1") .map(); EligibleCouple eligibleCouple = new EligibleCouple("ec id 1", "Woman A", "Husband A", "EC Number 1", "Bherya", null, EasyMap.create("wifeAge", "23") .put("isHighPriority", Boolean.toString(false)) .put("caste", "other") .put("economicStatus", "bpl") .map() ).asOutOfArea(); Mother mother = new Mother("Entity X", "ec id 1", "thayi 1", "2013-05-25").withDetails(details); Map<String, Visits> serviceToVisitsMap = EasyMap.create("tt", new Visits()).put("pnc", new Visits()).put("ifa", new Visits()).put("delivery_plan", new Visits()).put("anc", new Visits()).put("hb", new Visits()).map(); Mockito.when(allBeneficiaries.allANCsWithEC()).thenReturn(Arrays.asList(Pair.of(mother, eligibleCouple))); ANCClient expectedANCClient = new ANCClient("Entity X", "Bherya", "Woman A", "thayi 1", "Tue, 25 Feb 2014 00:00:00 GMT", "2013-05-25") .withECNumber("EC Number 1") .withIsHighPriority(false) .withAge("23") .withHusbandName("Husband A") .withIsOutOfArea(true) .withIsHighRisk(true) .withCaste("other") .withANCNumber("ANC X") .withHighRiskReason("Headache") .withPhotoPath("../../img/woman-placeholder.png") .withEconomicStatus("bpl") .withEntityIdToSavePhoto("ec id 1") .withAlerts(Collections.<AlertDTO>emptyList()) .withAshaPhoneNumber("Asha phone number 1") .withServicesProvided(Collections.<ServiceProvidedDTO>emptyList()) .withServiceToVisitMap(serviceToVisitsMap); ANCClients actualClients = controller.getClients(); Assert.assertEquals(Arrays.asList(expectedANCClient), actualClients); }
public ANCClients getClients() { return ancClientsCache.get(ANC_CLIENTS_LIST, new CacheableData<ANCClients>() { @Override public ANCClients fetch() { ANCClients ancClients = new ANCClients(); List<Pair<Mother, EligibleCouple>> ancsWithEcs = allBeneficiaries.allANCsWithEC(); for (Pair<Mother, EligibleCouple> ancWithEc : ancsWithEcs) { Mother anc = ancWithEc.getLeft(); EligibleCouple ec = ancWithEc.getRight(); String photoPath = isBlank(ec.photoPath()) ? DEFAULT_WOMAN_IMAGE_PLACEHOLDER_PATH : ec.photoPath(); List<ServiceProvidedDTO> servicesProvided = getServicesProvided(anc.caseId()); List<AlertDTO> alerts = getAlerts(anc.caseId()); ANCClient ancClient = new ANCClient(anc.caseId(), ec.village(), ec.wifeName(), anc.thayiCardNumber(), anc.getDetail(AllConstants.ANCRegistrationFields.EDD), anc.referenceDate()).withHusbandName(ec.husbandName()).withAge(ec.age()) .withECNumber(ec.ecNumber()).withANCNumber( anc.getDetail(AllConstants.ANCRegistrationFields.ANC_NUMBER)) .withIsHighPriority(ec.isHighPriority()) .withIsHighRisk(anc.isHighRisk()).withIsOutOfArea(ec.isOutOfArea()) .withHighRiskReason(anc.highRiskReason()) .withCaste(ec.getDetail(AllConstants.ECRegistrationFields.CASTE)) .withEconomicStatus( ec.getDetail(AllConstants.ECRegistrationFields.ECONOMIC_STATUS)) .withPhotoPath(photoPath).withEntityIdToSavePhoto(ec.caseId()) .withAlerts(alerts).withAshaPhoneNumber(anc.getDetail( AllConstants.ANCRegistrationFields.ASHA_PHONE_NUMBER)) .withServicesProvided(servicesProvided).withPreProcess(); ancClients.add(ancClient); } sortByName(ancClients); return ancClients; } }); }
ANCSmartRegisterController { public ANCClients getClients() { return ancClientsCache.get(ANC_CLIENTS_LIST, new CacheableData<ANCClients>() { @Override public ANCClients fetch() { ANCClients ancClients = new ANCClients(); List<Pair<Mother, EligibleCouple>> ancsWithEcs = allBeneficiaries.allANCsWithEC(); for (Pair<Mother, EligibleCouple> ancWithEc : ancsWithEcs) { Mother anc = ancWithEc.getLeft(); EligibleCouple ec = ancWithEc.getRight(); String photoPath = isBlank(ec.photoPath()) ? DEFAULT_WOMAN_IMAGE_PLACEHOLDER_PATH : ec.photoPath(); List<ServiceProvidedDTO> servicesProvided = getServicesProvided(anc.caseId()); List<AlertDTO> alerts = getAlerts(anc.caseId()); ANCClient ancClient = new ANCClient(anc.caseId(), ec.village(), ec.wifeName(), anc.thayiCardNumber(), anc.getDetail(AllConstants.ANCRegistrationFields.EDD), anc.referenceDate()).withHusbandName(ec.husbandName()).withAge(ec.age()) .withECNumber(ec.ecNumber()).withANCNumber( anc.getDetail(AllConstants.ANCRegistrationFields.ANC_NUMBER)) .withIsHighPriority(ec.isHighPriority()) .withIsHighRisk(anc.isHighRisk()).withIsOutOfArea(ec.isOutOfArea()) .withHighRiskReason(anc.highRiskReason()) .withCaste(ec.getDetail(AllConstants.ECRegistrationFields.CASTE)) .withEconomicStatus( ec.getDetail(AllConstants.ECRegistrationFields.ECONOMIC_STATUS)) .withPhotoPath(photoPath).withEntityIdToSavePhoto(ec.caseId()) .withAlerts(alerts).withAshaPhoneNumber(anc.getDetail( AllConstants.ANCRegistrationFields.ASHA_PHONE_NUMBER)) .withServicesProvided(servicesProvided).withPreProcess(); ancClients.add(ancClient); } sortByName(ancClients); return ancClients; } }); } }
ANCSmartRegisterController { public ANCClients getClients() { return ancClientsCache.get(ANC_CLIENTS_LIST, new CacheableData<ANCClients>() { @Override public ANCClients fetch() { ANCClients ancClients = new ANCClients(); List<Pair<Mother, EligibleCouple>> ancsWithEcs = allBeneficiaries.allANCsWithEC(); for (Pair<Mother, EligibleCouple> ancWithEc : ancsWithEcs) { Mother anc = ancWithEc.getLeft(); EligibleCouple ec = ancWithEc.getRight(); String photoPath = isBlank(ec.photoPath()) ? DEFAULT_WOMAN_IMAGE_PLACEHOLDER_PATH : ec.photoPath(); List<ServiceProvidedDTO> servicesProvided = getServicesProvided(anc.caseId()); List<AlertDTO> alerts = getAlerts(anc.caseId()); ANCClient ancClient = new ANCClient(anc.caseId(), ec.village(), ec.wifeName(), anc.thayiCardNumber(), anc.getDetail(AllConstants.ANCRegistrationFields.EDD), anc.referenceDate()).withHusbandName(ec.husbandName()).withAge(ec.age()) .withECNumber(ec.ecNumber()).withANCNumber( anc.getDetail(AllConstants.ANCRegistrationFields.ANC_NUMBER)) .withIsHighPriority(ec.isHighPriority()) .withIsHighRisk(anc.isHighRisk()).withIsOutOfArea(ec.isOutOfArea()) .withHighRiskReason(anc.highRiskReason()) .withCaste(ec.getDetail(AllConstants.ECRegistrationFields.CASTE)) .withEconomicStatus( ec.getDetail(AllConstants.ECRegistrationFields.ECONOMIC_STATUS)) .withPhotoPath(photoPath).withEntityIdToSavePhoto(ec.caseId()) .withAlerts(alerts).withAshaPhoneNumber(anc.getDetail( AllConstants.ANCRegistrationFields.ASHA_PHONE_NUMBER)) .withServicesProvided(servicesProvided).withPreProcess(); ancClients.add(ancClient); } sortByName(ancClients); return ancClients; } }); } ANCSmartRegisterController(ServiceProvidedService serviceProvidedService, AlertService alertService, AllBeneficiaries allBeneficiaries, Cache<String> cache, Cache<ANCClients> ancClientsCache); }
ANCSmartRegisterController { public ANCClients getClients() { return ancClientsCache.get(ANC_CLIENTS_LIST, new CacheableData<ANCClients>() { @Override public ANCClients fetch() { ANCClients ancClients = new ANCClients(); List<Pair<Mother, EligibleCouple>> ancsWithEcs = allBeneficiaries.allANCsWithEC(); for (Pair<Mother, EligibleCouple> ancWithEc : ancsWithEcs) { Mother anc = ancWithEc.getLeft(); EligibleCouple ec = ancWithEc.getRight(); String photoPath = isBlank(ec.photoPath()) ? DEFAULT_WOMAN_IMAGE_PLACEHOLDER_PATH : ec.photoPath(); List<ServiceProvidedDTO> servicesProvided = getServicesProvided(anc.caseId()); List<AlertDTO> alerts = getAlerts(anc.caseId()); ANCClient ancClient = new ANCClient(anc.caseId(), ec.village(), ec.wifeName(), anc.thayiCardNumber(), anc.getDetail(AllConstants.ANCRegistrationFields.EDD), anc.referenceDate()).withHusbandName(ec.husbandName()).withAge(ec.age()) .withECNumber(ec.ecNumber()).withANCNumber( anc.getDetail(AllConstants.ANCRegistrationFields.ANC_NUMBER)) .withIsHighPriority(ec.isHighPriority()) .withIsHighRisk(anc.isHighRisk()).withIsOutOfArea(ec.isOutOfArea()) .withHighRiskReason(anc.highRiskReason()) .withCaste(ec.getDetail(AllConstants.ECRegistrationFields.CASTE)) .withEconomicStatus( ec.getDetail(AllConstants.ECRegistrationFields.ECONOMIC_STATUS)) .withPhotoPath(photoPath).withEntityIdToSavePhoto(ec.caseId()) .withAlerts(alerts).withAshaPhoneNumber(anc.getDetail( AllConstants.ANCRegistrationFields.ASHA_PHONE_NUMBER)) .withServicesProvided(servicesProvided).withPreProcess(); ancClients.add(ancClient); } sortByName(ancClients); return ancClients; } }); } ANCSmartRegisterController(ServiceProvidedService serviceProvidedService, AlertService alertService, AllBeneficiaries allBeneficiaries, Cache<String> cache, Cache<ANCClients> ancClientsCache); ANCClients getClients(); }
ANCSmartRegisterController { public ANCClients getClients() { return ancClientsCache.get(ANC_CLIENTS_LIST, new CacheableData<ANCClients>() { @Override public ANCClients fetch() { ANCClients ancClients = new ANCClients(); List<Pair<Mother, EligibleCouple>> ancsWithEcs = allBeneficiaries.allANCsWithEC(); for (Pair<Mother, EligibleCouple> ancWithEc : ancsWithEcs) { Mother anc = ancWithEc.getLeft(); EligibleCouple ec = ancWithEc.getRight(); String photoPath = isBlank(ec.photoPath()) ? DEFAULT_WOMAN_IMAGE_PLACEHOLDER_PATH : ec.photoPath(); List<ServiceProvidedDTO> servicesProvided = getServicesProvided(anc.caseId()); List<AlertDTO> alerts = getAlerts(anc.caseId()); ANCClient ancClient = new ANCClient(anc.caseId(), ec.village(), ec.wifeName(), anc.thayiCardNumber(), anc.getDetail(AllConstants.ANCRegistrationFields.EDD), anc.referenceDate()).withHusbandName(ec.husbandName()).withAge(ec.age()) .withECNumber(ec.ecNumber()).withANCNumber( anc.getDetail(AllConstants.ANCRegistrationFields.ANC_NUMBER)) .withIsHighPriority(ec.isHighPriority()) .withIsHighRisk(anc.isHighRisk()).withIsOutOfArea(ec.isOutOfArea()) .withHighRiskReason(anc.highRiskReason()) .withCaste(ec.getDetail(AllConstants.ECRegistrationFields.CASTE)) .withEconomicStatus( ec.getDetail(AllConstants.ECRegistrationFields.ECONOMIC_STATUS)) .withPhotoPath(photoPath).withEntityIdToSavePhoto(ec.caseId()) .withAlerts(alerts).withAshaPhoneNumber(anc.getDetail( AllConstants.ANCRegistrationFields.ASHA_PHONE_NUMBER)) .withServicesProvided(servicesProvided).withPreProcess(); ancClients.add(ancClient); } sortByName(ancClients); return ancClients; } }); } ANCSmartRegisterController(ServiceProvidedService serviceProvidedService, AlertService alertService, AllBeneficiaries allBeneficiaries, Cache<String> cache, Cache<ANCClients> ancClientsCache); ANCClients getClients(); }
@Test public void shouldCreateANCClientsWithANC1AlertAndDeliveryPlanAlert() throws Exception { Map<String, String> details = EasyMap.mapOf("edd", "Tue, 25 Feb 2014 00:00:00 GMT"); EligibleCouple ec = new EligibleCouple("entity id 1", "Woman C", "Husband C", "EC Number 1", "Bherya", "Bherya SC", emptyMap); Mother mother = new Mother("Entity X", "entity id 1", "thayi 1", "2012-10-25").withDetails(details); Alert anc1Alert = new Alert("entity id 1", "ANC", "ANC 1", AlertStatus.normal, "2013-01-01", "2013-02-01"); Alert deliveryPlanAlert = new Alert("entity id 1", "Delivery Plan", "Delivery Plan", AlertStatus.normal, "2012-10-25", "2013-08-25"); Mockito.when(allBeneficiaries.allANCsWithEC()).thenReturn(Arrays.asList(Pair.of(mother, ec))); Mockito.when(alertService.findByEntityIdAndAlertNames("Entity X", ANC_ALERTS)).thenReturn(Arrays.asList(anc1Alert, deliveryPlanAlert)); ANCClients actualClients = controller.getClients(); Mockito.verify(alertService).findByEntityIdAndAlertNames("Entity X", ANC_ALERTS); AlertDTO expectedANC1AlertDto = new AlertDTO("ANC 1", "normal", "2013-01-01"); AlertDTO expectedDeliveryPlanAlertDto = new AlertDTO("Delivery Plan", "normal", "2012-10-25"); Visits emptyVisit = new Visits(); Visits expectedANCVisit = new Visits(); expectedANCVisit.toProvide = expectedANC1AlertDto; Visits expectedDeliveryPlanVisit = new Visits(); expectedDeliveryPlanVisit.toProvide = expectedDeliveryPlanAlertDto; Map<String, Visits> serviceToVisitsMap = EasyMap.create("tt", emptyVisit).put("pnc", emptyVisit).put("ifa", emptyVisit).put("delivery_plan", expectedDeliveryPlanVisit).put("anc", expectedANCVisit).put("hb", emptyVisit).map(); ANCClient expectedEC = createANCClient("Entity X", "Woman C", "Bherya", "thayi 1", "Tue, 25 Feb 2014 00:00:00 GMT", "2012-10-25") .withECNumber("EC Number 1") .withHusbandName("Husband C") .withEntityIdToSavePhoto("entity id 1") .withAlerts(Arrays.asList(expectedANC1AlertDto, expectedDeliveryPlanAlertDto)) .withServiceToVisitMap(serviceToVisitsMap) .withHighRiskReason(""); Assert.assertEquals(Arrays.asList(expectedEC), actualClients); }
public ANCClients getClients() { return ancClientsCache.get(ANC_CLIENTS_LIST, new CacheableData<ANCClients>() { @Override public ANCClients fetch() { ANCClients ancClients = new ANCClients(); List<Pair<Mother, EligibleCouple>> ancsWithEcs = allBeneficiaries.allANCsWithEC(); for (Pair<Mother, EligibleCouple> ancWithEc : ancsWithEcs) { Mother anc = ancWithEc.getLeft(); EligibleCouple ec = ancWithEc.getRight(); String photoPath = isBlank(ec.photoPath()) ? DEFAULT_WOMAN_IMAGE_PLACEHOLDER_PATH : ec.photoPath(); List<ServiceProvidedDTO> servicesProvided = getServicesProvided(anc.caseId()); List<AlertDTO> alerts = getAlerts(anc.caseId()); ANCClient ancClient = new ANCClient(anc.caseId(), ec.village(), ec.wifeName(), anc.thayiCardNumber(), anc.getDetail(AllConstants.ANCRegistrationFields.EDD), anc.referenceDate()).withHusbandName(ec.husbandName()).withAge(ec.age()) .withECNumber(ec.ecNumber()).withANCNumber( anc.getDetail(AllConstants.ANCRegistrationFields.ANC_NUMBER)) .withIsHighPriority(ec.isHighPriority()) .withIsHighRisk(anc.isHighRisk()).withIsOutOfArea(ec.isOutOfArea()) .withHighRiskReason(anc.highRiskReason()) .withCaste(ec.getDetail(AllConstants.ECRegistrationFields.CASTE)) .withEconomicStatus( ec.getDetail(AllConstants.ECRegistrationFields.ECONOMIC_STATUS)) .withPhotoPath(photoPath).withEntityIdToSavePhoto(ec.caseId()) .withAlerts(alerts).withAshaPhoneNumber(anc.getDetail( AllConstants.ANCRegistrationFields.ASHA_PHONE_NUMBER)) .withServicesProvided(servicesProvided).withPreProcess(); ancClients.add(ancClient); } sortByName(ancClients); return ancClients; } }); }
ANCSmartRegisterController { public ANCClients getClients() { return ancClientsCache.get(ANC_CLIENTS_LIST, new CacheableData<ANCClients>() { @Override public ANCClients fetch() { ANCClients ancClients = new ANCClients(); List<Pair<Mother, EligibleCouple>> ancsWithEcs = allBeneficiaries.allANCsWithEC(); for (Pair<Mother, EligibleCouple> ancWithEc : ancsWithEcs) { Mother anc = ancWithEc.getLeft(); EligibleCouple ec = ancWithEc.getRight(); String photoPath = isBlank(ec.photoPath()) ? DEFAULT_WOMAN_IMAGE_PLACEHOLDER_PATH : ec.photoPath(); List<ServiceProvidedDTO> servicesProvided = getServicesProvided(anc.caseId()); List<AlertDTO> alerts = getAlerts(anc.caseId()); ANCClient ancClient = new ANCClient(anc.caseId(), ec.village(), ec.wifeName(), anc.thayiCardNumber(), anc.getDetail(AllConstants.ANCRegistrationFields.EDD), anc.referenceDate()).withHusbandName(ec.husbandName()).withAge(ec.age()) .withECNumber(ec.ecNumber()).withANCNumber( anc.getDetail(AllConstants.ANCRegistrationFields.ANC_NUMBER)) .withIsHighPriority(ec.isHighPriority()) .withIsHighRisk(anc.isHighRisk()).withIsOutOfArea(ec.isOutOfArea()) .withHighRiskReason(anc.highRiskReason()) .withCaste(ec.getDetail(AllConstants.ECRegistrationFields.CASTE)) .withEconomicStatus( ec.getDetail(AllConstants.ECRegistrationFields.ECONOMIC_STATUS)) .withPhotoPath(photoPath).withEntityIdToSavePhoto(ec.caseId()) .withAlerts(alerts).withAshaPhoneNumber(anc.getDetail( AllConstants.ANCRegistrationFields.ASHA_PHONE_NUMBER)) .withServicesProvided(servicesProvided).withPreProcess(); ancClients.add(ancClient); } sortByName(ancClients); return ancClients; } }); } }
ANCSmartRegisterController { public ANCClients getClients() { return ancClientsCache.get(ANC_CLIENTS_LIST, new CacheableData<ANCClients>() { @Override public ANCClients fetch() { ANCClients ancClients = new ANCClients(); List<Pair<Mother, EligibleCouple>> ancsWithEcs = allBeneficiaries.allANCsWithEC(); for (Pair<Mother, EligibleCouple> ancWithEc : ancsWithEcs) { Mother anc = ancWithEc.getLeft(); EligibleCouple ec = ancWithEc.getRight(); String photoPath = isBlank(ec.photoPath()) ? DEFAULT_WOMAN_IMAGE_PLACEHOLDER_PATH : ec.photoPath(); List<ServiceProvidedDTO> servicesProvided = getServicesProvided(anc.caseId()); List<AlertDTO> alerts = getAlerts(anc.caseId()); ANCClient ancClient = new ANCClient(anc.caseId(), ec.village(), ec.wifeName(), anc.thayiCardNumber(), anc.getDetail(AllConstants.ANCRegistrationFields.EDD), anc.referenceDate()).withHusbandName(ec.husbandName()).withAge(ec.age()) .withECNumber(ec.ecNumber()).withANCNumber( anc.getDetail(AllConstants.ANCRegistrationFields.ANC_NUMBER)) .withIsHighPriority(ec.isHighPriority()) .withIsHighRisk(anc.isHighRisk()).withIsOutOfArea(ec.isOutOfArea()) .withHighRiskReason(anc.highRiskReason()) .withCaste(ec.getDetail(AllConstants.ECRegistrationFields.CASTE)) .withEconomicStatus( ec.getDetail(AllConstants.ECRegistrationFields.ECONOMIC_STATUS)) .withPhotoPath(photoPath).withEntityIdToSavePhoto(ec.caseId()) .withAlerts(alerts).withAshaPhoneNumber(anc.getDetail( AllConstants.ANCRegistrationFields.ASHA_PHONE_NUMBER)) .withServicesProvided(servicesProvided).withPreProcess(); ancClients.add(ancClient); } sortByName(ancClients); return ancClients; } }); } ANCSmartRegisterController(ServiceProvidedService serviceProvidedService, AlertService alertService, AllBeneficiaries allBeneficiaries, Cache<String> cache, Cache<ANCClients> ancClientsCache); }
ANCSmartRegisterController { public ANCClients getClients() { return ancClientsCache.get(ANC_CLIENTS_LIST, new CacheableData<ANCClients>() { @Override public ANCClients fetch() { ANCClients ancClients = new ANCClients(); List<Pair<Mother, EligibleCouple>> ancsWithEcs = allBeneficiaries.allANCsWithEC(); for (Pair<Mother, EligibleCouple> ancWithEc : ancsWithEcs) { Mother anc = ancWithEc.getLeft(); EligibleCouple ec = ancWithEc.getRight(); String photoPath = isBlank(ec.photoPath()) ? DEFAULT_WOMAN_IMAGE_PLACEHOLDER_PATH : ec.photoPath(); List<ServiceProvidedDTO> servicesProvided = getServicesProvided(anc.caseId()); List<AlertDTO> alerts = getAlerts(anc.caseId()); ANCClient ancClient = new ANCClient(anc.caseId(), ec.village(), ec.wifeName(), anc.thayiCardNumber(), anc.getDetail(AllConstants.ANCRegistrationFields.EDD), anc.referenceDate()).withHusbandName(ec.husbandName()).withAge(ec.age()) .withECNumber(ec.ecNumber()).withANCNumber( anc.getDetail(AllConstants.ANCRegistrationFields.ANC_NUMBER)) .withIsHighPriority(ec.isHighPriority()) .withIsHighRisk(anc.isHighRisk()).withIsOutOfArea(ec.isOutOfArea()) .withHighRiskReason(anc.highRiskReason()) .withCaste(ec.getDetail(AllConstants.ECRegistrationFields.CASTE)) .withEconomicStatus( ec.getDetail(AllConstants.ECRegistrationFields.ECONOMIC_STATUS)) .withPhotoPath(photoPath).withEntityIdToSavePhoto(ec.caseId()) .withAlerts(alerts).withAshaPhoneNumber(anc.getDetail( AllConstants.ANCRegistrationFields.ASHA_PHONE_NUMBER)) .withServicesProvided(servicesProvided).withPreProcess(); ancClients.add(ancClient); } sortByName(ancClients); return ancClients; } }); } ANCSmartRegisterController(ServiceProvidedService serviceProvidedService, AlertService alertService, AllBeneficiaries allBeneficiaries, Cache<String> cache, Cache<ANCClients> ancClientsCache); ANCClients getClients(); }
ANCSmartRegisterController { public ANCClients getClients() { return ancClientsCache.get(ANC_CLIENTS_LIST, new CacheableData<ANCClients>() { @Override public ANCClients fetch() { ANCClients ancClients = new ANCClients(); List<Pair<Mother, EligibleCouple>> ancsWithEcs = allBeneficiaries.allANCsWithEC(); for (Pair<Mother, EligibleCouple> ancWithEc : ancsWithEcs) { Mother anc = ancWithEc.getLeft(); EligibleCouple ec = ancWithEc.getRight(); String photoPath = isBlank(ec.photoPath()) ? DEFAULT_WOMAN_IMAGE_PLACEHOLDER_PATH : ec.photoPath(); List<ServiceProvidedDTO> servicesProvided = getServicesProvided(anc.caseId()); List<AlertDTO> alerts = getAlerts(anc.caseId()); ANCClient ancClient = new ANCClient(anc.caseId(), ec.village(), ec.wifeName(), anc.thayiCardNumber(), anc.getDetail(AllConstants.ANCRegistrationFields.EDD), anc.referenceDate()).withHusbandName(ec.husbandName()).withAge(ec.age()) .withECNumber(ec.ecNumber()).withANCNumber( anc.getDetail(AllConstants.ANCRegistrationFields.ANC_NUMBER)) .withIsHighPriority(ec.isHighPriority()) .withIsHighRisk(anc.isHighRisk()).withIsOutOfArea(ec.isOutOfArea()) .withHighRiskReason(anc.highRiskReason()) .withCaste(ec.getDetail(AllConstants.ECRegistrationFields.CASTE)) .withEconomicStatus( ec.getDetail(AllConstants.ECRegistrationFields.ECONOMIC_STATUS)) .withPhotoPath(photoPath).withEntityIdToSavePhoto(ec.caseId()) .withAlerts(alerts).withAshaPhoneNumber(anc.getDetail( AllConstants.ANCRegistrationFields.ASHA_PHONE_NUMBER)) .withServicesProvided(servicesProvided).withPreProcess(); ancClients.add(ancClient); } sortByName(ancClients); return ancClients; } }); } ANCSmartRegisterController(ServiceProvidedService serviceProvidedService, AlertService alertService, AllBeneficiaries allBeneficiaries, Cache<String> cache, Cache<ANCClients> ancClientsCache); ANCClients getClients(); }
@Test public void shouldCreateANCClientsWithServicesProvided() throws Exception { Map<String, String> details = EasyMap.mapOf("edd", "Tue, 25 Feb 2014 00:00:00 GMT"); EligibleCouple ec = new EligibleCouple("entity id 1", "Woman C", "Husband C", "EC Number 1", "Bherya", "Bherya SC", emptyMap); Mother mother = new Mother("Entity X", "entity id 1", "thayi 1", "2013-05-25").withDetails(details); Mockito.when(allBeneficiaries.allANCsWithEC()).thenReturn(Arrays.asList(Pair.of(mother, ec))); Mockito.when(alertService.findByEntityIdAndAlertNames("Entity X", ANC_ALERTS)).thenReturn(Collections.<Alert>emptyList()); Mockito.when(sericeProvidedService.findByEntityIdAndServiceNames("Entity X", ANC_SERVICES)) .thenReturn(Arrays.asList(new ServiceProvided("entity id 1", "IFA", "2013-01-01", EasyMap.mapOf("dose", "100")), new ServiceProvided("entity id 1", "TT 1", "2013-02-01", emptyMap), new ServiceProvided("entity id 1", "Delivery Plan", "2013-02-01", emptyMap) )); ANCClients actualClients = controller.getClients(); Mockito.verify(alertService).findByEntityIdAndAlertNames("Entity X", ANC_ALERTS); Mockito.verify(sericeProvidedService).findByEntityIdAndServiceNames("Entity X", ANC_SERVICES); ServiceProvidedDTO IFAServiceProvidedDTO = new ServiceProvidedDTO("IFA", "2013-01-01", EasyMap.mapOf("dose", "100")); ServiceProvidedDTO deliveryPlanServiceProvidedDTO = new ServiceProvidedDTO("Delivery Plan", "2013-02-01", emptyMap); ServiceProvidedDTO ttServiceProvidedDTO = new ServiceProvidedDTO("TT 1", "2013-02-01", emptyMap); List<ServiceProvidedDTO> expectedServicesProvided = Arrays.asList(IFAServiceProvidedDTO, ttServiceProvidedDTO, deliveryPlanServiceProvidedDTO); Visits emptyVisit = new Visits(); Visits expectedIFAServiceProvided = new Visits(); expectedIFAServiceProvided.provided = IFAServiceProvidedDTO; Visits expectedDeliveryPlanServiceProvided = new Visits(); expectedDeliveryPlanServiceProvided.provided = deliveryPlanServiceProvidedDTO; Visits expectedTTServiceProvided = new Visits(); expectedTTServiceProvided.provided = ttServiceProvidedDTO; Map<String, Visits> serviceToVisitsMap = EasyMap.create("tt", expectedTTServiceProvided).put("pnc", emptyVisit).put("ifa", expectedIFAServiceProvided).put("delivery_plan", expectedDeliveryPlanServiceProvided).put("anc", emptyVisit).put("hb", emptyVisit).map(); ANCClient expectedEC = createANCClient("Entity X", "Woman C", "Bherya", "thayi 1", "Tue, 25 Feb 2014 00:00:00 GMT", "2013-05-25") .withECNumber("EC Number 1") .withHusbandName("Husband C") .withEntityIdToSavePhoto("entity id 1") .withServicesProvided(expectedServicesProvided) .withServiceToVisitMap(serviceToVisitsMap) .withHighRiskReason(""); Assert.assertEquals(Arrays.asList(expectedEC), actualClients); }
public ANCClients getClients() { return ancClientsCache.get(ANC_CLIENTS_LIST, new CacheableData<ANCClients>() { @Override public ANCClients fetch() { ANCClients ancClients = new ANCClients(); List<Pair<Mother, EligibleCouple>> ancsWithEcs = allBeneficiaries.allANCsWithEC(); for (Pair<Mother, EligibleCouple> ancWithEc : ancsWithEcs) { Mother anc = ancWithEc.getLeft(); EligibleCouple ec = ancWithEc.getRight(); String photoPath = isBlank(ec.photoPath()) ? DEFAULT_WOMAN_IMAGE_PLACEHOLDER_PATH : ec.photoPath(); List<ServiceProvidedDTO> servicesProvided = getServicesProvided(anc.caseId()); List<AlertDTO> alerts = getAlerts(anc.caseId()); ANCClient ancClient = new ANCClient(anc.caseId(), ec.village(), ec.wifeName(), anc.thayiCardNumber(), anc.getDetail(AllConstants.ANCRegistrationFields.EDD), anc.referenceDate()).withHusbandName(ec.husbandName()).withAge(ec.age()) .withECNumber(ec.ecNumber()).withANCNumber( anc.getDetail(AllConstants.ANCRegistrationFields.ANC_NUMBER)) .withIsHighPriority(ec.isHighPriority()) .withIsHighRisk(anc.isHighRisk()).withIsOutOfArea(ec.isOutOfArea()) .withHighRiskReason(anc.highRiskReason()) .withCaste(ec.getDetail(AllConstants.ECRegistrationFields.CASTE)) .withEconomicStatus( ec.getDetail(AllConstants.ECRegistrationFields.ECONOMIC_STATUS)) .withPhotoPath(photoPath).withEntityIdToSavePhoto(ec.caseId()) .withAlerts(alerts).withAshaPhoneNumber(anc.getDetail( AllConstants.ANCRegistrationFields.ASHA_PHONE_NUMBER)) .withServicesProvided(servicesProvided).withPreProcess(); ancClients.add(ancClient); } sortByName(ancClients); return ancClients; } }); }
ANCSmartRegisterController { public ANCClients getClients() { return ancClientsCache.get(ANC_CLIENTS_LIST, new CacheableData<ANCClients>() { @Override public ANCClients fetch() { ANCClients ancClients = new ANCClients(); List<Pair<Mother, EligibleCouple>> ancsWithEcs = allBeneficiaries.allANCsWithEC(); for (Pair<Mother, EligibleCouple> ancWithEc : ancsWithEcs) { Mother anc = ancWithEc.getLeft(); EligibleCouple ec = ancWithEc.getRight(); String photoPath = isBlank(ec.photoPath()) ? DEFAULT_WOMAN_IMAGE_PLACEHOLDER_PATH : ec.photoPath(); List<ServiceProvidedDTO> servicesProvided = getServicesProvided(anc.caseId()); List<AlertDTO> alerts = getAlerts(anc.caseId()); ANCClient ancClient = new ANCClient(anc.caseId(), ec.village(), ec.wifeName(), anc.thayiCardNumber(), anc.getDetail(AllConstants.ANCRegistrationFields.EDD), anc.referenceDate()).withHusbandName(ec.husbandName()).withAge(ec.age()) .withECNumber(ec.ecNumber()).withANCNumber( anc.getDetail(AllConstants.ANCRegistrationFields.ANC_NUMBER)) .withIsHighPriority(ec.isHighPriority()) .withIsHighRisk(anc.isHighRisk()).withIsOutOfArea(ec.isOutOfArea()) .withHighRiskReason(anc.highRiskReason()) .withCaste(ec.getDetail(AllConstants.ECRegistrationFields.CASTE)) .withEconomicStatus( ec.getDetail(AllConstants.ECRegistrationFields.ECONOMIC_STATUS)) .withPhotoPath(photoPath).withEntityIdToSavePhoto(ec.caseId()) .withAlerts(alerts).withAshaPhoneNumber(anc.getDetail( AllConstants.ANCRegistrationFields.ASHA_PHONE_NUMBER)) .withServicesProvided(servicesProvided).withPreProcess(); ancClients.add(ancClient); } sortByName(ancClients); return ancClients; } }); } }
ANCSmartRegisterController { public ANCClients getClients() { return ancClientsCache.get(ANC_CLIENTS_LIST, new CacheableData<ANCClients>() { @Override public ANCClients fetch() { ANCClients ancClients = new ANCClients(); List<Pair<Mother, EligibleCouple>> ancsWithEcs = allBeneficiaries.allANCsWithEC(); for (Pair<Mother, EligibleCouple> ancWithEc : ancsWithEcs) { Mother anc = ancWithEc.getLeft(); EligibleCouple ec = ancWithEc.getRight(); String photoPath = isBlank(ec.photoPath()) ? DEFAULT_WOMAN_IMAGE_PLACEHOLDER_PATH : ec.photoPath(); List<ServiceProvidedDTO> servicesProvided = getServicesProvided(anc.caseId()); List<AlertDTO> alerts = getAlerts(anc.caseId()); ANCClient ancClient = new ANCClient(anc.caseId(), ec.village(), ec.wifeName(), anc.thayiCardNumber(), anc.getDetail(AllConstants.ANCRegistrationFields.EDD), anc.referenceDate()).withHusbandName(ec.husbandName()).withAge(ec.age()) .withECNumber(ec.ecNumber()).withANCNumber( anc.getDetail(AllConstants.ANCRegistrationFields.ANC_NUMBER)) .withIsHighPriority(ec.isHighPriority()) .withIsHighRisk(anc.isHighRisk()).withIsOutOfArea(ec.isOutOfArea()) .withHighRiskReason(anc.highRiskReason()) .withCaste(ec.getDetail(AllConstants.ECRegistrationFields.CASTE)) .withEconomicStatus( ec.getDetail(AllConstants.ECRegistrationFields.ECONOMIC_STATUS)) .withPhotoPath(photoPath).withEntityIdToSavePhoto(ec.caseId()) .withAlerts(alerts).withAshaPhoneNumber(anc.getDetail( AllConstants.ANCRegistrationFields.ASHA_PHONE_NUMBER)) .withServicesProvided(servicesProvided).withPreProcess(); ancClients.add(ancClient); } sortByName(ancClients); return ancClients; } }); } ANCSmartRegisterController(ServiceProvidedService serviceProvidedService, AlertService alertService, AllBeneficiaries allBeneficiaries, Cache<String> cache, Cache<ANCClients> ancClientsCache); }
ANCSmartRegisterController { public ANCClients getClients() { return ancClientsCache.get(ANC_CLIENTS_LIST, new CacheableData<ANCClients>() { @Override public ANCClients fetch() { ANCClients ancClients = new ANCClients(); List<Pair<Mother, EligibleCouple>> ancsWithEcs = allBeneficiaries.allANCsWithEC(); for (Pair<Mother, EligibleCouple> ancWithEc : ancsWithEcs) { Mother anc = ancWithEc.getLeft(); EligibleCouple ec = ancWithEc.getRight(); String photoPath = isBlank(ec.photoPath()) ? DEFAULT_WOMAN_IMAGE_PLACEHOLDER_PATH : ec.photoPath(); List<ServiceProvidedDTO> servicesProvided = getServicesProvided(anc.caseId()); List<AlertDTO> alerts = getAlerts(anc.caseId()); ANCClient ancClient = new ANCClient(anc.caseId(), ec.village(), ec.wifeName(), anc.thayiCardNumber(), anc.getDetail(AllConstants.ANCRegistrationFields.EDD), anc.referenceDate()).withHusbandName(ec.husbandName()).withAge(ec.age()) .withECNumber(ec.ecNumber()).withANCNumber( anc.getDetail(AllConstants.ANCRegistrationFields.ANC_NUMBER)) .withIsHighPriority(ec.isHighPriority()) .withIsHighRisk(anc.isHighRisk()).withIsOutOfArea(ec.isOutOfArea()) .withHighRiskReason(anc.highRiskReason()) .withCaste(ec.getDetail(AllConstants.ECRegistrationFields.CASTE)) .withEconomicStatus( ec.getDetail(AllConstants.ECRegistrationFields.ECONOMIC_STATUS)) .withPhotoPath(photoPath).withEntityIdToSavePhoto(ec.caseId()) .withAlerts(alerts).withAshaPhoneNumber(anc.getDetail( AllConstants.ANCRegistrationFields.ASHA_PHONE_NUMBER)) .withServicesProvided(servicesProvided).withPreProcess(); ancClients.add(ancClient); } sortByName(ancClients); return ancClients; } }); } ANCSmartRegisterController(ServiceProvidedService serviceProvidedService, AlertService alertService, AllBeneficiaries allBeneficiaries, Cache<String> cache, Cache<ANCClients> ancClientsCache); ANCClients getClients(); }
ANCSmartRegisterController { public ANCClients getClients() { return ancClientsCache.get(ANC_CLIENTS_LIST, new CacheableData<ANCClients>() { @Override public ANCClients fetch() { ANCClients ancClients = new ANCClients(); List<Pair<Mother, EligibleCouple>> ancsWithEcs = allBeneficiaries.allANCsWithEC(); for (Pair<Mother, EligibleCouple> ancWithEc : ancsWithEcs) { Mother anc = ancWithEc.getLeft(); EligibleCouple ec = ancWithEc.getRight(); String photoPath = isBlank(ec.photoPath()) ? DEFAULT_WOMAN_IMAGE_PLACEHOLDER_PATH : ec.photoPath(); List<ServiceProvidedDTO> servicesProvided = getServicesProvided(anc.caseId()); List<AlertDTO> alerts = getAlerts(anc.caseId()); ANCClient ancClient = new ANCClient(anc.caseId(), ec.village(), ec.wifeName(), anc.thayiCardNumber(), anc.getDetail(AllConstants.ANCRegistrationFields.EDD), anc.referenceDate()).withHusbandName(ec.husbandName()).withAge(ec.age()) .withECNumber(ec.ecNumber()).withANCNumber( anc.getDetail(AllConstants.ANCRegistrationFields.ANC_NUMBER)) .withIsHighPriority(ec.isHighPriority()) .withIsHighRisk(anc.isHighRisk()).withIsOutOfArea(ec.isOutOfArea()) .withHighRiskReason(anc.highRiskReason()) .withCaste(ec.getDetail(AllConstants.ECRegistrationFields.CASTE)) .withEconomicStatus( ec.getDetail(AllConstants.ECRegistrationFields.ECONOMIC_STATUS)) .withPhotoPath(photoPath).withEntityIdToSavePhoto(ec.caseId()) .withAlerts(alerts).withAshaPhoneNumber(anc.getDetail( AllConstants.ANCRegistrationFields.ASHA_PHONE_NUMBER)) .withServicesProvided(servicesProvided).withPreProcess(); ancClients.add(ancClient); } sortByName(ancClients); return ancClients; } }); } ANCSmartRegisterController(ServiceProvidedService serviceProvidedService, AlertService alertService, AllBeneficiaries allBeneficiaries, Cache<String> cache, Cache<ANCClients> ancClientsCache); ANCClients getClients(); }
@Test public void shouldGetIndicatorReportsForGivenCategory() throws Exception { List<MonthSummaryDatum> monthlySummaries = Arrays.asList(new MonthSummaryDatum("10", "2012", "2", "2", Arrays.asList("123", "456"))); Report iudReport = new Report("IUD", "40", new Gson().toJson(monthlySummaries)); Report condomReport = new Report("CONDOM", "30", new Gson().toJson(monthlySummaries)); Mockito.when(allReports.allFor(ArgumentMatchers.anyListOf(ReportIndicator.class))).thenReturn(Arrays.asList(iudReport, condomReport)); String indicatorReports = controller.get(); IndicatorReport iud = new IndicatorReport("IUD", "IUD Adoption", "40", "2", "10", "2012", "2"); IndicatorReport condom = new IndicatorReport("CONDOM", "Condom Usage", "30", "2", "10", "2012", "2"); String expectedIndicatorReports = new Gson().toJson(new CategoryReports("Family Planning Services", Arrays.asList(iud, condom))); Assert.assertEquals(expectedIndicatorReports, indicatorReports); }
public String get() { reportsCategory = ReportsCategory.valueOf(category); reports = allReports.allFor(reportsCategory.indicators()); List<IndicatorReport> indicatorReports = new ArrayList<IndicatorReport>(); for (Report report : reports) { ReportIndicator indicator = report.reportIndicator(); List<MonthSummaryDatum> monthSummaryData = report.monthlySummaries(); if (monthSummaryData.size() == 0) { continue; } sortMonthlySummaries(monthSummaryData); MonthSummaryDatum currentMonthSummary = monthSummaryData.get(0); String currentMonth = today().monthOfYear().getAsString(); String currentProgress = currentMonthSummary.month().equals(currentMonth) ? currentMonthSummary .currentProgress() : "0"; String annualTarget = (isBlank(report.annualTarget())) ? "NA" : report.annualTarget(); indicatorReports.add(new IndicatorReport(indicator.name(), indicator.description(), annualTarget, currentProgress, currentMonth, currentMonthSummary.year(), currentMonthSummary.aggregatedProgress())); } return new Gson() .toJson(new CategoryReports(reportsCategory.description(), indicatorReports)); }
ReportIndicatorListViewController { public String get() { reportsCategory = ReportsCategory.valueOf(category); reports = allReports.allFor(reportsCategory.indicators()); List<IndicatorReport> indicatorReports = new ArrayList<IndicatorReport>(); for (Report report : reports) { ReportIndicator indicator = report.reportIndicator(); List<MonthSummaryDatum> monthSummaryData = report.monthlySummaries(); if (monthSummaryData.size() == 0) { continue; } sortMonthlySummaries(monthSummaryData); MonthSummaryDatum currentMonthSummary = monthSummaryData.get(0); String currentMonth = today().monthOfYear().getAsString(); String currentProgress = currentMonthSummary.month().equals(currentMonth) ? currentMonthSummary .currentProgress() : "0"; String annualTarget = (isBlank(report.annualTarget())) ? "NA" : report.annualTarget(); indicatorReports.add(new IndicatorReport(indicator.name(), indicator.description(), annualTarget, currentProgress, currentMonth, currentMonthSummary.year(), currentMonthSummary.aggregatedProgress())); } return new Gson() .toJson(new CategoryReports(reportsCategory.description(), indicatorReports)); } }
ReportIndicatorListViewController { public String get() { reportsCategory = ReportsCategory.valueOf(category); reports = allReports.allFor(reportsCategory.indicators()); List<IndicatorReport> indicatorReports = new ArrayList<IndicatorReport>(); for (Report report : reports) { ReportIndicator indicator = report.reportIndicator(); List<MonthSummaryDatum> monthSummaryData = report.monthlySummaries(); if (monthSummaryData.size() == 0) { continue; } sortMonthlySummaries(monthSummaryData); MonthSummaryDatum currentMonthSummary = monthSummaryData.get(0); String currentMonth = today().monthOfYear().getAsString(); String currentProgress = currentMonthSummary.month().equals(currentMonth) ? currentMonthSummary .currentProgress() : "0"; String annualTarget = (isBlank(report.annualTarget())) ? "NA" : report.annualTarget(); indicatorReports.add(new IndicatorReport(indicator.name(), indicator.description(), annualTarget, currentProgress, currentMonth, currentMonthSummary.year(), currentMonthSummary.aggregatedProgress())); } return new Gson() .toJson(new CategoryReports(reportsCategory.description(), indicatorReports)); } ReportIndicatorListViewController(Context context, AllReports allReports, String category); }
ReportIndicatorListViewController { public String get() { reportsCategory = ReportsCategory.valueOf(category); reports = allReports.allFor(reportsCategory.indicators()); List<IndicatorReport> indicatorReports = new ArrayList<IndicatorReport>(); for (Report report : reports) { ReportIndicator indicator = report.reportIndicator(); List<MonthSummaryDatum> monthSummaryData = report.monthlySummaries(); if (monthSummaryData.size() == 0) { continue; } sortMonthlySummaries(monthSummaryData); MonthSummaryDatum currentMonthSummary = monthSummaryData.get(0); String currentMonth = today().monthOfYear().getAsString(); String currentProgress = currentMonthSummary.month().equals(currentMonth) ? currentMonthSummary .currentProgress() : "0"; String annualTarget = (isBlank(report.annualTarget())) ? "NA" : report.annualTarget(); indicatorReports.add(new IndicatorReport(indicator.name(), indicator.description(), annualTarget, currentProgress, currentMonth, currentMonthSummary.year(), currentMonthSummary.aggregatedProgress())); } return new Gson() .toJson(new CategoryReports(reportsCategory.description(), indicatorReports)); } ReportIndicatorListViewController(Context context, AllReports allReports, String category); String get(); void sortMonthlySummaries(List<MonthSummaryDatum> monthSummaryData); void startReportIndicatorDetail(String indicator); }
ReportIndicatorListViewController { public String get() { reportsCategory = ReportsCategory.valueOf(category); reports = allReports.allFor(reportsCategory.indicators()); List<IndicatorReport> indicatorReports = new ArrayList<IndicatorReport>(); for (Report report : reports) { ReportIndicator indicator = report.reportIndicator(); List<MonthSummaryDatum> monthSummaryData = report.monthlySummaries(); if (monthSummaryData.size() == 0) { continue; } sortMonthlySummaries(monthSummaryData); MonthSummaryDatum currentMonthSummary = monthSummaryData.get(0); String currentMonth = today().monthOfYear().getAsString(); String currentProgress = currentMonthSummary.month().equals(currentMonth) ? currentMonthSummary .currentProgress() : "0"; String annualTarget = (isBlank(report.annualTarget())) ? "NA" : report.annualTarget(); indicatorReports.add(new IndicatorReport(indicator.name(), indicator.description(), annualTarget, currentProgress, currentMonth, currentMonthSummary.year(), currentMonthSummary.aggregatedProgress())); } return new Gson() .toJson(new CategoryReports(reportsCategory.description(), indicatorReports)); } ReportIndicatorListViewController(Context context, AllReports allReports, String category); String get(); void sortMonthlySummaries(List<MonthSummaryDatum> monthSummaryData); void startReportIndicatorDetail(String indicator); }
@Test public void testAddPaginationCoreCreatesPaginationHolderWithCorrectValues() { Mockito.doReturn(layoutInflater).when(activity).getLayoutInflater(); Mockito.doReturn(paginationView).when(layoutInflater).inflate(R.layout.smart_register_pagination, null); Mockito.doReturn(activity).when(clientsView).getContext(); Mockito.doReturn(nextPageButton).when(paginationView).findViewById(R.id.btn_next_page); Mockito.doReturn(prevPageButton).when(paginationView).findViewById(R.id.btn_previous_page); Mockito.doReturn(infoTextView).when(paginationView).findViewById(R.id.txt_page_info); Mockito.doReturn(LayoutDirection.LTR).when(paginationView).getLayoutDirection(); Mockito.doReturn(resources).when(activity).getResources(); Mockito.doReturn(1985.0f).when(resources).getDimension(ArgumentMatchers.anyInt()); PaginationHolder paginationHolder = ViewHelper.addPaginationCore(clickListener, clientsView); Assert.assertNotNull(paginationHolder); Assert.assertEquals(nextPageButton, paginationHolder.getNextPageView()); Assert.assertEquals(prevPageButton, paginationHolder.getPreviousPageView()); Assert.assertEquals(infoTextView, paginationHolder.getPageInfoView()); Mockito.verify(nextPageButton).setOnClickListener(clickListener); Mockito.verify(prevPageButton).setOnClickListener(clickListener); }
public static PaginationHolder addPaginationCore(View.OnClickListener onClickListener, ListView clientsView) { ViewGroup footerView = getPaginationView((Activity) clientsView.getContext()); PaginationHolder paginationHolder = new PaginationHolder(); paginationHolder.setNextPageView(footerView.findViewById(R.id.btn_next_page)); paginationHolder.setPreviousPageView(footerView.findViewById(R.id.btn_previous_page)); paginationHolder.setPageInfoView(footerView.findViewById(R.id.txt_page_info)); paginationHolder.getNextPageView().setOnClickListener(onClickListener); paginationHolder.getPreviousPageView().setOnClickListener(onClickListener); footerView.setLayoutParams( new AbsListView.LayoutParams(AbsListView.LayoutParams.MATCH_PARENT, (int) clientsView.getContext().getResources().getDimension(R.dimen.pagination_bar_height))); clientsView.addFooterView(footerView); return paginationHolder; }
ViewHelper { public static PaginationHolder addPaginationCore(View.OnClickListener onClickListener, ListView clientsView) { ViewGroup footerView = getPaginationView((Activity) clientsView.getContext()); PaginationHolder paginationHolder = new PaginationHolder(); paginationHolder.setNextPageView(footerView.findViewById(R.id.btn_next_page)); paginationHolder.setPreviousPageView(footerView.findViewById(R.id.btn_previous_page)); paginationHolder.setPageInfoView(footerView.findViewById(R.id.txt_page_info)); paginationHolder.getNextPageView().setOnClickListener(onClickListener); paginationHolder.getPreviousPageView().setOnClickListener(onClickListener); footerView.setLayoutParams( new AbsListView.LayoutParams(AbsListView.LayoutParams.MATCH_PARENT, (int) clientsView.getContext().getResources().getDimension(R.dimen.pagination_bar_height))); clientsView.addFooterView(footerView); return paginationHolder; } }
ViewHelper { public static PaginationHolder addPaginationCore(View.OnClickListener onClickListener, ListView clientsView) { ViewGroup footerView = getPaginationView((Activity) clientsView.getContext()); PaginationHolder paginationHolder = new PaginationHolder(); paginationHolder.setNextPageView(footerView.findViewById(R.id.btn_next_page)); paginationHolder.setPreviousPageView(footerView.findViewById(R.id.btn_previous_page)); paginationHolder.setPageInfoView(footerView.findViewById(R.id.txt_page_info)); paginationHolder.getNextPageView().setOnClickListener(onClickListener); paginationHolder.getPreviousPageView().setOnClickListener(onClickListener); footerView.setLayoutParams( new AbsListView.LayoutParams(AbsListView.LayoutParams.MATCH_PARENT, (int) clientsView.getContext().getResources().getDimension(R.dimen.pagination_bar_height))); clientsView.addFooterView(footerView); return paginationHolder; } }
ViewHelper { public static PaginationHolder addPaginationCore(View.OnClickListener onClickListener, ListView clientsView) { ViewGroup footerView = getPaginationView((Activity) clientsView.getContext()); PaginationHolder paginationHolder = new PaginationHolder(); paginationHolder.setNextPageView(footerView.findViewById(R.id.btn_next_page)); paginationHolder.setPreviousPageView(footerView.findViewById(R.id.btn_previous_page)); paginationHolder.setPageInfoView(footerView.findViewById(R.id.txt_page_info)); paginationHolder.getNextPageView().setOnClickListener(onClickListener); paginationHolder.getPreviousPageView().setOnClickListener(onClickListener); footerView.setLayoutParams( new AbsListView.LayoutParams(AbsListView.LayoutParams.MATCH_PARENT, (int) clientsView.getContext().getResources().getDimension(R.dimen.pagination_bar_height))); clientsView.addFooterView(footerView); return paginationHolder; } static PaginationHolder addPaginationCore(View.OnClickListener onClickListener, ListView clientsView); static ViewGroup getPaginationView(Activity context); }
ViewHelper { public static PaginationHolder addPaginationCore(View.OnClickListener onClickListener, ListView clientsView) { ViewGroup footerView = getPaginationView((Activity) clientsView.getContext()); PaginationHolder paginationHolder = new PaginationHolder(); paginationHolder.setNextPageView(footerView.findViewById(R.id.btn_next_page)); paginationHolder.setPreviousPageView(footerView.findViewById(R.id.btn_previous_page)); paginationHolder.setPageInfoView(footerView.findViewById(R.id.txt_page_info)); paginationHolder.getNextPageView().setOnClickListener(onClickListener); paginationHolder.getPreviousPageView().setOnClickListener(onClickListener); footerView.setLayoutParams( new AbsListView.LayoutParams(AbsListView.LayoutParams.MATCH_PARENT, (int) clientsView.getContext().getResources().getDimension(R.dimen.pagination_bar_height))); clientsView.addFooterView(footerView); return paginationHolder; } static PaginationHolder addPaginationCore(View.OnClickListener onClickListener, ListView clientsView); static ViewGroup getPaginationView(Activity context); }
@Test public void shouldIgnoreThoseReportsWhichHaveEmptyMonthlySummary() throws Exception { List<MonthSummaryDatum> monthlySummaries = Arrays.asList(new MonthSummaryDatum("10", "2012", "2", "2", Arrays.asList("123", "456"))); Report iudReport = new Report("IUD", "40", new Gson().toJson(monthlySummaries)); Report condomReport = new Report("CONDOM", "30", "[]"); Mockito.when(allReports.allFor(ArgumentMatchers.anyListOf(ReportIndicator.class))).thenReturn(Arrays.asList(iudReport, condomReport)); String indicatorReports = controller.get(); IndicatorReport iud = new IndicatorReport("IUD", "IUD Adoption", "40", "2", "10", "2012", "2"); String expectedIndicatorReports = new Gson().toJson(new CategoryReports("Family Planning Services", Arrays.asList(iud))); Assert.assertEquals(expectedIndicatorReports, indicatorReports); }
public String get() { reportsCategory = ReportsCategory.valueOf(category); reports = allReports.allFor(reportsCategory.indicators()); List<IndicatorReport> indicatorReports = new ArrayList<IndicatorReport>(); for (Report report : reports) { ReportIndicator indicator = report.reportIndicator(); List<MonthSummaryDatum> monthSummaryData = report.monthlySummaries(); if (monthSummaryData.size() == 0) { continue; } sortMonthlySummaries(monthSummaryData); MonthSummaryDatum currentMonthSummary = monthSummaryData.get(0); String currentMonth = today().monthOfYear().getAsString(); String currentProgress = currentMonthSummary.month().equals(currentMonth) ? currentMonthSummary .currentProgress() : "0"; String annualTarget = (isBlank(report.annualTarget())) ? "NA" : report.annualTarget(); indicatorReports.add(new IndicatorReport(indicator.name(), indicator.description(), annualTarget, currentProgress, currentMonth, currentMonthSummary.year(), currentMonthSummary.aggregatedProgress())); } return new Gson() .toJson(new CategoryReports(reportsCategory.description(), indicatorReports)); }
ReportIndicatorListViewController { public String get() { reportsCategory = ReportsCategory.valueOf(category); reports = allReports.allFor(reportsCategory.indicators()); List<IndicatorReport> indicatorReports = new ArrayList<IndicatorReport>(); for (Report report : reports) { ReportIndicator indicator = report.reportIndicator(); List<MonthSummaryDatum> monthSummaryData = report.monthlySummaries(); if (monthSummaryData.size() == 0) { continue; } sortMonthlySummaries(monthSummaryData); MonthSummaryDatum currentMonthSummary = monthSummaryData.get(0); String currentMonth = today().monthOfYear().getAsString(); String currentProgress = currentMonthSummary.month().equals(currentMonth) ? currentMonthSummary .currentProgress() : "0"; String annualTarget = (isBlank(report.annualTarget())) ? "NA" : report.annualTarget(); indicatorReports.add(new IndicatorReport(indicator.name(), indicator.description(), annualTarget, currentProgress, currentMonth, currentMonthSummary.year(), currentMonthSummary.aggregatedProgress())); } return new Gson() .toJson(new CategoryReports(reportsCategory.description(), indicatorReports)); } }
ReportIndicatorListViewController { public String get() { reportsCategory = ReportsCategory.valueOf(category); reports = allReports.allFor(reportsCategory.indicators()); List<IndicatorReport> indicatorReports = new ArrayList<IndicatorReport>(); for (Report report : reports) { ReportIndicator indicator = report.reportIndicator(); List<MonthSummaryDatum> monthSummaryData = report.monthlySummaries(); if (monthSummaryData.size() == 0) { continue; } sortMonthlySummaries(monthSummaryData); MonthSummaryDatum currentMonthSummary = monthSummaryData.get(0); String currentMonth = today().monthOfYear().getAsString(); String currentProgress = currentMonthSummary.month().equals(currentMonth) ? currentMonthSummary .currentProgress() : "0"; String annualTarget = (isBlank(report.annualTarget())) ? "NA" : report.annualTarget(); indicatorReports.add(new IndicatorReport(indicator.name(), indicator.description(), annualTarget, currentProgress, currentMonth, currentMonthSummary.year(), currentMonthSummary.aggregatedProgress())); } return new Gson() .toJson(new CategoryReports(reportsCategory.description(), indicatorReports)); } ReportIndicatorListViewController(Context context, AllReports allReports, String category); }
ReportIndicatorListViewController { public String get() { reportsCategory = ReportsCategory.valueOf(category); reports = allReports.allFor(reportsCategory.indicators()); List<IndicatorReport> indicatorReports = new ArrayList<IndicatorReport>(); for (Report report : reports) { ReportIndicator indicator = report.reportIndicator(); List<MonthSummaryDatum> monthSummaryData = report.monthlySummaries(); if (monthSummaryData.size() == 0) { continue; } sortMonthlySummaries(monthSummaryData); MonthSummaryDatum currentMonthSummary = monthSummaryData.get(0); String currentMonth = today().monthOfYear().getAsString(); String currentProgress = currentMonthSummary.month().equals(currentMonth) ? currentMonthSummary .currentProgress() : "0"; String annualTarget = (isBlank(report.annualTarget())) ? "NA" : report.annualTarget(); indicatorReports.add(new IndicatorReport(indicator.name(), indicator.description(), annualTarget, currentProgress, currentMonth, currentMonthSummary.year(), currentMonthSummary.aggregatedProgress())); } return new Gson() .toJson(new CategoryReports(reportsCategory.description(), indicatorReports)); } ReportIndicatorListViewController(Context context, AllReports allReports, String category); String get(); void sortMonthlySummaries(List<MonthSummaryDatum> monthSummaryData); void startReportIndicatorDetail(String indicator); }
ReportIndicatorListViewController { public String get() { reportsCategory = ReportsCategory.valueOf(category); reports = allReports.allFor(reportsCategory.indicators()); List<IndicatorReport> indicatorReports = new ArrayList<IndicatorReport>(); for (Report report : reports) { ReportIndicator indicator = report.reportIndicator(); List<MonthSummaryDatum> monthSummaryData = report.monthlySummaries(); if (monthSummaryData.size() == 0) { continue; } sortMonthlySummaries(monthSummaryData); MonthSummaryDatum currentMonthSummary = monthSummaryData.get(0); String currentMonth = today().monthOfYear().getAsString(); String currentProgress = currentMonthSummary.month().equals(currentMonth) ? currentMonthSummary .currentProgress() : "0"; String annualTarget = (isBlank(report.annualTarget())) ? "NA" : report.annualTarget(); indicatorReports.add(new IndicatorReport(indicator.name(), indicator.description(), annualTarget, currentProgress, currentMonth, currentMonthSummary.year(), currentMonthSummary.aggregatedProgress())); } return new Gson() .toJson(new CategoryReports(reportsCategory.description(), indicatorReports)); } ReportIndicatorListViewController(Context context, AllReports allReports, String category); String get(); void sortMonthlySummaries(List<MonthSummaryDatum> monthSummaryData); void startReportIndicatorDetail(String indicator); }
@Test public void shouldUseCurrentMonthDataForIndicatorReport() throws Exception { List<MonthSummaryDatum> monthlySummaries = Arrays.asList(new MonthSummaryDatum("1", "2012", "2", "2", Arrays.asList("123", "456")), new MonthSummaryDatum("10", "2012", "2", "4", Arrays.asList("321", "654"))); Report earlyANCRegistrationReport = new Report("ANC_LT_12", "40", new Gson().toJson(monthlySummaries)); Mockito.when(allReports.allFor(ReportsCategory.ANC_SERVICES.indicators())).thenReturn(Arrays.asList(earlyANCRegistrationReport)); controller = new ReportIndicatorListViewController(context, allReports, ReportsCategory.ANC_SERVICES.value()); String reports = controller.get(); IndicatorReport earlyANCRegistration = new IndicatorReport("EARLY_ANC_REGISTRATIONS", "Early ANC Registration", "40", "2", "10", "2012", "4"); String expectedIndicatorReports = new Gson().toJson(new CategoryReports("ANC Services", Arrays.asList(earlyANCRegistration))); Assert.assertEquals(expectedIndicatorReports, reports); }
public String get() { reportsCategory = ReportsCategory.valueOf(category); reports = allReports.allFor(reportsCategory.indicators()); List<IndicatorReport> indicatorReports = new ArrayList<IndicatorReport>(); for (Report report : reports) { ReportIndicator indicator = report.reportIndicator(); List<MonthSummaryDatum> monthSummaryData = report.monthlySummaries(); if (monthSummaryData.size() == 0) { continue; } sortMonthlySummaries(monthSummaryData); MonthSummaryDatum currentMonthSummary = monthSummaryData.get(0); String currentMonth = today().monthOfYear().getAsString(); String currentProgress = currentMonthSummary.month().equals(currentMonth) ? currentMonthSummary .currentProgress() : "0"; String annualTarget = (isBlank(report.annualTarget())) ? "NA" : report.annualTarget(); indicatorReports.add(new IndicatorReport(indicator.name(), indicator.description(), annualTarget, currentProgress, currentMonth, currentMonthSummary.year(), currentMonthSummary.aggregatedProgress())); } return new Gson() .toJson(new CategoryReports(reportsCategory.description(), indicatorReports)); }
ReportIndicatorListViewController { public String get() { reportsCategory = ReportsCategory.valueOf(category); reports = allReports.allFor(reportsCategory.indicators()); List<IndicatorReport> indicatorReports = new ArrayList<IndicatorReport>(); for (Report report : reports) { ReportIndicator indicator = report.reportIndicator(); List<MonthSummaryDatum> monthSummaryData = report.monthlySummaries(); if (monthSummaryData.size() == 0) { continue; } sortMonthlySummaries(monthSummaryData); MonthSummaryDatum currentMonthSummary = monthSummaryData.get(0); String currentMonth = today().monthOfYear().getAsString(); String currentProgress = currentMonthSummary.month().equals(currentMonth) ? currentMonthSummary .currentProgress() : "0"; String annualTarget = (isBlank(report.annualTarget())) ? "NA" : report.annualTarget(); indicatorReports.add(new IndicatorReport(indicator.name(), indicator.description(), annualTarget, currentProgress, currentMonth, currentMonthSummary.year(), currentMonthSummary.aggregatedProgress())); } return new Gson() .toJson(new CategoryReports(reportsCategory.description(), indicatorReports)); } }
ReportIndicatorListViewController { public String get() { reportsCategory = ReportsCategory.valueOf(category); reports = allReports.allFor(reportsCategory.indicators()); List<IndicatorReport> indicatorReports = new ArrayList<IndicatorReport>(); for (Report report : reports) { ReportIndicator indicator = report.reportIndicator(); List<MonthSummaryDatum> monthSummaryData = report.monthlySummaries(); if (monthSummaryData.size() == 0) { continue; } sortMonthlySummaries(monthSummaryData); MonthSummaryDatum currentMonthSummary = monthSummaryData.get(0); String currentMonth = today().monthOfYear().getAsString(); String currentProgress = currentMonthSummary.month().equals(currentMonth) ? currentMonthSummary .currentProgress() : "0"; String annualTarget = (isBlank(report.annualTarget())) ? "NA" : report.annualTarget(); indicatorReports.add(new IndicatorReport(indicator.name(), indicator.description(), annualTarget, currentProgress, currentMonth, currentMonthSummary.year(), currentMonthSummary.aggregatedProgress())); } return new Gson() .toJson(new CategoryReports(reportsCategory.description(), indicatorReports)); } ReportIndicatorListViewController(Context context, AllReports allReports, String category); }
ReportIndicatorListViewController { public String get() { reportsCategory = ReportsCategory.valueOf(category); reports = allReports.allFor(reportsCategory.indicators()); List<IndicatorReport> indicatorReports = new ArrayList<IndicatorReport>(); for (Report report : reports) { ReportIndicator indicator = report.reportIndicator(); List<MonthSummaryDatum> monthSummaryData = report.monthlySummaries(); if (monthSummaryData.size() == 0) { continue; } sortMonthlySummaries(monthSummaryData); MonthSummaryDatum currentMonthSummary = monthSummaryData.get(0); String currentMonth = today().monthOfYear().getAsString(); String currentProgress = currentMonthSummary.month().equals(currentMonth) ? currentMonthSummary .currentProgress() : "0"; String annualTarget = (isBlank(report.annualTarget())) ? "NA" : report.annualTarget(); indicatorReports.add(new IndicatorReport(indicator.name(), indicator.description(), annualTarget, currentProgress, currentMonth, currentMonthSummary.year(), currentMonthSummary.aggregatedProgress())); } return new Gson() .toJson(new CategoryReports(reportsCategory.description(), indicatorReports)); } ReportIndicatorListViewController(Context context, AllReports allReports, String category); String get(); void sortMonthlySummaries(List<MonthSummaryDatum> monthSummaryData); void startReportIndicatorDetail(String indicator); }
ReportIndicatorListViewController { public String get() { reportsCategory = ReportsCategory.valueOf(category); reports = allReports.allFor(reportsCategory.indicators()); List<IndicatorReport> indicatorReports = new ArrayList<IndicatorReport>(); for (Report report : reports) { ReportIndicator indicator = report.reportIndicator(); List<MonthSummaryDatum> monthSummaryData = report.monthlySummaries(); if (monthSummaryData.size() == 0) { continue; } sortMonthlySummaries(monthSummaryData); MonthSummaryDatum currentMonthSummary = monthSummaryData.get(0); String currentMonth = today().monthOfYear().getAsString(); String currentProgress = currentMonthSummary.month().equals(currentMonth) ? currentMonthSummary .currentProgress() : "0"; String annualTarget = (isBlank(report.annualTarget())) ? "NA" : report.annualTarget(); indicatorReports.add(new IndicatorReport(indicator.name(), indicator.description(), annualTarget, currentProgress, currentMonth, currentMonthSummary.year(), currentMonthSummary.aggregatedProgress())); } return new Gson() .toJson(new CategoryReports(reportsCategory.description(), indicatorReports)); } ReportIndicatorListViewController(Context context, AllReports allReports, String category); String get(); void sortMonthlySummaries(List<MonthSummaryDatum> monthSummaryData); void startReportIndicatorDetail(String indicator); }
@Test public void shouldUseLatestMonthDataIfCurrentMonthDataNotAvailable() throws Exception { List<MonthSummaryDatum> monthlySummaries = Arrays.asList(new MonthSummaryDatum("6", "2012", "2", "2", Arrays.asList("123", "456")), new MonthSummaryDatum("8", "2012", "2", "4", Arrays.asList("321", "654"))); Report iudReport = new Report("IUD", "40", new Gson().toJson(monthlySummaries)); Mockito.when(allReports.allFor(ReportsCategory.FPS.indicators())).thenReturn(Arrays.asList(iudReport)); String indicatorReports = controller.get(); IndicatorReport iud = new IndicatorReport("IUD", "IUD Adoption", "40", "0", "10", "2012", "4"); String expectedIndicatorReports = new Gson().toJson(new CategoryReports("Family Planning Services", Arrays.asList(iud))); Assert.assertEquals(expectedIndicatorReports, indicatorReports); }
public String get() { reportsCategory = ReportsCategory.valueOf(category); reports = allReports.allFor(reportsCategory.indicators()); List<IndicatorReport> indicatorReports = new ArrayList<IndicatorReport>(); for (Report report : reports) { ReportIndicator indicator = report.reportIndicator(); List<MonthSummaryDatum> monthSummaryData = report.monthlySummaries(); if (monthSummaryData.size() == 0) { continue; } sortMonthlySummaries(monthSummaryData); MonthSummaryDatum currentMonthSummary = monthSummaryData.get(0); String currentMonth = today().monthOfYear().getAsString(); String currentProgress = currentMonthSummary.month().equals(currentMonth) ? currentMonthSummary .currentProgress() : "0"; String annualTarget = (isBlank(report.annualTarget())) ? "NA" : report.annualTarget(); indicatorReports.add(new IndicatorReport(indicator.name(), indicator.description(), annualTarget, currentProgress, currentMonth, currentMonthSummary.year(), currentMonthSummary.aggregatedProgress())); } return new Gson() .toJson(new CategoryReports(reportsCategory.description(), indicatorReports)); }
ReportIndicatorListViewController { public String get() { reportsCategory = ReportsCategory.valueOf(category); reports = allReports.allFor(reportsCategory.indicators()); List<IndicatorReport> indicatorReports = new ArrayList<IndicatorReport>(); for (Report report : reports) { ReportIndicator indicator = report.reportIndicator(); List<MonthSummaryDatum> monthSummaryData = report.monthlySummaries(); if (monthSummaryData.size() == 0) { continue; } sortMonthlySummaries(monthSummaryData); MonthSummaryDatum currentMonthSummary = monthSummaryData.get(0); String currentMonth = today().monthOfYear().getAsString(); String currentProgress = currentMonthSummary.month().equals(currentMonth) ? currentMonthSummary .currentProgress() : "0"; String annualTarget = (isBlank(report.annualTarget())) ? "NA" : report.annualTarget(); indicatorReports.add(new IndicatorReport(indicator.name(), indicator.description(), annualTarget, currentProgress, currentMonth, currentMonthSummary.year(), currentMonthSummary.aggregatedProgress())); } return new Gson() .toJson(new CategoryReports(reportsCategory.description(), indicatorReports)); } }
ReportIndicatorListViewController { public String get() { reportsCategory = ReportsCategory.valueOf(category); reports = allReports.allFor(reportsCategory.indicators()); List<IndicatorReport> indicatorReports = new ArrayList<IndicatorReport>(); for (Report report : reports) { ReportIndicator indicator = report.reportIndicator(); List<MonthSummaryDatum> monthSummaryData = report.monthlySummaries(); if (monthSummaryData.size() == 0) { continue; } sortMonthlySummaries(monthSummaryData); MonthSummaryDatum currentMonthSummary = monthSummaryData.get(0); String currentMonth = today().monthOfYear().getAsString(); String currentProgress = currentMonthSummary.month().equals(currentMonth) ? currentMonthSummary .currentProgress() : "0"; String annualTarget = (isBlank(report.annualTarget())) ? "NA" : report.annualTarget(); indicatorReports.add(new IndicatorReport(indicator.name(), indicator.description(), annualTarget, currentProgress, currentMonth, currentMonthSummary.year(), currentMonthSummary.aggregatedProgress())); } return new Gson() .toJson(new CategoryReports(reportsCategory.description(), indicatorReports)); } ReportIndicatorListViewController(Context context, AllReports allReports, String category); }
ReportIndicatorListViewController { public String get() { reportsCategory = ReportsCategory.valueOf(category); reports = allReports.allFor(reportsCategory.indicators()); List<IndicatorReport> indicatorReports = new ArrayList<IndicatorReport>(); for (Report report : reports) { ReportIndicator indicator = report.reportIndicator(); List<MonthSummaryDatum> monthSummaryData = report.monthlySummaries(); if (monthSummaryData.size() == 0) { continue; } sortMonthlySummaries(monthSummaryData); MonthSummaryDatum currentMonthSummary = monthSummaryData.get(0); String currentMonth = today().monthOfYear().getAsString(); String currentProgress = currentMonthSummary.month().equals(currentMonth) ? currentMonthSummary .currentProgress() : "0"; String annualTarget = (isBlank(report.annualTarget())) ? "NA" : report.annualTarget(); indicatorReports.add(new IndicatorReport(indicator.name(), indicator.description(), annualTarget, currentProgress, currentMonth, currentMonthSummary.year(), currentMonthSummary.aggregatedProgress())); } return new Gson() .toJson(new CategoryReports(reportsCategory.description(), indicatorReports)); } ReportIndicatorListViewController(Context context, AllReports allReports, String category); String get(); void sortMonthlySummaries(List<MonthSummaryDatum> monthSummaryData); void startReportIndicatorDetail(String indicator); }
ReportIndicatorListViewController { public String get() { reportsCategory = ReportsCategory.valueOf(category); reports = allReports.allFor(reportsCategory.indicators()); List<IndicatorReport> indicatorReports = new ArrayList<IndicatorReport>(); for (Report report : reports) { ReportIndicator indicator = report.reportIndicator(); List<MonthSummaryDatum> monthSummaryData = report.monthlySummaries(); if (monthSummaryData.size() == 0) { continue; } sortMonthlySummaries(monthSummaryData); MonthSummaryDatum currentMonthSummary = monthSummaryData.get(0); String currentMonth = today().monthOfYear().getAsString(); String currentProgress = currentMonthSummary.month().equals(currentMonth) ? currentMonthSummary .currentProgress() : "0"; String annualTarget = (isBlank(report.annualTarget())) ? "NA" : report.annualTarget(); indicatorReports.add(new IndicatorReport(indicator.name(), indicator.description(), annualTarget, currentProgress, currentMonth, currentMonthSummary.year(), currentMonthSummary.aggregatedProgress())); } return new Gson() .toJson(new CategoryReports(reportsCategory.description(), indicatorReports)); } ReportIndicatorListViewController(Context context, AllReports allReports, String category); String get(); void sortMonthlySummaries(List<MonthSummaryDatum> monthSummaryData); void startReportIndicatorDetail(String indicator); }
@Test public void shouldShowNAIfAnnualTargetNotAvailable() throws Exception { List<MonthSummaryDatum> monthlySummaries = Arrays.asList(new MonthSummaryDatum("6", "2012", "2", "2", Arrays.asList("123", "456")), new MonthSummaryDatum("8", "2012", "2", "4", Arrays.asList("321", "654"))); Report iudReport = new Report("IUD", null, new Gson().toJson(monthlySummaries)); Mockito.when(allReports.allFor(ReportsCategory.FPS.indicators())).thenReturn(Arrays.asList(iudReport)); String indicatorReports = controller.get(); IndicatorReport iud = new IndicatorReport("IUD", "IUD Adoption", "NA", "0", "10", "2012", "4"); String expectedIndicatorReports = new Gson().toJson(new CategoryReports("Family Planning Services", Arrays.asList(iud))); Assert.assertEquals(expectedIndicatorReports, indicatorReports); }
public String get() { reportsCategory = ReportsCategory.valueOf(category); reports = allReports.allFor(reportsCategory.indicators()); List<IndicatorReport> indicatorReports = new ArrayList<IndicatorReport>(); for (Report report : reports) { ReportIndicator indicator = report.reportIndicator(); List<MonthSummaryDatum> monthSummaryData = report.monthlySummaries(); if (monthSummaryData.size() == 0) { continue; } sortMonthlySummaries(monthSummaryData); MonthSummaryDatum currentMonthSummary = monthSummaryData.get(0); String currentMonth = today().monthOfYear().getAsString(); String currentProgress = currentMonthSummary.month().equals(currentMonth) ? currentMonthSummary .currentProgress() : "0"; String annualTarget = (isBlank(report.annualTarget())) ? "NA" : report.annualTarget(); indicatorReports.add(new IndicatorReport(indicator.name(), indicator.description(), annualTarget, currentProgress, currentMonth, currentMonthSummary.year(), currentMonthSummary.aggregatedProgress())); } return new Gson() .toJson(new CategoryReports(reportsCategory.description(), indicatorReports)); }
ReportIndicatorListViewController { public String get() { reportsCategory = ReportsCategory.valueOf(category); reports = allReports.allFor(reportsCategory.indicators()); List<IndicatorReport> indicatorReports = new ArrayList<IndicatorReport>(); for (Report report : reports) { ReportIndicator indicator = report.reportIndicator(); List<MonthSummaryDatum> monthSummaryData = report.monthlySummaries(); if (monthSummaryData.size() == 0) { continue; } sortMonthlySummaries(monthSummaryData); MonthSummaryDatum currentMonthSummary = monthSummaryData.get(0); String currentMonth = today().monthOfYear().getAsString(); String currentProgress = currentMonthSummary.month().equals(currentMonth) ? currentMonthSummary .currentProgress() : "0"; String annualTarget = (isBlank(report.annualTarget())) ? "NA" : report.annualTarget(); indicatorReports.add(new IndicatorReport(indicator.name(), indicator.description(), annualTarget, currentProgress, currentMonth, currentMonthSummary.year(), currentMonthSummary.aggregatedProgress())); } return new Gson() .toJson(new CategoryReports(reportsCategory.description(), indicatorReports)); } }
ReportIndicatorListViewController { public String get() { reportsCategory = ReportsCategory.valueOf(category); reports = allReports.allFor(reportsCategory.indicators()); List<IndicatorReport> indicatorReports = new ArrayList<IndicatorReport>(); for (Report report : reports) { ReportIndicator indicator = report.reportIndicator(); List<MonthSummaryDatum> monthSummaryData = report.monthlySummaries(); if (monthSummaryData.size() == 0) { continue; } sortMonthlySummaries(monthSummaryData); MonthSummaryDatum currentMonthSummary = monthSummaryData.get(0); String currentMonth = today().monthOfYear().getAsString(); String currentProgress = currentMonthSummary.month().equals(currentMonth) ? currentMonthSummary .currentProgress() : "0"; String annualTarget = (isBlank(report.annualTarget())) ? "NA" : report.annualTarget(); indicatorReports.add(new IndicatorReport(indicator.name(), indicator.description(), annualTarget, currentProgress, currentMonth, currentMonthSummary.year(), currentMonthSummary.aggregatedProgress())); } return new Gson() .toJson(new CategoryReports(reportsCategory.description(), indicatorReports)); } ReportIndicatorListViewController(Context context, AllReports allReports, String category); }
ReportIndicatorListViewController { public String get() { reportsCategory = ReportsCategory.valueOf(category); reports = allReports.allFor(reportsCategory.indicators()); List<IndicatorReport> indicatorReports = new ArrayList<IndicatorReport>(); for (Report report : reports) { ReportIndicator indicator = report.reportIndicator(); List<MonthSummaryDatum> monthSummaryData = report.monthlySummaries(); if (monthSummaryData.size() == 0) { continue; } sortMonthlySummaries(monthSummaryData); MonthSummaryDatum currentMonthSummary = monthSummaryData.get(0); String currentMonth = today().monthOfYear().getAsString(); String currentProgress = currentMonthSummary.month().equals(currentMonth) ? currentMonthSummary .currentProgress() : "0"; String annualTarget = (isBlank(report.annualTarget())) ? "NA" : report.annualTarget(); indicatorReports.add(new IndicatorReport(indicator.name(), indicator.description(), annualTarget, currentProgress, currentMonth, currentMonthSummary.year(), currentMonthSummary.aggregatedProgress())); } return new Gson() .toJson(new CategoryReports(reportsCategory.description(), indicatorReports)); } ReportIndicatorListViewController(Context context, AllReports allReports, String category); String get(); void sortMonthlySummaries(List<MonthSummaryDatum> monthSummaryData); void startReportIndicatorDetail(String indicator); }
ReportIndicatorListViewController { public String get() { reportsCategory = ReportsCategory.valueOf(category); reports = allReports.allFor(reportsCategory.indicators()); List<IndicatorReport> indicatorReports = new ArrayList<IndicatorReport>(); for (Report report : reports) { ReportIndicator indicator = report.reportIndicator(); List<MonthSummaryDatum> monthSummaryData = report.monthlySummaries(); if (monthSummaryData.size() == 0) { continue; } sortMonthlySummaries(monthSummaryData); MonthSummaryDatum currentMonthSummary = monthSummaryData.get(0); String currentMonth = today().monthOfYear().getAsString(); String currentProgress = currentMonthSummary.month().equals(currentMonth) ? currentMonthSummary .currentProgress() : "0"; String annualTarget = (isBlank(report.annualTarget())) ? "NA" : report.annualTarget(); indicatorReports.add(new IndicatorReport(indicator.name(), indicator.description(), annualTarget, currentProgress, currentMonth, currentMonthSummary.year(), currentMonthSummary.aggregatedProgress())); } return new Gson() .toJson(new CategoryReports(reportsCategory.description(), indicatorReports)); } ReportIndicatorListViewController(Context context, AllReports allReports, String category); String get(); void sortMonthlySummaries(List<MonthSummaryDatum> monthSummaryData); void startReportIndicatorDetail(String indicator); }
@Test public void shouldGetANCDetailsAsJSON() { TimelineEvent pregnancyEvent = TimelineEvent.forStartOfPregnancy(caseId, "2011-10-21", "2011-10-21"); TimelineEvent ancEvent = TimelineEvent.forANCCareProvided(caseId, "2", "2011-12-22", new HashMap<String, String>()); TimelineEvent eventVeryCloseToCurrentDate = TimelineEvent.forANCCareProvided(caseId, "2", "2012-07-29", new HashMap<String, String>()); HashMap<String, String> details = new HashMap<String, String>(); details.put("ashaName", "Shiwani"); Mockito.when(allBeneficiaries.findMotherWithOpenStatus(caseId)).thenReturn(new Mother(caseId, "EC CASE 1", "TC 1", "2011-10-22").withDetails(details)); Map<String, String> ecDetails = EasyMap.mapOf("caste", "st"); ecDetails.put("economicStatus", "bpl"); Mockito.when(allEligibleCouples.findByCaseID("EC CASE 1")).thenReturn(new EligibleCouple("EC CASE 1", "Woman 1", "Husband 1", "EC Number 1", "Village 1", "Subcenter 1", ecDetails).withPhotoPath("photo path")); Mockito.when(allTimelineEvents.forCase(caseId)).thenReturn(Arrays.asList(pregnancyEvent, ancEvent, eventVeryCloseToCurrentDate)); ANCDetail expectedDetail = new ANCDetail(caseId, "TC 1", new CoupleDetails("Woman 1", "Husband 1", "EC Number 1", false) .withCaste("st") .withEconomicStatus("bpl") .withPhotoPath("photo path"), new LocationDetails("Village 1", "Subcenter 1"), new PregnancyDetails("9", "2012-07-28", 4)) .addTimelineEvents(Arrays.asList(eventFor(eventVeryCloseToCurrentDate, "29-07-2012"), eventFor(ancEvent, "22-12-2011"), eventFor(pregnancyEvent, "21-10-2011"))) .addExtraDetails(details); String actualJson = controller.get(); ANCDetail actualDetail = new Gson().fromJson(actualJson, ANCDetail.class); Assert.assertEquals(expectedDetail, actualDetail); }
@JavascriptInterface public String get() { Mother mother = allBeneficiaries.findMotherWithOpenStatus(caseId); EligibleCouple couple = allEligibleCouples.findByCaseID(mother.ecCaseId()); LocalDate lmp = LocalDate.parse(mother.referenceDate()); String edd = lmp.plusWeeks(DURATION_OF_PREGNANCY_IN_WEEKS).toString(); Months numberOfMonthsPregnant = Months.monthsBetween(lmp, DateUtil.today()); String photoPath = isBlank(couple.photoPath()) ? DEFAULT_WOMAN_IMAGE_PLACEHOLDER_PATH : couple.photoPath(); int months = numberOfMonthsPregnant.getMonths(); LocalDate eddDate = LocalDate.parse(edd); Days daysPastEdd = Days.daysBetween(eddDate, DateUtil.today()); ANCDetail detail = new ANCDetail(caseId, mother.thayiCardNumber(), new CoupleDetails(couple.wifeName(), couple.husbandName(), couple.ecNumber(), couple.isOutOfArea()).withCaste(couple.details().get("caste")) .withEconomicStatus(couple.details().get("economicStatus")) .withPhotoPath(photoPath), new LocationDetails(couple.village(), couple.subCenter()), new PregnancyDetails(String.valueOf(months), edd, daysPastEdd.getDays())) .addTimelineEvents(getEvents()).addExtraDetails(mother.details()); return new Gson().toJson(detail); }
ANCDetailController { @JavascriptInterface public String get() { Mother mother = allBeneficiaries.findMotherWithOpenStatus(caseId); EligibleCouple couple = allEligibleCouples.findByCaseID(mother.ecCaseId()); LocalDate lmp = LocalDate.parse(mother.referenceDate()); String edd = lmp.plusWeeks(DURATION_OF_PREGNANCY_IN_WEEKS).toString(); Months numberOfMonthsPregnant = Months.monthsBetween(lmp, DateUtil.today()); String photoPath = isBlank(couple.photoPath()) ? DEFAULT_WOMAN_IMAGE_PLACEHOLDER_PATH : couple.photoPath(); int months = numberOfMonthsPregnant.getMonths(); LocalDate eddDate = LocalDate.parse(edd); Days daysPastEdd = Days.daysBetween(eddDate, DateUtil.today()); ANCDetail detail = new ANCDetail(caseId, mother.thayiCardNumber(), new CoupleDetails(couple.wifeName(), couple.husbandName(), couple.ecNumber(), couple.isOutOfArea()).withCaste(couple.details().get("caste")) .withEconomicStatus(couple.details().get("economicStatus")) .withPhotoPath(photoPath), new LocationDetails(couple.village(), couple.subCenter()), new PregnancyDetails(String.valueOf(months), edd, daysPastEdd.getDays())) .addTimelineEvents(getEvents()).addExtraDetails(mother.details()); return new Gson().toJson(detail); } }
ANCDetailController { @JavascriptInterface public String get() { Mother mother = allBeneficiaries.findMotherWithOpenStatus(caseId); EligibleCouple couple = allEligibleCouples.findByCaseID(mother.ecCaseId()); LocalDate lmp = LocalDate.parse(mother.referenceDate()); String edd = lmp.plusWeeks(DURATION_OF_PREGNANCY_IN_WEEKS).toString(); Months numberOfMonthsPregnant = Months.monthsBetween(lmp, DateUtil.today()); String photoPath = isBlank(couple.photoPath()) ? DEFAULT_WOMAN_IMAGE_PLACEHOLDER_PATH : couple.photoPath(); int months = numberOfMonthsPregnant.getMonths(); LocalDate eddDate = LocalDate.parse(edd); Days daysPastEdd = Days.daysBetween(eddDate, DateUtil.today()); ANCDetail detail = new ANCDetail(caseId, mother.thayiCardNumber(), new CoupleDetails(couple.wifeName(), couple.husbandName(), couple.ecNumber(), couple.isOutOfArea()).withCaste(couple.details().get("caste")) .withEconomicStatus(couple.details().get("economicStatus")) .withPhotoPath(photoPath), new LocationDetails(couple.village(), couple.subCenter()), new PregnancyDetails(String.valueOf(months), edd, daysPastEdd.getDays())) .addTimelineEvents(getEvents()).addExtraDetails(mother.details()); return new Gson().toJson(detail); } ANCDetailController(Context context, String caseId, AllEligibleCouples allEligibleCouples, AllBeneficiaries allBeneficiaries, AllTimelineEvents allTimelineEvents); }
ANCDetailController { @JavascriptInterface public String get() { Mother mother = allBeneficiaries.findMotherWithOpenStatus(caseId); EligibleCouple couple = allEligibleCouples.findByCaseID(mother.ecCaseId()); LocalDate lmp = LocalDate.parse(mother.referenceDate()); String edd = lmp.plusWeeks(DURATION_OF_PREGNANCY_IN_WEEKS).toString(); Months numberOfMonthsPregnant = Months.monthsBetween(lmp, DateUtil.today()); String photoPath = isBlank(couple.photoPath()) ? DEFAULT_WOMAN_IMAGE_PLACEHOLDER_PATH : couple.photoPath(); int months = numberOfMonthsPregnant.getMonths(); LocalDate eddDate = LocalDate.parse(edd); Days daysPastEdd = Days.daysBetween(eddDate, DateUtil.today()); ANCDetail detail = new ANCDetail(caseId, mother.thayiCardNumber(), new CoupleDetails(couple.wifeName(), couple.husbandName(), couple.ecNumber(), couple.isOutOfArea()).withCaste(couple.details().get("caste")) .withEconomicStatus(couple.details().get("economicStatus")) .withPhotoPath(photoPath), new LocationDetails(couple.village(), couple.subCenter()), new PregnancyDetails(String.valueOf(months), edd, daysPastEdd.getDays())) .addTimelineEvents(getEvents()).addExtraDetails(mother.details()); return new Gson().toJson(detail); } ANCDetailController(Context context, String caseId, AllEligibleCouples allEligibleCouples, AllBeneficiaries allBeneficiaries, AllTimelineEvents allTimelineEvents); @JavascriptInterface String get(); @JavascriptInterface void takePhoto(); }
ANCDetailController { @JavascriptInterface public String get() { Mother mother = allBeneficiaries.findMotherWithOpenStatus(caseId); EligibleCouple couple = allEligibleCouples.findByCaseID(mother.ecCaseId()); LocalDate lmp = LocalDate.parse(mother.referenceDate()); String edd = lmp.plusWeeks(DURATION_OF_PREGNANCY_IN_WEEKS).toString(); Months numberOfMonthsPregnant = Months.monthsBetween(lmp, DateUtil.today()); String photoPath = isBlank(couple.photoPath()) ? DEFAULT_WOMAN_IMAGE_PLACEHOLDER_PATH : couple.photoPath(); int months = numberOfMonthsPregnant.getMonths(); LocalDate eddDate = LocalDate.parse(edd); Days daysPastEdd = Days.daysBetween(eddDate, DateUtil.today()); ANCDetail detail = new ANCDetail(caseId, mother.thayiCardNumber(), new CoupleDetails(couple.wifeName(), couple.husbandName(), couple.ecNumber(), couple.isOutOfArea()).withCaste(couple.details().get("caste")) .withEconomicStatus(couple.details().get("economicStatus")) .withPhotoPath(photoPath), new LocationDetails(couple.village(), couple.subCenter()), new PregnancyDetails(String.valueOf(months), edd, daysPastEdd.getDays())) .addTimelineEvents(getEvents()).addExtraDetails(mother.details()); return new Gson().toJson(detail); } ANCDetailController(Context context, String caseId, AllEligibleCouples allEligibleCouples, AllBeneficiaries allBeneficiaries, AllTimelineEvents allTimelineEvents); @JavascriptInterface String get(); @JavascriptInterface void takePhoto(); static final int DURATION_OF_PREGNANCY_IN_WEEKS; }
@Test public void shouldSortPNCsByWifeName() throws Exception { Map<String, String> details = EasyMap.mapOf("edd", "Tue, 25 Feb 2014 00:00:00 GMT"); EligibleCouple ec2 = new EligibleCouple("EC Case 2", "Woman B", "Husband B", "EC Number 2", "kavalu_hosur", "Bherya SC", emptyMap); EligibleCouple ec3 = new EligibleCouple("EC Case 3", "Woman C", "Husband C", "EC Number 3", "Bherya", "Bherya SC", emptyMap); EligibleCouple ec1 = new EligibleCouple("EC Case 1", "Woman A", "Husband A", "EC Number 1", "Bherya", null, emptyMap); Mother m1 = new Mother("Entity X", "EC Case 2", "thayi 1", "2013-05-25").withDetails(details); Mother m2 = new Mother("Entity Y", "EC Case 3", "thayi 2", "2013-05-25").withDetails(details); Mother m3 = new Mother("Entity Z", "EC Case 1", "thayi 3", "2013-05-25").withDetails(details); PNCClient expectedClient1 = createPNCClient("Entity Z", "Woman A", "Bherya", "thayi 3", "2013-05-25").withECNumber("EC Number 1").withHusbandName("Husband A").withChildren(Collections.EMPTY_LIST).withEntityIdToSavePhoto("EC Case 1"); PNCClient expectedClient2 = createPNCClient("Entity X", "Woman B", "kavalu_hosur", "thayi 1", "2013-05-25").withECNumber("EC Number 2").withHusbandName("Husband B").withChildren(Collections.EMPTY_LIST).withEntityIdToSavePhoto("EC Case 2"); PNCClient expectedClient3 = createPNCClient("Entity Y", "Woman C", "Bherya", "thayi 2", "2013-05-25").withECNumber("EC Number 3").withHusbandName("Husband C").withChildren(Collections.EMPTY_LIST).withEntityIdToSavePhoto("EC Case 3"); Mockito.when(allBeneficiaries.allPNCsWithEC()).thenReturn(Arrays.asList(Pair.of(m1, ec2), Pair.of(m2, ec3), Pair.of(m3, ec1))); Mockito.when(preProcessor.preProcess(Mockito.any(PNCClient.class))).thenReturn(expectedClient1, expectedClient2, expectedClient3); PNCClients clients = controller.getClients(); Assert.assertEquals(expectedClient1.wifeName(), clients.get(0).wifeName()); Assert.assertEquals(expectedClient2.wifeName(), clients.get(1).wifeName()); Assert.assertEquals(expectedClient3.wifeName(), clients.get(2).wifeName()); }
public PNCClients getClients() { return pncClientsCache.get(PNC_CLIENTS_LIST, new CacheableData<PNCClients>() { @Override public PNCClients fetch() { PNCClients pncClients = new PNCClients(); List<Pair<Mother, EligibleCouple>> pncsWithEcs = allBeneficiaries.allPNCsWithEC(); for (Pair<Mother, EligibleCouple> pncWithEc : pncsWithEcs) { Mother pnc = pncWithEc.getLeft(); EligibleCouple ec = pncWithEc.getRight(); String photoPath = isBlank(ec.photoPath()) ? DEFAULT_WOMAN_IMAGE_PLACEHOLDER_PATH : ec.photoPath(); List<ServiceProvidedDTO> servicesProvided = getServicesProvided(pnc.caseId()); List<AlertDTO> alerts = getAlerts(pnc.caseId()); PNCClient client = new PNCClient(pnc.caseId(), ec.village(), ec.wifeName(), pnc.thayiCardNumber(), pnc.referenceDate()) .withHusbandName(ec.husbandName()).withAge(ec.age()) .withWomanDOB(ec.getDetail(WOMAN_DOB)).withECNumber(ec.ecNumber()) .withIsHighPriority(ec.isHighPriority()) .withIsHighRisk(pnc.isHighRisk()) .withEconomicStatus(ec.getDetail(ECONOMIC_STATUS)) .withIsOutOfArea(ec.isOutOfArea()).withCaste(ec.getDetail(CASTE)) .withPhotoPath(photoPath).withFPMethod(ec.getDetail(CURRENT_FP_METHOD)) .withIUDPlace(ec.getDetail(IUD_PLACE)) .withIUDPerson(ec.getDetail(IUD_PERSON)) .withNumberOfCondomsSupplied(ec.getDetail(NUMBER_OF_CONDOMS_SUPPLIED)) .withFamilyPlanningMethodChangeDate( ec.getDetail(FAMILY_PLANNING_METHOD_CHANGE_DATE)) .withNumberOfOCPDelivered(ec.getDetail(NUMBER_OF_OCP_DELIVERED)) .withNumberOfCentchromanPillsDelivered( ec.getDetail(NUMBER_OF_CENTCHROMAN_PILLS_DELIVERED)) .withDeliveryPlace(pnc.getDetail(DELIVERY_PLACE)) .withDeliveryType(pnc.getDetail(DELIVERY_TYPE)) .withDeliveryComplications(pnc.getDetail(DELIVERY_COMPLICATIONS)) .withPNCComplications(pnc.getDetail(IMMEDIATE_REFERRAL_REASON)) .withOtherDeliveryComplications( pnc.getDetail(OTHER_DELIVERY_COMPLICATIONS)) .withEntityIdToSavePhoto(ec.caseId()).withAlerts(alerts) .withServicesProvided(servicesProvided).withChildren(findChildren(pnc)) .withPreProcess(); pncClients.add(pncClientPreProcessor.preProcess(client)); } sortByName(pncClients); return pncClients; } }); }
PNCSmartRegisterController { public PNCClients getClients() { return pncClientsCache.get(PNC_CLIENTS_LIST, new CacheableData<PNCClients>() { @Override public PNCClients fetch() { PNCClients pncClients = new PNCClients(); List<Pair<Mother, EligibleCouple>> pncsWithEcs = allBeneficiaries.allPNCsWithEC(); for (Pair<Mother, EligibleCouple> pncWithEc : pncsWithEcs) { Mother pnc = pncWithEc.getLeft(); EligibleCouple ec = pncWithEc.getRight(); String photoPath = isBlank(ec.photoPath()) ? DEFAULT_WOMAN_IMAGE_PLACEHOLDER_PATH : ec.photoPath(); List<ServiceProvidedDTO> servicesProvided = getServicesProvided(pnc.caseId()); List<AlertDTO> alerts = getAlerts(pnc.caseId()); PNCClient client = new PNCClient(pnc.caseId(), ec.village(), ec.wifeName(), pnc.thayiCardNumber(), pnc.referenceDate()) .withHusbandName(ec.husbandName()).withAge(ec.age()) .withWomanDOB(ec.getDetail(WOMAN_DOB)).withECNumber(ec.ecNumber()) .withIsHighPriority(ec.isHighPriority()) .withIsHighRisk(pnc.isHighRisk()) .withEconomicStatus(ec.getDetail(ECONOMIC_STATUS)) .withIsOutOfArea(ec.isOutOfArea()).withCaste(ec.getDetail(CASTE)) .withPhotoPath(photoPath).withFPMethod(ec.getDetail(CURRENT_FP_METHOD)) .withIUDPlace(ec.getDetail(IUD_PLACE)) .withIUDPerson(ec.getDetail(IUD_PERSON)) .withNumberOfCondomsSupplied(ec.getDetail(NUMBER_OF_CONDOMS_SUPPLIED)) .withFamilyPlanningMethodChangeDate( ec.getDetail(FAMILY_PLANNING_METHOD_CHANGE_DATE)) .withNumberOfOCPDelivered(ec.getDetail(NUMBER_OF_OCP_DELIVERED)) .withNumberOfCentchromanPillsDelivered( ec.getDetail(NUMBER_OF_CENTCHROMAN_PILLS_DELIVERED)) .withDeliveryPlace(pnc.getDetail(DELIVERY_PLACE)) .withDeliveryType(pnc.getDetail(DELIVERY_TYPE)) .withDeliveryComplications(pnc.getDetail(DELIVERY_COMPLICATIONS)) .withPNCComplications(pnc.getDetail(IMMEDIATE_REFERRAL_REASON)) .withOtherDeliveryComplications( pnc.getDetail(OTHER_DELIVERY_COMPLICATIONS)) .withEntityIdToSavePhoto(ec.caseId()).withAlerts(alerts) .withServicesProvided(servicesProvided).withChildren(findChildren(pnc)) .withPreProcess(); pncClients.add(pncClientPreProcessor.preProcess(client)); } sortByName(pncClients); return pncClients; } }); } }
PNCSmartRegisterController { public PNCClients getClients() { return pncClientsCache.get(PNC_CLIENTS_LIST, new CacheableData<PNCClients>() { @Override public PNCClients fetch() { PNCClients pncClients = new PNCClients(); List<Pair<Mother, EligibleCouple>> pncsWithEcs = allBeneficiaries.allPNCsWithEC(); for (Pair<Mother, EligibleCouple> pncWithEc : pncsWithEcs) { Mother pnc = pncWithEc.getLeft(); EligibleCouple ec = pncWithEc.getRight(); String photoPath = isBlank(ec.photoPath()) ? DEFAULT_WOMAN_IMAGE_PLACEHOLDER_PATH : ec.photoPath(); List<ServiceProvidedDTO> servicesProvided = getServicesProvided(pnc.caseId()); List<AlertDTO> alerts = getAlerts(pnc.caseId()); PNCClient client = new PNCClient(pnc.caseId(), ec.village(), ec.wifeName(), pnc.thayiCardNumber(), pnc.referenceDate()) .withHusbandName(ec.husbandName()).withAge(ec.age()) .withWomanDOB(ec.getDetail(WOMAN_DOB)).withECNumber(ec.ecNumber()) .withIsHighPriority(ec.isHighPriority()) .withIsHighRisk(pnc.isHighRisk()) .withEconomicStatus(ec.getDetail(ECONOMIC_STATUS)) .withIsOutOfArea(ec.isOutOfArea()).withCaste(ec.getDetail(CASTE)) .withPhotoPath(photoPath).withFPMethod(ec.getDetail(CURRENT_FP_METHOD)) .withIUDPlace(ec.getDetail(IUD_PLACE)) .withIUDPerson(ec.getDetail(IUD_PERSON)) .withNumberOfCondomsSupplied(ec.getDetail(NUMBER_OF_CONDOMS_SUPPLIED)) .withFamilyPlanningMethodChangeDate( ec.getDetail(FAMILY_PLANNING_METHOD_CHANGE_DATE)) .withNumberOfOCPDelivered(ec.getDetail(NUMBER_OF_OCP_DELIVERED)) .withNumberOfCentchromanPillsDelivered( ec.getDetail(NUMBER_OF_CENTCHROMAN_PILLS_DELIVERED)) .withDeliveryPlace(pnc.getDetail(DELIVERY_PLACE)) .withDeliveryType(pnc.getDetail(DELIVERY_TYPE)) .withDeliveryComplications(pnc.getDetail(DELIVERY_COMPLICATIONS)) .withPNCComplications(pnc.getDetail(IMMEDIATE_REFERRAL_REASON)) .withOtherDeliveryComplications( pnc.getDetail(OTHER_DELIVERY_COMPLICATIONS)) .withEntityIdToSavePhoto(ec.caseId()).withAlerts(alerts) .withServicesProvided(servicesProvided).withChildren(findChildren(pnc)) .withPreProcess(); pncClients.add(pncClientPreProcessor.preProcess(client)); } sortByName(pncClients); return pncClients; } }); } PNCSmartRegisterController(ServiceProvidedService serviceProvidedService, AlertService alertService, AllEligibleCouples allEligibleCouples, AllBeneficiaries allBeneficiaries, Cache<String> cache, Cache<PNCClients> pncClientsCache); PNCSmartRegisterController(ServiceProvidedService serviceProvidedService, AlertService alertService, AllEligibleCouples allEligibleCouples, AllBeneficiaries allBeneficiaries, Cache<String> cache, Cache<PNCClients> pncClientsCache, PNCClientPreProcessor pncClientPreProcessor); }
PNCSmartRegisterController { public PNCClients getClients() { return pncClientsCache.get(PNC_CLIENTS_LIST, new CacheableData<PNCClients>() { @Override public PNCClients fetch() { PNCClients pncClients = new PNCClients(); List<Pair<Mother, EligibleCouple>> pncsWithEcs = allBeneficiaries.allPNCsWithEC(); for (Pair<Mother, EligibleCouple> pncWithEc : pncsWithEcs) { Mother pnc = pncWithEc.getLeft(); EligibleCouple ec = pncWithEc.getRight(); String photoPath = isBlank(ec.photoPath()) ? DEFAULT_WOMAN_IMAGE_PLACEHOLDER_PATH : ec.photoPath(); List<ServiceProvidedDTO> servicesProvided = getServicesProvided(pnc.caseId()); List<AlertDTO> alerts = getAlerts(pnc.caseId()); PNCClient client = new PNCClient(pnc.caseId(), ec.village(), ec.wifeName(), pnc.thayiCardNumber(), pnc.referenceDate()) .withHusbandName(ec.husbandName()).withAge(ec.age()) .withWomanDOB(ec.getDetail(WOMAN_DOB)).withECNumber(ec.ecNumber()) .withIsHighPriority(ec.isHighPriority()) .withIsHighRisk(pnc.isHighRisk()) .withEconomicStatus(ec.getDetail(ECONOMIC_STATUS)) .withIsOutOfArea(ec.isOutOfArea()).withCaste(ec.getDetail(CASTE)) .withPhotoPath(photoPath).withFPMethod(ec.getDetail(CURRENT_FP_METHOD)) .withIUDPlace(ec.getDetail(IUD_PLACE)) .withIUDPerson(ec.getDetail(IUD_PERSON)) .withNumberOfCondomsSupplied(ec.getDetail(NUMBER_OF_CONDOMS_SUPPLIED)) .withFamilyPlanningMethodChangeDate( ec.getDetail(FAMILY_PLANNING_METHOD_CHANGE_DATE)) .withNumberOfOCPDelivered(ec.getDetail(NUMBER_OF_OCP_DELIVERED)) .withNumberOfCentchromanPillsDelivered( ec.getDetail(NUMBER_OF_CENTCHROMAN_PILLS_DELIVERED)) .withDeliveryPlace(pnc.getDetail(DELIVERY_PLACE)) .withDeliveryType(pnc.getDetail(DELIVERY_TYPE)) .withDeliveryComplications(pnc.getDetail(DELIVERY_COMPLICATIONS)) .withPNCComplications(pnc.getDetail(IMMEDIATE_REFERRAL_REASON)) .withOtherDeliveryComplications( pnc.getDetail(OTHER_DELIVERY_COMPLICATIONS)) .withEntityIdToSavePhoto(ec.caseId()).withAlerts(alerts) .withServicesProvided(servicesProvided).withChildren(findChildren(pnc)) .withPreProcess(); pncClients.add(pncClientPreProcessor.preProcess(client)); } sortByName(pncClients); return pncClients; } }); } PNCSmartRegisterController(ServiceProvidedService serviceProvidedService, AlertService alertService, AllEligibleCouples allEligibleCouples, AllBeneficiaries allBeneficiaries, Cache<String> cache, Cache<PNCClients> pncClientsCache); PNCSmartRegisterController(ServiceProvidedService serviceProvidedService, AlertService alertService, AllEligibleCouples allEligibleCouples, AllBeneficiaries allBeneficiaries, Cache<String> cache, Cache<PNCClients> pncClientsCache, PNCClientPreProcessor pncClientPreProcessor); PNCClients getClients(); String villages(); }
PNCSmartRegisterController { public PNCClients getClients() { return pncClientsCache.get(PNC_CLIENTS_LIST, new CacheableData<PNCClients>() { @Override public PNCClients fetch() { PNCClients pncClients = new PNCClients(); List<Pair<Mother, EligibleCouple>> pncsWithEcs = allBeneficiaries.allPNCsWithEC(); for (Pair<Mother, EligibleCouple> pncWithEc : pncsWithEcs) { Mother pnc = pncWithEc.getLeft(); EligibleCouple ec = pncWithEc.getRight(); String photoPath = isBlank(ec.photoPath()) ? DEFAULT_WOMAN_IMAGE_PLACEHOLDER_PATH : ec.photoPath(); List<ServiceProvidedDTO> servicesProvided = getServicesProvided(pnc.caseId()); List<AlertDTO> alerts = getAlerts(pnc.caseId()); PNCClient client = new PNCClient(pnc.caseId(), ec.village(), ec.wifeName(), pnc.thayiCardNumber(), pnc.referenceDate()) .withHusbandName(ec.husbandName()).withAge(ec.age()) .withWomanDOB(ec.getDetail(WOMAN_DOB)).withECNumber(ec.ecNumber()) .withIsHighPriority(ec.isHighPriority()) .withIsHighRisk(pnc.isHighRisk()) .withEconomicStatus(ec.getDetail(ECONOMIC_STATUS)) .withIsOutOfArea(ec.isOutOfArea()).withCaste(ec.getDetail(CASTE)) .withPhotoPath(photoPath).withFPMethod(ec.getDetail(CURRENT_FP_METHOD)) .withIUDPlace(ec.getDetail(IUD_PLACE)) .withIUDPerson(ec.getDetail(IUD_PERSON)) .withNumberOfCondomsSupplied(ec.getDetail(NUMBER_OF_CONDOMS_SUPPLIED)) .withFamilyPlanningMethodChangeDate( ec.getDetail(FAMILY_PLANNING_METHOD_CHANGE_DATE)) .withNumberOfOCPDelivered(ec.getDetail(NUMBER_OF_OCP_DELIVERED)) .withNumberOfCentchromanPillsDelivered( ec.getDetail(NUMBER_OF_CENTCHROMAN_PILLS_DELIVERED)) .withDeliveryPlace(pnc.getDetail(DELIVERY_PLACE)) .withDeliveryType(pnc.getDetail(DELIVERY_TYPE)) .withDeliveryComplications(pnc.getDetail(DELIVERY_COMPLICATIONS)) .withPNCComplications(pnc.getDetail(IMMEDIATE_REFERRAL_REASON)) .withOtherDeliveryComplications( pnc.getDetail(OTHER_DELIVERY_COMPLICATIONS)) .withEntityIdToSavePhoto(ec.caseId()).withAlerts(alerts) .withServicesProvided(servicesProvided).withChildren(findChildren(pnc)) .withPreProcess(); pncClients.add(pncClientPreProcessor.preProcess(client)); } sortByName(pncClients); return pncClients; } }); } PNCSmartRegisterController(ServiceProvidedService serviceProvidedService, AlertService alertService, AllEligibleCouples allEligibleCouples, AllBeneficiaries allBeneficiaries, Cache<String> cache, Cache<PNCClients> pncClientsCache); PNCSmartRegisterController(ServiceProvidedService serviceProvidedService, AlertService alertService, AllEligibleCouples allEligibleCouples, AllBeneficiaries allBeneficiaries, Cache<String> cache, Cache<PNCClients> pncClientsCache, PNCClientPreProcessor pncClientPreProcessor); PNCClients getClients(); String villages(); }
@Test public void shouldMapPNCToPNCClient() throws Exception { Map<String, String> ecDetails = EasyMap.create("wifeAge", "22") .put("currentMethod", "condom") .put("familyPlanningMethodChangeDate", "2013-01-02") .put("isHighPriority", Boolean.toString(false)) .put("deliveryDate", "2011-05-05") .put("womanDOB", "2011-05-05") .put("caste", "sc") .put("economicStatus", "bpl") .put("iudPlace", "iudPlace") .put("iudPerson", "iudPerson") .put("numberOfCondomsSupplied", "20") .put("numberOfCentchromanPillsDelivered", "10") .put("numberOfOCPDelivered", "5") .map(); Map<String, String> motherDetails = EasyMap.create("deliveryPlace", "PHC") .put("deliveryType", "live_birth") .put("deliveryComplications", "Headache") .put("otherDeliveryComplications", "Vomiting") .map(); EligibleCouple eligibleCouple = new EligibleCouple("entity id 1", "Woman A", "Husband A", "EC Number 1", "Bherya", null, ecDetails).asOutOfArea(); Mother mother = new Mother("Entity X", "entity id 1", "thayi 1", "2013-05-25").withDetails(motherDetails); Mockito.when(allBeneficiaries.allPNCsWithEC()).thenReturn(Arrays.asList(Pair.of(mother, eligibleCouple))); Mockito.when(allBeneficiaries.findAllChildrenByMotherId("Entity X")).thenReturn(Arrays.asList(new Child("child id 1", "Entity X", "male", EasyMap.mapOf("weight", "2.4")), new Child("child id 2", "Entity X", "female", EasyMap.mapOf("weight", "2.5")))); PNCClient expectedPNCClient = new PNCClient("Entity X", "Bherya", "Woman A", "thayi 1", "2013-05-25") .withECNumber("EC Number 1") .withIsHighPriority(false) .withAge("22") .withWomanDOB("2011-05-05") .withEconomicStatus("bpl") .withIUDPerson("iudPerson") .withIUDPlace("iudPlace") .withHusbandName("Husband A") .withIsOutOfArea(true) .withIsHighRisk(false) .withCaste("sc") .withFPMethod("condom") .withFamilyPlanningMethodChangeDate("2013-01-02") .withNumberOfCondomsSupplied("20") .withNumberOfCentchromanPillsDelivered("10") .withNumberOfOCPDelivered("5") .withDeliveryPlace("PHC") .withDeliveryType("live_birth") .withDeliveryComplications("Headache") .withOtherDeliveryComplications("Vomiting") .withPhotoPath("../../img/woman-placeholder.png") .withEntityIdToSavePhoto("entity id 1") .withAlerts(Collections.<AlertDTO>emptyList()) .withChildren(Arrays.asList(new ChildClient("child id 1", "male", "2.4", "thayi 1"), new ChildClient("child id 2", "female", "2.5", "thayi 1"))) .withServicesProvided(Collections.<ServiceProvidedDTO>emptyList()); Mockito.when(preProcessor.preProcess(Mockito.any(PNCClient.class))).thenReturn(expectedPNCClient); PNCClients clients = controller.getClients(); Assert.assertEquals(expectedPNCClient, clients.get(0)); }
public PNCClients getClients() { return pncClientsCache.get(PNC_CLIENTS_LIST, new CacheableData<PNCClients>() { @Override public PNCClients fetch() { PNCClients pncClients = new PNCClients(); List<Pair<Mother, EligibleCouple>> pncsWithEcs = allBeneficiaries.allPNCsWithEC(); for (Pair<Mother, EligibleCouple> pncWithEc : pncsWithEcs) { Mother pnc = pncWithEc.getLeft(); EligibleCouple ec = pncWithEc.getRight(); String photoPath = isBlank(ec.photoPath()) ? DEFAULT_WOMAN_IMAGE_PLACEHOLDER_PATH : ec.photoPath(); List<ServiceProvidedDTO> servicesProvided = getServicesProvided(pnc.caseId()); List<AlertDTO> alerts = getAlerts(pnc.caseId()); PNCClient client = new PNCClient(pnc.caseId(), ec.village(), ec.wifeName(), pnc.thayiCardNumber(), pnc.referenceDate()) .withHusbandName(ec.husbandName()).withAge(ec.age()) .withWomanDOB(ec.getDetail(WOMAN_DOB)).withECNumber(ec.ecNumber()) .withIsHighPriority(ec.isHighPriority()) .withIsHighRisk(pnc.isHighRisk()) .withEconomicStatus(ec.getDetail(ECONOMIC_STATUS)) .withIsOutOfArea(ec.isOutOfArea()).withCaste(ec.getDetail(CASTE)) .withPhotoPath(photoPath).withFPMethod(ec.getDetail(CURRENT_FP_METHOD)) .withIUDPlace(ec.getDetail(IUD_PLACE)) .withIUDPerson(ec.getDetail(IUD_PERSON)) .withNumberOfCondomsSupplied(ec.getDetail(NUMBER_OF_CONDOMS_SUPPLIED)) .withFamilyPlanningMethodChangeDate( ec.getDetail(FAMILY_PLANNING_METHOD_CHANGE_DATE)) .withNumberOfOCPDelivered(ec.getDetail(NUMBER_OF_OCP_DELIVERED)) .withNumberOfCentchromanPillsDelivered( ec.getDetail(NUMBER_OF_CENTCHROMAN_PILLS_DELIVERED)) .withDeliveryPlace(pnc.getDetail(DELIVERY_PLACE)) .withDeliveryType(pnc.getDetail(DELIVERY_TYPE)) .withDeliveryComplications(pnc.getDetail(DELIVERY_COMPLICATIONS)) .withPNCComplications(pnc.getDetail(IMMEDIATE_REFERRAL_REASON)) .withOtherDeliveryComplications( pnc.getDetail(OTHER_DELIVERY_COMPLICATIONS)) .withEntityIdToSavePhoto(ec.caseId()).withAlerts(alerts) .withServicesProvided(servicesProvided).withChildren(findChildren(pnc)) .withPreProcess(); pncClients.add(pncClientPreProcessor.preProcess(client)); } sortByName(pncClients); return pncClients; } }); }
PNCSmartRegisterController { public PNCClients getClients() { return pncClientsCache.get(PNC_CLIENTS_LIST, new CacheableData<PNCClients>() { @Override public PNCClients fetch() { PNCClients pncClients = new PNCClients(); List<Pair<Mother, EligibleCouple>> pncsWithEcs = allBeneficiaries.allPNCsWithEC(); for (Pair<Mother, EligibleCouple> pncWithEc : pncsWithEcs) { Mother pnc = pncWithEc.getLeft(); EligibleCouple ec = pncWithEc.getRight(); String photoPath = isBlank(ec.photoPath()) ? DEFAULT_WOMAN_IMAGE_PLACEHOLDER_PATH : ec.photoPath(); List<ServiceProvidedDTO> servicesProvided = getServicesProvided(pnc.caseId()); List<AlertDTO> alerts = getAlerts(pnc.caseId()); PNCClient client = new PNCClient(pnc.caseId(), ec.village(), ec.wifeName(), pnc.thayiCardNumber(), pnc.referenceDate()) .withHusbandName(ec.husbandName()).withAge(ec.age()) .withWomanDOB(ec.getDetail(WOMAN_DOB)).withECNumber(ec.ecNumber()) .withIsHighPriority(ec.isHighPriority()) .withIsHighRisk(pnc.isHighRisk()) .withEconomicStatus(ec.getDetail(ECONOMIC_STATUS)) .withIsOutOfArea(ec.isOutOfArea()).withCaste(ec.getDetail(CASTE)) .withPhotoPath(photoPath).withFPMethod(ec.getDetail(CURRENT_FP_METHOD)) .withIUDPlace(ec.getDetail(IUD_PLACE)) .withIUDPerson(ec.getDetail(IUD_PERSON)) .withNumberOfCondomsSupplied(ec.getDetail(NUMBER_OF_CONDOMS_SUPPLIED)) .withFamilyPlanningMethodChangeDate( ec.getDetail(FAMILY_PLANNING_METHOD_CHANGE_DATE)) .withNumberOfOCPDelivered(ec.getDetail(NUMBER_OF_OCP_DELIVERED)) .withNumberOfCentchromanPillsDelivered( ec.getDetail(NUMBER_OF_CENTCHROMAN_PILLS_DELIVERED)) .withDeliveryPlace(pnc.getDetail(DELIVERY_PLACE)) .withDeliveryType(pnc.getDetail(DELIVERY_TYPE)) .withDeliveryComplications(pnc.getDetail(DELIVERY_COMPLICATIONS)) .withPNCComplications(pnc.getDetail(IMMEDIATE_REFERRAL_REASON)) .withOtherDeliveryComplications( pnc.getDetail(OTHER_DELIVERY_COMPLICATIONS)) .withEntityIdToSavePhoto(ec.caseId()).withAlerts(alerts) .withServicesProvided(servicesProvided).withChildren(findChildren(pnc)) .withPreProcess(); pncClients.add(pncClientPreProcessor.preProcess(client)); } sortByName(pncClients); return pncClients; } }); } }
PNCSmartRegisterController { public PNCClients getClients() { return pncClientsCache.get(PNC_CLIENTS_LIST, new CacheableData<PNCClients>() { @Override public PNCClients fetch() { PNCClients pncClients = new PNCClients(); List<Pair<Mother, EligibleCouple>> pncsWithEcs = allBeneficiaries.allPNCsWithEC(); for (Pair<Mother, EligibleCouple> pncWithEc : pncsWithEcs) { Mother pnc = pncWithEc.getLeft(); EligibleCouple ec = pncWithEc.getRight(); String photoPath = isBlank(ec.photoPath()) ? DEFAULT_WOMAN_IMAGE_PLACEHOLDER_PATH : ec.photoPath(); List<ServiceProvidedDTO> servicesProvided = getServicesProvided(pnc.caseId()); List<AlertDTO> alerts = getAlerts(pnc.caseId()); PNCClient client = new PNCClient(pnc.caseId(), ec.village(), ec.wifeName(), pnc.thayiCardNumber(), pnc.referenceDate()) .withHusbandName(ec.husbandName()).withAge(ec.age()) .withWomanDOB(ec.getDetail(WOMAN_DOB)).withECNumber(ec.ecNumber()) .withIsHighPriority(ec.isHighPriority()) .withIsHighRisk(pnc.isHighRisk()) .withEconomicStatus(ec.getDetail(ECONOMIC_STATUS)) .withIsOutOfArea(ec.isOutOfArea()).withCaste(ec.getDetail(CASTE)) .withPhotoPath(photoPath).withFPMethod(ec.getDetail(CURRENT_FP_METHOD)) .withIUDPlace(ec.getDetail(IUD_PLACE)) .withIUDPerson(ec.getDetail(IUD_PERSON)) .withNumberOfCondomsSupplied(ec.getDetail(NUMBER_OF_CONDOMS_SUPPLIED)) .withFamilyPlanningMethodChangeDate( ec.getDetail(FAMILY_PLANNING_METHOD_CHANGE_DATE)) .withNumberOfOCPDelivered(ec.getDetail(NUMBER_OF_OCP_DELIVERED)) .withNumberOfCentchromanPillsDelivered( ec.getDetail(NUMBER_OF_CENTCHROMAN_PILLS_DELIVERED)) .withDeliveryPlace(pnc.getDetail(DELIVERY_PLACE)) .withDeliveryType(pnc.getDetail(DELIVERY_TYPE)) .withDeliveryComplications(pnc.getDetail(DELIVERY_COMPLICATIONS)) .withPNCComplications(pnc.getDetail(IMMEDIATE_REFERRAL_REASON)) .withOtherDeliveryComplications( pnc.getDetail(OTHER_DELIVERY_COMPLICATIONS)) .withEntityIdToSavePhoto(ec.caseId()).withAlerts(alerts) .withServicesProvided(servicesProvided).withChildren(findChildren(pnc)) .withPreProcess(); pncClients.add(pncClientPreProcessor.preProcess(client)); } sortByName(pncClients); return pncClients; } }); } PNCSmartRegisterController(ServiceProvidedService serviceProvidedService, AlertService alertService, AllEligibleCouples allEligibleCouples, AllBeneficiaries allBeneficiaries, Cache<String> cache, Cache<PNCClients> pncClientsCache); PNCSmartRegisterController(ServiceProvidedService serviceProvidedService, AlertService alertService, AllEligibleCouples allEligibleCouples, AllBeneficiaries allBeneficiaries, Cache<String> cache, Cache<PNCClients> pncClientsCache, PNCClientPreProcessor pncClientPreProcessor); }
PNCSmartRegisterController { public PNCClients getClients() { return pncClientsCache.get(PNC_CLIENTS_LIST, new CacheableData<PNCClients>() { @Override public PNCClients fetch() { PNCClients pncClients = new PNCClients(); List<Pair<Mother, EligibleCouple>> pncsWithEcs = allBeneficiaries.allPNCsWithEC(); for (Pair<Mother, EligibleCouple> pncWithEc : pncsWithEcs) { Mother pnc = pncWithEc.getLeft(); EligibleCouple ec = pncWithEc.getRight(); String photoPath = isBlank(ec.photoPath()) ? DEFAULT_WOMAN_IMAGE_PLACEHOLDER_PATH : ec.photoPath(); List<ServiceProvidedDTO> servicesProvided = getServicesProvided(pnc.caseId()); List<AlertDTO> alerts = getAlerts(pnc.caseId()); PNCClient client = new PNCClient(pnc.caseId(), ec.village(), ec.wifeName(), pnc.thayiCardNumber(), pnc.referenceDate()) .withHusbandName(ec.husbandName()).withAge(ec.age()) .withWomanDOB(ec.getDetail(WOMAN_DOB)).withECNumber(ec.ecNumber()) .withIsHighPriority(ec.isHighPriority()) .withIsHighRisk(pnc.isHighRisk()) .withEconomicStatus(ec.getDetail(ECONOMIC_STATUS)) .withIsOutOfArea(ec.isOutOfArea()).withCaste(ec.getDetail(CASTE)) .withPhotoPath(photoPath).withFPMethod(ec.getDetail(CURRENT_FP_METHOD)) .withIUDPlace(ec.getDetail(IUD_PLACE)) .withIUDPerson(ec.getDetail(IUD_PERSON)) .withNumberOfCondomsSupplied(ec.getDetail(NUMBER_OF_CONDOMS_SUPPLIED)) .withFamilyPlanningMethodChangeDate( ec.getDetail(FAMILY_PLANNING_METHOD_CHANGE_DATE)) .withNumberOfOCPDelivered(ec.getDetail(NUMBER_OF_OCP_DELIVERED)) .withNumberOfCentchromanPillsDelivered( ec.getDetail(NUMBER_OF_CENTCHROMAN_PILLS_DELIVERED)) .withDeliveryPlace(pnc.getDetail(DELIVERY_PLACE)) .withDeliveryType(pnc.getDetail(DELIVERY_TYPE)) .withDeliveryComplications(pnc.getDetail(DELIVERY_COMPLICATIONS)) .withPNCComplications(pnc.getDetail(IMMEDIATE_REFERRAL_REASON)) .withOtherDeliveryComplications( pnc.getDetail(OTHER_DELIVERY_COMPLICATIONS)) .withEntityIdToSavePhoto(ec.caseId()).withAlerts(alerts) .withServicesProvided(servicesProvided).withChildren(findChildren(pnc)) .withPreProcess(); pncClients.add(pncClientPreProcessor.preProcess(client)); } sortByName(pncClients); return pncClients; } }); } PNCSmartRegisterController(ServiceProvidedService serviceProvidedService, AlertService alertService, AllEligibleCouples allEligibleCouples, AllBeneficiaries allBeneficiaries, Cache<String> cache, Cache<PNCClients> pncClientsCache); PNCSmartRegisterController(ServiceProvidedService serviceProvidedService, AlertService alertService, AllEligibleCouples allEligibleCouples, AllBeneficiaries allBeneficiaries, Cache<String> cache, Cache<PNCClients> pncClientsCache, PNCClientPreProcessor pncClientPreProcessor); PNCClients getClients(); String villages(); }
PNCSmartRegisterController { public PNCClients getClients() { return pncClientsCache.get(PNC_CLIENTS_LIST, new CacheableData<PNCClients>() { @Override public PNCClients fetch() { PNCClients pncClients = new PNCClients(); List<Pair<Mother, EligibleCouple>> pncsWithEcs = allBeneficiaries.allPNCsWithEC(); for (Pair<Mother, EligibleCouple> pncWithEc : pncsWithEcs) { Mother pnc = pncWithEc.getLeft(); EligibleCouple ec = pncWithEc.getRight(); String photoPath = isBlank(ec.photoPath()) ? DEFAULT_WOMAN_IMAGE_PLACEHOLDER_PATH : ec.photoPath(); List<ServiceProvidedDTO> servicesProvided = getServicesProvided(pnc.caseId()); List<AlertDTO> alerts = getAlerts(pnc.caseId()); PNCClient client = new PNCClient(pnc.caseId(), ec.village(), ec.wifeName(), pnc.thayiCardNumber(), pnc.referenceDate()) .withHusbandName(ec.husbandName()).withAge(ec.age()) .withWomanDOB(ec.getDetail(WOMAN_DOB)).withECNumber(ec.ecNumber()) .withIsHighPriority(ec.isHighPriority()) .withIsHighRisk(pnc.isHighRisk()) .withEconomicStatus(ec.getDetail(ECONOMIC_STATUS)) .withIsOutOfArea(ec.isOutOfArea()).withCaste(ec.getDetail(CASTE)) .withPhotoPath(photoPath).withFPMethod(ec.getDetail(CURRENT_FP_METHOD)) .withIUDPlace(ec.getDetail(IUD_PLACE)) .withIUDPerson(ec.getDetail(IUD_PERSON)) .withNumberOfCondomsSupplied(ec.getDetail(NUMBER_OF_CONDOMS_SUPPLIED)) .withFamilyPlanningMethodChangeDate( ec.getDetail(FAMILY_PLANNING_METHOD_CHANGE_DATE)) .withNumberOfOCPDelivered(ec.getDetail(NUMBER_OF_OCP_DELIVERED)) .withNumberOfCentchromanPillsDelivered( ec.getDetail(NUMBER_OF_CENTCHROMAN_PILLS_DELIVERED)) .withDeliveryPlace(pnc.getDetail(DELIVERY_PLACE)) .withDeliveryType(pnc.getDetail(DELIVERY_TYPE)) .withDeliveryComplications(pnc.getDetail(DELIVERY_COMPLICATIONS)) .withPNCComplications(pnc.getDetail(IMMEDIATE_REFERRAL_REASON)) .withOtherDeliveryComplications( pnc.getDetail(OTHER_DELIVERY_COMPLICATIONS)) .withEntityIdToSavePhoto(ec.caseId()).withAlerts(alerts) .withServicesProvided(servicesProvided).withChildren(findChildren(pnc)) .withPreProcess(); pncClients.add(pncClientPreProcessor.preProcess(client)); } sortByName(pncClients); return pncClients; } }); } PNCSmartRegisterController(ServiceProvidedService serviceProvidedService, AlertService alertService, AllEligibleCouples allEligibleCouples, AllBeneficiaries allBeneficiaries, Cache<String> cache, Cache<PNCClients> pncClientsCache); PNCSmartRegisterController(ServiceProvidedService serviceProvidedService, AlertService alertService, AllEligibleCouples allEligibleCouples, AllBeneficiaries allBeneficiaries, Cache<String> cache, Cache<PNCClients> pncClientsCache, PNCClientPreProcessor pncClientPreProcessor); PNCClients getClients(); String villages(); }
@Test public void shouldCreatePNCClientsWithPNC1Alert() throws Exception { EligibleCouple ec = new EligibleCouple("entity id 1", "Woman C", "Husband C", "EC Number 1", "Bherya", "Bherya SC", emptyMap); Mother mother = new Mother("Entity X", "entity id 1", "thayi 1", "2013-05-25"); Alert pnc1Alert = new Alert("entity id 1", "PNC", "PNC 1", AlertStatus.normal, "2013-01-01", "2013-02-01"); Mockito.when(allBeneficiaries.allPNCsWithEC()).thenReturn(Arrays.asList(Pair.of(mother, ec))); Mockito.when(alertService.findByEntityIdAndAlertNames("Entity X", PNC_ALERTS)).thenReturn(Arrays.asList(pnc1Alert)); AlertDTO expectedAlertDto = new AlertDTO("PNC 1", "normal", "2013-01-01"); PNCClient expectedEC = createPNCClient("Entity X", "Woman C", "Bherya", "thayi 1", "2013-05-25") .withECNumber("EC Number 1") .withHusbandName("Husband C") .withEntityIdToSavePhoto("entity id 1") .withAlerts(Arrays.asList(expectedAlertDto)) .withChildren(Collections.EMPTY_LIST) .withServiceToVisitMap(new HashMap<String, Visits>()); Mockito.when(preProcessor.preProcess(Mockito.any(PNCClient.class))).thenReturn(expectedEC); PNCClients clients = controller.getClients(); Mockito.verify(alertService).findByEntityIdAndAlertNames("Entity X", PNC_ALERTS); Assert.assertEquals(Arrays.asList(expectedEC), clients); }
public PNCClients getClients() { return pncClientsCache.get(PNC_CLIENTS_LIST, new CacheableData<PNCClients>() { @Override public PNCClients fetch() { PNCClients pncClients = new PNCClients(); List<Pair<Mother, EligibleCouple>> pncsWithEcs = allBeneficiaries.allPNCsWithEC(); for (Pair<Mother, EligibleCouple> pncWithEc : pncsWithEcs) { Mother pnc = pncWithEc.getLeft(); EligibleCouple ec = pncWithEc.getRight(); String photoPath = isBlank(ec.photoPath()) ? DEFAULT_WOMAN_IMAGE_PLACEHOLDER_PATH : ec.photoPath(); List<ServiceProvidedDTO> servicesProvided = getServicesProvided(pnc.caseId()); List<AlertDTO> alerts = getAlerts(pnc.caseId()); PNCClient client = new PNCClient(pnc.caseId(), ec.village(), ec.wifeName(), pnc.thayiCardNumber(), pnc.referenceDate()) .withHusbandName(ec.husbandName()).withAge(ec.age()) .withWomanDOB(ec.getDetail(WOMAN_DOB)).withECNumber(ec.ecNumber()) .withIsHighPriority(ec.isHighPriority()) .withIsHighRisk(pnc.isHighRisk()) .withEconomicStatus(ec.getDetail(ECONOMIC_STATUS)) .withIsOutOfArea(ec.isOutOfArea()).withCaste(ec.getDetail(CASTE)) .withPhotoPath(photoPath).withFPMethod(ec.getDetail(CURRENT_FP_METHOD)) .withIUDPlace(ec.getDetail(IUD_PLACE)) .withIUDPerson(ec.getDetail(IUD_PERSON)) .withNumberOfCondomsSupplied(ec.getDetail(NUMBER_OF_CONDOMS_SUPPLIED)) .withFamilyPlanningMethodChangeDate( ec.getDetail(FAMILY_PLANNING_METHOD_CHANGE_DATE)) .withNumberOfOCPDelivered(ec.getDetail(NUMBER_OF_OCP_DELIVERED)) .withNumberOfCentchromanPillsDelivered( ec.getDetail(NUMBER_OF_CENTCHROMAN_PILLS_DELIVERED)) .withDeliveryPlace(pnc.getDetail(DELIVERY_PLACE)) .withDeliveryType(pnc.getDetail(DELIVERY_TYPE)) .withDeliveryComplications(pnc.getDetail(DELIVERY_COMPLICATIONS)) .withPNCComplications(pnc.getDetail(IMMEDIATE_REFERRAL_REASON)) .withOtherDeliveryComplications( pnc.getDetail(OTHER_DELIVERY_COMPLICATIONS)) .withEntityIdToSavePhoto(ec.caseId()).withAlerts(alerts) .withServicesProvided(servicesProvided).withChildren(findChildren(pnc)) .withPreProcess(); pncClients.add(pncClientPreProcessor.preProcess(client)); } sortByName(pncClients); return pncClients; } }); }
PNCSmartRegisterController { public PNCClients getClients() { return pncClientsCache.get(PNC_CLIENTS_LIST, new CacheableData<PNCClients>() { @Override public PNCClients fetch() { PNCClients pncClients = new PNCClients(); List<Pair<Mother, EligibleCouple>> pncsWithEcs = allBeneficiaries.allPNCsWithEC(); for (Pair<Mother, EligibleCouple> pncWithEc : pncsWithEcs) { Mother pnc = pncWithEc.getLeft(); EligibleCouple ec = pncWithEc.getRight(); String photoPath = isBlank(ec.photoPath()) ? DEFAULT_WOMAN_IMAGE_PLACEHOLDER_PATH : ec.photoPath(); List<ServiceProvidedDTO> servicesProvided = getServicesProvided(pnc.caseId()); List<AlertDTO> alerts = getAlerts(pnc.caseId()); PNCClient client = new PNCClient(pnc.caseId(), ec.village(), ec.wifeName(), pnc.thayiCardNumber(), pnc.referenceDate()) .withHusbandName(ec.husbandName()).withAge(ec.age()) .withWomanDOB(ec.getDetail(WOMAN_DOB)).withECNumber(ec.ecNumber()) .withIsHighPriority(ec.isHighPriority()) .withIsHighRisk(pnc.isHighRisk()) .withEconomicStatus(ec.getDetail(ECONOMIC_STATUS)) .withIsOutOfArea(ec.isOutOfArea()).withCaste(ec.getDetail(CASTE)) .withPhotoPath(photoPath).withFPMethod(ec.getDetail(CURRENT_FP_METHOD)) .withIUDPlace(ec.getDetail(IUD_PLACE)) .withIUDPerson(ec.getDetail(IUD_PERSON)) .withNumberOfCondomsSupplied(ec.getDetail(NUMBER_OF_CONDOMS_SUPPLIED)) .withFamilyPlanningMethodChangeDate( ec.getDetail(FAMILY_PLANNING_METHOD_CHANGE_DATE)) .withNumberOfOCPDelivered(ec.getDetail(NUMBER_OF_OCP_DELIVERED)) .withNumberOfCentchromanPillsDelivered( ec.getDetail(NUMBER_OF_CENTCHROMAN_PILLS_DELIVERED)) .withDeliveryPlace(pnc.getDetail(DELIVERY_PLACE)) .withDeliveryType(pnc.getDetail(DELIVERY_TYPE)) .withDeliveryComplications(pnc.getDetail(DELIVERY_COMPLICATIONS)) .withPNCComplications(pnc.getDetail(IMMEDIATE_REFERRAL_REASON)) .withOtherDeliveryComplications( pnc.getDetail(OTHER_DELIVERY_COMPLICATIONS)) .withEntityIdToSavePhoto(ec.caseId()).withAlerts(alerts) .withServicesProvided(servicesProvided).withChildren(findChildren(pnc)) .withPreProcess(); pncClients.add(pncClientPreProcessor.preProcess(client)); } sortByName(pncClients); return pncClients; } }); } }
PNCSmartRegisterController { public PNCClients getClients() { return pncClientsCache.get(PNC_CLIENTS_LIST, new CacheableData<PNCClients>() { @Override public PNCClients fetch() { PNCClients pncClients = new PNCClients(); List<Pair<Mother, EligibleCouple>> pncsWithEcs = allBeneficiaries.allPNCsWithEC(); for (Pair<Mother, EligibleCouple> pncWithEc : pncsWithEcs) { Mother pnc = pncWithEc.getLeft(); EligibleCouple ec = pncWithEc.getRight(); String photoPath = isBlank(ec.photoPath()) ? DEFAULT_WOMAN_IMAGE_PLACEHOLDER_PATH : ec.photoPath(); List<ServiceProvidedDTO> servicesProvided = getServicesProvided(pnc.caseId()); List<AlertDTO> alerts = getAlerts(pnc.caseId()); PNCClient client = new PNCClient(pnc.caseId(), ec.village(), ec.wifeName(), pnc.thayiCardNumber(), pnc.referenceDate()) .withHusbandName(ec.husbandName()).withAge(ec.age()) .withWomanDOB(ec.getDetail(WOMAN_DOB)).withECNumber(ec.ecNumber()) .withIsHighPriority(ec.isHighPriority()) .withIsHighRisk(pnc.isHighRisk()) .withEconomicStatus(ec.getDetail(ECONOMIC_STATUS)) .withIsOutOfArea(ec.isOutOfArea()).withCaste(ec.getDetail(CASTE)) .withPhotoPath(photoPath).withFPMethod(ec.getDetail(CURRENT_FP_METHOD)) .withIUDPlace(ec.getDetail(IUD_PLACE)) .withIUDPerson(ec.getDetail(IUD_PERSON)) .withNumberOfCondomsSupplied(ec.getDetail(NUMBER_OF_CONDOMS_SUPPLIED)) .withFamilyPlanningMethodChangeDate( ec.getDetail(FAMILY_PLANNING_METHOD_CHANGE_DATE)) .withNumberOfOCPDelivered(ec.getDetail(NUMBER_OF_OCP_DELIVERED)) .withNumberOfCentchromanPillsDelivered( ec.getDetail(NUMBER_OF_CENTCHROMAN_PILLS_DELIVERED)) .withDeliveryPlace(pnc.getDetail(DELIVERY_PLACE)) .withDeliveryType(pnc.getDetail(DELIVERY_TYPE)) .withDeliveryComplications(pnc.getDetail(DELIVERY_COMPLICATIONS)) .withPNCComplications(pnc.getDetail(IMMEDIATE_REFERRAL_REASON)) .withOtherDeliveryComplications( pnc.getDetail(OTHER_DELIVERY_COMPLICATIONS)) .withEntityIdToSavePhoto(ec.caseId()).withAlerts(alerts) .withServicesProvided(servicesProvided).withChildren(findChildren(pnc)) .withPreProcess(); pncClients.add(pncClientPreProcessor.preProcess(client)); } sortByName(pncClients); return pncClients; } }); } PNCSmartRegisterController(ServiceProvidedService serviceProvidedService, AlertService alertService, AllEligibleCouples allEligibleCouples, AllBeneficiaries allBeneficiaries, Cache<String> cache, Cache<PNCClients> pncClientsCache); PNCSmartRegisterController(ServiceProvidedService serviceProvidedService, AlertService alertService, AllEligibleCouples allEligibleCouples, AllBeneficiaries allBeneficiaries, Cache<String> cache, Cache<PNCClients> pncClientsCache, PNCClientPreProcessor pncClientPreProcessor); }
PNCSmartRegisterController { public PNCClients getClients() { return pncClientsCache.get(PNC_CLIENTS_LIST, new CacheableData<PNCClients>() { @Override public PNCClients fetch() { PNCClients pncClients = new PNCClients(); List<Pair<Mother, EligibleCouple>> pncsWithEcs = allBeneficiaries.allPNCsWithEC(); for (Pair<Mother, EligibleCouple> pncWithEc : pncsWithEcs) { Mother pnc = pncWithEc.getLeft(); EligibleCouple ec = pncWithEc.getRight(); String photoPath = isBlank(ec.photoPath()) ? DEFAULT_WOMAN_IMAGE_PLACEHOLDER_PATH : ec.photoPath(); List<ServiceProvidedDTO> servicesProvided = getServicesProvided(pnc.caseId()); List<AlertDTO> alerts = getAlerts(pnc.caseId()); PNCClient client = new PNCClient(pnc.caseId(), ec.village(), ec.wifeName(), pnc.thayiCardNumber(), pnc.referenceDate()) .withHusbandName(ec.husbandName()).withAge(ec.age()) .withWomanDOB(ec.getDetail(WOMAN_DOB)).withECNumber(ec.ecNumber()) .withIsHighPriority(ec.isHighPriority()) .withIsHighRisk(pnc.isHighRisk()) .withEconomicStatus(ec.getDetail(ECONOMIC_STATUS)) .withIsOutOfArea(ec.isOutOfArea()).withCaste(ec.getDetail(CASTE)) .withPhotoPath(photoPath).withFPMethod(ec.getDetail(CURRENT_FP_METHOD)) .withIUDPlace(ec.getDetail(IUD_PLACE)) .withIUDPerson(ec.getDetail(IUD_PERSON)) .withNumberOfCondomsSupplied(ec.getDetail(NUMBER_OF_CONDOMS_SUPPLIED)) .withFamilyPlanningMethodChangeDate( ec.getDetail(FAMILY_PLANNING_METHOD_CHANGE_DATE)) .withNumberOfOCPDelivered(ec.getDetail(NUMBER_OF_OCP_DELIVERED)) .withNumberOfCentchromanPillsDelivered( ec.getDetail(NUMBER_OF_CENTCHROMAN_PILLS_DELIVERED)) .withDeliveryPlace(pnc.getDetail(DELIVERY_PLACE)) .withDeliveryType(pnc.getDetail(DELIVERY_TYPE)) .withDeliveryComplications(pnc.getDetail(DELIVERY_COMPLICATIONS)) .withPNCComplications(pnc.getDetail(IMMEDIATE_REFERRAL_REASON)) .withOtherDeliveryComplications( pnc.getDetail(OTHER_DELIVERY_COMPLICATIONS)) .withEntityIdToSavePhoto(ec.caseId()).withAlerts(alerts) .withServicesProvided(servicesProvided).withChildren(findChildren(pnc)) .withPreProcess(); pncClients.add(pncClientPreProcessor.preProcess(client)); } sortByName(pncClients); return pncClients; } }); } PNCSmartRegisterController(ServiceProvidedService serviceProvidedService, AlertService alertService, AllEligibleCouples allEligibleCouples, AllBeneficiaries allBeneficiaries, Cache<String> cache, Cache<PNCClients> pncClientsCache); PNCSmartRegisterController(ServiceProvidedService serviceProvidedService, AlertService alertService, AllEligibleCouples allEligibleCouples, AllBeneficiaries allBeneficiaries, Cache<String> cache, Cache<PNCClients> pncClientsCache, PNCClientPreProcessor pncClientPreProcessor); PNCClients getClients(); String villages(); }
PNCSmartRegisterController { public PNCClients getClients() { return pncClientsCache.get(PNC_CLIENTS_LIST, new CacheableData<PNCClients>() { @Override public PNCClients fetch() { PNCClients pncClients = new PNCClients(); List<Pair<Mother, EligibleCouple>> pncsWithEcs = allBeneficiaries.allPNCsWithEC(); for (Pair<Mother, EligibleCouple> pncWithEc : pncsWithEcs) { Mother pnc = pncWithEc.getLeft(); EligibleCouple ec = pncWithEc.getRight(); String photoPath = isBlank(ec.photoPath()) ? DEFAULT_WOMAN_IMAGE_PLACEHOLDER_PATH : ec.photoPath(); List<ServiceProvidedDTO> servicesProvided = getServicesProvided(pnc.caseId()); List<AlertDTO> alerts = getAlerts(pnc.caseId()); PNCClient client = new PNCClient(pnc.caseId(), ec.village(), ec.wifeName(), pnc.thayiCardNumber(), pnc.referenceDate()) .withHusbandName(ec.husbandName()).withAge(ec.age()) .withWomanDOB(ec.getDetail(WOMAN_DOB)).withECNumber(ec.ecNumber()) .withIsHighPriority(ec.isHighPriority()) .withIsHighRisk(pnc.isHighRisk()) .withEconomicStatus(ec.getDetail(ECONOMIC_STATUS)) .withIsOutOfArea(ec.isOutOfArea()).withCaste(ec.getDetail(CASTE)) .withPhotoPath(photoPath).withFPMethod(ec.getDetail(CURRENT_FP_METHOD)) .withIUDPlace(ec.getDetail(IUD_PLACE)) .withIUDPerson(ec.getDetail(IUD_PERSON)) .withNumberOfCondomsSupplied(ec.getDetail(NUMBER_OF_CONDOMS_SUPPLIED)) .withFamilyPlanningMethodChangeDate( ec.getDetail(FAMILY_PLANNING_METHOD_CHANGE_DATE)) .withNumberOfOCPDelivered(ec.getDetail(NUMBER_OF_OCP_DELIVERED)) .withNumberOfCentchromanPillsDelivered( ec.getDetail(NUMBER_OF_CENTCHROMAN_PILLS_DELIVERED)) .withDeliveryPlace(pnc.getDetail(DELIVERY_PLACE)) .withDeliveryType(pnc.getDetail(DELIVERY_TYPE)) .withDeliveryComplications(pnc.getDetail(DELIVERY_COMPLICATIONS)) .withPNCComplications(pnc.getDetail(IMMEDIATE_REFERRAL_REASON)) .withOtherDeliveryComplications( pnc.getDetail(OTHER_DELIVERY_COMPLICATIONS)) .withEntityIdToSavePhoto(ec.caseId()).withAlerts(alerts) .withServicesProvided(servicesProvided).withChildren(findChildren(pnc)) .withPreProcess(); pncClients.add(pncClientPreProcessor.preProcess(client)); } sortByName(pncClients); return pncClients; } }); } PNCSmartRegisterController(ServiceProvidedService serviceProvidedService, AlertService alertService, AllEligibleCouples allEligibleCouples, AllBeneficiaries allBeneficiaries, Cache<String> cache, Cache<PNCClients> pncClientsCache); PNCSmartRegisterController(ServiceProvidedService serviceProvidedService, AlertService alertService, AllEligibleCouples allEligibleCouples, AllBeneficiaries allBeneficiaries, Cache<String> cache, Cache<PNCClients> pncClientsCache, PNCClientPreProcessor pncClientPreProcessor); PNCClients getClients(); String villages(); }
@Test public void shouldCreatePNCClientsWithServicesProvided() throws Exception { EligibleCouple ec = new EligibleCouple("entity id 1", "Woman C", "Husband C", "EC Number 1", "Bherya", "Bherya SC", emptyMap); Mother mother = new Mother("Entity X", "entity id 1", "thayi 1", "2013-05-25"); Mockito.when(allBeneficiaries.allPNCsWithEC()).thenReturn(Arrays.asList(Pair.of(mother, ec))); Mockito.when(alertService.findByEntityIdAndAlertNames("Entity X", PNC_ALERTS)).thenReturn(Collections.<Alert>emptyList()); Mockito.when(serviceProvidedService.findByEntityIdAndServiceNames("Entity X", PNC_SERVICES)) .thenReturn(Arrays.asList(new ServiceProvided("entity id 1", "PNC 1", "2013-01-01", EasyMap.mapOf("dose", "100")), new ServiceProvided("entity id 1", "PNC 1", "2013-02-01", emptyMap))); List<ServiceProvidedDTO> expectedServicesProvided = Arrays.asList(new ServiceProvidedDTO("PNC 1", "2013-01-01", EasyMap.mapOf("dose", "100")), new ServiceProvidedDTO("PNC 1", "2013-02-01", emptyMap)); PNCClient expectedEC = createPNCClient("Entity X", "Woman C", "Bherya", "thayi 1", "2013-05-25") .withECNumber("EC Number 1") .withHusbandName("Husband C") .withEntityIdToSavePhoto("entity id 1") .withServicesProvided(expectedServicesProvided) .withChildren(Collections.EMPTY_LIST); Mockito.when(preProcessor.preProcess(Mockito.any(PNCClient.class))).thenReturn(expectedEC); PNCClients clients = controller.getClients(); Mockito.verify(alertService).findByEntityIdAndAlertNames("Entity X", PNC_ALERTS); Mockito.verify(serviceProvidedService).findByEntityIdAndServiceNames("Entity X", PNC_SERVICES); Assert.assertEquals(Arrays.asList(expectedEC), clients); }
public PNCClients getClients() { return pncClientsCache.get(PNC_CLIENTS_LIST, new CacheableData<PNCClients>() { @Override public PNCClients fetch() { PNCClients pncClients = new PNCClients(); List<Pair<Mother, EligibleCouple>> pncsWithEcs = allBeneficiaries.allPNCsWithEC(); for (Pair<Mother, EligibleCouple> pncWithEc : pncsWithEcs) { Mother pnc = pncWithEc.getLeft(); EligibleCouple ec = pncWithEc.getRight(); String photoPath = isBlank(ec.photoPath()) ? DEFAULT_WOMAN_IMAGE_PLACEHOLDER_PATH : ec.photoPath(); List<ServiceProvidedDTO> servicesProvided = getServicesProvided(pnc.caseId()); List<AlertDTO> alerts = getAlerts(pnc.caseId()); PNCClient client = new PNCClient(pnc.caseId(), ec.village(), ec.wifeName(), pnc.thayiCardNumber(), pnc.referenceDate()) .withHusbandName(ec.husbandName()).withAge(ec.age()) .withWomanDOB(ec.getDetail(WOMAN_DOB)).withECNumber(ec.ecNumber()) .withIsHighPriority(ec.isHighPriority()) .withIsHighRisk(pnc.isHighRisk()) .withEconomicStatus(ec.getDetail(ECONOMIC_STATUS)) .withIsOutOfArea(ec.isOutOfArea()).withCaste(ec.getDetail(CASTE)) .withPhotoPath(photoPath).withFPMethod(ec.getDetail(CURRENT_FP_METHOD)) .withIUDPlace(ec.getDetail(IUD_PLACE)) .withIUDPerson(ec.getDetail(IUD_PERSON)) .withNumberOfCondomsSupplied(ec.getDetail(NUMBER_OF_CONDOMS_SUPPLIED)) .withFamilyPlanningMethodChangeDate( ec.getDetail(FAMILY_PLANNING_METHOD_CHANGE_DATE)) .withNumberOfOCPDelivered(ec.getDetail(NUMBER_OF_OCP_DELIVERED)) .withNumberOfCentchromanPillsDelivered( ec.getDetail(NUMBER_OF_CENTCHROMAN_PILLS_DELIVERED)) .withDeliveryPlace(pnc.getDetail(DELIVERY_PLACE)) .withDeliveryType(pnc.getDetail(DELIVERY_TYPE)) .withDeliveryComplications(pnc.getDetail(DELIVERY_COMPLICATIONS)) .withPNCComplications(pnc.getDetail(IMMEDIATE_REFERRAL_REASON)) .withOtherDeliveryComplications( pnc.getDetail(OTHER_DELIVERY_COMPLICATIONS)) .withEntityIdToSavePhoto(ec.caseId()).withAlerts(alerts) .withServicesProvided(servicesProvided).withChildren(findChildren(pnc)) .withPreProcess(); pncClients.add(pncClientPreProcessor.preProcess(client)); } sortByName(pncClients); return pncClients; } }); }
PNCSmartRegisterController { public PNCClients getClients() { return pncClientsCache.get(PNC_CLIENTS_LIST, new CacheableData<PNCClients>() { @Override public PNCClients fetch() { PNCClients pncClients = new PNCClients(); List<Pair<Mother, EligibleCouple>> pncsWithEcs = allBeneficiaries.allPNCsWithEC(); for (Pair<Mother, EligibleCouple> pncWithEc : pncsWithEcs) { Mother pnc = pncWithEc.getLeft(); EligibleCouple ec = pncWithEc.getRight(); String photoPath = isBlank(ec.photoPath()) ? DEFAULT_WOMAN_IMAGE_PLACEHOLDER_PATH : ec.photoPath(); List<ServiceProvidedDTO> servicesProvided = getServicesProvided(pnc.caseId()); List<AlertDTO> alerts = getAlerts(pnc.caseId()); PNCClient client = new PNCClient(pnc.caseId(), ec.village(), ec.wifeName(), pnc.thayiCardNumber(), pnc.referenceDate()) .withHusbandName(ec.husbandName()).withAge(ec.age()) .withWomanDOB(ec.getDetail(WOMAN_DOB)).withECNumber(ec.ecNumber()) .withIsHighPriority(ec.isHighPriority()) .withIsHighRisk(pnc.isHighRisk()) .withEconomicStatus(ec.getDetail(ECONOMIC_STATUS)) .withIsOutOfArea(ec.isOutOfArea()).withCaste(ec.getDetail(CASTE)) .withPhotoPath(photoPath).withFPMethod(ec.getDetail(CURRENT_FP_METHOD)) .withIUDPlace(ec.getDetail(IUD_PLACE)) .withIUDPerson(ec.getDetail(IUD_PERSON)) .withNumberOfCondomsSupplied(ec.getDetail(NUMBER_OF_CONDOMS_SUPPLIED)) .withFamilyPlanningMethodChangeDate( ec.getDetail(FAMILY_PLANNING_METHOD_CHANGE_DATE)) .withNumberOfOCPDelivered(ec.getDetail(NUMBER_OF_OCP_DELIVERED)) .withNumberOfCentchromanPillsDelivered( ec.getDetail(NUMBER_OF_CENTCHROMAN_PILLS_DELIVERED)) .withDeliveryPlace(pnc.getDetail(DELIVERY_PLACE)) .withDeliveryType(pnc.getDetail(DELIVERY_TYPE)) .withDeliveryComplications(pnc.getDetail(DELIVERY_COMPLICATIONS)) .withPNCComplications(pnc.getDetail(IMMEDIATE_REFERRAL_REASON)) .withOtherDeliveryComplications( pnc.getDetail(OTHER_DELIVERY_COMPLICATIONS)) .withEntityIdToSavePhoto(ec.caseId()).withAlerts(alerts) .withServicesProvided(servicesProvided).withChildren(findChildren(pnc)) .withPreProcess(); pncClients.add(pncClientPreProcessor.preProcess(client)); } sortByName(pncClients); return pncClients; } }); } }
PNCSmartRegisterController { public PNCClients getClients() { return pncClientsCache.get(PNC_CLIENTS_LIST, new CacheableData<PNCClients>() { @Override public PNCClients fetch() { PNCClients pncClients = new PNCClients(); List<Pair<Mother, EligibleCouple>> pncsWithEcs = allBeneficiaries.allPNCsWithEC(); for (Pair<Mother, EligibleCouple> pncWithEc : pncsWithEcs) { Mother pnc = pncWithEc.getLeft(); EligibleCouple ec = pncWithEc.getRight(); String photoPath = isBlank(ec.photoPath()) ? DEFAULT_WOMAN_IMAGE_PLACEHOLDER_PATH : ec.photoPath(); List<ServiceProvidedDTO> servicesProvided = getServicesProvided(pnc.caseId()); List<AlertDTO> alerts = getAlerts(pnc.caseId()); PNCClient client = new PNCClient(pnc.caseId(), ec.village(), ec.wifeName(), pnc.thayiCardNumber(), pnc.referenceDate()) .withHusbandName(ec.husbandName()).withAge(ec.age()) .withWomanDOB(ec.getDetail(WOMAN_DOB)).withECNumber(ec.ecNumber()) .withIsHighPriority(ec.isHighPriority()) .withIsHighRisk(pnc.isHighRisk()) .withEconomicStatus(ec.getDetail(ECONOMIC_STATUS)) .withIsOutOfArea(ec.isOutOfArea()).withCaste(ec.getDetail(CASTE)) .withPhotoPath(photoPath).withFPMethod(ec.getDetail(CURRENT_FP_METHOD)) .withIUDPlace(ec.getDetail(IUD_PLACE)) .withIUDPerson(ec.getDetail(IUD_PERSON)) .withNumberOfCondomsSupplied(ec.getDetail(NUMBER_OF_CONDOMS_SUPPLIED)) .withFamilyPlanningMethodChangeDate( ec.getDetail(FAMILY_PLANNING_METHOD_CHANGE_DATE)) .withNumberOfOCPDelivered(ec.getDetail(NUMBER_OF_OCP_DELIVERED)) .withNumberOfCentchromanPillsDelivered( ec.getDetail(NUMBER_OF_CENTCHROMAN_PILLS_DELIVERED)) .withDeliveryPlace(pnc.getDetail(DELIVERY_PLACE)) .withDeliveryType(pnc.getDetail(DELIVERY_TYPE)) .withDeliveryComplications(pnc.getDetail(DELIVERY_COMPLICATIONS)) .withPNCComplications(pnc.getDetail(IMMEDIATE_REFERRAL_REASON)) .withOtherDeliveryComplications( pnc.getDetail(OTHER_DELIVERY_COMPLICATIONS)) .withEntityIdToSavePhoto(ec.caseId()).withAlerts(alerts) .withServicesProvided(servicesProvided).withChildren(findChildren(pnc)) .withPreProcess(); pncClients.add(pncClientPreProcessor.preProcess(client)); } sortByName(pncClients); return pncClients; } }); } PNCSmartRegisterController(ServiceProvidedService serviceProvidedService, AlertService alertService, AllEligibleCouples allEligibleCouples, AllBeneficiaries allBeneficiaries, Cache<String> cache, Cache<PNCClients> pncClientsCache); PNCSmartRegisterController(ServiceProvidedService serviceProvidedService, AlertService alertService, AllEligibleCouples allEligibleCouples, AllBeneficiaries allBeneficiaries, Cache<String> cache, Cache<PNCClients> pncClientsCache, PNCClientPreProcessor pncClientPreProcessor); }
PNCSmartRegisterController { public PNCClients getClients() { return pncClientsCache.get(PNC_CLIENTS_LIST, new CacheableData<PNCClients>() { @Override public PNCClients fetch() { PNCClients pncClients = new PNCClients(); List<Pair<Mother, EligibleCouple>> pncsWithEcs = allBeneficiaries.allPNCsWithEC(); for (Pair<Mother, EligibleCouple> pncWithEc : pncsWithEcs) { Mother pnc = pncWithEc.getLeft(); EligibleCouple ec = pncWithEc.getRight(); String photoPath = isBlank(ec.photoPath()) ? DEFAULT_WOMAN_IMAGE_PLACEHOLDER_PATH : ec.photoPath(); List<ServiceProvidedDTO> servicesProvided = getServicesProvided(pnc.caseId()); List<AlertDTO> alerts = getAlerts(pnc.caseId()); PNCClient client = new PNCClient(pnc.caseId(), ec.village(), ec.wifeName(), pnc.thayiCardNumber(), pnc.referenceDate()) .withHusbandName(ec.husbandName()).withAge(ec.age()) .withWomanDOB(ec.getDetail(WOMAN_DOB)).withECNumber(ec.ecNumber()) .withIsHighPriority(ec.isHighPriority()) .withIsHighRisk(pnc.isHighRisk()) .withEconomicStatus(ec.getDetail(ECONOMIC_STATUS)) .withIsOutOfArea(ec.isOutOfArea()).withCaste(ec.getDetail(CASTE)) .withPhotoPath(photoPath).withFPMethod(ec.getDetail(CURRENT_FP_METHOD)) .withIUDPlace(ec.getDetail(IUD_PLACE)) .withIUDPerson(ec.getDetail(IUD_PERSON)) .withNumberOfCondomsSupplied(ec.getDetail(NUMBER_OF_CONDOMS_SUPPLIED)) .withFamilyPlanningMethodChangeDate( ec.getDetail(FAMILY_PLANNING_METHOD_CHANGE_DATE)) .withNumberOfOCPDelivered(ec.getDetail(NUMBER_OF_OCP_DELIVERED)) .withNumberOfCentchromanPillsDelivered( ec.getDetail(NUMBER_OF_CENTCHROMAN_PILLS_DELIVERED)) .withDeliveryPlace(pnc.getDetail(DELIVERY_PLACE)) .withDeliveryType(pnc.getDetail(DELIVERY_TYPE)) .withDeliveryComplications(pnc.getDetail(DELIVERY_COMPLICATIONS)) .withPNCComplications(pnc.getDetail(IMMEDIATE_REFERRAL_REASON)) .withOtherDeliveryComplications( pnc.getDetail(OTHER_DELIVERY_COMPLICATIONS)) .withEntityIdToSavePhoto(ec.caseId()).withAlerts(alerts) .withServicesProvided(servicesProvided).withChildren(findChildren(pnc)) .withPreProcess(); pncClients.add(pncClientPreProcessor.preProcess(client)); } sortByName(pncClients); return pncClients; } }); } PNCSmartRegisterController(ServiceProvidedService serviceProvidedService, AlertService alertService, AllEligibleCouples allEligibleCouples, AllBeneficiaries allBeneficiaries, Cache<String> cache, Cache<PNCClients> pncClientsCache); PNCSmartRegisterController(ServiceProvidedService serviceProvidedService, AlertService alertService, AllEligibleCouples allEligibleCouples, AllBeneficiaries allBeneficiaries, Cache<String> cache, Cache<PNCClients> pncClientsCache, PNCClientPreProcessor pncClientPreProcessor); PNCClients getClients(); String villages(); }
PNCSmartRegisterController { public PNCClients getClients() { return pncClientsCache.get(PNC_CLIENTS_LIST, new CacheableData<PNCClients>() { @Override public PNCClients fetch() { PNCClients pncClients = new PNCClients(); List<Pair<Mother, EligibleCouple>> pncsWithEcs = allBeneficiaries.allPNCsWithEC(); for (Pair<Mother, EligibleCouple> pncWithEc : pncsWithEcs) { Mother pnc = pncWithEc.getLeft(); EligibleCouple ec = pncWithEc.getRight(); String photoPath = isBlank(ec.photoPath()) ? DEFAULT_WOMAN_IMAGE_PLACEHOLDER_PATH : ec.photoPath(); List<ServiceProvidedDTO> servicesProvided = getServicesProvided(pnc.caseId()); List<AlertDTO> alerts = getAlerts(pnc.caseId()); PNCClient client = new PNCClient(pnc.caseId(), ec.village(), ec.wifeName(), pnc.thayiCardNumber(), pnc.referenceDate()) .withHusbandName(ec.husbandName()).withAge(ec.age()) .withWomanDOB(ec.getDetail(WOMAN_DOB)).withECNumber(ec.ecNumber()) .withIsHighPriority(ec.isHighPriority()) .withIsHighRisk(pnc.isHighRisk()) .withEconomicStatus(ec.getDetail(ECONOMIC_STATUS)) .withIsOutOfArea(ec.isOutOfArea()).withCaste(ec.getDetail(CASTE)) .withPhotoPath(photoPath).withFPMethod(ec.getDetail(CURRENT_FP_METHOD)) .withIUDPlace(ec.getDetail(IUD_PLACE)) .withIUDPerson(ec.getDetail(IUD_PERSON)) .withNumberOfCondomsSupplied(ec.getDetail(NUMBER_OF_CONDOMS_SUPPLIED)) .withFamilyPlanningMethodChangeDate( ec.getDetail(FAMILY_PLANNING_METHOD_CHANGE_DATE)) .withNumberOfOCPDelivered(ec.getDetail(NUMBER_OF_OCP_DELIVERED)) .withNumberOfCentchromanPillsDelivered( ec.getDetail(NUMBER_OF_CENTCHROMAN_PILLS_DELIVERED)) .withDeliveryPlace(pnc.getDetail(DELIVERY_PLACE)) .withDeliveryType(pnc.getDetail(DELIVERY_TYPE)) .withDeliveryComplications(pnc.getDetail(DELIVERY_COMPLICATIONS)) .withPNCComplications(pnc.getDetail(IMMEDIATE_REFERRAL_REASON)) .withOtherDeliveryComplications( pnc.getDetail(OTHER_DELIVERY_COMPLICATIONS)) .withEntityIdToSavePhoto(ec.caseId()).withAlerts(alerts) .withServicesProvided(servicesProvided).withChildren(findChildren(pnc)) .withPreProcess(); pncClients.add(pncClientPreProcessor.preProcess(client)); } sortByName(pncClients); return pncClients; } }); } PNCSmartRegisterController(ServiceProvidedService serviceProvidedService, AlertService alertService, AllEligibleCouples allEligibleCouples, AllBeneficiaries allBeneficiaries, Cache<String> cache, Cache<PNCClients> pncClientsCache); PNCSmartRegisterController(ServiceProvidedService serviceProvidedService, AlertService alertService, AllEligibleCouples allEligibleCouples, AllBeneficiaries allBeneficiaries, Cache<String> cache, Cache<PNCClients> pncClientsCache, PNCClientPreProcessor pncClientPreProcessor); PNCClients getClients(); String villages(); }
@Test public void shouldGetIndicatorReportsForGivenCategory() throws Exception { List<MonthSummaryDatum> monthlySummaries = Arrays.asList(new MonthSummaryDatum("10", "2012", "2", "2", Arrays.asList("123", "456"))); Report iudReport = new Report("IUD", "40", new Gson().toJson(monthlySummaries)); ReportIndicatorDetailViewController controller = new ReportIndicatorDetailViewController(context, iudReport, "Family Planning"); String indicatorReportDetail = controller.get(); String expectedIndicatorReports = new Gson().toJson(new IndicatorReportDetail("Family Planning", "IUD Adoption", "IUD", "40", monthlySummaries)); Assert.assertEquals(expectedIndicatorReports, indicatorReportDetail); }
public String get() { String annualTarget = (isBlank(indicatorDetails.annualTarget())) ? "NA" : indicatorDetails.annualTarget(); return new Gson().toJson(new IndicatorReportDetail(categoryDescription, indicatorDetails.reportIndicator().description(), indicatorDetails.reportIndicator().name(), annualTarget, indicatorDetails.monthlySummaries())); }
ReportIndicatorDetailViewController { public String get() { String annualTarget = (isBlank(indicatorDetails.annualTarget())) ? "NA" : indicatorDetails.annualTarget(); return new Gson().toJson(new IndicatorReportDetail(categoryDescription, indicatorDetails.reportIndicator().description(), indicatorDetails.reportIndicator().name(), annualTarget, indicatorDetails.monthlySummaries())); } }
ReportIndicatorDetailViewController { public String get() { String annualTarget = (isBlank(indicatorDetails.annualTarget())) ? "NA" : indicatorDetails.annualTarget(); return new Gson().toJson(new IndicatorReportDetail(categoryDescription, indicatorDetails.reportIndicator().description(), indicatorDetails.reportIndicator().name(), annualTarget, indicatorDetails.monthlySummaries())); } ReportIndicatorDetailViewController(Context context, Report indicatorDetails, String categoryDescription); }
ReportIndicatorDetailViewController { public String get() { String annualTarget = (isBlank(indicatorDetails.annualTarget())) ? "NA" : indicatorDetails.annualTarget(); return new Gson().toJson(new IndicatorReportDetail(categoryDescription, indicatorDetails.reportIndicator().description(), indicatorDetails.reportIndicator().name(), annualTarget, indicatorDetails.monthlySummaries())); } ReportIndicatorDetailViewController(Context context, Report indicatorDetails, String categoryDescription); String get(); void startReportIndicatorCaseList(String month); }
ReportIndicatorDetailViewController { public String get() { String annualTarget = (isBlank(indicatorDetails.annualTarget())) ? "NA" : indicatorDetails.annualTarget(); return new Gson().toJson(new IndicatorReportDetail(categoryDescription, indicatorDetails.reportIndicator().description(), indicatorDetails.reportIndicator().name(), annualTarget, indicatorDetails.monthlySummaries())); } ReportIndicatorDetailViewController(Context context, Report indicatorDetails, String categoryDescription); String get(); void startReportIndicatorCaseList(String month); }
@Test public void testAddPaginationCoreCreatesFooterViewCorrectly() { Mockito.doReturn(layoutInflater).when(activity).getLayoutInflater(); Mockito.doReturn(paginationView).when(layoutInflater).inflate(R.layout.smart_register_pagination, null); Mockito.doReturn(activity).when(clientsView).getContext(); Mockito.doReturn(nextPageButton).when(paginationView).findViewById(R.id.btn_next_page); Mockito.doReturn(prevPageButton).when(paginationView).findViewById(R.id.btn_previous_page); Mockito.doReturn(infoTextView).when(paginationView).findViewById(R.id.txt_page_info); Mockito.doReturn(LayoutDirection.LTR).when(paginationView).getLayoutDirection(); Mockito.doReturn(resources).when(activity).getResources(); Mockito.doReturn(TEST_DIMENSION).when(resources).getDimension(ArgumentMatchers.anyInt()); PaginationHolder paginationHolder = ViewHelper.addPaginationCore(clickListener, clientsView); Assert.assertNotNull(paginationHolder); AbsListView.LayoutParams layoutParams = (AbsListView.LayoutParams) paginationView.getLayoutParams(); Assert.assertNotNull(layoutParams); Assert.assertEquals(-1, layoutParams.width); Assert.assertEquals(1985.0f, layoutParams.height, 0); Mockito.verify(clientsView).addFooterView(paginationView); }
public static PaginationHolder addPaginationCore(View.OnClickListener onClickListener, ListView clientsView) { ViewGroup footerView = getPaginationView((Activity) clientsView.getContext()); PaginationHolder paginationHolder = new PaginationHolder(); paginationHolder.setNextPageView(footerView.findViewById(R.id.btn_next_page)); paginationHolder.setPreviousPageView(footerView.findViewById(R.id.btn_previous_page)); paginationHolder.setPageInfoView(footerView.findViewById(R.id.txt_page_info)); paginationHolder.getNextPageView().setOnClickListener(onClickListener); paginationHolder.getPreviousPageView().setOnClickListener(onClickListener); footerView.setLayoutParams( new AbsListView.LayoutParams(AbsListView.LayoutParams.MATCH_PARENT, (int) clientsView.getContext().getResources().getDimension(R.dimen.pagination_bar_height))); clientsView.addFooterView(footerView); return paginationHolder; }
ViewHelper { public static PaginationHolder addPaginationCore(View.OnClickListener onClickListener, ListView clientsView) { ViewGroup footerView = getPaginationView((Activity) clientsView.getContext()); PaginationHolder paginationHolder = new PaginationHolder(); paginationHolder.setNextPageView(footerView.findViewById(R.id.btn_next_page)); paginationHolder.setPreviousPageView(footerView.findViewById(R.id.btn_previous_page)); paginationHolder.setPageInfoView(footerView.findViewById(R.id.txt_page_info)); paginationHolder.getNextPageView().setOnClickListener(onClickListener); paginationHolder.getPreviousPageView().setOnClickListener(onClickListener); footerView.setLayoutParams( new AbsListView.LayoutParams(AbsListView.LayoutParams.MATCH_PARENT, (int) clientsView.getContext().getResources().getDimension(R.dimen.pagination_bar_height))); clientsView.addFooterView(footerView); return paginationHolder; } }
ViewHelper { public static PaginationHolder addPaginationCore(View.OnClickListener onClickListener, ListView clientsView) { ViewGroup footerView = getPaginationView((Activity) clientsView.getContext()); PaginationHolder paginationHolder = new PaginationHolder(); paginationHolder.setNextPageView(footerView.findViewById(R.id.btn_next_page)); paginationHolder.setPreviousPageView(footerView.findViewById(R.id.btn_previous_page)); paginationHolder.setPageInfoView(footerView.findViewById(R.id.txt_page_info)); paginationHolder.getNextPageView().setOnClickListener(onClickListener); paginationHolder.getPreviousPageView().setOnClickListener(onClickListener); footerView.setLayoutParams( new AbsListView.LayoutParams(AbsListView.LayoutParams.MATCH_PARENT, (int) clientsView.getContext().getResources().getDimension(R.dimen.pagination_bar_height))); clientsView.addFooterView(footerView); return paginationHolder; } }
ViewHelper { public static PaginationHolder addPaginationCore(View.OnClickListener onClickListener, ListView clientsView) { ViewGroup footerView = getPaginationView((Activity) clientsView.getContext()); PaginationHolder paginationHolder = new PaginationHolder(); paginationHolder.setNextPageView(footerView.findViewById(R.id.btn_next_page)); paginationHolder.setPreviousPageView(footerView.findViewById(R.id.btn_previous_page)); paginationHolder.setPageInfoView(footerView.findViewById(R.id.txt_page_info)); paginationHolder.getNextPageView().setOnClickListener(onClickListener); paginationHolder.getPreviousPageView().setOnClickListener(onClickListener); footerView.setLayoutParams( new AbsListView.LayoutParams(AbsListView.LayoutParams.MATCH_PARENT, (int) clientsView.getContext().getResources().getDimension(R.dimen.pagination_bar_height))); clientsView.addFooterView(footerView); return paginationHolder; } static PaginationHolder addPaginationCore(View.OnClickListener onClickListener, ListView clientsView); static ViewGroup getPaginationView(Activity context); }
ViewHelper { public static PaginationHolder addPaginationCore(View.OnClickListener onClickListener, ListView clientsView) { ViewGroup footerView = getPaginationView((Activity) clientsView.getContext()); PaginationHolder paginationHolder = new PaginationHolder(); paginationHolder.setNextPageView(footerView.findViewById(R.id.btn_next_page)); paginationHolder.setPreviousPageView(footerView.findViewById(R.id.btn_previous_page)); paginationHolder.setPageInfoView(footerView.findViewById(R.id.txt_page_info)); paginationHolder.getNextPageView().setOnClickListener(onClickListener); paginationHolder.getPreviousPageView().setOnClickListener(onClickListener); footerView.setLayoutParams( new AbsListView.LayoutParams(AbsListView.LayoutParams.MATCH_PARENT, (int) clientsView.getContext().getResources().getDimension(R.dimen.pagination_bar_height))); clientsView.addFooterView(footerView); return paginationHolder; } static PaginationHolder addPaginationCore(View.OnClickListener onClickListener, ListView clientsView); static ViewGroup getPaginationView(Activity context); }
@Test public void shouldShowNAIfAnnualTargetNotAvailable() throws Exception { List<MonthSummaryDatum> monthlySummaries = Arrays.asList(new MonthSummaryDatum("6", "2012", "2", "2", Arrays.asList("123", "456")), new MonthSummaryDatum("8", "2012", "2", "4", Arrays.asList("321", "654"))); Report iudReport = new Report("IUD", null, new Gson().toJson(monthlySummaries)); ReportIndicatorDetailViewController controller = new ReportIndicatorDetailViewController(context, iudReport, "Family Planning"); String indicatorReportDetail = controller.get(); String expectedIndicatorReports = new Gson().toJson(new IndicatorReportDetail("Family Planning", "IUD Adoption", "IUD", "NA", monthlySummaries)); Assert.assertEquals(expectedIndicatorReports, indicatorReportDetail); }
public String get() { String annualTarget = (isBlank(indicatorDetails.annualTarget())) ? "NA" : indicatorDetails.annualTarget(); return new Gson().toJson(new IndicatorReportDetail(categoryDescription, indicatorDetails.reportIndicator().description(), indicatorDetails.reportIndicator().name(), annualTarget, indicatorDetails.monthlySummaries())); }
ReportIndicatorDetailViewController { public String get() { String annualTarget = (isBlank(indicatorDetails.annualTarget())) ? "NA" : indicatorDetails.annualTarget(); return new Gson().toJson(new IndicatorReportDetail(categoryDescription, indicatorDetails.reportIndicator().description(), indicatorDetails.reportIndicator().name(), annualTarget, indicatorDetails.monthlySummaries())); } }
ReportIndicatorDetailViewController { public String get() { String annualTarget = (isBlank(indicatorDetails.annualTarget())) ? "NA" : indicatorDetails.annualTarget(); return new Gson().toJson(new IndicatorReportDetail(categoryDescription, indicatorDetails.reportIndicator().description(), indicatorDetails.reportIndicator().name(), annualTarget, indicatorDetails.monthlySummaries())); } ReportIndicatorDetailViewController(Context context, Report indicatorDetails, String categoryDescription); }
ReportIndicatorDetailViewController { public String get() { String annualTarget = (isBlank(indicatorDetails.annualTarget())) ? "NA" : indicatorDetails.annualTarget(); return new Gson().toJson(new IndicatorReportDetail(categoryDescription, indicatorDetails.reportIndicator().description(), indicatorDetails.reportIndicator().name(), annualTarget, indicatorDetails.monthlySummaries())); } ReportIndicatorDetailViewController(Context context, Report indicatorDetails, String categoryDescription); String get(); void startReportIndicatorCaseList(String month); }
ReportIndicatorDetailViewController { public String get() { String annualTarget = (isBlank(indicatorDetails.annualTarget())) ? "NA" : indicatorDetails.annualTarget(); return new Gson().toJson(new IndicatorReportDetail(categoryDescription, indicatorDetails.reportIndicator().description(), indicatorDetails.reportIndicator().name(), annualTarget, indicatorDetails.monthlySummaries())); } ReportIndicatorDetailViewController(Context context, Report indicatorDetails, String categoryDescription); String get(); void startReportIndicatorCaseList(String month); }
@Test public void shouldSortChildrenByMotherName() throws Exception { EligibleCouple ec1 = new EligibleCouple("ec id 1", "amma", "appa", "ec no 1", "chikkamagalur", null, emptyMap).asOutOfArea(); Mother mother1 = new Mother("mother id 1", "ec id 1", "thayi no 1", "2013-01-01").withDetails(emptyMap); Child child1 = new Child("child id 1", "mother id 1", "male", emptyMap).withDateOfBirth("2013-01-01").withMother(mother1).withEC(ec1); EligibleCouple ec2 = new EligibleCouple("ec id 2", "thayi", "appa", "ec no 2", "chikkamagalur", null, emptyMap).asOutOfArea(); Mother mother2 = new Mother("mother id 2", "ec id 2", "thayi no 2", "2013-01-01").withDetails(emptyMap); Child child2 = new Child("child id 2", "mother id 2", "male", emptyMap).withDateOfBirth("2013-01-01").withMother(mother2).withEC(ec2); Mockito.when(allBeneficiaries.allChildrenWithMotherAndEC()).thenReturn(Arrays.asList(child2, child1)); ChildClient expectedClient1 = createChildClient("child id 1", "thayi no 1", "amma", "ec no 1"); ChildClient expectedClient2 = createChildClient("child id 2", "thayi no 2", "thayi", "ec no 2"); String clients = controller.get(); List<ChildClient> actualClients = new Gson().fromJson(clients, new TypeToken<List<ChildClient>>() { }.getType()); Assert.assertEquals(Arrays.asList(expectedClient1, expectedClient2), actualClients); }
public String get() { return cache.get(CHILD_CLIENTS_LIST_CACHE_ENTRY_NAME, new CacheableData<String>() { @Override public String fetch() { List<Child> children = allBeneficiaries.allChildrenWithMotherAndEC(); List<ChildClient> childrenClient = new ArrayList<ChildClient>(); for (Child child : children) { String photoPath = isBlank(child.photoPath()) ? ( AllConstants.FEMALE_GENDER.equalsIgnoreCase(child.gender()) ? AllConstants.DEFAULT_GIRL_INFANT_IMAGE_PLACEHOLDER_PATH : AllConstants.DEFAULT_BOY_INFANT_IMAGE_PLACEHOLDER_PATH) : child.photoPath(); List<AlertDTO> alerts = getAlerts(child.caseId()); List<ServiceProvidedDTO> servicesProvided = getServicesProvided(child.caseId()); ChildClient childClient = new ChildClient(child.caseId(), child.gender(), child.getDetail(AllConstants.ChildRegistrationFields.WEIGHT), child.mother().thayiCardNumber()) .withName(child.getDetail(AllConstants.ChildRegistrationFields.NAME)) .withEntityIdToSavePhoto(child.caseId()) .withMotherName(child.ec().wifeName()).withDOB(child.dateOfBirth()) .withMotherAge(child.ec().age()) .withFatherName(child.ec().husbandName()) .withVillage(child.ec().village()) .withOutOfArea(child.ec().isOutOfArea()).withEconomicStatus(child.ec() .getDetail(AllConstants.ECRegistrationFields.ECONOMIC_STATUS)) .withCaste( child.ec().getDetail(AllConstants.ECRegistrationFields.CASTE)) .withIsHighRisk(child.isHighRisk()).withPhotoPath(photoPath) .withECNumber(child.ec().ecNumber()).withAlerts(alerts) .withServicesProvided(servicesProvided); childrenClient.add(childClient); } sortByMotherName(childrenClient); return new Gson().toJson(childrenClient); } }); }
ChildSmartRegisterController { public String get() { return cache.get(CHILD_CLIENTS_LIST_CACHE_ENTRY_NAME, new CacheableData<String>() { @Override public String fetch() { List<Child> children = allBeneficiaries.allChildrenWithMotherAndEC(); List<ChildClient> childrenClient = new ArrayList<ChildClient>(); for (Child child : children) { String photoPath = isBlank(child.photoPath()) ? ( AllConstants.FEMALE_GENDER.equalsIgnoreCase(child.gender()) ? AllConstants.DEFAULT_GIRL_INFANT_IMAGE_PLACEHOLDER_PATH : AllConstants.DEFAULT_BOY_INFANT_IMAGE_PLACEHOLDER_PATH) : child.photoPath(); List<AlertDTO> alerts = getAlerts(child.caseId()); List<ServiceProvidedDTO> servicesProvided = getServicesProvided(child.caseId()); ChildClient childClient = new ChildClient(child.caseId(), child.gender(), child.getDetail(AllConstants.ChildRegistrationFields.WEIGHT), child.mother().thayiCardNumber()) .withName(child.getDetail(AllConstants.ChildRegistrationFields.NAME)) .withEntityIdToSavePhoto(child.caseId()) .withMotherName(child.ec().wifeName()).withDOB(child.dateOfBirth()) .withMotherAge(child.ec().age()) .withFatherName(child.ec().husbandName()) .withVillage(child.ec().village()) .withOutOfArea(child.ec().isOutOfArea()).withEconomicStatus(child.ec() .getDetail(AllConstants.ECRegistrationFields.ECONOMIC_STATUS)) .withCaste( child.ec().getDetail(AllConstants.ECRegistrationFields.CASTE)) .withIsHighRisk(child.isHighRisk()).withPhotoPath(photoPath) .withECNumber(child.ec().ecNumber()).withAlerts(alerts) .withServicesProvided(servicesProvided); childrenClient.add(childClient); } sortByMotherName(childrenClient); return new Gson().toJson(childrenClient); } }); } }
ChildSmartRegisterController { public String get() { return cache.get(CHILD_CLIENTS_LIST_CACHE_ENTRY_NAME, new CacheableData<String>() { @Override public String fetch() { List<Child> children = allBeneficiaries.allChildrenWithMotherAndEC(); List<ChildClient> childrenClient = new ArrayList<ChildClient>(); for (Child child : children) { String photoPath = isBlank(child.photoPath()) ? ( AllConstants.FEMALE_GENDER.equalsIgnoreCase(child.gender()) ? AllConstants.DEFAULT_GIRL_INFANT_IMAGE_PLACEHOLDER_PATH : AllConstants.DEFAULT_BOY_INFANT_IMAGE_PLACEHOLDER_PATH) : child.photoPath(); List<AlertDTO> alerts = getAlerts(child.caseId()); List<ServiceProvidedDTO> servicesProvided = getServicesProvided(child.caseId()); ChildClient childClient = new ChildClient(child.caseId(), child.gender(), child.getDetail(AllConstants.ChildRegistrationFields.WEIGHT), child.mother().thayiCardNumber()) .withName(child.getDetail(AllConstants.ChildRegistrationFields.NAME)) .withEntityIdToSavePhoto(child.caseId()) .withMotherName(child.ec().wifeName()).withDOB(child.dateOfBirth()) .withMotherAge(child.ec().age()) .withFatherName(child.ec().husbandName()) .withVillage(child.ec().village()) .withOutOfArea(child.ec().isOutOfArea()).withEconomicStatus(child.ec() .getDetail(AllConstants.ECRegistrationFields.ECONOMIC_STATUS)) .withCaste( child.ec().getDetail(AllConstants.ECRegistrationFields.CASTE)) .withIsHighRisk(child.isHighRisk()).withPhotoPath(photoPath) .withECNumber(child.ec().ecNumber()).withAlerts(alerts) .withServicesProvided(servicesProvided); childrenClient.add(childClient); } sortByMotherName(childrenClient); return new Gson().toJson(childrenClient); } }); } ChildSmartRegisterController(ServiceProvidedService serviceProvidedService, AlertService alertService, AllBeneficiaries allBeneficiaries, Cache<String> cache, Cache<SmartRegisterClients> smartRegisterCache); }
ChildSmartRegisterController { public String get() { return cache.get(CHILD_CLIENTS_LIST_CACHE_ENTRY_NAME, new CacheableData<String>() { @Override public String fetch() { List<Child> children = allBeneficiaries.allChildrenWithMotherAndEC(); List<ChildClient> childrenClient = new ArrayList<ChildClient>(); for (Child child : children) { String photoPath = isBlank(child.photoPath()) ? ( AllConstants.FEMALE_GENDER.equalsIgnoreCase(child.gender()) ? AllConstants.DEFAULT_GIRL_INFANT_IMAGE_PLACEHOLDER_PATH : AllConstants.DEFAULT_BOY_INFANT_IMAGE_PLACEHOLDER_PATH) : child.photoPath(); List<AlertDTO> alerts = getAlerts(child.caseId()); List<ServiceProvidedDTO> servicesProvided = getServicesProvided(child.caseId()); ChildClient childClient = new ChildClient(child.caseId(), child.gender(), child.getDetail(AllConstants.ChildRegistrationFields.WEIGHT), child.mother().thayiCardNumber()) .withName(child.getDetail(AllConstants.ChildRegistrationFields.NAME)) .withEntityIdToSavePhoto(child.caseId()) .withMotherName(child.ec().wifeName()).withDOB(child.dateOfBirth()) .withMotherAge(child.ec().age()) .withFatherName(child.ec().husbandName()) .withVillage(child.ec().village()) .withOutOfArea(child.ec().isOutOfArea()).withEconomicStatus(child.ec() .getDetail(AllConstants.ECRegistrationFields.ECONOMIC_STATUS)) .withCaste( child.ec().getDetail(AllConstants.ECRegistrationFields.CASTE)) .withIsHighRisk(child.isHighRisk()).withPhotoPath(photoPath) .withECNumber(child.ec().ecNumber()).withAlerts(alerts) .withServicesProvided(servicesProvided); childrenClient.add(childClient); } sortByMotherName(childrenClient); return new Gson().toJson(childrenClient); } }); } ChildSmartRegisterController(ServiceProvidedService serviceProvidedService, AlertService alertService, AllBeneficiaries allBeneficiaries, Cache<String> cache, Cache<SmartRegisterClients> smartRegisterCache); String get(); SmartRegisterClients getClients(); }
ChildSmartRegisterController { public String get() { return cache.get(CHILD_CLIENTS_LIST_CACHE_ENTRY_NAME, new CacheableData<String>() { @Override public String fetch() { List<Child> children = allBeneficiaries.allChildrenWithMotherAndEC(); List<ChildClient> childrenClient = new ArrayList<ChildClient>(); for (Child child : children) { String photoPath = isBlank(child.photoPath()) ? ( AllConstants.FEMALE_GENDER.equalsIgnoreCase(child.gender()) ? AllConstants.DEFAULT_GIRL_INFANT_IMAGE_PLACEHOLDER_PATH : AllConstants.DEFAULT_BOY_INFANT_IMAGE_PLACEHOLDER_PATH) : child.photoPath(); List<AlertDTO> alerts = getAlerts(child.caseId()); List<ServiceProvidedDTO> servicesProvided = getServicesProvided(child.caseId()); ChildClient childClient = new ChildClient(child.caseId(), child.gender(), child.getDetail(AllConstants.ChildRegistrationFields.WEIGHT), child.mother().thayiCardNumber()) .withName(child.getDetail(AllConstants.ChildRegistrationFields.NAME)) .withEntityIdToSavePhoto(child.caseId()) .withMotherName(child.ec().wifeName()).withDOB(child.dateOfBirth()) .withMotherAge(child.ec().age()) .withFatherName(child.ec().husbandName()) .withVillage(child.ec().village()) .withOutOfArea(child.ec().isOutOfArea()).withEconomicStatus(child.ec() .getDetail(AllConstants.ECRegistrationFields.ECONOMIC_STATUS)) .withCaste( child.ec().getDetail(AllConstants.ECRegistrationFields.CASTE)) .withIsHighRisk(child.isHighRisk()).withPhotoPath(photoPath) .withECNumber(child.ec().ecNumber()).withAlerts(alerts) .withServicesProvided(servicesProvided); childrenClient.add(childClient); } sortByMotherName(childrenClient); return new Gson().toJson(childrenClient); } }); } ChildSmartRegisterController(ServiceProvidedService serviceProvidedService, AlertService alertService, AllBeneficiaries allBeneficiaries, Cache<String> cache, Cache<SmartRegisterClients> smartRegisterCache); String get(); SmartRegisterClients getClients(); }
@Test public void shouldMapPNCToPNCClient() throws Exception { Map<String, String> ecDetails = EasyMap.create("wifeAge", "26") .put("caste", "others") .put("economicStatus", "apl") .map(); Map<String, String> childDetails = EasyMap.create("weight", "3") .put("name", "chinnu") .put("isChildHighRisk", "yes") .map(); EligibleCouple eligibleCouple = new EligibleCouple("ec id 1", "amma", "appa", "ec no 1", "chikkamagalur", null, ecDetails).asOutOfArea(); Mother mother = new Mother("mother id 1", "ec id 1", "thayi no 1", "2013-01-01").withDetails(emptyMap); Child child = new Child("child id 1", "mother id 1", "female", childDetails).withDateOfBirth("2013-01-01").withMother(mother).withEC(eligibleCouple); Mockito.when(allBeneficiaries.allChildrenWithMotherAndEC()).thenReturn(Arrays.asList(child)); ChildClient expectedPNCClient = new ChildClient("child id 1", "female", "3", "thayi no 1") .withEntityIdToSavePhoto("child id 1") .withName("chinnu") .withMotherName("amma") .withDOB("2013-01-01") .withMotherAge("26") .withFatherName("appa") .withVillage("chikkamagalur") .withOutOfArea(true) .withEconomicStatus("apl") .withCaste("others") .withIsHighRisk(true) .withPhotoPath("../../img/icons/[email protected]") .withEntityIdToSavePhoto("child id 1") .withECNumber("ec no 1") .withAlerts(Collections.<AlertDTO>emptyList()) .withServicesProvided(Collections.<ServiceProvidedDTO>emptyList()); String clients = controller.get(); List<ChildClient> actualClients = new Gson().fromJson(clients, new TypeToken<List<ChildClient>>() { }.getType()); Assert.assertEquals(Arrays.asList(expectedPNCClient), actualClients); }
public String get() { return cache.get(CHILD_CLIENTS_LIST_CACHE_ENTRY_NAME, new CacheableData<String>() { @Override public String fetch() { List<Child> children = allBeneficiaries.allChildrenWithMotherAndEC(); List<ChildClient> childrenClient = new ArrayList<ChildClient>(); for (Child child : children) { String photoPath = isBlank(child.photoPath()) ? ( AllConstants.FEMALE_GENDER.equalsIgnoreCase(child.gender()) ? AllConstants.DEFAULT_GIRL_INFANT_IMAGE_PLACEHOLDER_PATH : AllConstants.DEFAULT_BOY_INFANT_IMAGE_PLACEHOLDER_PATH) : child.photoPath(); List<AlertDTO> alerts = getAlerts(child.caseId()); List<ServiceProvidedDTO> servicesProvided = getServicesProvided(child.caseId()); ChildClient childClient = new ChildClient(child.caseId(), child.gender(), child.getDetail(AllConstants.ChildRegistrationFields.WEIGHT), child.mother().thayiCardNumber()) .withName(child.getDetail(AllConstants.ChildRegistrationFields.NAME)) .withEntityIdToSavePhoto(child.caseId()) .withMotherName(child.ec().wifeName()).withDOB(child.dateOfBirth()) .withMotherAge(child.ec().age()) .withFatherName(child.ec().husbandName()) .withVillage(child.ec().village()) .withOutOfArea(child.ec().isOutOfArea()).withEconomicStatus(child.ec() .getDetail(AllConstants.ECRegistrationFields.ECONOMIC_STATUS)) .withCaste( child.ec().getDetail(AllConstants.ECRegistrationFields.CASTE)) .withIsHighRisk(child.isHighRisk()).withPhotoPath(photoPath) .withECNumber(child.ec().ecNumber()).withAlerts(alerts) .withServicesProvided(servicesProvided); childrenClient.add(childClient); } sortByMotherName(childrenClient); return new Gson().toJson(childrenClient); } }); }
ChildSmartRegisterController { public String get() { return cache.get(CHILD_CLIENTS_LIST_CACHE_ENTRY_NAME, new CacheableData<String>() { @Override public String fetch() { List<Child> children = allBeneficiaries.allChildrenWithMotherAndEC(); List<ChildClient> childrenClient = new ArrayList<ChildClient>(); for (Child child : children) { String photoPath = isBlank(child.photoPath()) ? ( AllConstants.FEMALE_GENDER.equalsIgnoreCase(child.gender()) ? AllConstants.DEFAULT_GIRL_INFANT_IMAGE_PLACEHOLDER_PATH : AllConstants.DEFAULT_BOY_INFANT_IMAGE_PLACEHOLDER_PATH) : child.photoPath(); List<AlertDTO> alerts = getAlerts(child.caseId()); List<ServiceProvidedDTO> servicesProvided = getServicesProvided(child.caseId()); ChildClient childClient = new ChildClient(child.caseId(), child.gender(), child.getDetail(AllConstants.ChildRegistrationFields.WEIGHT), child.mother().thayiCardNumber()) .withName(child.getDetail(AllConstants.ChildRegistrationFields.NAME)) .withEntityIdToSavePhoto(child.caseId()) .withMotherName(child.ec().wifeName()).withDOB(child.dateOfBirth()) .withMotherAge(child.ec().age()) .withFatherName(child.ec().husbandName()) .withVillage(child.ec().village()) .withOutOfArea(child.ec().isOutOfArea()).withEconomicStatus(child.ec() .getDetail(AllConstants.ECRegistrationFields.ECONOMIC_STATUS)) .withCaste( child.ec().getDetail(AllConstants.ECRegistrationFields.CASTE)) .withIsHighRisk(child.isHighRisk()).withPhotoPath(photoPath) .withECNumber(child.ec().ecNumber()).withAlerts(alerts) .withServicesProvided(servicesProvided); childrenClient.add(childClient); } sortByMotherName(childrenClient); return new Gson().toJson(childrenClient); } }); } }
ChildSmartRegisterController { public String get() { return cache.get(CHILD_CLIENTS_LIST_CACHE_ENTRY_NAME, new CacheableData<String>() { @Override public String fetch() { List<Child> children = allBeneficiaries.allChildrenWithMotherAndEC(); List<ChildClient> childrenClient = new ArrayList<ChildClient>(); for (Child child : children) { String photoPath = isBlank(child.photoPath()) ? ( AllConstants.FEMALE_GENDER.equalsIgnoreCase(child.gender()) ? AllConstants.DEFAULT_GIRL_INFANT_IMAGE_PLACEHOLDER_PATH : AllConstants.DEFAULT_BOY_INFANT_IMAGE_PLACEHOLDER_PATH) : child.photoPath(); List<AlertDTO> alerts = getAlerts(child.caseId()); List<ServiceProvidedDTO> servicesProvided = getServicesProvided(child.caseId()); ChildClient childClient = new ChildClient(child.caseId(), child.gender(), child.getDetail(AllConstants.ChildRegistrationFields.WEIGHT), child.mother().thayiCardNumber()) .withName(child.getDetail(AllConstants.ChildRegistrationFields.NAME)) .withEntityIdToSavePhoto(child.caseId()) .withMotherName(child.ec().wifeName()).withDOB(child.dateOfBirth()) .withMotherAge(child.ec().age()) .withFatherName(child.ec().husbandName()) .withVillage(child.ec().village()) .withOutOfArea(child.ec().isOutOfArea()).withEconomicStatus(child.ec() .getDetail(AllConstants.ECRegistrationFields.ECONOMIC_STATUS)) .withCaste( child.ec().getDetail(AllConstants.ECRegistrationFields.CASTE)) .withIsHighRisk(child.isHighRisk()).withPhotoPath(photoPath) .withECNumber(child.ec().ecNumber()).withAlerts(alerts) .withServicesProvided(servicesProvided); childrenClient.add(childClient); } sortByMotherName(childrenClient); return new Gson().toJson(childrenClient); } }); } ChildSmartRegisterController(ServiceProvidedService serviceProvidedService, AlertService alertService, AllBeneficiaries allBeneficiaries, Cache<String> cache, Cache<SmartRegisterClients> smartRegisterCache); }
ChildSmartRegisterController { public String get() { return cache.get(CHILD_CLIENTS_LIST_CACHE_ENTRY_NAME, new CacheableData<String>() { @Override public String fetch() { List<Child> children = allBeneficiaries.allChildrenWithMotherAndEC(); List<ChildClient> childrenClient = new ArrayList<ChildClient>(); for (Child child : children) { String photoPath = isBlank(child.photoPath()) ? ( AllConstants.FEMALE_GENDER.equalsIgnoreCase(child.gender()) ? AllConstants.DEFAULT_GIRL_INFANT_IMAGE_PLACEHOLDER_PATH : AllConstants.DEFAULT_BOY_INFANT_IMAGE_PLACEHOLDER_PATH) : child.photoPath(); List<AlertDTO> alerts = getAlerts(child.caseId()); List<ServiceProvidedDTO> servicesProvided = getServicesProvided(child.caseId()); ChildClient childClient = new ChildClient(child.caseId(), child.gender(), child.getDetail(AllConstants.ChildRegistrationFields.WEIGHT), child.mother().thayiCardNumber()) .withName(child.getDetail(AllConstants.ChildRegistrationFields.NAME)) .withEntityIdToSavePhoto(child.caseId()) .withMotherName(child.ec().wifeName()).withDOB(child.dateOfBirth()) .withMotherAge(child.ec().age()) .withFatherName(child.ec().husbandName()) .withVillage(child.ec().village()) .withOutOfArea(child.ec().isOutOfArea()).withEconomicStatus(child.ec() .getDetail(AllConstants.ECRegistrationFields.ECONOMIC_STATUS)) .withCaste( child.ec().getDetail(AllConstants.ECRegistrationFields.CASTE)) .withIsHighRisk(child.isHighRisk()).withPhotoPath(photoPath) .withECNumber(child.ec().ecNumber()).withAlerts(alerts) .withServicesProvided(servicesProvided); childrenClient.add(childClient); } sortByMotherName(childrenClient); return new Gson().toJson(childrenClient); } }); } ChildSmartRegisterController(ServiceProvidedService serviceProvidedService, AlertService alertService, AllBeneficiaries allBeneficiaries, Cache<String> cache, Cache<SmartRegisterClients> smartRegisterCache); String get(); SmartRegisterClients getClients(); }
ChildSmartRegisterController { public String get() { return cache.get(CHILD_CLIENTS_LIST_CACHE_ENTRY_NAME, new CacheableData<String>() { @Override public String fetch() { List<Child> children = allBeneficiaries.allChildrenWithMotherAndEC(); List<ChildClient> childrenClient = new ArrayList<ChildClient>(); for (Child child : children) { String photoPath = isBlank(child.photoPath()) ? ( AllConstants.FEMALE_GENDER.equalsIgnoreCase(child.gender()) ? AllConstants.DEFAULT_GIRL_INFANT_IMAGE_PLACEHOLDER_PATH : AllConstants.DEFAULT_BOY_INFANT_IMAGE_PLACEHOLDER_PATH) : child.photoPath(); List<AlertDTO> alerts = getAlerts(child.caseId()); List<ServiceProvidedDTO> servicesProvided = getServicesProvided(child.caseId()); ChildClient childClient = new ChildClient(child.caseId(), child.gender(), child.getDetail(AllConstants.ChildRegistrationFields.WEIGHT), child.mother().thayiCardNumber()) .withName(child.getDetail(AllConstants.ChildRegistrationFields.NAME)) .withEntityIdToSavePhoto(child.caseId()) .withMotherName(child.ec().wifeName()).withDOB(child.dateOfBirth()) .withMotherAge(child.ec().age()) .withFatherName(child.ec().husbandName()) .withVillage(child.ec().village()) .withOutOfArea(child.ec().isOutOfArea()).withEconomicStatus(child.ec() .getDetail(AllConstants.ECRegistrationFields.ECONOMIC_STATUS)) .withCaste( child.ec().getDetail(AllConstants.ECRegistrationFields.CASTE)) .withIsHighRisk(child.isHighRisk()).withPhotoPath(photoPath) .withECNumber(child.ec().ecNumber()).withAlerts(alerts) .withServicesProvided(servicesProvided); childrenClient.add(childClient); } sortByMotherName(childrenClient); return new Gson().toJson(childrenClient); } }); } ChildSmartRegisterController(ServiceProvidedService serviceProvidedService, AlertService alertService, AllBeneficiaries allBeneficiaries, Cache<String> cache, Cache<SmartRegisterClients> smartRegisterCache); String get(); SmartRegisterClients getClients(); }
@Test public void shouldCreateChildClientsWithAlerts() throws Exception { EligibleCouple eligibleCouple = new EligibleCouple("ec id 1", "amma", "appa", "ec no 1", "chikkamagalur", null, emptyMap).asOutOfArea(); Mother mother = new Mother("mother id 1", "ec id 1", "thayi no 1", "2013-01-01").withDetails(emptyMap); Child child = new Child("child id 1", "mother id 1", "male", emptyMap).withDateOfBirth("2013-01-01").withMother(mother).withEC(eligibleCouple); Alert bcgAlert = new Alert("child id 1", "BCG", "bcg", AlertStatus.normal, "2013-01-01", "2013-02-01"); Mockito.when(allBeneficiaries.allChildrenWithMotherAndEC()).thenReturn(Arrays.asList(child)); Mockito.when(alertService.findByEntityIdAndAlertNames("child id 1", CHILD_ALERTS)).thenReturn(Arrays.asList(bcgAlert)); String clients = controller.get(); List<ChildClient> actualClients = new Gson().fromJson(clients, new TypeToken<List<ChildClient>>() { }.getType()); Mockito.verify(alertService).findByEntityIdAndAlertNames("child id 1", CHILD_ALERTS); AlertDTO expectedAlertDto = new AlertDTO("bcg", "normal", "2013-01-01"); ChildClient expectedPNCClient = new ChildClient("child id 1", "male", null, "thayi no 1") .withEntityIdToSavePhoto("child id 1") .withMotherName("amma") .withDOB("2013-01-01") .withFatherName("appa") .withVillage("chikkamagalur") .withOutOfArea(true) .withPhotoPath("../../img/icons/[email protected]") .withEntityIdToSavePhoto("child id 1") .withECNumber("ec no 1") .withAlerts(Arrays.asList(expectedAlertDto)) .withServicesProvided(Collections.<ServiceProvidedDTO>emptyList()); Assert.assertEquals(Arrays.asList(expectedPNCClient), actualClients); }
public String get() { return cache.get(CHILD_CLIENTS_LIST_CACHE_ENTRY_NAME, new CacheableData<String>() { @Override public String fetch() { List<Child> children = allBeneficiaries.allChildrenWithMotherAndEC(); List<ChildClient> childrenClient = new ArrayList<ChildClient>(); for (Child child : children) { String photoPath = isBlank(child.photoPath()) ? ( AllConstants.FEMALE_GENDER.equalsIgnoreCase(child.gender()) ? AllConstants.DEFAULT_GIRL_INFANT_IMAGE_PLACEHOLDER_PATH : AllConstants.DEFAULT_BOY_INFANT_IMAGE_PLACEHOLDER_PATH) : child.photoPath(); List<AlertDTO> alerts = getAlerts(child.caseId()); List<ServiceProvidedDTO> servicesProvided = getServicesProvided(child.caseId()); ChildClient childClient = new ChildClient(child.caseId(), child.gender(), child.getDetail(AllConstants.ChildRegistrationFields.WEIGHT), child.mother().thayiCardNumber()) .withName(child.getDetail(AllConstants.ChildRegistrationFields.NAME)) .withEntityIdToSavePhoto(child.caseId()) .withMotherName(child.ec().wifeName()).withDOB(child.dateOfBirth()) .withMotherAge(child.ec().age()) .withFatherName(child.ec().husbandName()) .withVillage(child.ec().village()) .withOutOfArea(child.ec().isOutOfArea()).withEconomicStatus(child.ec() .getDetail(AllConstants.ECRegistrationFields.ECONOMIC_STATUS)) .withCaste( child.ec().getDetail(AllConstants.ECRegistrationFields.CASTE)) .withIsHighRisk(child.isHighRisk()).withPhotoPath(photoPath) .withECNumber(child.ec().ecNumber()).withAlerts(alerts) .withServicesProvided(servicesProvided); childrenClient.add(childClient); } sortByMotherName(childrenClient); return new Gson().toJson(childrenClient); } }); }
ChildSmartRegisterController { public String get() { return cache.get(CHILD_CLIENTS_LIST_CACHE_ENTRY_NAME, new CacheableData<String>() { @Override public String fetch() { List<Child> children = allBeneficiaries.allChildrenWithMotherAndEC(); List<ChildClient> childrenClient = new ArrayList<ChildClient>(); for (Child child : children) { String photoPath = isBlank(child.photoPath()) ? ( AllConstants.FEMALE_GENDER.equalsIgnoreCase(child.gender()) ? AllConstants.DEFAULT_GIRL_INFANT_IMAGE_PLACEHOLDER_PATH : AllConstants.DEFAULT_BOY_INFANT_IMAGE_PLACEHOLDER_PATH) : child.photoPath(); List<AlertDTO> alerts = getAlerts(child.caseId()); List<ServiceProvidedDTO> servicesProvided = getServicesProvided(child.caseId()); ChildClient childClient = new ChildClient(child.caseId(), child.gender(), child.getDetail(AllConstants.ChildRegistrationFields.WEIGHT), child.mother().thayiCardNumber()) .withName(child.getDetail(AllConstants.ChildRegistrationFields.NAME)) .withEntityIdToSavePhoto(child.caseId()) .withMotherName(child.ec().wifeName()).withDOB(child.dateOfBirth()) .withMotherAge(child.ec().age()) .withFatherName(child.ec().husbandName()) .withVillage(child.ec().village()) .withOutOfArea(child.ec().isOutOfArea()).withEconomicStatus(child.ec() .getDetail(AllConstants.ECRegistrationFields.ECONOMIC_STATUS)) .withCaste( child.ec().getDetail(AllConstants.ECRegistrationFields.CASTE)) .withIsHighRisk(child.isHighRisk()).withPhotoPath(photoPath) .withECNumber(child.ec().ecNumber()).withAlerts(alerts) .withServicesProvided(servicesProvided); childrenClient.add(childClient); } sortByMotherName(childrenClient); return new Gson().toJson(childrenClient); } }); } }
ChildSmartRegisterController { public String get() { return cache.get(CHILD_CLIENTS_LIST_CACHE_ENTRY_NAME, new CacheableData<String>() { @Override public String fetch() { List<Child> children = allBeneficiaries.allChildrenWithMotherAndEC(); List<ChildClient> childrenClient = new ArrayList<ChildClient>(); for (Child child : children) { String photoPath = isBlank(child.photoPath()) ? ( AllConstants.FEMALE_GENDER.equalsIgnoreCase(child.gender()) ? AllConstants.DEFAULT_GIRL_INFANT_IMAGE_PLACEHOLDER_PATH : AllConstants.DEFAULT_BOY_INFANT_IMAGE_PLACEHOLDER_PATH) : child.photoPath(); List<AlertDTO> alerts = getAlerts(child.caseId()); List<ServiceProvidedDTO> servicesProvided = getServicesProvided(child.caseId()); ChildClient childClient = new ChildClient(child.caseId(), child.gender(), child.getDetail(AllConstants.ChildRegistrationFields.WEIGHT), child.mother().thayiCardNumber()) .withName(child.getDetail(AllConstants.ChildRegistrationFields.NAME)) .withEntityIdToSavePhoto(child.caseId()) .withMotherName(child.ec().wifeName()).withDOB(child.dateOfBirth()) .withMotherAge(child.ec().age()) .withFatherName(child.ec().husbandName()) .withVillage(child.ec().village()) .withOutOfArea(child.ec().isOutOfArea()).withEconomicStatus(child.ec() .getDetail(AllConstants.ECRegistrationFields.ECONOMIC_STATUS)) .withCaste( child.ec().getDetail(AllConstants.ECRegistrationFields.CASTE)) .withIsHighRisk(child.isHighRisk()).withPhotoPath(photoPath) .withECNumber(child.ec().ecNumber()).withAlerts(alerts) .withServicesProvided(servicesProvided); childrenClient.add(childClient); } sortByMotherName(childrenClient); return new Gson().toJson(childrenClient); } }); } ChildSmartRegisterController(ServiceProvidedService serviceProvidedService, AlertService alertService, AllBeneficiaries allBeneficiaries, Cache<String> cache, Cache<SmartRegisterClients> smartRegisterCache); }
ChildSmartRegisterController { public String get() { return cache.get(CHILD_CLIENTS_LIST_CACHE_ENTRY_NAME, new CacheableData<String>() { @Override public String fetch() { List<Child> children = allBeneficiaries.allChildrenWithMotherAndEC(); List<ChildClient> childrenClient = new ArrayList<ChildClient>(); for (Child child : children) { String photoPath = isBlank(child.photoPath()) ? ( AllConstants.FEMALE_GENDER.equalsIgnoreCase(child.gender()) ? AllConstants.DEFAULT_GIRL_INFANT_IMAGE_PLACEHOLDER_PATH : AllConstants.DEFAULT_BOY_INFANT_IMAGE_PLACEHOLDER_PATH) : child.photoPath(); List<AlertDTO> alerts = getAlerts(child.caseId()); List<ServiceProvidedDTO> servicesProvided = getServicesProvided(child.caseId()); ChildClient childClient = new ChildClient(child.caseId(), child.gender(), child.getDetail(AllConstants.ChildRegistrationFields.WEIGHT), child.mother().thayiCardNumber()) .withName(child.getDetail(AllConstants.ChildRegistrationFields.NAME)) .withEntityIdToSavePhoto(child.caseId()) .withMotherName(child.ec().wifeName()).withDOB(child.dateOfBirth()) .withMotherAge(child.ec().age()) .withFatherName(child.ec().husbandName()) .withVillage(child.ec().village()) .withOutOfArea(child.ec().isOutOfArea()).withEconomicStatus(child.ec() .getDetail(AllConstants.ECRegistrationFields.ECONOMIC_STATUS)) .withCaste( child.ec().getDetail(AllConstants.ECRegistrationFields.CASTE)) .withIsHighRisk(child.isHighRisk()).withPhotoPath(photoPath) .withECNumber(child.ec().ecNumber()).withAlerts(alerts) .withServicesProvided(servicesProvided); childrenClient.add(childClient); } sortByMotherName(childrenClient); return new Gson().toJson(childrenClient); } }); } ChildSmartRegisterController(ServiceProvidedService serviceProvidedService, AlertService alertService, AllBeneficiaries allBeneficiaries, Cache<String> cache, Cache<SmartRegisterClients> smartRegisterCache); String get(); SmartRegisterClients getClients(); }
ChildSmartRegisterController { public String get() { return cache.get(CHILD_CLIENTS_LIST_CACHE_ENTRY_NAME, new CacheableData<String>() { @Override public String fetch() { List<Child> children = allBeneficiaries.allChildrenWithMotherAndEC(); List<ChildClient> childrenClient = new ArrayList<ChildClient>(); for (Child child : children) { String photoPath = isBlank(child.photoPath()) ? ( AllConstants.FEMALE_GENDER.equalsIgnoreCase(child.gender()) ? AllConstants.DEFAULT_GIRL_INFANT_IMAGE_PLACEHOLDER_PATH : AllConstants.DEFAULT_BOY_INFANT_IMAGE_PLACEHOLDER_PATH) : child.photoPath(); List<AlertDTO> alerts = getAlerts(child.caseId()); List<ServiceProvidedDTO> servicesProvided = getServicesProvided(child.caseId()); ChildClient childClient = new ChildClient(child.caseId(), child.gender(), child.getDetail(AllConstants.ChildRegistrationFields.WEIGHT), child.mother().thayiCardNumber()) .withName(child.getDetail(AllConstants.ChildRegistrationFields.NAME)) .withEntityIdToSavePhoto(child.caseId()) .withMotherName(child.ec().wifeName()).withDOB(child.dateOfBirth()) .withMotherAge(child.ec().age()) .withFatherName(child.ec().husbandName()) .withVillage(child.ec().village()) .withOutOfArea(child.ec().isOutOfArea()).withEconomicStatus(child.ec() .getDetail(AllConstants.ECRegistrationFields.ECONOMIC_STATUS)) .withCaste( child.ec().getDetail(AllConstants.ECRegistrationFields.CASTE)) .withIsHighRisk(child.isHighRisk()).withPhotoPath(photoPath) .withECNumber(child.ec().ecNumber()).withAlerts(alerts) .withServicesProvided(servicesProvided); childrenClient.add(childClient); } sortByMotherName(childrenClient); return new Gson().toJson(childrenClient); } }); } ChildSmartRegisterController(ServiceProvidedService serviceProvidedService, AlertService alertService, AllBeneficiaries allBeneficiaries, Cache<String> cache, Cache<SmartRegisterClients> smartRegisterCache); String get(); SmartRegisterClients getClients(); }
@Test public void shouldCreateChildClientsWithServicesProvided() throws Exception { EligibleCouple eligibleCouple = new EligibleCouple("ec id 1", "amma", "appa", "ec no 1", "chikkamagalur", null, emptyMap).asOutOfArea(); Mother mother = new Mother("mother id 1", "ec id 1", "thayi no 1", "2013-01-01").withDetails(emptyMap); Child child = new Child("child id 1", "mother id 1", "male", emptyMap).withDateOfBirth("2013-01-01").withMother(mother).withEC(eligibleCouple); Mockito.when(allBeneficiaries.allChildrenWithMotherAndEC()).thenReturn(Arrays.asList(child)); Mockito.when(alertService.findByEntityIdAndAlertNames("child id 1", CHILD_ALERTS)).thenReturn(Collections.<Alert>emptyList()); Mockito.when(serviceProvidedService.findByEntityIdAndServiceNames("child id 1", CHILD_SERVICES)) .thenReturn(Arrays.asList(new ServiceProvided("entity id 1", "bcg", "2013-01-01", null))); String clients = controller.get(); List<ChildClient> actualClients = new Gson().fromJson(clients, new TypeToken<List<ChildClient>>() { }.getType()); Mockito.verify(serviceProvidedService).findByEntityIdAndServiceNames("child id 1", CHILD_SERVICES); List<ServiceProvidedDTO> expectedServicesProvided = Arrays.asList(new ServiceProvidedDTO("bcg", "2013-01-01", null)); ChildClient expectedPNCClient = createChildClient("child id 1", "thayi no 1", "amma", "ec no 1").withServicesProvided(expectedServicesProvided); Assert.assertEquals(Arrays.asList(expectedPNCClient), actualClients); }
public String get() { return cache.get(CHILD_CLIENTS_LIST_CACHE_ENTRY_NAME, new CacheableData<String>() { @Override public String fetch() { List<Child> children = allBeneficiaries.allChildrenWithMotherAndEC(); List<ChildClient> childrenClient = new ArrayList<ChildClient>(); for (Child child : children) { String photoPath = isBlank(child.photoPath()) ? ( AllConstants.FEMALE_GENDER.equalsIgnoreCase(child.gender()) ? AllConstants.DEFAULT_GIRL_INFANT_IMAGE_PLACEHOLDER_PATH : AllConstants.DEFAULT_BOY_INFANT_IMAGE_PLACEHOLDER_PATH) : child.photoPath(); List<AlertDTO> alerts = getAlerts(child.caseId()); List<ServiceProvidedDTO> servicesProvided = getServicesProvided(child.caseId()); ChildClient childClient = new ChildClient(child.caseId(), child.gender(), child.getDetail(AllConstants.ChildRegistrationFields.WEIGHT), child.mother().thayiCardNumber()) .withName(child.getDetail(AllConstants.ChildRegistrationFields.NAME)) .withEntityIdToSavePhoto(child.caseId()) .withMotherName(child.ec().wifeName()).withDOB(child.dateOfBirth()) .withMotherAge(child.ec().age()) .withFatherName(child.ec().husbandName()) .withVillage(child.ec().village()) .withOutOfArea(child.ec().isOutOfArea()).withEconomicStatus(child.ec() .getDetail(AllConstants.ECRegistrationFields.ECONOMIC_STATUS)) .withCaste( child.ec().getDetail(AllConstants.ECRegistrationFields.CASTE)) .withIsHighRisk(child.isHighRisk()).withPhotoPath(photoPath) .withECNumber(child.ec().ecNumber()).withAlerts(alerts) .withServicesProvided(servicesProvided); childrenClient.add(childClient); } sortByMotherName(childrenClient); return new Gson().toJson(childrenClient); } }); }
ChildSmartRegisterController { public String get() { return cache.get(CHILD_CLIENTS_LIST_CACHE_ENTRY_NAME, new CacheableData<String>() { @Override public String fetch() { List<Child> children = allBeneficiaries.allChildrenWithMotherAndEC(); List<ChildClient> childrenClient = new ArrayList<ChildClient>(); for (Child child : children) { String photoPath = isBlank(child.photoPath()) ? ( AllConstants.FEMALE_GENDER.equalsIgnoreCase(child.gender()) ? AllConstants.DEFAULT_GIRL_INFANT_IMAGE_PLACEHOLDER_PATH : AllConstants.DEFAULT_BOY_INFANT_IMAGE_PLACEHOLDER_PATH) : child.photoPath(); List<AlertDTO> alerts = getAlerts(child.caseId()); List<ServiceProvidedDTO> servicesProvided = getServicesProvided(child.caseId()); ChildClient childClient = new ChildClient(child.caseId(), child.gender(), child.getDetail(AllConstants.ChildRegistrationFields.WEIGHT), child.mother().thayiCardNumber()) .withName(child.getDetail(AllConstants.ChildRegistrationFields.NAME)) .withEntityIdToSavePhoto(child.caseId()) .withMotherName(child.ec().wifeName()).withDOB(child.dateOfBirth()) .withMotherAge(child.ec().age()) .withFatherName(child.ec().husbandName()) .withVillage(child.ec().village()) .withOutOfArea(child.ec().isOutOfArea()).withEconomicStatus(child.ec() .getDetail(AllConstants.ECRegistrationFields.ECONOMIC_STATUS)) .withCaste( child.ec().getDetail(AllConstants.ECRegistrationFields.CASTE)) .withIsHighRisk(child.isHighRisk()).withPhotoPath(photoPath) .withECNumber(child.ec().ecNumber()).withAlerts(alerts) .withServicesProvided(servicesProvided); childrenClient.add(childClient); } sortByMotherName(childrenClient); return new Gson().toJson(childrenClient); } }); } }
ChildSmartRegisterController { public String get() { return cache.get(CHILD_CLIENTS_LIST_CACHE_ENTRY_NAME, new CacheableData<String>() { @Override public String fetch() { List<Child> children = allBeneficiaries.allChildrenWithMotherAndEC(); List<ChildClient> childrenClient = new ArrayList<ChildClient>(); for (Child child : children) { String photoPath = isBlank(child.photoPath()) ? ( AllConstants.FEMALE_GENDER.equalsIgnoreCase(child.gender()) ? AllConstants.DEFAULT_GIRL_INFANT_IMAGE_PLACEHOLDER_PATH : AllConstants.DEFAULT_BOY_INFANT_IMAGE_PLACEHOLDER_PATH) : child.photoPath(); List<AlertDTO> alerts = getAlerts(child.caseId()); List<ServiceProvidedDTO> servicesProvided = getServicesProvided(child.caseId()); ChildClient childClient = new ChildClient(child.caseId(), child.gender(), child.getDetail(AllConstants.ChildRegistrationFields.WEIGHT), child.mother().thayiCardNumber()) .withName(child.getDetail(AllConstants.ChildRegistrationFields.NAME)) .withEntityIdToSavePhoto(child.caseId()) .withMotherName(child.ec().wifeName()).withDOB(child.dateOfBirth()) .withMotherAge(child.ec().age()) .withFatherName(child.ec().husbandName()) .withVillage(child.ec().village()) .withOutOfArea(child.ec().isOutOfArea()).withEconomicStatus(child.ec() .getDetail(AllConstants.ECRegistrationFields.ECONOMIC_STATUS)) .withCaste( child.ec().getDetail(AllConstants.ECRegistrationFields.CASTE)) .withIsHighRisk(child.isHighRisk()).withPhotoPath(photoPath) .withECNumber(child.ec().ecNumber()).withAlerts(alerts) .withServicesProvided(servicesProvided); childrenClient.add(childClient); } sortByMotherName(childrenClient); return new Gson().toJson(childrenClient); } }); } ChildSmartRegisterController(ServiceProvidedService serviceProvidedService, AlertService alertService, AllBeneficiaries allBeneficiaries, Cache<String> cache, Cache<SmartRegisterClients> smartRegisterCache); }
ChildSmartRegisterController { public String get() { return cache.get(CHILD_CLIENTS_LIST_CACHE_ENTRY_NAME, new CacheableData<String>() { @Override public String fetch() { List<Child> children = allBeneficiaries.allChildrenWithMotherAndEC(); List<ChildClient> childrenClient = new ArrayList<ChildClient>(); for (Child child : children) { String photoPath = isBlank(child.photoPath()) ? ( AllConstants.FEMALE_GENDER.equalsIgnoreCase(child.gender()) ? AllConstants.DEFAULT_GIRL_INFANT_IMAGE_PLACEHOLDER_PATH : AllConstants.DEFAULT_BOY_INFANT_IMAGE_PLACEHOLDER_PATH) : child.photoPath(); List<AlertDTO> alerts = getAlerts(child.caseId()); List<ServiceProvidedDTO> servicesProvided = getServicesProvided(child.caseId()); ChildClient childClient = new ChildClient(child.caseId(), child.gender(), child.getDetail(AllConstants.ChildRegistrationFields.WEIGHT), child.mother().thayiCardNumber()) .withName(child.getDetail(AllConstants.ChildRegistrationFields.NAME)) .withEntityIdToSavePhoto(child.caseId()) .withMotherName(child.ec().wifeName()).withDOB(child.dateOfBirth()) .withMotherAge(child.ec().age()) .withFatherName(child.ec().husbandName()) .withVillage(child.ec().village()) .withOutOfArea(child.ec().isOutOfArea()).withEconomicStatus(child.ec() .getDetail(AllConstants.ECRegistrationFields.ECONOMIC_STATUS)) .withCaste( child.ec().getDetail(AllConstants.ECRegistrationFields.CASTE)) .withIsHighRisk(child.isHighRisk()).withPhotoPath(photoPath) .withECNumber(child.ec().ecNumber()).withAlerts(alerts) .withServicesProvided(servicesProvided); childrenClient.add(childClient); } sortByMotherName(childrenClient); return new Gson().toJson(childrenClient); } }); } ChildSmartRegisterController(ServiceProvidedService serviceProvidedService, AlertService alertService, AllBeneficiaries allBeneficiaries, Cache<String> cache, Cache<SmartRegisterClients> smartRegisterCache); String get(); SmartRegisterClients getClients(); }
ChildSmartRegisterController { public String get() { return cache.get(CHILD_CLIENTS_LIST_CACHE_ENTRY_NAME, new CacheableData<String>() { @Override public String fetch() { List<Child> children = allBeneficiaries.allChildrenWithMotherAndEC(); List<ChildClient> childrenClient = new ArrayList<ChildClient>(); for (Child child : children) { String photoPath = isBlank(child.photoPath()) ? ( AllConstants.FEMALE_GENDER.equalsIgnoreCase(child.gender()) ? AllConstants.DEFAULT_GIRL_INFANT_IMAGE_PLACEHOLDER_PATH : AllConstants.DEFAULT_BOY_INFANT_IMAGE_PLACEHOLDER_PATH) : child.photoPath(); List<AlertDTO> alerts = getAlerts(child.caseId()); List<ServiceProvidedDTO> servicesProvided = getServicesProvided(child.caseId()); ChildClient childClient = new ChildClient(child.caseId(), child.gender(), child.getDetail(AllConstants.ChildRegistrationFields.WEIGHT), child.mother().thayiCardNumber()) .withName(child.getDetail(AllConstants.ChildRegistrationFields.NAME)) .withEntityIdToSavePhoto(child.caseId()) .withMotherName(child.ec().wifeName()).withDOB(child.dateOfBirth()) .withMotherAge(child.ec().age()) .withFatherName(child.ec().husbandName()) .withVillage(child.ec().village()) .withOutOfArea(child.ec().isOutOfArea()).withEconomicStatus(child.ec() .getDetail(AllConstants.ECRegistrationFields.ECONOMIC_STATUS)) .withCaste( child.ec().getDetail(AllConstants.ECRegistrationFields.CASTE)) .withIsHighRisk(child.isHighRisk()).withPhotoPath(photoPath) .withECNumber(child.ec().ecNumber()).withAlerts(alerts) .withServicesProvided(servicesProvided); childrenClient.add(childClient); } sortByMotherName(childrenClient); return new Gson().toJson(childrenClient); } }); } ChildSmartRegisterController(ServiceProvidedService serviceProvidedService, AlertService alertService, AllBeneficiaries allBeneficiaries, Cache<String> cache, Cache<SmartRegisterClients> smartRegisterCache); String get(); SmartRegisterClients getClients(); }
@Test public void shouldGetANCDetailsAsJSON() { TimelineEvent pregnancyEvent = TimelineEvent.forStartOfPregnancyForEC(caseId, "TC 1", "2011-10-21", "2011-10-21"); TimelineEvent fpEvent = TimelineEvent.forChangeOfFPMethod(caseId, "condom", "iud", "2011-12-22"); TimelineEvent eventVeryCloseToCurrentDate = TimelineEvent.forChangeOfFPMethod(caseId, "iud", "condom", "2012-07-29"); HashMap<String, String> details = new HashMap<String, String>(); details.put("ashaName", "Shiwani"); details.put("isHighPriority", "1"); Mockito.when(allEligibleCouples.findByCaseID(caseId)).thenReturn(new EligibleCouple("EC CASE 1", "Woman 1", "Husband 1", "EC Number 1", "Village 1", "Subcenter 1", details)); Mockito.when(allTimelineEvents.forCase(caseId)).thenReturn(Arrays.asList(pregnancyEvent, fpEvent, eventVeryCloseToCurrentDate)); ECDetail expectedDetail = new ECDetail(caseId, "Village 1", "Subcenter 1", "EC Number 1", true, null, null, new ArrayList<Child>(), new CoupleDetails("Woman 1", "Husband 1", "EC Number 1", false), details) .addTimelineEvents(Arrays.asList(eventFor(eventVeryCloseToCurrentDate, "29-07-2012"), eventFor(fpEvent, "22-12-2011"), eventFor(pregnancyEvent, "21-10-2011"))); String actualJson = controller.get(); ECDetail actualDetail = new Gson().fromJson(actualJson, ECDetail.class); Assert.assertEquals(expectedDetail, actualDetail); }
@JavascriptInterface public String get() { EligibleCouple eligibleCouple = allEligibleCouples.findByCaseID(caseId); ECDetail ecContext = new ECDetail(caseId, eligibleCouple.village(), eligibleCouple.subCenter(), eligibleCouple.ecNumber(), eligibleCouple.isHighPriority(), null, eligibleCouple.photoPath(), new ArrayList<Child>(), new CoupleDetails(eligibleCouple.wifeName(), eligibleCouple.husbandName(), eligibleCouple.ecNumber(), eligibleCouple.isOutOfArea()), eligibleCouple.details()). addTimelineEvents(getEvents()); return new Gson().toJson(ecContext); }
EligibleCoupleDetailController { @JavascriptInterface public String get() { EligibleCouple eligibleCouple = allEligibleCouples.findByCaseID(caseId); ECDetail ecContext = new ECDetail(caseId, eligibleCouple.village(), eligibleCouple.subCenter(), eligibleCouple.ecNumber(), eligibleCouple.isHighPriority(), null, eligibleCouple.photoPath(), new ArrayList<Child>(), new CoupleDetails(eligibleCouple.wifeName(), eligibleCouple.husbandName(), eligibleCouple.ecNumber(), eligibleCouple.isOutOfArea()), eligibleCouple.details()). addTimelineEvents(getEvents()); return new Gson().toJson(ecContext); } }
EligibleCoupleDetailController { @JavascriptInterface public String get() { EligibleCouple eligibleCouple = allEligibleCouples.findByCaseID(caseId); ECDetail ecContext = new ECDetail(caseId, eligibleCouple.village(), eligibleCouple.subCenter(), eligibleCouple.ecNumber(), eligibleCouple.isHighPriority(), null, eligibleCouple.photoPath(), new ArrayList<Child>(), new CoupleDetails(eligibleCouple.wifeName(), eligibleCouple.husbandName(), eligibleCouple.ecNumber(), eligibleCouple.isOutOfArea()), eligibleCouple.details()). addTimelineEvents(getEvents()); return new Gson().toJson(ecContext); } EligibleCoupleDetailController(Context context, String caseId, AllEligibleCouples allEligibleCouples, AllTimelineEvents allTimelineEvents); }
EligibleCoupleDetailController { @JavascriptInterface public String get() { EligibleCouple eligibleCouple = allEligibleCouples.findByCaseID(caseId); ECDetail ecContext = new ECDetail(caseId, eligibleCouple.village(), eligibleCouple.subCenter(), eligibleCouple.ecNumber(), eligibleCouple.isHighPriority(), null, eligibleCouple.photoPath(), new ArrayList<Child>(), new CoupleDetails(eligibleCouple.wifeName(), eligibleCouple.husbandName(), eligibleCouple.ecNumber(), eligibleCouple.isOutOfArea()), eligibleCouple.details()). addTimelineEvents(getEvents()); return new Gson().toJson(ecContext); } EligibleCoupleDetailController(Context context, String caseId, AllEligibleCouples allEligibleCouples, AllTimelineEvents allTimelineEvents); @JavascriptInterface String get(); @JavascriptInterface void takePhoto(); }
EligibleCoupleDetailController { @JavascriptInterface public String get() { EligibleCouple eligibleCouple = allEligibleCouples.findByCaseID(caseId); ECDetail ecContext = new ECDetail(caseId, eligibleCouple.village(), eligibleCouple.subCenter(), eligibleCouple.ecNumber(), eligibleCouple.isHighPriority(), null, eligibleCouple.photoPath(), new ArrayList<Child>(), new CoupleDetails(eligibleCouple.wifeName(), eligibleCouple.husbandName(), eligibleCouple.ecNumber(), eligibleCouple.isOutOfArea()), eligibleCouple.details()). addTimelineEvents(getEvents()); return new Gson().toJson(ecContext); } EligibleCoupleDetailController(Context context, String caseId, AllEligibleCouples allEligibleCouples, AllTimelineEvents allTimelineEvents); @JavascriptInterface String get(); @JavascriptInterface void takePhoto(); }
@Test public void shouldLoadVillages() throws Exception { List<Village> expectedVillages = Arrays.asList(new Village("village1"), new Village("village2")); Mockito.when(allEligibleCouples.villages()).thenReturn(Arrays.asList("village1", "village2")); String villages = controller.villages(); List<Village> actualVillages = new Gson().fromJson(villages, new TypeToken<List<Village>>() { }.getType()); Assert.assertEquals(actualVillages, expectedVillages); }
public String villages() { return cache.get(VILLAGE_LIST, new CacheableData<String>() { @Override public String fetch() { List<Village> villagesList = new ArrayList<Village>(); List<String> villages = allEligibleCouples.villages(); for (String village : villages) { villagesList.add(new Village(village)); } return new Gson().toJson(villagesList); } }); }
VillageController { public String villages() { return cache.get(VILLAGE_LIST, new CacheableData<String>() { @Override public String fetch() { List<Village> villagesList = new ArrayList<Village>(); List<String> villages = allEligibleCouples.villages(); for (String village : villages) { villagesList.add(new Village(village)); } return new Gson().toJson(villagesList); } }); } }
VillageController { public String villages() { return cache.get(VILLAGE_LIST, new CacheableData<String>() { @Override public String fetch() { List<Village> villagesList = new ArrayList<Village>(); List<String> villages = allEligibleCouples.villages(); for (String village : villages) { villagesList.add(new Village(village)); } return new Gson().toJson(villagesList); } }); } VillageController(AllEligibleCouples allEligibleCouples, Cache<String> cache, Cache<Villages> villagesCache); }
VillageController { public String villages() { return cache.get(VILLAGE_LIST, new CacheableData<String>() { @Override public String fetch() { List<Village> villagesList = new ArrayList<Village>(); List<String> villages = allEligibleCouples.villages(); for (String village : villages) { villagesList.add(new Village(village)); } return new Gson().toJson(villagesList); } }); } VillageController(AllEligibleCouples allEligibleCouples, Cache<String> cache, Cache<Villages> villagesCache); String villages(); Villages getVillages(); }
VillageController { public String villages() { return cache.get(VILLAGE_LIST, new CacheableData<String>() { @Override public String fetch() { List<Village> villagesList = new ArrayList<Village>(); List<String> villages = allEligibleCouples.villages(); for (String village : villages) { villagesList.add(new Village(village)); } return new Gson().toJson(villagesList); } }); } VillageController(AllEligibleCouples allEligibleCouples, Cache<String> cache, Cache<Villages> villagesCache); String villages(); Villages getVillages(); }
@Test public void shouldSortECsByName() throws Exception { EligibleCouple ec2 = new EligibleCouple("entity id 2", "Woman B", "Husband B", "2", "kavalu_hosur", "Bherya SC", emptyDetails); EligibleCouple ec3 = new EligibleCouple("entity id 3", "Woman C", "Husband C", "3", "Bherya", "Bherya SC", emptyDetails); EligibleCouple ec1 = new EligibleCouple("entity id 1", "Woman A", "Husband A", "1", "Bherya", null, emptyDetails); Mockito.when(allEligibleCouples.all()).thenReturn(Arrays.asList(ec2, ec3, ec1)); ECClient expectedClient1 = createECClient("entity id 1", "Woman A", "Husband A", "Bherya", 1); ECClient expectedClient2 = createECClient("entity id 2", "Woman B", "Husband B", "kavalu_hosur", 2); ECClient expectedClient3 = createECClient("entity id 3", "Woman C", "Husband C", "Bherya", 3); String clients = controller.get(); List<ECClient> actualClients = new Gson().fromJson(clients, new TypeToken<List<ECClient>>() { }.getType()); Assert.assertEquals(Arrays.asList(expectedClient1, expectedClient2, expectedClient3), actualClients); }
public String get() { return cache.get(EC_CLIENTS_LIST, new CacheableData<String>() { @Override public String fetch() { List<EligibleCouple> ecs = allEligibleCouples.all(); List<ECClient> ecClients = new ArrayList<ECClient>(); for (EligibleCouple ec : ecs) { String photoPath = isBlank(ec.photoPath()) ? DEFAULT_WOMAN_IMAGE_PLACEHOLDER_PATH : ec.photoPath(); ECClient ecClient = new ECClient(ec.caseId(), ec.wifeName(), ec.husbandName(), ec.village(), IntegerUtil.tryParse(ec.ecNumber(), 0)) .withDateOfBirth(ec.getDetail(WOMAN_DOB)) .withFPMethod(ec.getDetail(CURRENT_FP_METHOD)) .withFamilyPlanningMethodChangeDate( ec.getDetail(FAMILY_PLANNING_METHOD_CHANGE_DATE)) .withIUDPlace(ec.getDetail(IUD_PLACE)) .withIUDPerson(ec.getDetail(IUD_PERSON)) .withNumberOfCondomsSupplied(ec.getDetail(NUMBER_OF_CONDOMS_SUPPLIED)) .withNumberOfCentchromanPillsDelivered( ec.getDetail(NUMBER_OF_CENTCHROMAN_PILLS_DELIVERED)) .withNumberOfOCPDelivered(ec.getDetail(NUMBER_OF_OCP_DELIVERED)) .withCaste(ec.getDetail(CASTE)) .withEconomicStatus(ec.getDetail(ECONOMIC_STATUS)) .withNumberOfPregnancies(ec.getDetail(NUMBER_OF_PREGNANCIES)) .withParity(ec.getDetail(PARITY)) .withNumberOfLivingChildren(ec.getDetail(NUMBER_OF_LIVING_CHILDREN)) .withNumberOfStillBirths(ec.getDetail(NUMBER_OF_STILL_BIRTHS)) .withNumberOfAbortions(ec.getDetail(NUMBER_OF_ABORTIONS)) .withIsHighPriority(ec.isHighPriority()).withPhotoPath(photoPath) .withHighPriorityReason(ec.getDetail(HIGH_PRIORITY_REASON)) .withIsOutOfArea(ec.isOutOfArea()); updateStatusInformation(ec, ecClient); updateChildrenInformation(ecClient); ecClients.add(ecClient); } sortByName(ecClients); return new Gson().toJson(ecClients); } }); }
ECSmartRegisterController { public String get() { return cache.get(EC_CLIENTS_LIST, new CacheableData<String>() { @Override public String fetch() { List<EligibleCouple> ecs = allEligibleCouples.all(); List<ECClient> ecClients = new ArrayList<ECClient>(); for (EligibleCouple ec : ecs) { String photoPath = isBlank(ec.photoPath()) ? DEFAULT_WOMAN_IMAGE_PLACEHOLDER_PATH : ec.photoPath(); ECClient ecClient = new ECClient(ec.caseId(), ec.wifeName(), ec.husbandName(), ec.village(), IntegerUtil.tryParse(ec.ecNumber(), 0)) .withDateOfBirth(ec.getDetail(WOMAN_DOB)) .withFPMethod(ec.getDetail(CURRENT_FP_METHOD)) .withFamilyPlanningMethodChangeDate( ec.getDetail(FAMILY_PLANNING_METHOD_CHANGE_DATE)) .withIUDPlace(ec.getDetail(IUD_PLACE)) .withIUDPerson(ec.getDetail(IUD_PERSON)) .withNumberOfCondomsSupplied(ec.getDetail(NUMBER_OF_CONDOMS_SUPPLIED)) .withNumberOfCentchromanPillsDelivered( ec.getDetail(NUMBER_OF_CENTCHROMAN_PILLS_DELIVERED)) .withNumberOfOCPDelivered(ec.getDetail(NUMBER_OF_OCP_DELIVERED)) .withCaste(ec.getDetail(CASTE)) .withEconomicStatus(ec.getDetail(ECONOMIC_STATUS)) .withNumberOfPregnancies(ec.getDetail(NUMBER_OF_PREGNANCIES)) .withParity(ec.getDetail(PARITY)) .withNumberOfLivingChildren(ec.getDetail(NUMBER_OF_LIVING_CHILDREN)) .withNumberOfStillBirths(ec.getDetail(NUMBER_OF_STILL_BIRTHS)) .withNumberOfAbortions(ec.getDetail(NUMBER_OF_ABORTIONS)) .withIsHighPriority(ec.isHighPriority()).withPhotoPath(photoPath) .withHighPriorityReason(ec.getDetail(HIGH_PRIORITY_REASON)) .withIsOutOfArea(ec.isOutOfArea()); updateStatusInformation(ec, ecClient); updateChildrenInformation(ecClient); ecClients.add(ecClient); } sortByName(ecClients); return new Gson().toJson(ecClients); } }); } }
ECSmartRegisterController { public String get() { return cache.get(EC_CLIENTS_LIST, new CacheableData<String>() { @Override public String fetch() { List<EligibleCouple> ecs = allEligibleCouples.all(); List<ECClient> ecClients = new ArrayList<ECClient>(); for (EligibleCouple ec : ecs) { String photoPath = isBlank(ec.photoPath()) ? DEFAULT_WOMAN_IMAGE_PLACEHOLDER_PATH : ec.photoPath(); ECClient ecClient = new ECClient(ec.caseId(), ec.wifeName(), ec.husbandName(), ec.village(), IntegerUtil.tryParse(ec.ecNumber(), 0)) .withDateOfBirth(ec.getDetail(WOMAN_DOB)) .withFPMethod(ec.getDetail(CURRENT_FP_METHOD)) .withFamilyPlanningMethodChangeDate( ec.getDetail(FAMILY_PLANNING_METHOD_CHANGE_DATE)) .withIUDPlace(ec.getDetail(IUD_PLACE)) .withIUDPerson(ec.getDetail(IUD_PERSON)) .withNumberOfCondomsSupplied(ec.getDetail(NUMBER_OF_CONDOMS_SUPPLIED)) .withNumberOfCentchromanPillsDelivered( ec.getDetail(NUMBER_OF_CENTCHROMAN_PILLS_DELIVERED)) .withNumberOfOCPDelivered(ec.getDetail(NUMBER_OF_OCP_DELIVERED)) .withCaste(ec.getDetail(CASTE)) .withEconomicStatus(ec.getDetail(ECONOMIC_STATUS)) .withNumberOfPregnancies(ec.getDetail(NUMBER_OF_PREGNANCIES)) .withParity(ec.getDetail(PARITY)) .withNumberOfLivingChildren(ec.getDetail(NUMBER_OF_LIVING_CHILDREN)) .withNumberOfStillBirths(ec.getDetail(NUMBER_OF_STILL_BIRTHS)) .withNumberOfAbortions(ec.getDetail(NUMBER_OF_ABORTIONS)) .withIsHighPriority(ec.isHighPriority()).withPhotoPath(photoPath) .withHighPriorityReason(ec.getDetail(HIGH_PRIORITY_REASON)) .withIsOutOfArea(ec.isOutOfArea()); updateStatusInformation(ec, ecClient); updateChildrenInformation(ecClient); ecClients.add(ecClient); } sortByName(ecClients); return new Gson().toJson(ecClients); } }); } ECSmartRegisterController(AllEligibleCouples allEligibleCouples, AllBeneficiaries allBeneficiaries, Cache<String> cache, Cache<ECClients> ecClientsCache); }
ECSmartRegisterController { public String get() { return cache.get(EC_CLIENTS_LIST, new CacheableData<String>() { @Override public String fetch() { List<EligibleCouple> ecs = allEligibleCouples.all(); List<ECClient> ecClients = new ArrayList<ECClient>(); for (EligibleCouple ec : ecs) { String photoPath = isBlank(ec.photoPath()) ? DEFAULT_WOMAN_IMAGE_PLACEHOLDER_PATH : ec.photoPath(); ECClient ecClient = new ECClient(ec.caseId(), ec.wifeName(), ec.husbandName(), ec.village(), IntegerUtil.tryParse(ec.ecNumber(), 0)) .withDateOfBirth(ec.getDetail(WOMAN_DOB)) .withFPMethod(ec.getDetail(CURRENT_FP_METHOD)) .withFamilyPlanningMethodChangeDate( ec.getDetail(FAMILY_PLANNING_METHOD_CHANGE_DATE)) .withIUDPlace(ec.getDetail(IUD_PLACE)) .withIUDPerson(ec.getDetail(IUD_PERSON)) .withNumberOfCondomsSupplied(ec.getDetail(NUMBER_OF_CONDOMS_SUPPLIED)) .withNumberOfCentchromanPillsDelivered( ec.getDetail(NUMBER_OF_CENTCHROMAN_PILLS_DELIVERED)) .withNumberOfOCPDelivered(ec.getDetail(NUMBER_OF_OCP_DELIVERED)) .withCaste(ec.getDetail(CASTE)) .withEconomicStatus(ec.getDetail(ECONOMIC_STATUS)) .withNumberOfPregnancies(ec.getDetail(NUMBER_OF_PREGNANCIES)) .withParity(ec.getDetail(PARITY)) .withNumberOfLivingChildren(ec.getDetail(NUMBER_OF_LIVING_CHILDREN)) .withNumberOfStillBirths(ec.getDetail(NUMBER_OF_STILL_BIRTHS)) .withNumberOfAbortions(ec.getDetail(NUMBER_OF_ABORTIONS)) .withIsHighPriority(ec.isHighPriority()).withPhotoPath(photoPath) .withHighPriorityReason(ec.getDetail(HIGH_PRIORITY_REASON)) .withIsOutOfArea(ec.isOutOfArea()); updateStatusInformation(ec, ecClient); updateChildrenInformation(ecClient); ecClients.add(ecClient); } sortByName(ecClients); return new Gson().toJson(ecClients); } }); } ECSmartRegisterController(AllEligibleCouples allEligibleCouples, AllBeneficiaries allBeneficiaries, Cache<String> cache, Cache<ECClients> ecClientsCache); String get(); ECClients getClients(); }
ECSmartRegisterController { public String get() { return cache.get(EC_CLIENTS_LIST, new CacheableData<String>() { @Override public String fetch() { List<EligibleCouple> ecs = allEligibleCouples.all(); List<ECClient> ecClients = new ArrayList<ECClient>(); for (EligibleCouple ec : ecs) { String photoPath = isBlank(ec.photoPath()) ? DEFAULT_WOMAN_IMAGE_PLACEHOLDER_PATH : ec.photoPath(); ECClient ecClient = new ECClient(ec.caseId(), ec.wifeName(), ec.husbandName(), ec.village(), IntegerUtil.tryParse(ec.ecNumber(), 0)) .withDateOfBirth(ec.getDetail(WOMAN_DOB)) .withFPMethod(ec.getDetail(CURRENT_FP_METHOD)) .withFamilyPlanningMethodChangeDate( ec.getDetail(FAMILY_PLANNING_METHOD_CHANGE_DATE)) .withIUDPlace(ec.getDetail(IUD_PLACE)) .withIUDPerson(ec.getDetail(IUD_PERSON)) .withNumberOfCondomsSupplied(ec.getDetail(NUMBER_OF_CONDOMS_SUPPLIED)) .withNumberOfCentchromanPillsDelivered( ec.getDetail(NUMBER_OF_CENTCHROMAN_PILLS_DELIVERED)) .withNumberOfOCPDelivered(ec.getDetail(NUMBER_OF_OCP_DELIVERED)) .withCaste(ec.getDetail(CASTE)) .withEconomicStatus(ec.getDetail(ECONOMIC_STATUS)) .withNumberOfPregnancies(ec.getDetail(NUMBER_OF_PREGNANCIES)) .withParity(ec.getDetail(PARITY)) .withNumberOfLivingChildren(ec.getDetail(NUMBER_OF_LIVING_CHILDREN)) .withNumberOfStillBirths(ec.getDetail(NUMBER_OF_STILL_BIRTHS)) .withNumberOfAbortions(ec.getDetail(NUMBER_OF_ABORTIONS)) .withIsHighPriority(ec.isHighPriority()).withPhotoPath(photoPath) .withHighPriorityReason(ec.getDetail(HIGH_PRIORITY_REASON)) .withIsOutOfArea(ec.isOutOfArea()); updateStatusInformation(ec, ecClient); updateChildrenInformation(ecClient); ecClients.add(ecClient); } sortByName(ecClients); return new Gson().toJson(ecClients); } }); } ECSmartRegisterController(AllEligibleCouples allEligibleCouples, AllBeneficiaries allBeneficiaries, Cache<String> cache, Cache<ECClients> ecClientsCache); String get(); ECClients getClients(); static final String STATUS_TYPE_FIELD; static final String STATUS_DATE_FIELD; static final String EC_STATUS; static final String ANC_STATUS; static final String PNC_STATUS; static final String PNC_FP_STATUS; static final String FP_STATUS; static final String STATUS_EDD_FIELD; static final String FP_METHOD_DATE_FIELD; }
@Test public void shouldMapECToECClient() throws Exception { Map<String, String> details = EasyMap.create("wifeAge", "22") .put("womanDOB", "1984-01-01") .put("currentMethod", "condom") .put("familyPlanningMethodChangeDate", "2013-01-02") .put("numberOfPregnancies", "2") .put("parity", "2") .put("numberOfLivingChildren", "1") .put("numberOfStillBirths", "1") .put("numberOfAbortions", "0") .put("isHighPriority", Boolean.toString(false)) .put("caste", "sc") .put("economicStatus", "bpl") .put("iudPlace", "iudPlace") .put("iudPerson", "iudPerson") .put("numberOfCondomsSupplied", "numberOfCondomsSupplied") .put("numberOfCentchromanPillsDelivered", "numberOfCentchromanPillsDelivered") .put("numberOfOCPDelivered", "numberOfOCPDelivered") .put("highPriorityReason", "high priority reason") .map(); EligibleCouple ec = new EligibleCouple("entity id 1", "Woman A", "Husband A", "1", "Bherya", "Bherya SC", details) .withPhotoPath("new photo path").asOutOfArea(); Mockito.when(allEligibleCouples.all()).thenReturn(Arrays.asList(ec)); ECClient expectedECClient = new ECClient("entity id 1", "Woman A", "Husband A", "Bherya", 1) .withDateOfBirth("1984-01-01") .withFPMethod("condom") .withFamilyPlanningMethodChangeDate("2013-01-02") .withIUDPlace("iudPlace") .withIUDPerson("iudPerson") .withNumberOfCondomsSupplied("numberOfCondomsSupplied") .withNumberOfCentchromanPillsDelivered("numberOfCentchromanPillsDelivered") .withNumberOfOCPDelivered("numberOfOCPDelivered") .withCaste("sc") .withEconomicStatus("bpl") .withNumberOfPregnancies("2") .withParity("2") .withNumberOfLivingChildren("1") .withNumberOfStillBirths("1") .withNumberOfAbortions("0") .withIsHighPriority(false) .withPhotoPath("new photo path") .withHighPriorityReason("high priority reason") .withStatus(EasyMap.create("date", "2013-01-02").put("type", "fp").map()) .withIsOutOfArea(ec.isOutOfArea()); String clients = controller.get(); List<ECClient> actualClients = new Gson().fromJson(clients, new TypeToken<List<ECClient>>() { }.getType()); Assert.assertEquals(Arrays.asList(expectedECClient), actualClients); }
public String get() { return cache.get(EC_CLIENTS_LIST, new CacheableData<String>() { @Override public String fetch() { List<EligibleCouple> ecs = allEligibleCouples.all(); List<ECClient> ecClients = new ArrayList<ECClient>(); for (EligibleCouple ec : ecs) { String photoPath = isBlank(ec.photoPath()) ? DEFAULT_WOMAN_IMAGE_PLACEHOLDER_PATH : ec.photoPath(); ECClient ecClient = new ECClient(ec.caseId(), ec.wifeName(), ec.husbandName(), ec.village(), IntegerUtil.tryParse(ec.ecNumber(), 0)) .withDateOfBirth(ec.getDetail(WOMAN_DOB)) .withFPMethod(ec.getDetail(CURRENT_FP_METHOD)) .withFamilyPlanningMethodChangeDate( ec.getDetail(FAMILY_PLANNING_METHOD_CHANGE_DATE)) .withIUDPlace(ec.getDetail(IUD_PLACE)) .withIUDPerson(ec.getDetail(IUD_PERSON)) .withNumberOfCondomsSupplied(ec.getDetail(NUMBER_OF_CONDOMS_SUPPLIED)) .withNumberOfCentchromanPillsDelivered( ec.getDetail(NUMBER_OF_CENTCHROMAN_PILLS_DELIVERED)) .withNumberOfOCPDelivered(ec.getDetail(NUMBER_OF_OCP_DELIVERED)) .withCaste(ec.getDetail(CASTE)) .withEconomicStatus(ec.getDetail(ECONOMIC_STATUS)) .withNumberOfPregnancies(ec.getDetail(NUMBER_OF_PREGNANCIES)) .withParity(ec.getDetail(PARITY)) .withNumberOfLivingChildren(ec.getDetail(NUMBER_OF_LIVING_CHILDREN)) .withNumberOfStillBirths(ec.getDetail(NUMBER_OF_STILL_BIRTHS)) .withNumberOfAbortions(ec.getDetail(NUMBER_OF_ABORTIONS)) .withIsHighPriority(ec.isHighPriority()).withPhotoPath(photoPath) .withHighPriorityReason(ec.getDetail(HIGH_PRIORITY_REASON)) .withIsOutOfArea(ec.isOutOfArea()); updateStatusInformation(ec, ecClient); updateChildrenInformation(ecClient); ecClients.add(ecClient); } sortByName(ecClients); return new Gson().toJson(ecClients); } }); }
ECSmartRegisterController { public String get() { return cache.get(EC_CLIENTS_LIST, new CacheableData<String>() { @Override public String fetch() { List<EligibleCouple> ecs = allEligibleCouples.all(); List<ECClient> ecClients = new ArrayList<ECClient>(); for (EligibleCouple ec : ecs) { String photoPath = isBlank(ec.photoPath()) ? DEFAULT_WOMAN_IMAGE_PLACEHOLDER_PATH : ec.photoPath(); ECClient ecClient = new ECClient(ec.caseId(), ec.wifeName(), ec.husbandName(), ec.village(), IntegerUtil.tryParse(ec.ecNumber(), 0)) .withDateOfBirth(ec.getDetail(WOMAN_DOB)) .withFPMethod(ec.getDetail(CURRENT_FP_METHOD)) .withFamilyPlanningMethodChangeDate( ec.getDetail(FAMILY_PLANNING_METHOD_CHANGE_DATE)) .withIUDPlace(ec.getDetail(IUD_PLACE)) .withIUDPerson(ec.getDetail(IUD_PERSON)) .withNumberOfCondomsSupplied(ec.getDetail(NUMBER_OF_CONDOMS_SUPPLIED)) .withNumberOfCentchromanPillsDelivered( ec.getDetail(NUMBER_OF_CENTCHROMAN_PILLS_DELIVERED)) .withNumberOfOCPDelivered(ec.getDetail(NUMBER_OF_OCP_DELIVERED)) .withCaste(ec.getDetail(CASTE)) .withEconomicStatus(ec.getDetail(ECONOMIC_STATUS)) .withNumberOfPregnancies(ec.getDetail(NUMBER_OF_PREGNANCIES)) .withParity(ec.getDetail(PARITY)) .withNumberOfLivingChildren(ec.getDetail(NUMBER_OF_LIVING_CHILDREN)) .withNumberOfStillBirths(ec.getDetail(NUMBER_OF_STILL_BIRTHS)) .withNumberOfAbortions(ec.getDetail(NUMBER_OF_ABORTIONS)) .withIsHighPriority(ec.isHighPriority()).withPhotoPath(photoPath) .withHighPriorityReason(ec.getDetail(HIGH_PRIORITY_REASON)) .withIsOutOfArea(ec.isOutOfArea()); updateStatusInformation(ec, ecClient); updateChildrenInformation(ecClient); ecClients.add(ecClient); } sortByName(ecClients); return new Gson().toJson(ecClients); } }); } }
ECSmartRegisterController { public String get() { return cache.get(EC_CLIENTS_LIST, new CacheableData<String>() { @Override public String fetch() { List<EligibleCouple> ecs = allEligibleCouples.all(); List<ECClient> ecClients = new ArrayList<ECClient>(); for (EligibleCouple ec : ecs) { String photoPath = isBlank(ec.photoPath()) ? DEFAULT_WOMAN_IMAGE_PLACEHOLDER_PATH : ec.photoPath(); ECClient ecClient = new ECClient(ec.caseId(), ec.wifeName(), ec.husbandName(), ec.village(), IntegerUtil.tryParse(ec.ecNumber(), 0)) .withDateOfBirth(ec.getDetail(WOMAN_DOB)) .withFPMethod(ec.getDetail(CURRENT_FP_METHOD)) .withFamilyPlanningMethodChangeDate( ec.getDetail(FAMILY_PLANNING_METHOD_CHANGE_DATE)) .withIUDPlace(ec.getDetail(IUD_PLACE)) .withIUDPerson(ec.getDetail(IUD_PERSON)) .withNumberOfCondomsSupplied(ec.getDetail(NUMBER_OF_CONDOMS_SUPPLIED)) .withNumberOfCentchromanPillsDelivered( ec.getDetail(NUMBER_OF_CENTCHROMAN_PILLS_DELIVERED)) .withNumberOfOCPDelivered(ec.getDetail(NUMBER_OF_OCP_DELIVERED)) .withCaste(ec.getDetail(CASTE)) .withEconomicStatus(ec.getDetail(ECONOMIC_STATUS)) .withNumberOfPregnancies(ec.getDetail(NUMBER_OF_PREGNANCIES)) .withParity(ec.getDetail(PARITY)) .withNumberOfLivingChildren(ec.getDetail(NUMBER_OF_LIVING_CHILDREN)) .withNumberOfStillBirths(ec.getDetail(NUMBER_OF_STILL_BIRTHS)) .withNumberOfAbortions(ec.getDetail(NUMBER_OF_ABORTIONS)) .withIsHighPriority(ec.isHighPriority()).withPhotoPath(photoPath) .withHighPriorityReason(ec.getDetail(HIGH_PRIORITY_REASON)) .withIsOutOfArea(ec.isOutOfArea()); updateStatusInformation(ec, ecClient); updateChildrenInformation(ecClient); ecClients.add(ecClient); } sortByName(ecClients); return new Gson().toJson(ecClients); } }); } ECSmartRegisterController(AllEligibleCouples allEligibleCouples, AllBeneficiaries allBeneficiaries, Cache<String> cache, Cache<ECClients> ecClientsCache); }
ECSmartRegisterController { public String get() { return cache.get(EC_CLIENTS_LIST, new CacheableData<String>() { @Override public String fetch() { List<EligibleCouple> ecs = allEligibleCouples.all(); List<ECClient> ecClients = new ArrayList<ECClient>(); for (EligibleCouple ec : ecs) { String photoPath = isBlank(ec.photoPath()) ? DEFAULT_WOMAN_IMAGE_PLACEHOLDER_PATH : ec.photoPath(); ECClient ecClient = new ECClient(ec.caseId(), ec.wifeName(), ec.husbandName(), ec.village(), IntegerUtil.tryParse(ec.ecNumber(), 0)) .withDateOfBirth(ec.getDetail(WOMAN_DOB)) .withFPMethod(ec.getDetail(CURRENT_FP_METHOD)) .withFamilyPlanningMethodChangeDate( ec.getDetail(FAMILY_PLANNING_METHOD_CHANGE_DATE)) .withIUDPlace(ec.getDetail(IUD_PLACE)) .withIUDPerson(ec.getDetail(IUD_PERSON)) .withNumberOfCondomsSupplied(ec.getDetail(NUMBER_OF_CONDOMS_SUPPLIED)) .withNumberOfCentchromanPillsDelivered( ec.getDetail(NUMBER_OF_CENTCHROMAN_PILLS_DELIVERED)) .withNumberOfOCPDelivered(ec.getDetail(NUMBER_OF_OCP_DELIVERED)) .withCaste(ec.getDetail(CASTE)) .withEconomicStatus(ec.getDetail(ECONOMIC_STATUS)) .withNumberOfPregnancies(ec.getDetail(NUMBER_OF_PREGNANCIES)) .withParity(ec.getDetail(PARITY)) .withNumberOfLivingChildren(ec.getDetail(NUMBER_OF_LIVING_CHILDREN)) .withNumberOfStillBirths(ec.getDetail(NUMBER_OF_STILL_BIRTHS)) .withNumberOfAbortions(ec.getDetail(NUMBER_OF_ABORTIONS)) .withIsHighPriority(ec.isHighPriority()).withPhotoPath(photoPath) .withHighPriorityReason(ec.getDetail(HIGH_PRIORITY_REASON)) .withIsOutOfArea(ec.isOutOfArea()); updateStatusInformation(ec, ecClient); updateChildrenInformation(ecClient); ecClients.add(ecClient); } sortByName(ecClients); return new Gson().toJson(ecClients); } }); } ECSmartRegisterController(AllEligibleCouples allEligibleCouples, AllBeneficiaries allBeneficiaries, Cache<String> cache, Cache<ECClients> ecClientsCache); String get(); ECClients getClients(); }
ECSmartRegisterController { public String get() { return cache.get(EC_CLIENTS_LIST, new CacheableData<String>() { @Override public String fetch() { List<EligibleCouple> ecs = allEligibleCouples.all(); List<ECClient> ecClients = new ArrayList<ECClient>(); for (EligibleCouple ec : ecs) { String photoPath = isBlank(ec.photoPath()) ? DEFAULT_WOMAN_IMAGE_PLACEHOLDER_PATH : ec.photoPath(); ECClient ecClient = new ECClient(ec.caseId(), ec.wifeName(), ec.husbandName(), ec.village(), IntegerUtil.tryParse(ec.ecNumber(), 0)) .withDateOfBirth(ec.getDetail(WOMAN_DOB)) .withFPMethod(ec.getDetail(CURRENT_FP_METHOD)) .withFamilyPlanningMethodChangeDate( ec.getDetail(FAMILY_PLANNING_METHOD_CHANGE_DATE)) .withIUDPlace(ec.getDetail(IUD_PLACE)) .withIUDPerson(ec.getDetail(IUD_PERSON)) .withNumberOfCondomsSupplied(ec.getDetail(NUMBER_OF_CONDOMS_SUPPLIED)) .withNumberOfCentchromanPillsDelivered( ec.getDetail(NUMBER_OF_CENTCHROMAN_PILLS_DELIVERED)) .withNumberOfOCPDelivered(ec.getDetail(NUMBER_OF_OCP_DELIVERED)) .withCaste(ec.getDetail(CASTE)) .withEconomicStatus(ec.getDetail(ECONOMIC_STATUS)) .withNumberOfPregnancies(ec.getDetail(NUMBER_OF_PREGNANCIES)) .withParity(ec.getDetail(PARITY)) .withNumberOfLivingChildren(ec.getDetail(NUMBER_OF_LIVING_CHILDREN)) .withNumberOfStillBirths(ec.getDetail(NUMBER_OF_STILL_BIRTHS)) .withNumberOfAbortions(ec.getDetail(NUMBER_OF_ABORTIONS)) .withIsHighPriority(ec.isHighPriority()).withPhotoPath(photoPath) .withHighPriorityReason(ec.getDetail(HIGH_PRIORITY_REASON)) .withIsOutOfArea(ec.isOutOfArea()); updateStatusInformation(ec, ecClient); updateChildrenInformation(ecClient); ecClients.add(ecClient); } sortByName(ecClients); return new Gson().toJson(ecClients); } }); } ECSmartRegisterController(AllEligibleCouples allEligibleCouples, AllBeneficiaries allBeneficiaries, Cache<String> cache, Cache<ECClients> ecClientsCache); String get(); ECClients getClients(); static final String STATUS_TYPE_FIELD; static final String STATUS_DATE_FIELD; static final String EC_STATUS; static final String ANC_STATUS; static final String PNC_STATUS; static final String PNC_FP_STATUS; static final String FP_STATUS; static final String STATUS_EDD_FIELD; static final String FP_METHOD_DATE_FIELD; }
@Test public void shouldAddYoungestTwoChildrenToECClient() throws Exception { EligibleCouple ec1 = new EligibleCouple("entity id 1", "Woman A", "Husband A", "1", "Bherya", null, emptyDetails); Child firstChild = new Child("child id 1", "mother id 1", "1234567", "2010-01-01", "female", emptyDetails); Child secondChild = new Child("child id 2", "mother id 1", "1234568", "2011-01-01", "female", emptyDetails); Child thirdChild = new Child("child id 3", "mother id 1", "1234569", "2012-01-01", "male", emptyDetails); Mockito.when(allEligibleCouples.all()).thenReturn(Arrays.asList(ec1)); Mockito.when(allBeneficiaries.findAllChildrenByECId("entity id 1")).thenReturn(Arrays.asList(firstChild, secondChild, thirdChild)); ECClient expectedClient1 = createECClient("entity id 1", "Woman A", "Husband A", "Bherya", 1) .withChildren(Arrays.asList(new ECChildClient("child id 2", "female", "2011-01-01"), new ECChildClient("child id 3", "male", "2012-01-01"))); String clients = controller.get(); List<ECClient> actualClients = new Gson().fromJson(clients, new TypeToken<List<ECClient>>() { }.getType()); Assert.assertEquals(Arrays.asList(expectedClient1), actualClients); }
public String get() { return cache.get(EC_CLIENTS_LIST, new CacheableData<String>() { @Override public String fetch() { List<EligibleCouple> ecs = allEligibleCouples.all(); List<ECClient> ecClients = new ArrayList<ECClient>(); for (EligibleCouple ec : ecs) { String photoPath = isBlank(ec.photoPath()) ? DEFAULT_WOMAN_IMAGE_PLACEHOLDER_PATH : ec.photoPath(); ECClient ecClient = new ECClient(ec.caseId(), ec.wifeName(), ec.husbandName(), ec.village(), IntegerUtil.tryParse(ec.ecNumber(), 0)) .withDateOfBirth(ec.getDetail(WOMAN_DOB)) .withFPMethod(ec.getDetail(CURRENT_FP_METHOD)) .withFamilyPlanningMethodChangeDate( ec.getDetail(FAMILY_PLANNING_METHOD_CHANGE_DATE)) .withIUDPlace(ec.getDetail(IUD_PLACE)) .withIUDPerson(ec.getDetail(IUD_PERSON)) .withNumberOfCondomsSupplied(ec.getDetail(NUMBER_OF_CONDOMS_SUPPLIED)) .withNumberOfCentchromanPillsDelivered( ec.getDetail(NUMBER_OF_CENTCHROMAN_PILLS_DELIVERED)) .withNumberOfOCPDelivered(ec.getDetail(NUMBER_OF_OCP_DELIVERED)) .withCaste(ec.getDetail(CASTE)) .withEconomicStatus(ec.getDetail(ECONOMIC_STATUS)) .withNumberOfPregnancies(ec.getDetail(NUMBER_OF_PREGNANCIES)) .withParity(ec.getDetail(PARITY)) .withNumberOfLivingChildren(ec.getDetail(NUMBER_OF_LIVING_CHILDREN)) .withNumberOfStillBirths(ec.getDetail(NUMBER_OF_STILL_BIRTHS)) .withNumberOfAbortions(ec.getDetail(NUMBER_OF_ABORTIONS)) .withIsHighPriority(ec.isHighPriority()).withPhotoPath(photoPath) .withHighPriorityReason(ec.getDetail(HIGH_PRIORITY_REASON)) .withIsOutOfArea(ec.isOutOfArea()); updateStatusInformation(ec, ecClient); updateChildrenInformation(ecClient); ecClients.add(ecClient); } sortByName(ecClients); return new Gson().toJson(ecClients); } }); }
ECSmartRegisterController { public String get() { return cache.get(EC_CLIENTS_LIST, new CacheableData<String>() { @Override public String fetch() { List<EligibleCouple> ecs = allEligibleCouples.all(); List<ECClient> ecClients = new ArrayList<ECClient>(); for (EligibleCouple ec : ecs) { String photoPath = isBlank(ec.photoPath()) ? DEFAULT_WOMAN_IMAGE_PLACEHOLDER_PATH : ec.photoPath(); ECClient ecClient = new ECClient(ec.caseId(), ec.wifeName(), ec.husbandName(), ec.village(), IntegerUtil.tryParse(ec.ecNumber(), 0)) .withDateOfBirth(ec.getDetail(WOMAN_DOB)) .withFPMethod(ec.getDetail(CURRENT_FP_METHOD)) .withFamilyPlanningMethodChangeDate( ec.getDetail(FAMILY_PLANNING_METHOD_CHANGE_DATE)) .withIUDPlace(ec.getDetail(IUD_PLACE)) .withIUDPerson(ec.getDetail(IUD_PERSON)) .withNumberOfCondomsSupplied(ec.getDetail(NUMBER_OF_CONDOMS_SUPPLIED)) .withNumberOfCentchromanPillsDelivered( ec.getDetail(NUMBER_OF_CENTCHROMAN_PILLS_DELIVERED)) .withNumberOfOCPDelivered(ec.getDetail(NUMBER_OF_OCP_DELIVERED)) .withCaste(ec.getDetail(CASTE)) .withEconomicStatus(ec.getDetail(ECONOMIC_STATUS)) .withNumberOfPregnancies(ec.getDetail(NUMBER_OF_PREGNANCIES)) .withParity(ec.getDetail(PARITY)) .withNumberOfLivingChildren(ec.getDetail(NUMBER_OF_LIVING_CHILDREN)) .withNumberOfStillBirths(ec.getDetail(NUMBER_OF_STILL_BIRTHS)) .withNumberOfAbortions(ec.getDetail(NUMBER_OF_ABORTIONS)) .withIsHighPriority(ec.isHighPriority()).withPhotoPath(photoPath) .withHighPriorityReason(ec.getDetail(HIGH_PRIORITY_REASON)) .withIsOutOfArea(ec.isOutOfArea()); updateStatusInformation(ec, ecClient); updateChildrenInformation(ecClient); ecClients.add(ecClient); } sortByName(ecClients); return new Gson().toJson(ecClients); } }); } }
ECSmartRegisterController { public String get() { return cache.get(EC_CLIENTS_LIST, new CacheableData<String>() { @Override public String fetch() { List<EligibleCouple> ecs = allEligibleCouples.all(); List<ECClient> ecClients = new ArrayList<ECClient>(); for (EligibleCouple ec : ecs) { String photoPath = isBlank(ec.photoPath()) ? DEFAULT_WOMAN_IMAGE_PLACEHOLDER_PATH : ec.photoPath(); ECClient ecClient = new ECClient(ec.caseId(), ec.wifeName(), ec.husbandName(), ec.village(), IntegerUtil.tryParse(ec.ecNumber(), 0)) .withDateOfBirth(ec.getDetail(WOMAN_DOB)) .withFPMethod(ec.getDetail(CURRENT_FP_METHOD)) .withFamilyPlanningMethodChangeDate( ec.getDetail(FAMILY_PLANNING_METHOD_CHANGE_DATE)) .withIUDPlace(ec.getDetail(IUD_PLACE)) .withIUDPerson(ec.getDetail(IUD_PERSON)) .withNumberOfCondomsSupplied(ec.getDetail(NUMBER_OF_CONDOMS_SUPPLIED)) .withNumberOfCentchromanPillsDelivered( ec.getDetail(NUMBER_OF_CENTCHROMAN_PILLS_DELIVERED)) .withNumberOfOCPDelivered(ec.getDetail(NUMBER_OF_OCP_DELIVERED)) .withCaste(ec.getDetail(CASTE)) .withEconomicStatus(ec.getDetail(ECONOMIC_STATUS)) .withNumberOfPregnancies(ec.getDetail(NUMBER_OF_PREGNANCIES)) .withParity(ec.getDetail(PARITY)) .withNumberOfLivingChildren(ec.getDetail(NUMBER_OF_LIVING_CHILDREN)) .withNumberOfStillBirths(ec.getDetail(NUMBER_OF_STILL_BIRTHS)) .withNumberOfAbortions(ec.getDetail(NUMBER_OF_ABORTIONS)) .withIsHighPriority(ec.isHighPriority()).withPhotoPath(photoPath) .withHighPriorityReason(ec.getDetail(HIGH_PRIORITY_REASON)) .withIsOutOfArea(ec.isOutOfArea()); updateStatusInformation(ec, ecClient); updateChildrenInformation(ecClient); ecClients.add(ecClient); } sortByName(ecClients); return new Gson().toJson(ecClients); } }); } ECSmartRegisterController(AllEligibleCouples allEligibleCouples, AllBeneficiaries allBeneficiaries, Cache<String> cache, Cache<ECClients> ecClientsCache); }
ECSmartRegisterController { public String get() { return cache.get(EC_CLIENTS_LIST, new CacheableData<String>() { @Override public String fetch() { List<EligibleCouple> ecs = allEligibleCouples.all(); List<ECClient> ecClients = new ArrayList<ECClient>(); for (EligibleCouple ec : ecs) { String photoPath = isBlank(ec.photoPath()) ? DEFAULT_WOMAN_IMAGE_PLACEHOLDER_PATH : ec.photoPath(); ECClient ecClient = new ECClient(ec.caseId(), ec.wifeName(), ec.husbandName(), ec.village(), IntegerUtil.tryParse(ec.ecNumber(), 0)) .withDateOfBirth(ec.getDetail(WOMAN_DOB)) .withFPMethod(ec.getDetail(CURRENT_FP_METHOD)) .withFamilyPlanningMethodChangeDate( ec.getDetail(FAMILY_PLANNING_METHOD_CHANGE_DATE)) .withIUDPlace(ec.getDetail(IUD_PLACE)) .withIUDPerson(ec.getDetail(IUD_PERSON)) .withNumberOfCondomsSupplied(ec.getDetail(NUMBER_OF_CONDOMS_SUPPLIED)) .withNumberOfCentchromanPillsDelivered( ec.getDetail(NUMBER_OF_CENTCHROMAN_PILLS_DELIVERED)) .withNumberOfOCPDelivered(ec.getDetail(NUMBER_OF_OCP_DELIVERED)) .withCaste(ec.getDetail(CASTE)) .withEconomicStatus(ec.getDetail(ECONOMIC_STATUS)) .withNumberOfPregnancies(ec.getDetail(NUMBER_OF_PREGNANCIES)) .withParity(ec.getDetail(PARITY)) .withNumberOfLivingChildren(ec.getDetail(NUMBER_OF_LIVING_CHILDREN)) .withNumberOfStillBirths(ec.getDetail(NUMBER_OF_STILL_BIRTHS)) .withNumberOfAbortions(ec.getDetail(NUMBER_OF_ABORTIONS)) .withIsHighPriority(ec.isHighPriority()).withPhotoPath(photoPath) .withHighPriorityReason(ec.getDetail(HIGH_PRIORITY_REASON)) .withIsOutOfArea(ec.isOutOfArea()); updateStatusInformation(ec, ecClient); updateChildrenInformation(ecClient); ecClients.add(ecClient); } sortByName(ecClients); return new Gson().toJson(ecClients); } }); } ECSmartRegisterController(AllEligibleCouples allEligibleCouples, AllBeneficiaries allBeneficiaries, Cache<String> cache, Cache<ECClients> ecClientsCache); String get(); ECClients getClients(); }
ECSmartRegisterController { public String get() { return cache.get(EC_CLIENTS_LIST, new CacheableData<String>() { @Override public String fetch() { List<EligibleCouple> ecs = allEligibleCouples.all(); List<ECClient> ecClients = new ArrayList<ECClient>(); for (EligibleCouple ec : ecs) { String photoPath = isBlank(ec.photoPath()) ? DEFAULT_WOMAN_IMAGE_PLACEHOLDER_PATH : ec.photoPath(); ECClient ecClient = new ECClient(ec.caseId(), ec.wifeName(), ec.husbandName(), ec.village(), IntegerUtil.tryParse(ec.ecNumber(), 0)) .withDateOfBirth(ec.getDetail(WOMAN_DOB)) .withFPMethod(ec.getDetail(CURRENT_FP_METHOD)) .withFamilyPlanningMethodChangeDate( ec.getDetail(FAMILY_PLANNING_METHOD_CHANGE_DATE)) .withIUDPlace(ec.getDetail(IUD_PLACE)) .withIUDPerson(ec.getDetail(IUD_PERSON)) .withNumberOfCondomsSupplied(ec.getDetail(NUMBER_OF_CONDOMS_SUPPLIED)) .withNumberOfCentchromanPillsDelivered( ec.getDetail(NUMBER_OF_CENTCHROMAN_PILLS_DELIVERED)) .withNumberOfOCPDelivered(ec.getDetail(NUMBER_OF_OCP_DELIVERED)) .withCaste(ec.getDetail(CASTE)) .withEconomicStatus(ec.getDetail(ECONOMIC_STATUS)) .withNumberOfPregnancies(ec.getDetail(NUMBER_OF_PREGNANCIES)) .withParity(ec.getDetail(PARITY)) .withNumberOfLivingChildren(ec.getDetail(NUMBER_OF_LIVING_CHILDREN)) .withNumberOfStillBirths(ec.getDetail(NUMBER_OF_STILL_BIRTHS)) .withNumberOfAbortions(ec.getDetail(NUMBER_OF_ABORTIONS)) .withIsHighPriority(ec.isHighPriority()).withPhotoPath(photoPath) .withHighPriorityReason(ec.getDetail(HIGH_PRIORITY_REASON)) .withIsOutOfArea(ec.isOutOfArea()); updateStatusInformation(ec, ecClient); updateChildrenInformation(ecClient); ecClients.add(ecClient); } sortByName(ecClients); return new Gson().toJson(ecClients); } }); } ECSmartRegisterController(AllEligibleCouples allEligibleCouples, AllBeneficiaries allBeneficiaries, Cache<String> cache, Cache<ECClients> ecClientsCache); String get(); ECClients getClients(); static final String STATUS_TYPE_FIELD; static final String STATUS_DATE_FIELD; static final String EC_STATUS; static final String ANC_STATUS; static final String PNC_STATUS; static final String PNC_FP_STATUS; static final String FP_STATUS; static final String STATUS_EDD_FIELD; static final String FP_METHOD_DATE_FIELD; }
@Test public void shouldGetAndCacheValueOnlyWhenItDoesNotExist() throws Exception { Cache<String> cache = new Cache<String>(); Mockito.when(cacheableData.fetch()).thenReturn("value"); Assert.assertEquals("value", cache.get("key", cacheableData)); Mockito.verify(cacheableData).fetch(); Assert.assertEquals("value", cache.get("key", cacheableData)); Mockito.verify(cacheableData, Mockito.times(1)).fetch(); }
public T get(String key, CacheableData<T> cacheableData) { if (value.get(key) != null) { return value.get(key); } T fetchedData = cacheableData.fetch(); value.put(key, fetchedData); return fetchedData; }
Cache { public T get(String key, CacheableData<T> cacheableData) { if (value.get(key) != null) { return value.get(key); } T fetchedData = cacheableData.fetch(); value.put(key, fetchedData); return fetchedData; } }
Cache { public T get(String key, CacheableData<T> cacheableData) { if (value.get(key) != null) { return value.get(key); } T fetchedData = cacheableData.fetch(); value.put(key, fetchedData); return fetchedData; } Cache(); }
Cache { public T get(String key, CacheableData<T> cacheableData) { if (value.get(key) != null) { return value.get(key); } T fetchedData = cacheableData.fetch(); value.put(key, fetchedData); return fetchedData; } Cache(); T get(String key, CacheableData<T> cacheableData); void evict(String key); }
Cache { public T get(String key, CacheableData<T> cacheableData) { if (value.get(key) != null) { return value.get(key); } T fetchedData = cacheableData.fetch(); value.put(key, fetchedData); return fetchedData; } Cache(); T get(String key, CacheableData<T> cacheableData); void evict(String key); }
@Test public void shouldAddStatusToECClientAsECWhenNoMotherAndNoFPMethod() throws Exception { EligibleCouple ec1 = new EligibleCouple("entity id 1", "Woman A", "Husband A", "1", "Bherya", null, EasyMap.create("registrationDate", "2013-02-02").put("currentMethod", "none").map()); Mockito.when(allEligibleCouples.all()).thenReturn(Arrays.asList(ec1)); Mockito.when(allBeneficiaries.findMotherWithOpenStatusByECId("entity id 1")).thenReturn(null); ECClient expectedClient1 = createECClient("entity id 1", "Woman A", "Husband A", "Bherya", 1) .withFPMethod("none") .withStatus(EasyMap.create("type", "ec").put("date", "2013-02-02").map()); String clients = controller.get(); List<ECClient> actualClients = new Gson().fromJson(clients, new TypeToken<List<ECClient>>() { }.getType()); Assert.assertEquals(Arrays.asList(expectedClient1), actualClients); }
public String get() { return cache.get(EC_CLIENTS_LIST, new CacheableData<String>() { @Override public String fetch() { List<EligibleCouple> ecs = allEligibleCouples.all(); List<ECClient> ecClients = new ArrayList<ECClient>(); for (EligibleCouple ec : ecs) { String photoPath = isBlank(ec.photoPath()) ? DEFAULT_WOMAN_IMAGE_PLACEHOLDER_PATH : ec.photoPath(); ECClient ecClient = new ECClient(ec.caseId(), ec.wifeName(), ec.husbandName(), ec.village(), IntegerUtil.tryParse(ec.ecNumber(), 0)) .withDateOfBirth(ec.getDetail(WOMAN_DOB)) .withFPMethod(ec.getDetail(CURRENT_FP_METHOD)) .withFamilyPlanningMethodChangeDate( ec.getDetail(FAMILY_PLANNING_METHOD_CHANGE_DATE)) .withIUDPlace(ec.getDetail(IUD_PLACE)) .withIUDPerson(ec.getDetail(IUD_PERSON)) .withNumberOfCondomsSupplied(ec.getDetail(NUMBER_OF_CONDOMS_SUPPLIED)) .withNumberOfCentchromanPillsDelivered( ec.getDetail(NUMBER_OF_CENTCHROMAN_PILLS_DELIVERED)) .withNumberOfOCPDelivered(ec.getDetail(NUMBER_OF_OCP_DELIVERED)) .withCaste(ec.getDetail(CASTE)) .withEconomicStatus(ec.getDetail(ECONOMIC_STATUS)) .withNumberOfPregnancies(ec.getDetail(NUMBER_OF_PREGNANCIES)) .withParity(ec.getDetail(PARITY)) .withNumberOfLivingChildren(ec.getDetail(NUMBER_OF_LIVING_CHILDREN)) .withNumberOfStillBirths(ec.getDetail(NUMBER_OF_STILL_BIRTHS)) .withNumberOfAbortions(ec.getDetail(NUMBER_OF_ABORTIONS)) .withIsHighPriority(ec.isHighPriority()).withPhotoPath(photoPath) .withHighPriorityReason(ec.getDetail(HIGH_PRIORITY_REASON)) .withIsOutOfArea(ec.isOutOfArea()); updateStatusInformation(ec, ecClient); updateChildrenInformation(ecClient); ecClients.add(ecClient); } sortByName(ecClients); return new Gson().toJson(ecClients); } }); }
ECSmartRegisterController { public String get() { return cache.get(EC_CLIENTS_LIST, new CacheableData<String>() { @Override public String fetch() { List<EligibleCouple> ecs = allEligibleCouples.all(); List<ECClient> ecClients = new ArrayList<ECClient>(); for (EligibleCouple ec : ecs) { String photoPath = isBlank(ec.photoPath()) ? DEFAULT_WOMAN_IMAGE_PLACEHOLDER_PATH : ec.photoPath(); ECClient ecClient = new ECClient(ec.caseId(), ec.wifeName(), ec.husbandName(), ec.village(), IntegerUtil.tryParse(ec.ecNumber(), 0)) .withDateOfBirth(ec.getDetail(WOMAN_DOB)) .withFPMethod(ec.getDetail(CURRENT_FP_METHOD)) .withFamilyPlanningMethodChangeDate( ec.getDetail(FAMILY_PLANNING_METHOD_CHANGE_DATE)) .withIUDPlace(ec.getDetail(IUD_PLACE)) .withIUDPerson(ec.getDetail(IUD_PERSON)) .withNumberOfCondomsSupplied(ec.getDetail(NUMBER_OF_CONDOMS_SUPPLIED)) .withNumberOfCentchromanPillsDelivered( ec.getDetail(NUMBER_OF_CENTCHROMAN_PILLS_DELIVERED)) .withNumberOfOCPDelivered(ec.getDetail(NUMBER_OF_OCP_DELIVERED)) .withCaste(ec.getDetail(CASTE)) .withEconomicStatus(ec.getDetail(ECONOMIC_STATUS)) .withNumberOfPregnancies(ec.getDetail(NUMBER_OF_PREGNANCIES)) .withParity(ec.getDetail(PARITY)) .withNumberOfLivingChildren(ec.getDetail(NUMBER_OF_LIVING_CHILDREN)) .withNumberOfStillBirths(ec.getDetail(NUMBER_OF_STILL_BIRTHS)) .withNumberOfAbortions(ec.getDetail(NUMBER_OF_ABORTIONS)) .withIsHighPriority(ec.isHighPriority()).withPhotoPath(photoPath) .withHighPriorityReason(ec.getDetail(HIGH_PRIORITY_REASON)) .withIsOutOfArea(ec.isOutOfArea()); updateStatusInformation(ec, ecClient); updateChildrenInformation(ecClient); ecClients.add(ecClient); } sortByName(ecClients); return new Gson().toJson(ecClients); } }); } }
ECSmartRegisterController { public String get() { return cache.get(EC_CLIENTS_LIST, new CacheableData<String>() { @Override public String fetch() { List<EligibleCouple> ecs = allEligibleCouples.all(); List<ECClient> ecClients = new ArrayList<ECClient>(); for (EligibleCouple ec : ecs) { String photoPath = isBlank(ec.photoPath()) ? DEFAULT_WOMAN_IMAGE_PLACEHOLDER_PATH : ec.photoPath(); ECClient ecClient = new ECClient(ec.caseId(), ec.wifeName(), ec.husbandName(), ec.village(), IntegerUtil.tryParse(ec.ecNumber(), 0)) .withDateOfBirth(ec.getDetail(WOMAN_DOB)) .withFPMethod(ec.getDetail(CURRENT_FP_METHOD)) .withFamilyPlanningMethodChangeDate( ec.getDetail(FAMILY_PLANNING_METHOD_CHANGE_DATE)) .withIUDPlace(ec.getDetail(IUD_PLACE)) .withIUDPerson(ec.getDetail(IUD_PERSON)) .withNumberOfCondomsSupplied(ec.getDetail(NUMBER_OF_CONDOMS_SUPPLIED)) .withNumberOfCentchromanPillsDelivered( ec.getDetail(NUMBER_OF_CENTCHROMAN_PILLS_DELIVERED)) .withNumberOfOCPDelivered(ec.getDetail(NUMBER_OF_OCP_DELIVERED)) .withCaste(ec.getDetail(CASTE)) .withEconomicStatus(ec.getDetail(ECONOMIC_STATUS)) .withNumberOfPregnancies(ec.getDetail(NUMBER_OF_PREGNANCIES)) .withParity(ec.getDetail(PARITY)) .withNumberOfLivingChildren(ec.getDetail(NUMBER_OF_LIVING_CHILDREN)) .withNumberOfStillBirths(ec.getDetail(NUMBER_OF_STILL_BIRTHS)) .withNumberOfAbortions(ec.getDetail(NUMBER_OF_ABORTIONS)) .withIsHighPriority(ec.isHighPriority()).withPhotoPath(photoPath) .withHighPriorityReason(ec.getDetail(HIGH_PRIORITY_REASON)) .withIsOutOfArea(ec.isOutOfArea()); updateStatusInformation(ec, ecClient); updateChildrenInformation(ecClient); ecClients.add(ecClient); } sortByName(ecClients); return new Gson().toJson(ecClients); } }); } ECSmartRegisterController(AllEligibleCouples allEligibleCouples, AllBeneficiaries allBeneficiaries, Cache<String> cache, Cache<ECClients> ecClientsCache); }
ECSmartRegisterController { public String get() { return cache.get(EC_CLIENTS_LIST, new CacheableData<String>() { @Override public String fetch() { List<EligibleCouple> ecs = allEligibleCouples.all(); List<ECClient> ecClients = new ArrayList<ECClient>(); for (EligibleCouple ec : ecs) { String photoPath = isBlank(ec.photoPath()) ? DEFAULT_WOMAN_IMAGE_PLACEHOLDER_PATH : ec.photoPath(); ECClient ecClient = new ECClient(ec.caseId(), ec.wifeName(), ec.husbandName(), ec.village(), IntegerUtil.tryParse(ec.ecNumber(), 0)) .withDateOfBirth(ec.getDetail(WOMAN_DOB)) .withFPMethod(ec.getDetail(CURRENT_FP_METHOD)) .withFamilyPlanningMethodChangeDate( ec.getDetail(FAMILY_PLANNING_METHOD_CHANGE_DATE)) .withIUDPlace(ec.getDetail(IUD_PLACE)) .withIUDPerson(ec.getDetail(IUD_PERSON)) .withNumberOfCondomsSupplied(ec.getDetail(NUMBER_OF_CONDOMS_SUPPLIED)) .withNumberOfCentchromanPillsDelivered( ec.getDetail(NUMBER_OF_CENTCHROMAN_PILLS_DELIVERED)) .withNumberOfOCPDelivered(ec.getDetail(NUMBER_OF_OCP_DELIVERED)) .withCaste(ec.getDetail(CASTE)) .withEconomicStatus(ec.getDetail(ECONOMIC_STATUS)) .withNumberOfPregnancies(ec.getDetail(NUMBER_OF_PREGNANCIES)) .withParity(ec.getDetail(PARITY)) .withNumberOfLivingChildren(ec.getDetail(NUMBER_OF_LIVING_CHILDREN)) .withNumberOfStillBirths(ec.getDetail(NUMBER_OF_STILL_BIRTHS)) .withNumberOfAbortions(ec.getDetail(NUMBER_OF_ABORTIONS)) .withIsHighPriority(ec.isHighPriority()).withPhotoPath(photoPath) .withHighPriorityReason(ec.getDetail(HIGH_PRIORITY_REASON)) .withIsOutOfArea(ec.isOutOfArea()); updateStatusInformation(ec, ecClient); updateChildrenInformation(ecClient); ecClients.add(ecClient); } sortByName(ecClients); return new Gson().toJson(ecClients); } }); } ECSmartRegisterController(AllEligibleCouples allEligibleCouples, AllBeneficiaries allBeneficiaries, Cache<String> cache, Cache<ECClients> ecClientsCache); String get(); ECClients getClients(); }
ECSmartRegisterController { public String get() { return cache.get(EC_CLIENTS_LIST, new CacheableData<String>() { @Override public String fetch() { List<EligibleCouple> ecs = allEligibleCouples.all(); List<ECClient> ecClients = new ArrayList<ECClient>(); for (EligibleCouple ec : ecs) { String photoPath = isBlank(ec.photoPath()) ? DEFAULT_WOMAN_IMAGE_PLACEHOLDER_PATH : ec.photoPath(); ECClient ecClient = new ECClient(ec.caseId(), ec.wifeName(), ec.husbandName(), ec.village(), IntegerUtil.tryParse(ec.ecNumber(), 0)) .withDateOfBirth(ec.getDetail(WOMAN_DOB)) .withFPMethod(ec.getDetail(CURRENT_FP_METHOD)) .withFamilyPlanningMethodChangeDate( ec.getDetail(FAMILY_PLANNING_METHOD_CHANGE_DATE)) .withIUDPlace(ec.getDetail(IUD_PLACE)) .withIUDPerson(ec.getDetail(IUD_PERSON)) .withNumberOfCondomsSupplied(ec.getDetail(NUMBER_OF_CONDOMS_SUPPLIED)) .withNumberOfCentchromanPillsDelivered( ec.getDetail(NUMBER_OF_CENTCHROMAN_PILLS_DELIVERED)) .withNumberOfOCPDelivered(ec.getDetail(NUMBER_OF_OCP_DELIVERED)) .withCaste(ec.getDetail(CASTE)) .withEconomicStatus(ec.getDetail(ECONOMIC_STATUS)) .withNumberOfPregnancies(ec.getDetail(NUMBER_OF_PREGNANCIES)) .withParity(ec.getDetail(PARITY)) .withNumberOfLivingChildren(ec.getDetail(NUMBER_OF_LIVING_CHILDREN)) .withNumberOfStillBirths(ec.getDetail(NUMBER_OF_STILL_BIRTHS)) .withNumberOfAbortions(ec.getDetail(NUMBER_OF_ABORTIONS)) .withIsHighPriority(ec.isHighPriority()).withPhotoPath(photoPath) .withHighPriorityReason(ec.getDetail(HIGH_PRIORITY_REASON)) .withIsOutOfArea(ec.isOutOfArea()); updateStatusInformation(ec, ecClient); updateChildrenInformation(ecClient); ecClients.add(ecClient); } sortByName(ecClients); return new Gson().toJson(ecClients); } }); } ECSmartRegisterController(AllEligibleCouples allEligibleCouples, AllBeneficiaries allBeneficiaries, Cache<String> cache, Cache<ECClients> ecClientsCache); String get(); ECClients getClients(); static final String STATUS_TYPE_FIELD; static final String STATUS_DATE_FIELD; static final String EC_STATUS; static final String ANC_STATUS; static final String PNC_STATUS; static final String PNC_FP_STATUS; static final String FP_STATUS; static final String STATUS_EDD_FIELD; static final String FP_METHOD_DATE_FIELD; }
@Test public void shouldAddStatusToECClientAsECWhenNoMotherAndHasFPMethod() throws Exception { EligibleCouple ec1 = new EligibleCouple("entity id 1", "Woman A", "Husband A", "1", "Bherya", null, EasyMap.create("familyPlanningMethodChangeDate", "2013-02-02").put("currentMethod", "condom").map()); Mockito.when(allEligibleCouples.all()).thenReturn(Arrays.asList(ec1)); Mockito.when(allBeneficiaries.findMotherWithOpenStatusByECId("entity id 1")).thenReturn(null); ECClient expectedClient1 = createECClient("entity id 1", "Woman A", "Husband A", "Bherya", 1) .withFamilyPlanningMethodChangeDate("2013-02-02") .withFPMethod("condom") .withStatus(EasyMap.create("type", "fp").put("date", "2013-02-02").map()); String clients = controller.get(); List<ECClient> actualClients = new Gson().fromJson(clients, new TypeToken<List<ECClient>>() { }.getType()); Assert.assertEquals(Arrays.asList(expectedClient1), actualClients); }
public String get() { return cache.get(EC_CLIENTS_LIST, new CacheableData<String>() { @Override public String fetch() { List<EligibleCouple> ecs = allEligibleCouples.all(); List<ECClient> ecClients = new ArrayList<ECClient>(); for (EligibleCouple ec : ecs) { String photoPath = isBlank(ec.photoPath()) ? DEFAULT_WOMAN_IMAGE_PLACEHOLDER_PATH : ec.photoPath(); ECClient ecClient = new ECClient(ec.caseId(), ec.wifeName(), ec.husbandName(), ec.village(), IntegerUtil.tryParse(ec.ecNumber(), 0)) .withDateOfBirth(ec.getDetail(WOMAN_DOB)) .withFPMethod(ec.getDetail(CURRENT_FP_METHOD)) .withFamilyPlanningMethodChangeDate( ec.getDetail(FAMILY_PLANNING_METHOD_CHANGE_DATE)) .withIUDPlace(ec.getDetail(IUD_PLACE)) .withIUDPerson(ec.getDetail(IUD_PERSON)) .withNumberOfCondomsSupplied(ec.getDetail(NUMBER_OF_CONDOMS_SUPPLIED)) .withNumberOfCentchromanPillsDelivered( ec.getDetail(NUMBER_OF_CENTCHROMAN_PILLS_DELIVERED)) .withNumberOfOCPDelivered(ec.getDetail(NUMBER_OF_OCP_DELIVERED)) .withCaste(ec.getDetail(CASTE)) .withEconomicStatus(ec.getDetail(ECONOMIC_STATUS)) .withNumberOfPregnancies(ec.getDetail(NUMBER_OF_PREGNANCIES)) .withParity(ec.getDetail(PARITY)) .withNumberOfLivingChildren(ec.getDetail(NUMBER_OF_LIVING_CHILDREN)) .withNumberOfStillBirths(ec.getDetail(NUMBER_OF_STILL_BIRTHS)) .withNumberOfAbortions(ec.getDetail(NUMBER_OF_ABORTIONS)) .withIsHighPriority(ec.isHighPriority()).withPhotoPath(photoPath) .withHighPriorityReason(ec.getDetail(HIGH_PRIORITY_REASON)) .withIsOutOfArea(ec.isOutOfArea()); updateStatusInformation(ec, ecClient); updateChildrenInformation(ecClient); ecClients.add(ecClient); } sortByName(ecClients); return new Gson().toJson(ecClients); } }); }
ECSmartRegisterController { public String get() { return cache.get(EC_CLIENTS_LIST, new CacheableData<String>() { @Override public String fetch() { List<EligibleCouple> ecs = allEligibleCouples.all(); List<ECClient> ecClients = new ArrayList<ECClient>(); for (EligibleCouple ec : ecs) { String photoPath = isBlank(ec.photoPath()) ? DEFAULT_WOMAN_IMAGE_PLACEHOLDER_PATH : ec.photoPath(); ECClient ecClient = new ECClient(ec.caseId(), ec.wifeName(), ec.husbandName(), ec.village(), IntegerUtil.tryParse(ec.ecNumber(), 0)) .withDateOfBirth(ec.getDetail(WOMAN_DOB)) .withFPMethod(ec.getDetail(CURRENT_FP_METHOD)) .withFamilyPlanningMethodChangeDate( ec.getDetail(FAMILY_PLANNING_METHOD_CHANGE_DATE)) .withIUDPlace(ec.getDetail(IUD_PLACE)) .withIUDPerson(ec.getDetail(IUD_PERSON)) .withNumberOfCondomsSupplied(ec.getDetail(NUMBER_OF_CONDOMS_SUPPLIED)) .withNumberOfCentchromanPillsDelivered( ec.getDetail(NUMBER_OF_CENTCHROMAN_PILLS_DELIVERED)) .withNumberOfOCPDelivered(ec.getDetail(NUMBER_OF_OCP_DELIVERED)) .withCaste(ec.getDetail(CASTE)) .withEconomicStatus(ec.getDetail(ECONOMIC_STATUS)) .withNumberOfPregnancies(ec.getDetail(NUMBER_OF_PREGNANCIES)) .withParity(ec.getDetail(PARITY)) .withNumberOfLivingChildren(ec.getDetail(NUMBER_OF_LIVING_CHILDREN)) .withNumberOfStillBirths(ec.getDetail(NUMBER_OF_STILL_BIRTHS)) .withNumberOfAbortions(ec.getDetail(NUMBER_OF_ABORTIONS)) .withIsHighPriority(ec.isHighPriority()).withPhotoPath(photoPath) .withHighPriorityReason(ec.getDetail(HIGH_PRIORITY_REASON)) .withIsOutOfArea(ec.isOutOfArea()); updateStatusInformation(ec, ecClient); updateChildrenInformation(ecClient); ecClients.add(ecClient); } sortByName(ecClients); return new Gson().toJson(ecClients); } }); } }
ECSmartRegisterController { public String get() { return cache.get(EC_CLIENTS_LIST, new CacheableData<String>() { @Override public String fetch() { List<EligibleCouple> ecs = allEligibleCouples.all(); List<ECClient> ecClients = new ArrayList<ECClient>(); for (EligibleCouple ec : ecs) { String photoPath = isBlank(ec.photoPath()) ? DEFAULT_WOMAN_IMAGE_PLACEHOLDER_PATH : ec.photoPath(); ECClient ecClient = new ECClient(ec.caseId(), ec.wifeName(), ec.husbandName(), ec.village(), IntegerUtil.tryParse(ec.ecNumber(), 0)) .withDateOfBirth(ec.getDetail(WOMAN_DOB)) .withFPMethod(ec.getDetail(CURRENT_FP_METHOD)) .withFamilyPlanningMethodChangeDate( ec.getDetail(FAMILY_PLANNING_METHOD_CHANGE_DATE)) .withIUDPlace(ec.getDetail(IUD_PLACE)) .withIUDPerson(ec.getDetail(IUD_PERSON)) .withNumberOfCondomsSupplied(ec.getDetail(NUMBER_OF_CONDOMS_SUPPLIED)) .withNumberOfCentchromanPillsDelivered( ec.getDetail(NUMBER_OF_CENTCHROMAN_PILLS_DELIVERED)) .withNumberOfOCPDelivered(ec.getDetail(NUMBER_OF_OCP_DELIVERED)) .withCaste(ec.getDetail(CASTE)) .withEconomicStatus(ec.getDetail(ECONOMIC_STATUS)) .withNumberOfPregnancies(ec.getDetail(NUMBER_OF_PREGNANCIES)) .withParity(ec.getDetail(PARITY)) .withNumberOfLivingChildren(ec.getDetail(NUMBER_OF_LIVING_CHILDREN)) .withNumberOfStillBirths(ec.getDetail(NUMBER_OF_STILL_BIRTHS)) .withNumberOfAbortions(ec.getDetail(NUMBER_OF_ABORTIONS)) .withIsHighPriority(ec.isHighPriority()).withPhotoPath(photoPath) .withHighPriorityReason(ec.getDetail(HIGH_PRIORITY_REASON)) .withIsOutOfArea(ec.isOutOfArea()); updateStatusInformation(ec, ecClient); updateChildrenInformation(ecClient); ecClients.add(ecClient); } sortByName(ecClients); return new Gson().toJson(ecClients); } }); } ECSmartRegisterController(AllEligibleCouples allEligibleCouples, AllBeneficiaries allBeneficiaries, Cache<String> cache, Cache<ECClients> ecClientsCache); }
ECSmartRegisterController { public String get() { return cache.get(EC_CLIENTS_LIST, new CacheableData<String>() { @Override public String fetch() { List<EligibleCouple> ecs = allEligibleCouples.all(); List<ECClient> ecClients = new ArrayList<ECClient>(); for (EligibleCouple ec : ecs) { String photoPath = isBlank(ec.photoPath()) ? DEFAULT_WOMAN_IMAGE_PLACEHOLDER_PATH : ec.photoPath(); ECClient ecClient = new ECClient(ec.caseId(), ec.wifeName(), ec.husbandName(), ec.village(), IntegerUtil.tryParse(ec.ecNumber(), 0)) .withDateOfBirth(ec.getDetail(WOMAN_DOB)) .withFPMethod(ec.getDetail(CURRENT_FP_METHOD)) .withFamilyPlanningMethodChangeDate( ec.getDetail(FAMILY_PLANNING_METHOD_CHANGE_DATE)) .withIUDPlace(ec.getDetail(IUD_PLACE)) .withIUDPerson(ec.getDetail(IUD_PERSON)) .withNumberOfCondomsSupplied(ec.getDetail(NUMBER_OF_CONDOMS_SUPPLIED)) .withNumberOfCentchromanPillsDelivered( ec.getDetail(NUMBER_OF_CENTCHROMAN_PILLS_DELIVERED)) .withNumberOfOCPDelivered(ec.getDetail(NUMBER_OF_OCP_DELIVERED)) .withCaste(ec.getDetail(CASTE)) .withEconomicStatus(ec.getDetail(ECONOMIC_STATUS)) .withNumberOfPregnancies(ec.getDetail(NUMBER_OF_PREGNANCIES)) .withParity(ec.getDetail(PARITY)) .withNumberOfLivingChildren(ec.getDetail(NUMBER_OF_LIVING_CHILDREN)) .withNumberOfStillBirths(ec.getDetail(NUMBER_OF_STILL_BIRTHS)) .withNumberOfAbortions(ec.getDetail(NUMBER_OF_ABORTIONS)) .withIsHighPriority(ec.isHighPriority()).withPhotoPath(photoPath) .withHighPriorityReason(ec.getDetail(HIGH_PRIORITY_REASON)) .withIsOutOfArea(ec.isOutOfArea()); updateStatusInformation(ec, ecClient); updateChildrenInformation(ecClient); ecClients.add(ecClient); } sortByName(ecClients); return new Gson().toJson(ecClients); } }); } ECSmartRegisterController(AllEligibleCouples allEligibleCouples, AllBeneficiaries allBeneficiaries, Cache<String> cache, Cache<ECClients> ecClientsCache); String get(); ECClients getClients(); }
ECSmartRegisterController { public String get() { return cache.get(EC_CLIENTS_LIST, new CacheableData<String>() { @Override public String fetch() { List<EligibleCouple> ecs = allEligibleCouples.all(); List<ECClient> ecClients = new ArrayList<ECClient>(); for (EligibleCouple ec : ecs) { String photoPath = isBlank(ec.photoPath()) ? DEFAULT_WOMAN_IMAGE_PLACEHOLDER_PATH : ec.photoPath(); ECClient ecClient = new ECClient(ec.caseId(), ec.wifeName(), ec.husbandName(), ec.village(), IntegerUtil.tryParse(ec.ecNumber(), 0)) .withDateOfBirth(ec.getDetail(WOMAN_DOB)) .withFPMethod(ec.getDetail(CURRENT_FP_METHOD)) .withFamilyPlanningMethodChangeDate( ec.getDetail(FAMILY_PLANNING_METHOD_CHANGE_DATE)) .withIUDPlace(ec.getDetail(IUD_PLACE)) .withIUDPerson(ec.getDetail(IUD_PERSON)) .withNumberOfCondomsSupplied(ec.getDetail(NUMBER_OF_CONDOMS_SUPPLIED)) .withNumberOfCentchromanPillsDelivered( ec.getDetail(NUMBER_OF_CENTCHROMAN_PILLS_DELIVERED)) .withNumberOfOCPDelivered(ec.getDetail(NUMBER_OF_OCP_DELIVERED)) .withCaste(ec.getDetail(CASTE)) .withEconomicStatus(ec.getDetail(ECONOMIC_STATUS)) .withNumberOfPregnancies(ec.getDetail(NUMBER_OF_PREGNANCIES)) .withParity(ec.getDetail(PARITY)) .withNumberOfLivingChildren(ec.getDetail(NUMBER_OF_LIVING_CHILDREN)) .withNumberOfStillBirths(ec.getDetail(NUMBER_OF_STILL_BIRTHS)) .withNumberOfAbortions(ec.getDetail(NUMBER_OF_ABORTIONS)) .withIsHighPriority(ec.isHighPriority()).withPhotoPath(photoPath) .withHighPriorityReason(ec.getDetail(HIGH_PRIORITY_REASON)) .withIsOutOfArea(ec.isOutOfArea()); updateStatusInformation(ec, ecClient); updateChildrenInformation(ecClient); ecClients.add(ecClient); } sortByName(ecClients); return new Gson().toJson(ecClients); } }); } ECSmartRegisterController(AllEligibleCouples allEligibleCouples, AllBeneficiaries allBeneficiaries, Cache<String> cache, Cache<ECClients> ecClientsCache); String get(); ECClients getClients(); static final String STATUS_TYPE_FIELD; static final String STATUS_DATE_FIELD; static final String EC_STATUS; static final String ANC_STATUS; static final String PNC_STATUS; static final String PNC_FP_STATUS; static final String FP_STATUS; static final String STATUS_EDD_FIELD; static final String FP_METHOD_DATE_FIELD; }
@Test public void shouldAddStatusToECClientAsANCWhenMotherIsActiveAndIsInANCState() throws Exception { EligibleCouple ec1 = new EligibleCouple("entity id 1", "Woman A", "Husband A", "1", "Bherya", null, emptyDetails); Mother mother = new Mother("mother id 1", "entity id 1", "thayi card 1", "2013-01-01").withType("anc").withDetails(EasyMap.mapOf("edd", "Sat, 12 Oct 2013 00:00:00 GMT")); Mockito.when(allEligibleCouples.all()).thenReturn(Arrays.asList(ec1)); Mockito.when(allBeneficiaries.findMotherWithOpenStatusByECId("entity id 1")).thenReturn(mother); ECClient expectedClient1 = createECClient("entity id 1", "Woman A", "Husband A", "Bherya", 1) .withStatus(EasyMap.create("date", "2013-01-01").put("edd", "2013-10-12").put("type", "anc").map()); String clients = controller.get(); List<ECClient> actualClients = new Gson().fromJson(clients, new TypeToken<List<ECClient>>() { }.getType()); Assert.assertEquals(Arrays.asList(expectedClient1), actualClients); }
public String get() { return cache.get(EC_CLIENTS_LIST, new CacheableData<String>() { @Override public String fetch() { List<EligibleCouple> ecs = allEligibleCouples.all(); List<ECClient> ecClients = new ArrayList<ECClient>(); for (EligibleCouple ec : ecs) { String photoPath = isBlank(ec.photoPath()) ? DEFAULT_WOMAN_IMAGE_PLACEHOLDER_PATH : ec.photoPath(); ECClient ecClient = new ECClient(ec.caseId(), ec.wifeName(), ec.husbandName(), ec.village(), IntegerUtil.tryParse(ec.ecNumber(), 0)) .withDateOfBirth(ec.getDetail(WOMAN_DOB)) .withFPMethod(ec.getDetail(CURRENT_FP_METHOD)) .withFamilyPlanningMethodChangeDate( ec.getDetail(FAMILY_PLANNING_METHOD_CHANGE_DATE)) .withIUDPlace(ec.getDetail(IUD_PLACE)) .withIUDPerson(ec.getDetail(IUD_PERSON)) .withNumberOfCondomsSupplied(ec.getDetail(NUMBER_OF_CONDOMS_SUPPLIED)) .withNumberOfCentchromanPillsDelivered( ec.getDetail(NUMBER_OF_CENTCHROMAN_PILLS_DELIVERED)) .withNumberOfOCPDelivered(ec.getDetail(NUMBER_OF_OCP_DELIVERED)) .withCaste(ec.getDetail(CASTE)) .withEconomicStatus(ec.getDetail(ECONOMIC_STATUS)) .withNumberOfPregnancies(ec.getDetail(NUMBER_OF_PREGNANCIES)) .withParity(ec.getDetail(PARITY)) .withNumberOfLivingChildren(ec.getDetail(NUMBER_OF_LIVING_CHILDREN)) .withNumberOfStillBirths(ec.getDetail(NUMBER_OF_STILL_BIRTHS)) .withNumberOfAbortions(ec.getDetail(NUMBER_OF_ABORTIONS)) .withIsHighPriority(ec.isHighPriority()).withPhotoPath(photoPath) .withHighPriorityReason(ec.getDetail(HIGH_PRIORITY_REASON)) .withIsOutOfArea(ec.isOutOfArea()); updateStatusInformation(ec, ecClient); updateChildrenInformation(ecClient); ecClients.add(ecClient); } sortByName(ecClients); return new Gson().toJson(ecClients); } }); }
ECSmartRegisterController { public String get() { return cache.get(EC_CLIENTS_LIST, new CacheableData<String>() { @Override public String fetch() { List<EligibleCouple> ecs = allEligibleCouples.all(); List<ECClient> ecClients = new ArrayList<ECClient>(); for (EligibleCouple ec : ecs) { String photoPath = isBlank(ec.photoPath()) ? DEFAULT_WOMAN_IMAGE_PLACEHOLDER_PATH : ec.photoPath(); ECClient ecClient = new ECClient(ec.caseId(), ec.wifeName(), ec.husbandName(), ec.village(), IntegerUtil.tryParse(ec.ecNumber(), 0)) .withDateOfBirth(ec.getDetail(WOMAN_DOB)) .withFPMethod(ec.getDetail(CURRENT_FP_METHOD)) .withFamilyPlanningMethodChangeDate( ec.getDetail(FAMILY_PLANNING_METHOD_CHANGE_DATE)) .withIUDPlace(ec.getDetail(IUD_PLACE)) .withIUDPerson(ec.getDetail(IUD_PERSON)) .withNumberOfCondomsSupplied(ec.getDetail(NUMBER_OF_CONDOMS_SUPPLIED)) .withNumberOfCentchromanPillsDelivered( ec.getDetail(NUMBER_OF_CENTCHROMAN_PILLS_DELIVERED)) .withNumberOfOCPDelivered(ec.getDetail(NUMBER_OF_OCP_DELIVERED)) .withCaste(ec.getDetail(CASTE)) .withEconomicStatus(ec.getDetail(ECONOMIC_STATUS)) .withNumberOfPregnancies(ec.getDetail(NUMBER_OF_PREGNANCIES)) .withParity(ec.getDetail(PARITY)) .withNumberOfLivingChildren(ec.getDetail(NUMBER_OF_LIVING_CHILDREN)) .withNumberOfStillBirths(ec.getDetail(NUMBER_OF_STILL_BIRTHS)) .withNumberOfAbortions(ec.getDetail(NUMBER_OF_ABORTIONS)) .withIsHighPriority(ec.isHighPriority()).withPhotoPath(photoPath) .withHighPriorityReason(ec.getDetail(HIGH_PRIORITY_REASON)) .withIsOutOfArea(ec.isOutOfArea()); updateStatusInformation(ec, ecClient); updateChildrenInformation(ecClient); ecClients.add(ecClient); } sortByName(ecClients); return new Gson().toJson(ecClients); } }); } }
ECSmartRegisterController { public String get() { return cache.get(EC_CLIENTS_LIST, new CacheableData<String>() { @Override public String fetch() { List<EligibleCouple> ecs = allEligibleCouples.all(); List<ECClient> ecClients = new ArrayList<ECClient>(); for (EligibleCouple ec : ecs) { String photoPath = isBlank(ec.photoPath()) ? DEFAULT_WOMAN_IMAGE_PLACEHOLDER_PATH : ec.photoPath(); ECClient ecClient = new ECClient(ec.caseId(), ec.wifeName(), ec.husbandName(), ec.village(), IntegerUtil.tryParse(ec.ecNumber(), 0)) .withDateOfBirth(ec.getDetail(WOMAN_DOB)) .withFPMethod(ec.getDetail(CURRENT_FP_METHOD)) .withFamilyPlanningMethodChangeDate( ec.getDetail(FAMILY_PLANNING_METHOD_CHANGE_DATE)) .withIUDPlace(ec.getDetail(IUD_PLACE)) .withIUDPerson(ec.getDetail(IUD_PERSON)) .withNumberOfCondomsSupplied(ec.getDetail(NUMBER_OF_CONDOMS_SUPPLIED)) .withNumberOfCentchromanPillsDelivered( ec.getDetail(NUMBER_OF_CENTCHROMAN_PILLS_DELIVERED)) .withNumberOfOCPDelivered(ec.getDetail(NUMBER_OF_OCP_DELIVERED)) .withCaste(ec.getDetail(CASTE)) .withEconomicStatus(ec.getDetail(ECONOMIC_STATUS)) .withNumberOfPregnancies(ec.getDetail(NUMBER_OF_PREGNANCIES)) .withParity(ec.getDetail(PARITY)) .withNumberOfLivingChildren(ec.getDetail(NUMBER_OF_LIVING_CHILDREN)) .withNumberOfStillBirths(ec.getDetail(NUMBER_OF_STILL_BIRTHS)) .withNumberOfAbortions(ec.getDetail(NUMBER_OF_ABORTIONS)) .withIsHighPriority(ec.isHighPriority()).withPhotoPath(photoPath) .withHighPriorityReason(ec.getDetail(HIGH_PRIORITY_REASON)) .withIsOutOfArea(ec.isOutOfArea()); updateStatusInformation(ec, ecClient); updateChildrenInformation(ecClient); ecClients.add(ecClient); } sortByName(ecClients); return new Gson().toJson(ecClients); } }); } ECSmartRegisterController(AllEligibleCouples allEligibleCouples, AllBeneficiaries allBeneficiaries, Cache<String> cache, Cache<ECClients> ecClientsCache); }
ECSmartRegisterController { public String get() { return cache.get(EC_CLIENTS_LIST, new CacheableData<String>() { @Override public String fetch() { List<EligibleCouple> ecs = allEligibleCouples.all(); List<ECClient> ecClients = new ArrayList<ECClient>(); for (EligibleCouple ec : ecs) { String photoPath = isBlank(ec.photoPath()) ? DEFAULT_WOMAN_IMAGE_PLACEHOLDER_PATH : ec.photoPath(); ECClient ecClient = new ECClient(ec.caseId(), ec.wifeName(), ec.husbandName(), ec.village(), IntegerUtil.tryParse(ec.ecNumber(), 0)) .withDateOfBirth(ec.getDetail(WOMAN_DOB)) .withFPMethod(ec.getDetail(CURRENT_FP_METHOD)) .withFamilyPlanningMethodChangeDate( ec.getDetail(FAMILY_PLANNING_METHOD_CHANGE_DATE)) .withIUDPlace(ec.getDetail(IUD_PLACE)) .withIUDPerson(ec.getDetail(IUD_PERSON)) .withNumberOfCondomsSupplied(ec.getDetail(NUMBER_OF_CONDOMS_SUPPLIED)) .withNumberOfCentchromanPillsDelivered( ec.getDetail(NUMBER_OF_CENTCHROMAN_PILLS_DELIVERED)) .withNumberOfOCPDelivered(ec.getDetail(NUMBER_OF_OCP_DELIVERED)) .withCaste(ec.getDetail(CASTE)) .withEconomicStatus(ec.getDetail(ECONOMIC_STATUS)) .withNumberOfPregnancies(ec.getDetail(NUMBER_OF_PREGNANCIES)) .withParity(ec.getDetail(PARITY)) .withNumberOfLivingChildren(ec.getDetail(NUMBER_OF_LIVING_CHILDREN)) .withNumberOfStillBirths(ec.getDetail(NUMBER_OF_STILL_BIRTHS)) .withNumberOfAbortions(ec.getDetail(NUMBER_OF_ABORTIONS)) .withIsHighPriority(ec.isHighPriority()).withPhotoPath(photoPath) .withHighPriorityReason(ec.getDetail(HIGH_PRIORITY_REASON)) .withIsOutOfArea(ec.isOutOfArea()); updateStatusInformation(ec, ecClient); updateChildrenInformation(ecClient); ecClients.add(ecClient); } sortByName(ecClients); return new Gson().toJson(ecClients); } }); } ECSmartRegisterController(AllEligibleCouples allEligibleCouples, AllBeneficiaries allBeneficiaries, Cache<String> cache, Cache<ECClients> ecClientsCache); String get(); ECClients getClients(); }
ECSmartRegisterController { public String get() { return cache.get(EC_CLIENTS_LIST, new CacheableData<String>() { @Override public String fetch() { List<EligibleCouple> ecs = allEligibleCouples.all(); List<ECClient> ecClients = new ArrayList<ECClient>(); for (EligibleCouple ec : ecs) { String photoPath = isBlank(ec.photoPath()) ? DEFAULT_WOMAN_IMAGE_PLACEHOLDER_PATH : ec.photoPath(); ECClient ecClient = new ECClient(ec.caseId(), ec.wifeName(), ec.husbandName(), ec.village(), IntegerUtil.tryParse(ec.ecNumber(), 0)) .withDateOfBirth(ec.getDetail(WOMAN_DOB)) .withFPMethod(ec.getDetail(CURRENT_FP_METHOD)) .withFamilyPlanningMethodChangeDate( ec.getDetail(FAMILY_PLANNING_METHOD_CHANGE_DATE)) .withIUDPlace(ec.getDetail(IUD_PLACE)) .withIUDPerson(ec.getDetail(IUD_PERSON)) .withNumberOfCondomsSupplied(ec.getDetail(NUMBER_OF_CONDOMS_SUPPLIED)) .withNumberOfCentchromanPillsDelivered( ec.getDetail(NUMBER_OF_CENTCHROMAN_PILLS_DELIVERED)) .withNumberOfOCPDelivered(ec.getDetail(NUMBER_OF_OCP_DELIVERED)) .withCaste(ec.getDetail(CASTE)) .withEconomicStatus(ec.getDetail(ECONOMIC_STATUS)) .withNumberOfPregnancies(ec.getDetail(NUMBER_OF_PREGNANCIES)) .withParity(ec.getDetail(PARITY)) .withNumberOfLivingChildren(ec.getDetail(NUMBER_OF_LIVING_CHILDREN)) .withNumberOfStillBirths(ec.getDetail(NUMBER_OF_STILL_BIRTHS)) .withNumberOfAbortions(ec.getDetail(NUMBER_OF_ABORTIONS)) .withIsHighPriority(ec.isHighPriority()).withPhotoPath(photoPath) .withHighPriorityReason(ec.getDetail(HIGH_PRIORITY_REASON)) .withIsOutOfArea(ec.isOutOfArea()); updateStatusInformation(ec, ecClient); updateChildrenInformation(ecClient); ecClients.add(ecClient); } sortByName(ecClients); return new Gson().toJson(ecClients); } }); } ECSmartRegisterController(AllEligibleCouples allEligibleCouples, AllBeneficiaries allBeneficiaries, Cache<String> cache, Cache<ECClients> ecClientsCache); String get(); ECClients getClients(); static final String STATUS_TYPE_FIELD; static final String STATUS_DATE_FIELD; static final String EC_STATUS; static final String ANC_STATUS; static final String PNC_STATUS; static final String PNC_FP_STATUS; static final String FP_STATUS; static final String STATUS_EDD_FIELD; static final String FP_METHOD_DATE_FIELD; }
@Test public void shouldAddStatusToECClientAsPNCWhenMotherIsActiveAndIsInPNCStateAndHasNoFP() throws Exception { EligibleCouple ec1 = new EligibleCouple("entity id 1", "Woman A", "Husband A", "1", "Bherya", null, EasyMap.mapOf("currentMethod", "none")); Mother mother = new Mother("mother id 1", "entity id 1", "thayi card 1", "2013-01-01").withType("pnc"); Mockito.when(allEligibleCouples.all()).thenReturn(Arrays.asList(ec1)); Mockito.when(allBeneficiaries.findMotherWithOpenStatusByECId("entity id 1")).thenReturn(mother); ECClient expectedClient1 = createECClient("entity id 1", "Woman A", "Husband A", "Bherya", 1).withFPMethod("none") .withStatus(EasyMap.create("date", "2013-01-01").put("type", "pnc").map()); String clients = controller.get(); List<ECClient> actualClients = new Gson().fromJson(clients, new TypeToken<List<ECClient>>() { }.getType()); Assert.assertEquals(Arrays.asList(expectedClient1), actualClients); }
public String get() { return cache.get(EC_CLIENTS_LIST, new CacheableData<String>() { @Override public String fetch() { List<EligibleCouple> ecs = allEligibleCouples.all(); List<ECClient> ecClients = new ArrayList<ECClient>(); for (EligibleCouple ec : ecs) { String photoPath = isBlank(ec.photoPath()) ? DEFAULT_WOMAN_IMAGE_PLACEHOLDER_PATH : ec.photoPath(); ECClient ecClient = new ECClient(ec.caseId(), ec.wifeName(), ec.husbandName(), ec.village(), IntegerUtil.tryParse(ec.ecNumber(), 0)) .withDateOfBirth(ec.getDetail(WOMAN_DOB)) .withFPMethod(ec.getDetail(CURRENT_FP_METHOD)) .withFamilyPlanningMethodChangeDate( ec.getDetail(FAMILY_PLANNING_METHOD_CHANGE_DATE)) .withIUDPlace(ec.getDetail(IUD_PLACE)) .withIUDPerson(ec.getDetail(IUD_PERSON)) .withNumberOfCondomsSupplied(ec.getDetail(NUMBER_OF_CONDOMS_SUPPLIED)) .withNumberOfCentchromanPillsDelivered( ec.getDetail(NUMBER_OF_CENTCHROMAN_PILLS_DELIVERED)) .withNumberOfOCPDelivered(ec.getDetail(NUMBER_OF_OCP_DELIVERED)) .withCaste(ec.getDetail(CASTE)) .withEconomicStatus(ec.getDetail(ECONOMIC_STATUS)) .withNumberOfPregnancies(ec.getDetail(NUMBER_OF_PREGNANCIES)) .withParity(ec.getDetail(PARITY)) .withNumberOfLivingChildren(ec.getDetail(NUMBER_OF_LIVING_CHILDREN)) .withNumberOfStillBirths(ec.getDetail(NUMBER_OF_STILL_BIRTHS)) .withNumberOfAbortions(ec.getDetail(NUMBER_OF_ABORTIONS)) .withIsHighPriority(ec.isHighPriority()).withPhotoPath(photoPath) .withHighPriorityReason(ec.getDetail(HIGH_PRIORITY_REASON)) .withIsOutOfArea(ec.isOutOfArea()); updateStatusInformation(ec, ecClient); updateChildrenInformation(ecClient); ecClients.add(ecClient); } sortByName(ecClients); return new Gson().toJson(ecClients); } }); }
ECSmartRegisterController { public String get() { return cache.get(EC_CLIENTS_LIST, new CacheableData<String>() { @Override public String fetch() { List<EligibleCouple> ecs = allEligibleCouples.all(); List<ECClient> ecClients = new ArrayList<ECClient>(); for (EligibleCouple ec : ecs) { String photoPath = isBlank(ec.photoPath()) ? DEFAULT_WOMAN_IMAGE_PLACEHOLDER_PATH : ec.photoPath(); ECClient ecClient = new ECClient(ec.caseId(), ec.wifeName(), ec.husbandName(), ec.village(), IntegerUtil.tryParse(ec.ecNumber(), 0)) .withDateOfBirth(ec.getDetail(WOMAN_DOB)) .withFPMethod(ec.getDetail(CURRENT_FP_METHOD)) .withFamilyPlanningMethodChangeDate( ec.getDetail(FAMILY_PLANNING_METHOD_CHANGE_DATE)) .withIUDPlace(ec.getDetail(IUD_PLACE)) .withIUDPerson(ec.getDetail(IUD_PERSON)) .withNumberOfCondomsSupplied(ec.getDetail(NUMBER_OF_CONDOMS_SUPPLIED)) .withNumberOfCentchromanPillsDelivered( ec.getDetail(NUMBER_OF_CENTCHROMAN_PILLS_DELIVERED)) .withNumberOfOCPDelivered(ec.getDetail(NUMBER_OF_OCP_DELIVERED)) .withCaste(ec.getDetail(CASTE)) .withEconomicStatus(ec.getDetail(ECONOMIC_STATUS)) .withNumberOfPregnancies(ec.getDetail(NUMBER_OF_PREGNANCIES)) .withParity(ec.getDetail(PARITY)) .withNumberOfLivingChildren(ec.getDetail(NUMBER_OF_LIVING_CHILDREN)) .withNumberOfStillBirths(ec.getDetail(NUMBER_OF_STILL_BIRTHS)) .withNumberOfAbortions(ec.getDetail(NUMBER_OF_ABORTIONS)) .withIsHighPriority(ec.isHighPriority()).withPhotoPath(photoPath) .withHighPriorityReason(ec.getDetail(HIGH_PRIORITY_REASON)) .withIsOutOfArea(ec.isOutOfArea()); updateStatusInformation(ec, ecClient); updateChildrenInformation(ecClient); ecClients.add(ecClient); } sortByName(ecClients); return new Gson().toJson(ecClients); } }); } }
ECSmartRegisterController { public String get() { return cache.get(EC_CLIENTS_LIST, new CacheableData<String>() { @Override public String fetch() { List<EligibleCouple> ecs = allEligibleCouples.all(); List<ECClient> ecClients = new ArrayList<ECClient>(); for (EligibleCouple ec : ecs) { String photoPath = isBlank(ec.photoPath()) ? DEFAULT_WOMAN_IMAGE_PLACEHOLDER_PATH : ec.photoPath(); ECClient ecClient = new ECClient(ec.caseId(), ec.wifeName(), ec.husbandName(), ec.village(), IntegerUtil.tryParse(ec.ecNumber(), 0)) .withDateOfBirth(ec.getDetail(WOMAN_DOB)) .withFPMethod(ec.getDetail(CURRENT_FP_METHOD)) .withFamilyPlanningMethodChangeDate( ec.getDetail(FAMILY_PLANNING_METHOD_CHANGE_DATE)) .withIUDPlace(ec.getDetail(IUD_PLACE)) .withIUDPerson(ec.getDetail(IUD_PERSON)) .withNumberOfCondomsSupplied(ec.getDetail(NUMBER_OF_CONDOMS_SUPPLIED)) .withNumberOfCentchromanPillsDelivered( ec.getDetail(NUMBER_OF_CENTCHROMAN_PILLS_DELIVERED)) .withNumberOfOCPDelivered(ec.getDetail(NUMBER_OF_OCP_DELIVERED)) .withCaste(ec.getDetail(CASTE)) .withEconomicStatus(ec.getDetail(ECONOMIC_STATUS)) .withNumberOfPregnancies(ec.getDetail(NUMBER_OF_PREGNANCIES)) .withParity(ec.getDetail(PARITY)) .withNumberOfLivingChildren(ec.getDetail(NUMBER_OF_LIVING_CHILDREN)) .withNumberOfStillBirths(ec.getDetail(NUMBER_OF_STILL_BIRTHS)) .withNumberOfAbortions(ec.getDetail(NUMBER_OF_ABORTIONS)) .withIsHighPriority(ec.isHighPriority()).withPhotoPath(photoPath) .withHighPriorityReason(ec.getDetail(HIGH_PRIORITY_REASON)) .withIsOutOfArea(ec.isOutOfArea()); updateStatusInformation(ec, ecClient); updateChildrenInformation(ecClient); ecClients.add(ecClient); } sortByName(ecClients); return new Gson().toJson(ecClients); } }); } ECSmartRegisterController(AllEligibleCouples allEligibleCouples, AllBeneficiaries allBeneficiaries, Cache<String> cache, Cache<ECClients> ecClientsCache); }
ECSmartRegisterController { public String get() { return cache.get(EC_CLIENTS_LIST, new CacheableData<String>() { @Override public String fetch() { List<EligibleCouple> ecs = allEligibleCouples.all(); List<ECClient> ecClients = new ArrayList<ECClient>(); for (EligibleCouple ec : ecs) { String photoPath = isBlank(ec.photoPath()) ? DEFAULT_WOMAN_IMAGE_PLACEHOLDER_PATH : ec.photoPath(); ECClient ecClient = new ECClient(ec.caseId(), ec.wifeName(), ec.husbandName(), ec.village(), IntegerUtil.tryParse(ec.ecNumber(), 0)) .withDateOfBirth(ec.getDetail(WOMAN_DOB)) .withFPMethod(ec.getDetail(CURRENT_FP_METHOD)) .withFamilyPlanningMethodChangeDate( ec.getDetail(FAMILY_PLANNING_METHOD_CHANGE_DATE)) .withIUDPlace(ec.getDetail(IUD_PLACE)) .withIUDPerson(ec.getDetail(IUD_PERSON)) .withNumberOfCondomsSupplied(ec.getDetail(NUMBER_OF_CONDOMS_SUPPLIED)) .withNumberOfCentchromanPillsDelivered( ec.getDetail(NUMBER_OF_CENTCHROMAN_PILLS_DELIVERED)) .withNumberOfOCPDelivered(ec.getDetail(NUMBER_OF_OCP_DELIVERED)) .withCaste(ec.getDetail(CASTE)) .withEconomicStatus(ec.getDetail(ECONOMIC_STATUS)) .withNumberOfPregnancies(ec.getDetail(NUMBER_OF_PREGNANCIES)) .withParity(ec.getDetail(PARITY)) .withNumberOfLivingChildren(ec.getDetail(NUMBER_OF_LIVING_CHILDREN)) .withNumberOfStillBirths(ec.getDetail(NUMBER_OF_STILL_BIRTHS)) .withNumberOfAbortions(ec.getDetail(NUMBER_OF_ABORTIONS)) .withIsHighPriority(ec.isHighPriority()).withPhotoPath(photoPath) .withHighPriorityReason(ec.getDetail(HIGH_PRIORITY_REASON)) .withIsOutOfArea(ec.isOutOfArea()); updateStatusInformation(ec, ecClient); updateChildrenInformation(ecClient); ecClients.add(ecClient); } sortByName(ecClients); return new Gson().toJson(ecClients); } }); } ECSmartRegisterController(AllEligibleCouples allEligibleCouples, AllBeneficiaries allBeneficiaries, Cache<String> cache, Cache<ECClients> ecClientsCache); String get(); ECClients getClients(); }
ECSmartRegisterController { public String get() { return cache.get(EC_CLIENTS_LIST, new CacheableData<String>() { @Override public String fetch() { List<EligibleCouple> ecs = allEligibleCouples.all(); List<ECClient> ecClients = new ArrayList<ECClient>(); for (EligibleCouple ec : ecs) { String photoPath = isBlank(ec.photoPath()) ? DEFAULT_WOMAN_IMAGE_PLACEHOLDER_PATH : ec.photoPath(); ECClient ecClient = new ECClient(ec.caseId(), ec.wifeName(), ec.husbandName(), ec.village(), IntegerUtil.tryParse(ec.ecNumber(), 0)) .withDateOfBirth(ec.getDetail(WOMAN_DOB)) .withFPMethod(ec.getDetail(CURRENT_FP_METHOD)) .withFamilyPlanningMethodChangeDate( ec.getDetail(FAMILY_PLANNING_METHOD_CHANGE_DATE)) .withIUDPlace(ec.getDetail(IUD_PLACE)) .withIUDPerson(ec.getDetail(IUD_PERSON)) .withNumberOfCondomsSupplied(ec.getDetail(NUMBER_OF_CONDOMS_SUPPLIED)) .withNumberOfCentchromanPillsDelivered( ec.getDetail(NUMBER_OF_CENTCHROMAN_PILLS_DELIVERED)) .withNumberOfOCPDelivered(ec.getDetail(NUMBER_OF_OCP_DELIVERED)) .withCaste(ec.getDetail(CASTE)) .withEconomicStatus(ec.getDetail(ECONOMIC_STATUS)) .withNumberOfPregnancies(ec.getDetail(NUMBER_OF_PREGNANCIES)) .withParity(ec.getDetail(PARITY)) .withNumberOfLivingChildren(ec.getDetail(NUMBER_OF_LIVING_CHILDREN)) .withNumberOfStillBirths(ec.getDetail(NUMBER_OF_STILL_BIRTHS)) .withNumberOfAbortions(ec.getDetail(NUMBER_OF_ABORTIONS)) .withIsHighPriority(ec.isHighPriority()).withPhotoPath(photoPath) .withHighPriorityReason(ec.getDetail(HIGH_PRIORITY_REASON)) .withIsOutOfArea(ec.isOutOfArea()); updateStatusInformation(ec, ecClient); updateChildrenInformation(ecClient); ecClients.add(ecClient); } sortByName(ecClients); return new Gson().toJson(ecClients); } }); } ECSmartRegisterController(AllEligibleCouples allEligibleCouples, AllBeneficiaries allBeneficiaries, Cache<String> cache, Cache<ECClients> ecClientsCache); String get(); ECClients getClients(); static final String STATUS_TYPE_FIELD; static final String STATUS_DATE_FIELD; static final String EC_STATUS; static final String ANC_STATUS; static final String PNC_STATUS; static final String PNC_FP_STATUS; static final String FP_STATUS; static final String STATUS_EDD_FIELD; static final String FP_METHOD_DATE_FIELD; }
@Test public void shouldAddStatusToECClientAsPNCWhenMotherIsActiveAndIsInPNCStateAndHasFPMethod() throws Exception { EligibleCouple ec1 = new EligibleCouple("entity id 1", "Woman A", "Husband A", "1", "Bherya", null, EasyMap.create("familyPlanningMethodChangeDate", "2013-01-01").put("currentMethod", "condom").map()); Mother mother = new Mother("mother id 1", "entity id 1", "thayi card 1", "2013-01-01").withType("pnc"); Mockito.when(allEligibleCouples.all()).thenReturn(Arrays.asList(ec1)); Mockito.when(allBeneficiaries.findMotherWithOpenStatusByECId("entity id 1")).thenReturn(mother); ECClient expectedClient1 = createECClient("entity id 1", "Woman A", "Husband A", "Bherya", 1).withFPMethod("condom") .withFamilyPlanningMethodChangeDate("2013-01-01") .withFPMethod("condom") .withStatus(EasyMap.create("type", "pnc/fp") .put("date", "2013-01-01") .put("fpMethodDate", "2013-01-01") .map()); String clients = controller.get(); List<ECClient> actualClients = new Gson().fromJson(clients, new TypeToken<List<ECClient>>() { }.getType()); Assert.assertEquals(Arrays.asList(expectedClient1), actualClients); }
public String get() { return cache.get(EC_CLIENTS_LIST, new CacheableData<String>() { @Override public String fetch() { List<EligibleCouple> ecs = allEligibleCouples.all(); List<ECClient> ecClients = new ArrayList<ECClient>(); for (EligibleCouple ec : ecs) { String photoPath = isBlank(ec.photoPath()) ? DEFAULT_WOMAN_IMAGE_PLACEHOLDER_PATH : ec.photoPath(); ECClient ecClient = new ECClient(ec.caseId(), ec.wifeName(), ec.husbandName(), ec.village(), IntegerUtil.tryParse(ec.ecNumber(), 0)) .withDateOfBirth(ec.getDetail(WOMAN_DOB)) .withFPMethod(ec.getDetail(CURRENT_FP_METHOD)) .withFamilyPlanningMethodChangeDate( ec.getDetail(FAMILY_PLANNING_METHOD_CHANGE_DATE)) .withIUDPlace(ec.getDetail(IUD_PLACE)) .withIUDPerson(ec.getDetail(IUD_PERSON)) .withNumberOfCondomsSupplied(ec.getDetail(NUMBER_OF_CONDOMS_SUPPLIED)) .withNumberOfCentchromanPillsDelivered( ec.getDetail(NUMBER_OF_CENTCHROMAN_PILLS_DELIVERED)) .withNumberOfOCPDelivered(ec.getDetail(NUMBER_OF_OCP_DELIVERED)) .withCaste(ec.getDetail(CASTE)) .withEconomicStatus(ec.getDetail(ECONOMIC_STATUS)) .withNumberOfPregnancies(ec.getDetail(NUMBER_OF_PREGNANCIES)) .withParity(ec.getDetail(PARITY)) .withNumberOfLivingChildren(ec.getDetail(NUMBER_OF_LIVING_CHILDREN)) .withNumberOfStillBirths(ec.getDetail(NUMBER_OF_STILL_BIRTHS)) .withNumberOfAbortions(ec.getDetail(NUMBER_OF_ABORTIONS)) .withIsHighPriority(ec.isHighPriority()).withPhotoPath(photoPath) .withHighPriorityReason(ec.getDetail(HIGH_PRIORITY_REASON)) .withIsOutOfArea(ec.isOutOfArea()); updateStatusInformation(ec, ecClient); updateChildrenInformation(ecClient); ecClients.add(ecClient); } sortByName(ecClients); return new Gson().toJson(ecClients); } }); }
ECSmartRegisterController { public String get() { return cache.get(EC_CLIENTS_LIST, new CacheableData<String>() { @Override public String fetch() { List<EligibleCouple> ecs = allEligibleCouples.all(); List<ECClient> ecClients = new ArrayList<ECClient>(); for (EligibleCouple ec : ecs) { String photoPath = isBlank(ec.photoPath()) ? DEFAULT_WOMAN_IMAGE_PLACEHOLDER_PATH : ec.photoPath(); ECClient ecClient = new ECClient(ec.caseId(), ec.wifeName(), ec.husbandName(), ec.village(), IntegerUtil.tryParse(ec.ecNumber(), 0)) .withDateOfBirth(ec.getDetail(WOMAN_DOB)) .withFPMethod(ec.getDetail(CURRENT_FP_METHOD)) .withFamilyPlanningMethodChangeDate( ec.getDetail(FAMILY_PLANNING_METHOD_CHANGE_DATE)) .withIUDPlace(ec.getDetail(IUD_PLACE)) .withIUDPerson(ec.getDetail(IUD_PERSON)) .withNumberOfCondomsSupplied(ec.getDetail(NUMBER_OF_CONDOMS_SUPPLIED)) .withNumberOfCentchromanPillsDelivered( ec.getDetail(NUMBER_OF_CENTCHROMAN_PILLS_DELIVERED)) .withNumberOfOCPDelivered(ec.getDetail(NUMBER_OF_OCP_DELIVERED)) .withCaste(ec.getDetail(CASTE)) .withEconomicStatus(ec.getDetail(ECONOMIC_STATUS)) .withNumberOfPregnancies(ec.getDetail(NUMBER_OF_PREGNANCIES)) .withParity(ec.getDetail(PARITY)) .withNumberOfLivingChildren(ec.getDetail(NUMBER_OF_LIVING_CHILDREN)) .withNumberOfStillBirths(ec.getDetail(NUMBER_OF_STILL_BIRTHS)) .withNumberOfAbortions(ec.getDetail(NUMBER_OF_ABORTIONS)) .withIsHighPriority(ec.isHighPriority()).withPhotoPath(photoPath) .withHighPriorityReason(ec.getDetail(HIGH_PRIORITY_REASON)) .withIsOutOfArea(ec.isOutOfArea()); updateStatusInformation(ec, ecClient); updateChildrenInformation(ecClient); ecClients.add(ecClient); } sortByName(ecClients); return new Gson().toJson(ecClients); } }); } }
ECSmartRegisterController { public String get() { return cache.get(EC_CLIENTS_LIST, new CacheableData<String>() { @Override public String fetch() { List<EligibleCouple> ecs = allEligibleCouples.all(); List<ECClient> ecClients = new ArrayList<ECClient>(); for (EligibleCouple ec : ecs) { String photoPath = isBlank(ec.photoPath()) ? DEFAULT_WOMAN_IMAGE_PLACEHOLDER_PATH : ec.photoPath(); ECClient ecClient = new ECClient(ec.caseId(), ec.wifeName(), ec.husbandName(), ec.village(), IntegerUtil.tryParse(ec.ecNumber(), 0)) .withDateOfBirth(ec.getDetail(WOMAN_DOB)) .withFPMethod(ec.getDetail(CURRENT_FP_METHOD)) .withFamilyPlanningMethodChangeDate( ec.getDetail(FAMILY_PLANNING_METHOD_CHANGE_DATE)) .withIUDPlace(ec.getDetail(IUD_PLACE)) .withIUDPerson(ec.getDetail(IUD_PERSON)) .withNumberOfCondomsSupplied(ec.getDetail(NUMBER_OF_CONDOMS_SUPPLIED)) .withNumberOfCentchromanPillsDelivered( ec.getDetail(NUMBER_OF_CENTCHROMAN_PILLS_DELIVERED)) .withNumberOfOCPDelivered(ec.getDetail(NUMBER_OF_OCP_DELIVERED)) .withCaste(ec.getDetail(CASTE)) .withEconomicStatus(ec.getDetail(ECONOMIC_STATUS)) .withNumberOfPregnancies(ec.getDetail(NUMBER_OF_PREGNANCIES)) .withParity(ec.getDetail(PARITY)) .withNumberOfLivingChildren(ec.getDetail(NUMBER_OF_LIVING_CHILDREN)) .withNumberOfStillBirths(ec.getDetail(NUMBER_OF_STILL_BIRTHS)) .withNumberOfAbortions(ec.getDetail(NUMBER_OF_ABORTIONS)) .withIsHighPriority(ec.isHighPriority()).withPhotoPath(photoPath) .withHighPriorityReason(ec.getDetail(HIGH_PRIORITY_REASON)) .withIsOutOfArea(ec.isOutOfArea()); updateStatusInformation(ec, ecClient); updateChildrenInformation(ecClient); ecClients.add(ecClient); } sortByName(ecClients); return new Gson().toJson(ecClients); } }); } ECSmartRegisterController(AllEligibleCouples allEligibleCouples, AllBeneficiaries allBeneficiaries, Cache<String> cache, Cache<ECClients> ecClientsCache); }
ECSmartRegisterController { public String get() { return cache.get(EC_CLIENTS_LIST, new CacheableData<String>() { @Override public String fetch() { List<EligibleCouple> ecs = allEligibleCouples.all(); List<ECClient> ecClients = new ArrayList<ECClient>(); for (EligibleCouple ec : ecs) { String photoPath = isBlank(ec.photoPath()) ? DEFAULT_WOMAN_IMAGE_PLACEHOLDER_PATH : ec.photoPath(); ECClient ecClient = new ECClient(ec.caseId(), ec.wifeName(), ec.husbandName(), ec.village(), IntegerUtil.tryParse(ec.ecNumber(), 0)) .withDateOfBirth(ec.getDetail(WOMAN_DOB)) .withFPMethod(ec.getDetail(CURRENT_FP_METHOD)) .withFamilyPlanningMethodChangeDate( ec.getDetail(FAMILY_PLANNING_METHOD_CHANGE_DATE)) .withIUDPlace(ec.getDetail(IUD_PLACE)) .withIUDPerson(ec.getDetail(IUD_PERSON)) .withNumberOfCondomsSupplied(ec.getDetail(NUMBER_OF_CONDOMS_SUPPLIED)) .withNumberOfCentchromanPillsDelivered( ec.getDetail(NUMBER_OF_CENTCHROMAN_PILLS_DELIVERED)) .withNumberOfOCPDelivered(ec.getDetail(NUMBER_OF_OCP_DELIVERED)) .withCaste(ec.getDetail(CASTE)) .withEconomicStatus(ec.getDetail(ECONOMIC_STATUS)) .withNumberOfPregnancies(ec.getDetail(NUMBER_OF_PREGNANCIES)) .withParity(ec.getDetail(PARITY)) .withNumberOfLivingChildren(ec.getDetail(NUMBER_OF_LIVING_CHILDREN)) .withNumberOfStillBirths(ec.getDetail(NUMBER_OF_STILL_BIRTHS)) .withNumberOfAbortions(ec.getDetail(NUMBER_OF_ABORTIONS)) .withIsHighPriority(ec.isHighPriority()).withPhotoPath(photoPath) .withHighPriorityReason(ec.getDetail(HIGH_PRIORITY_REASON)) .withIsOutOfArea(ec.isOutOfArea()); updateStatusInformation(ec, ecClient); updateChildrenInformation(ecClient); ecClients.add(ecClient); } sortByName(ecClients); return new Gson().toJson(ecClients); } }); } ECSmartRegisterController(AllEligibleCouples allEligibleCouples, AllBeneficiaries allBeneficiaries, Cache<String> cache, Cache<ECClients> ecClientsCache); String get(); ECClients getClients(); }
ECSmartRegisterController { public String get() { return cache.get(EC_CLIENTS_LIST, new CacheableData<String>() { @Override public String fetch() { List<EligibleCouple> ecs = allEligibleCouples.all(); List<ECClient> ecClients = new ArrayList<ECClient>(); for (EligibleCouple ec : ecs) { String photoPath = isBlank(ec.photoPath()) ? DEFAULT_WOMAN_IMAGE_PLACEHOLDER_PATH : ec.photoPath(); ECClient ecClient = new ECClient(ec.caseId(), ec.wifeName(), ec.husbandName(), ec.village(), IntegerUtil.tryParse(ec.ecNumber(), 0)) .withDateOfBirth(ec.getDetail(WOMAN_DOB)) .withFPMethod(ec.getDetail(CURRENT_FP_METHOD)) .withFamilyPlanningMethodChangeDate( ec.getDetail(FAMILY_PLANNING_METHOD_CHANGE_DATE)) .withIUDPlace(ec.getDetail(IUD_PLACE)) .withIUDPerson(ec.getDetail(IUD_PERSON)) .withNumberOfCondomsSupplied(ec.getDetail(NUMBER_OF_CONDOMS_SUPPLIED)) .withNumberOfCentchromanPillsDelivered( ec.getDetail(NUMBER_OF_CENTCHROMAN_PILLS_DELIVERED)) .withNumberOfOCPDelivered(ec.getDetail(NUMBER_OF_OCP_DELIVERED)) .withCaste(ec.getDetail(CASTE)) .withEconomicStatus(ec.getDetail(ECONOMIC_STATUS)) .withNumberOfPregnancies(ec.getDetail(NUMBER_OF_PREGNANCIES)) .withParity(ec.getDetail(PARITY)) .withNumberOfLivingChildren(ec.getDetail(NUMBER_OF_LIVING_CHILDREN)) .withNumberOfStillBirths(ec.getDetail(NUMBER_OF_STILL_BIRTHS)) .withNumberOfAbortions(ec.getDetail(NUMBER_OF_ABORTIONS)) .withIsHighPriority(ec.isHighPriority()).withPhotoPath(photoPath) .withHighPriorityReason(ec.getDetail(HIGH_PRIORITY_REASON)) .withIsOutOfArea(ec.isOutOfArea()); updateStatusInformation(ec, ecClient); updateChildrenInformation(ecClient); ecClients.add(ecClient); } sortByName(ecClients); return new Gson().toJson(ecClients); } }); } ECSmartRegisterController(AllEligibleCouples allEligibleCouples, AllBeneficiaries allBeneficiaries, Cache<String> cache, Cache<ECClients> ecClientsCache); String get(); ECClients getClients(); static final String STATUS_TYPE_FIELD; static final String STATUS_DATE_FIELD; static final String EC_STATUS; static final String ANC_STATUS; static final String PNC_STATUS; static final String PNC_FP_STATUS; static final String FP_STATUS; static final String STATUS_EDD_FIELD; static final String FP_METHOD_DATE_FIELD; }
@Test public void shouldGetChildDetailsAsJSON() throws Exception { TimelineEvent birthEvent = TimelineEvent.forChildBirthInChildProfile(caseId, "2011-10-21", null, null); TimelineEvent ancEvent = TimelineEvent.forMotherPNCVisit(caseId, "2", "2011-12-22", "bps 1", "bpd 1", "temp 1", "hb 1"); TimelineEvent eventVeryCloseToCurrentDate = TimelineEvent.forMotherPNCVisit(caseId, "2", "2012-07-29", "bps 2", "bpd 2", "temp 2", "hb 2"); HashMap<String, String> details = new HashMap<String, String>(); details.put("ashaName", "Shiwani"); details.put("dateOfDelivery", "2012-07-28"); details.put("isHighRisk", "yes"); details.put("highRiskReason", "Anaemia"); Mockito.when(allBeneficiaries.findChild(caseId)).thenReturn(new Child(caseId, "Mother-Case-Id", "TC 1", "2012-07-28", "male", details).withPhotoPath("photo path")); Mockito.when(allBeneficiaries.findMother("Mother-Case-Id")).thenReturn(new Mother(caseId, "EC CASE 1", "TC 1", "2011-10-22").withDetails(details)); Mockito.when(allEligibleCouples.findByCaseID("EC CASE 1")).thenReturn(new EligibleCouple("EC CASE 1", "Woman 1", "Husband 1", "EC Number 1", "Village 1", "Subcenter 1", new HashMap<String, String>())); Mockito.when(allTimelineEvents.forCase(caseId)).thenReturn(Arrays.asList(birthEvent, ancEvent, eventVeryCloseToCurrentDate)); ChildDetail expectedDetail = new ChildDetail(caseId, "TC 1", new CoupleDetails("Woman 1", "Husband 1", "EC Number 1", false), new LocationDetails("Village 1", "Subcenter 1"), new BirthDetails("2012-07-28", "4 days", "male"), "photo path") .addTimelineEvents(Arrays.asList(eventFor(eventVeryCloseToCurrentDate, "29-07-2012"), eventFor(ancEvent, "22-12-2011"), eventFor(birthEvent, "21-10-2011"))) .addExtraDetails(details); String actualJson = controller.get(); ChildDetail actualDetail = new Gson().fromJson(actualJson, ChildDetail.class); Assert.assertEquals(expectedDetail, actualDetail); }
@JavascriptInterface public String get() { Child child = allBeneficiaries.findChild(caseId); Mother mother = allBeneficiaries.findMother(child.motherCaseId()); EligibleCouple couple = allEligibleCouples.findByCaseID(mother.ecCaseId()); LocalDate deliveryDate = LocalDate.parse(child.dateOfBirth()); String photoPath = isBlank(child.photoPath()) ? ( AllConstants.FEMALE_GENDER.equalsIgnoreCase(child.gender()) ? AllConstants.DEFAULT_GIRL_INFANT_IMAGE_PLACEHOLDER_PATH : AllConstants.DEFAULT_BOY_INFANT_IMAGE_PLACEHOLDER_PATH) : child.photoPath(); ChildDetail detail = new ChildDetail(caseId, mother.thayiCardNumber(), new CoupleDetails(couple.wifeName(), couple.husbandName(), couple.ecNumber(), couple.isOutOfArea()), new LocationDetails(couple.village(), couple.subCenter()), new BirthDetails(deliveryDate.toString(), calculateAge(deliveryDate), child.gender()), photoPath).addTimelineEvents(getEvents()) .addExtraDetails(child.details()); return new Gson().toJson(detail); }
ChildDetailController { @JavascriptInterface public String get() { Child child = allBeneficiaries.findChild(caseId); Mother mother = allBeneficiaries.findMother(child.motherCaseId()); EligibleCouple couple = allEligibleCouples.findByCaseID(mother.ecCaseId()); LocalDate deliveryDate = LocalDate.parse(child.dateOfBirth()); String photoPath = isBlank(child.photoPath()) ? ( AllConstants.FEMALE_GENDER.equalsIgnoreCase(child.gender()) ? AllConstants.DEFAULT_GIRL_INFANT_IMAGE_PLACEHOLDER_PATH : AllConstants.DEFAULT_BOY_INFANT_IMAGE_PLACEHOLDER_PATH) : child.photoPath(); ChildDetail detail = new ChildDetail(caseId, mother.thayiCardNumber(), new CoupleDetails(couple.wifeName(), couple.husbandName(), couple.ecNumber(), couple.isOutOfArea()), new LocationDetails(couple.village(), couple.subCenter()), new BirthDetails(deliveryDate.toString(), calculateAge(deliveryDate), child.gender()), photoPath).addTimelineEvents(getEvents()) .addExtraDetails(child.details()); return new Gson().toJson(detail); } }
ChildDetailController { @JavascriptInterface public String get() { Child child = allBeneficiaries.findChild(caseId); Mother mother = allBeneficiaries.findMother(child.motherCaseId()); EligibleCouple couple = allEligibleCouples.findByCaseID(mother.ecCaseId()); LocalDate deliveryDate = LocalDate.parse(child.dateOfBirth()); String photoPath = isBlank(child.photoPath()) ? ( AllConstants.FEMALE_GENDER.equalsIgnoreCase(child.gender()) ? AllConstants.DEFAULT_GIRL_INFANT_IMAGE_PLACEHOLDER_PATH : AllConstants.DEFAULT_BOY_INFANT_IMAGE_PLACEHOLDER_PATH) : child.photoPath(); ChildDetail detail = new ChildDetail(caseId, mother.thayiCardNumber(), new CoupleDetails(couple.wifeName(), couple.husbandName(), couple.ecNumber(), couple.isOutOfArea()), new LocationDetails(couple.village(), couple.subCenter()), new BirthDetails(deliveryDate.toString(), calculateAge(deliveryDate), child.gender()), photoPath).addTimelineEvents(getEvents()) .addExtraDetails(child.details()); return new Gson().toJson(detail); } ChildDetailController(Context context, String caseId, AllEligibleCouples allEligibleCouples, AllBeneficiaries allBeneficiaries, AllTimelineEvents allTimelineEvents); }
ChildDetailController { @JavascriptInterface public String get() { Child child = allBeneficiaries.findChild(caseId); Mother mother = allBeneficiaries.findMother(child.motherCaseId()); EligibleCouple couple = allEligibleCouples.findByCaseID(mother.ecCaseId()); LocalDate deliveryDate = LocalDate.parse(child.dateOfBirth()); String photoPath = isBlank(child.photoPath()) ? ( AllConstants.FEMALE_GENDER.equalsIgnoreCase(child.gender()) ? AllConstants.DEFAULT_GIRL_INFANT_IMAGE_PLACEHOLDER_PATH : AllConstants.DEFAULT_BOY_INFANT_IMAGE_PLACEHOLDER_PATH) : child.photoPath(); ChildDetail detail = new ChildDetail(caseId, mother.thayiCardNumber(), new CoupleDetails(couple.wifeName(), couple.husbandName(), couple.ecNumber(), couple.isOutOfArea()), new LocationDetails(couple.village(), couple.subCenter()), new BirthDetails(deliveryDate.toString(), calculateAge(deliveryDate), child.gender()), photoPath).addTimelineEvents(getEvents()) .addExtraDetails(child.details()); return new Gson().toJson(detail); } ChildDetailController(Context context, String caseId, AllEligibleCouples allEligibleCouples, AllBeneficiaries allBeneficiaries, AllTimelineEvents allTimelineEvents); @JavascriptInterface String get(); @JavascriptInterface void takePhoto(); }
ChildDetailController { @JavascriptInterface public String get() { Child child = allBeneficiaries.findChild(caseId); Mother mother = allBeneficiaries.findMother(child.motherCaseId()); EligibleCouple couple = allEligibleCouples.findByCaseID(mother.ecCaseId()); LocalDate deliveryDate = LocalDate.parse(child.dateOfBirth()); String photoPath = isBlank(child.photoPath()) ? ( AllConstants.FEMALE_GENDER.equalsIgnoreCase(child.gender()) ? AllConstants.DEFAULT_GIRL_INFANT_IMAGE_PLACEHOLDER_PATH : AllConstants.DEFAULT_BOY_INFANT_IMAGE_PLACEHOLDER_PATH) : child.photoPath(); ChildDetail detail = new ChildDetail(caseId, mother.thayiCardNumber(), new CoupleDetails(couple.wifeName(), couple.husbandName(), couple.ecNumber(), couple.isOutOfArea()), new LocationDetails(couple.village(), couple.subCenter()), new BirthDetails(deliveryDate.toString(), calculateAge(deliveryDate), child.gender()), photoPath).addTimelineEvents(getEvents()) .addExtraDetails(child.details()); return new Gson().toJson(detail); } ChildDetailController(Context context, String caseId, AllEligibleCouples allEligibleCouples, AllBeneficiaries allBeneficiaries, AllTimelineEvents allTimelineEvents); @JavascriptInterface String get(); @JavascriptInterface void takePhoto(); }
@Test public void shouldGetPNCDetailsAsJSON() throws Exception { TimelineEvent pregnancyEvent = TimelineEvent.forStartOfPregnancy(caseId, "2011-10-21", "2011-10-21"); TimelineEvent ancEvent = TimelineEvent.forANCCareProvided(caseId, "2", "2011-12-22", new HashMap<String, String>()); TimelineEvent eventVeryCloseToCurrentDate = TimelineEvent.forANCCareProvided(caseId, "2", "2012-07-29", new HashMap<String, String>()); HashMap<String, String> details = new HashMap<String, String>(); details.put("ashaName", "Shiwani"); details.put("isHighRisk", "yes"); details.put("highRiskReason", "Anaemia"); Mockito.when(allBeneficiaries.findMotherWithOpenStatus(caseId)).thenReturn(new Mother(caseId, "EC CASE 1", "TC 1", "2012-07-28").withDetails(details)); HashMap<String, String> ecDetails = new HashMap<String, String>(); ecDetails.put("caste", "c_others"); ecDetails.put("economicStatus", "apl"); Mockito.when(allEligibleCouples.findByCaseID("EC CASE 1")).thenReturn(new EligibleCouple("EC CASE 1", "Woman 1", "Husband 1", "EC Number 1", "Village 1", "Subcenter 1", ecDetails).withPhotoPath("photo path")); Mockito.when(allTimelineEvents.forCase(caseId)).thenReturn(Arrays.asList(pregnancyEvent, ancEvent, eventVeryCloseToCurrentDate)); PNCDetail expectedDetail = new PNCDetail(caseId, "TC 1", new CoupleDetails("Woman 1", "Husband 1", "EC Number 1", false).withCaste("c_others").withEconomicStatus("apl").withPhotoPath("photo path"), new LocationDetails("Village 1", "Subcenter 1"), new PregnancyOutcomeDetails("2012-07-28", 4)) .addTimelineEvents(Arrays.asList(eventFor(eventVeryCloseToCurrentDate, "29-07-2012"), eventFor(ancEvent, "22-12-2011"), eventFor(pregnancyEvent, "21-10-2011"))) .addExtraDetails(details); String actualJson = controller.get(); PNCDetail actualDetail = new Gson().fromJson(actualJson, PNCDetail.class); Assert.assertEquals(expectedDetail, actualDetail); }
@JavascriptInterface public String get() { Mother mother = allBeneficiaries.findMotherWithOpenStatus(caseId); EligibleCouple couple = allEligibleCouples.findByCaseID(mother.ecCaseId()); LocalDate deliveryDate = LocalDate.parse(mother.referenceDate()); Days postPartumDuration = Days.daysBetween(deliveryDate, DateUtil.today()); PNCDetail detail = new PNCDetail(caseId, mother.thayiCardNumber(), new CoupleDetails(couple.wifeName(), couple.husbandName(), couple.ecNumber(), couple.isOutOfArea()).withCaste(couple.getDetail("caste")) .withEconomicStatus(couple.getDetail("economicStatus")) .withPhotoPath(couple.photoPath()), new LocationDetails(couple.village(), couple.subCenter()), new PregnancyOutcomeDetails(deliveryDate.toString(), postPartumDuration.getDays())) .addTimelineEvents(getEvents()).addExtraDetails(mother.details()); return new Gson().toJson(detail); }
PNCDetailController { @JavascriptInterface public String get() { Mother mother = allBeneficiaries.findMotherWithOpenStatus(caseId); EligibleCouple couple = allEligibleCouples.findByCaseID(mother.ecCaseId()); LocalDate deliveryDate = LocalDate.parse(mother.referenceDate()); Days postPartumDuration = Days.daysBetween(deliveryDate, DateUtil.today()); PNCDetail detail = new PNCDetail(caseId, mother.thayiCardNumber(), new CoupleDetails(couple.wifeName(), couple.husbandName(), couple.ecNumber(), couple.isOutOfArea()).withCaste(couple.getDetail("caste")) .withEconomicStatus(couple.getDetail("economicStatus")) .withPhotoPath(couple.photoPath()), new LocationDetails(couple.village(), couple.subCenter()), new PregnancyOutcomeDetails(deliveryDate.toString(), postPartumDuration.getDays())) .addTimelineEvents(getEvents()).addExtraDetails(mother.details()); return new Gson().toJson(detail); } }
PNCDetailController { @JavascriptInterface public String get() { Mother mother = allBeneficiaries.findMotherWithOpenStatus(caseId); EligibleCouple couple = allEligibleCouples.findByCaseID(mother.ecCaseId()); LocalDate deliveryDate = LocalDate.parse(mother.referenceDate()); Days postPartumDuration = Days.daysBetween(deliveryDate, DateUtil.today()); PNCDetail detail = new PNCDetail(caseId, mother.thayiCardNumber(), new CoupleDetails(couple.wifeName(), couple.husbandName(), couple.ecNumber(), couple.isOutOfArea()).withCaste(couple.getDetail("caste")) .withEconomicStatus(couple.getDetail("economicStatus")) .withPhotoPath(couple.photoPath()), new LocationDetails(couple.village(), couple.subCenter()), new PregnancyOutcomeDetails(deliveryDate.toString(), postPartumDuration.getDays())) .addTimelineEvents(getEvents()).addExtraDetails(mother.details()); return new Gson().toJson(detail); } PNCDetailController(Context context, String caseId, AllEligibleCouples allEligibleCouples, AllBeneficiaries allBeneficiaries, AllTimelineEvents allTimelineEvents); }
PNCDetailController { @JavascriptInterface public String get() { Mother mother = allBeneficiaries.findMotherWithOpenStatus(caseId); EligibleCouple couple = allEligibleCouples.findByCaseID(mother.ecCaseId()); LocalDate deliveryDate = LocalDate.parse(mother.referenceDate()); Days postPartumDuration = Days.daysBetween(deliveryDate, DateUtil.today()); PNCDetail detail = new PNCDetail(caseId, mother.thayiCardNumber(), new CoupleDetails(couple.wifeName(), couple.husbandName(), couple.ecNumber(), couple.isOutOfArea()).withCaste(couple.getDetail("caste")) .withEconomicStatus(couple.getDetail("economicStatus")) .withPhotoPath(couple.photoPath()), new LocationDetails(couple.village(), couple.subCenter()), new PregnancyOutcomeDetails(deliveryDate.toString(), postPartumDuration.getDays())) .addTimelineEvents(getEvents()).addExtraDetails(mother.details()); return new Gson().toJson(detail); } PNCDetailController(Context context, String caseId, AllEligibleCouples allEligibleCouples, AllBeneficiaries allBeneficiaries, AllTimelineEvents allTimelineEvents); @JavascriptInterface String get(); @JavascriptInterface void takePhoto(); }
PNCDetailController { @JavascriptInterface public String get() { Mother mother = allBeneficiaries.findMotherWithOpenStatus(caseId); EligibleCouple couple = allEligibleCouples.findByCaseID(mother.ecCaseId()); LocalDate deliveryDate = LocalDate.parse(mother.referenceDate()); Days postPartumDuration = Days.daysBetween(deliveryDate, DateUtil.today()); PNCDetail detail = new PNCDetail(caseId, mother.thayiCardNumber(), new CoupleDetails(couple.wifeName(), couple.husbandName(), couple.ecNumber(), couple.isOutOfArea()).withCaste(couple.getDetail("caste")) .withEconomicStatus(couple.getDetail("economicStatus")) .withPhotoPath(couple.photoPath()), new LocationDetails(couple.village(), couple.subCenter()), new PregnancyOutcomeDetails(deliveryDate.toString(), postPartumDuration.getDays())) .addTimelineEvents(getEvents()).addExtraDetails(mother.details()); return new Gson().toJson(detail); } PNCDetailController(Context context, String caseId, AllEligibleCouples allEligibleCouples, AllBeneficiaries allBeneficiaries, AllTimelineEvents allTimelineEvents); @JavascriptInterface String get(); @JavascriptInterface void takePhoto(); }