dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #35751
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 18299: Added adhoc command RandomEventPopulator
------------------------------------------------------------
revno: 18299
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2015-02-17 22:39:32 +0100
message:
Added adhoc command RandomEventPopulator
added:
tools/dhis-adhoc/src/main/java/org/hisp/dhis/adhoc/command/RandomEventPopulator.java
modified:
tools/dhis-adhoc/pom.xml
tools/dhis-adhoc/src/main/java/org/hisp/dhis/adhoc/RunMe.java
tools/dhis-adhoc/src/main/resources/META-INF/dhis/beans.xml
--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk
Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'tools/dhis-adhoc/pom.xml'
--- tools/dhis-adhoc/pom.xml 2015-02-17 19:23:09 +0000
+++ tools/dhis-adhoc/pom.xml 2015-02-17 21:39:32 +0000
@@ -27,6 +27,10 @@
</dependency>
<dependency>
<groupId>org.hisp.dhis</groupId>
+ <artifactId>dhis-service-dxf2</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.hisp.dhis</groupId>
<artifactId>dhis-service-reporting</artifactId>
</dependency>
<dependency>
=== modified file 'tools/dhis-adhoc/src/main/java/org/hisp/dhis/adhoc/RunMe.java'
--- tools/dhis-adhoc/src/main/java/org/hisp/dhis/adhoc/RunMe.java 2014-10-23 07:27:29 +0000
+++ tools/dhis-adhoc/src/main/java/org/hisp/dhis/adhoc/RunMe.java 2015-02-17 21:39:32 +0000
@@ -35,7 +35,7 @@
*/
public static List<String> commands()
{
- return Arrays.asList( "exampleCommand" );
+ return Arrays.asList( "randomEventPopulator" );
}
public static void main( String[] args )
=== added file 'tools/dhis-adhoc/src/main/java/org/hisp/dhis/adhoc/command/RandomEventPopulator.java'
--- tools/dhis-adhoc/src/main/java/org/hisp/dhis/adhoc/command/RandomEventPopulator.java 1970-01-01 00:00:00 +0000
+++ tools/dhis-adhoc/src/main/java/org/hisp/dhis/adhoc/command/RandomEventPopulator.java 2015-02-17 21:39:32 +0000
@@ -0,0 +1,76 @@
+package org.hisp.dhis.adhoc.command;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Random;
+
+import org.hisp.dhis.adhoc.Command;
+import org.hisp.dhis.dxf2.common.ImportOptions;
+import org.hisp.dhis.dxf2.events.event.DataValue;
+import org.hisp.dhis.dxf2.events.event.Event;
+import org.hisp.dhis.dxf2.events.event.EventService;
+import org.hisp.dhis.event.EventStatus;
+import org.hisp.dhis.option.Option;
+import org.hisp.dhis.option.OptionService;
+import org.hisp.dhis.organisationunit.OrganisationUnit;
+import org.hisp.dhis.organisationunit.OrganisationUnitService;
+import org.hisp.dhis.program.ProgramService;
+import org.hisp.dhis.system.util.DateUtils;
+import org.joda.time.DateTime;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.transaction.annotation.Transactional;
+
+public class RandomEventPopulator
+ implements Command
+{
+ private static final int EVENT_NO = 1000;
+ private static final List<String> OPT_GENDER = Arrays.asList( "male", "female" );
+
+ @Autowired
+ private ProgramService programService;
+
+ @Autowired
+ private EventService eventService;
+
+ @Autowired
+ private OptionService optionService;
+
+ @Autowired
+ private OrganisationUnitService organisationUnitService;
+
+ @Override
+ @Transactional
+ public void execute()
+ throws Exception
+ {
+ List<Event> events = new ArrayList<Event>();
+
+ List<Option> modeDischargeOptionSet = optionService.getOptionSet( "iDFPKpFTiVw" ).getOptions();
+ List<Option> icd10OptionSet = optionService.getOptionSet( "eUZ79clX7y1" ).getOptions();
+ List<OrganisationUnit> ous = new ArrayList<OrganisationUnit>( organisationUnitService.getOrganisationUnitsAtLevel( 4 ) );
+
+ for ( int i = 0; i < EVENT_NO; i++ )
+ {
+ DateTime date = new DateTime( 2015, 1, 1, 12, 5 ).plusDays( new Random().nextInt( 363 ) );
+
+ Event event = new Event();
+ event.setStatus( EventStatus.COMPLETED );
+ event.setProgram( "eBAyeGv0exc" ); // In-patient
+ event.setProgramStage( "Zj7UnCAulEk" );
+ event.setOrgUnit( ous.get( new Random().nextInt( ous.size() ) ).getUid() );
+ event.setEventDate( DateUtils.getLongDateString( date.toDate() ) );
+
+ event.getDataValues().add( new DataValue( "qrur9Dvnyt5", String.valueOf( new Random().nextInt( 89 ) ) ) );
+ event.getDataValues().add( new DataValue( "oZg33kd9taw", OPT_GENDER.get( new Random().nextInt( 2 ) ) ) );
+ event.getDataValues().add( new DataValue( "eMyVanycQSC", DateUtils.getMediumDateString( new DateTime( date ).minusDays( 14 ).toDate() ) ) );
+ event.getDataValues().add( new DataValue( "msodh3rEMJa", DateUtils.getMediumDateString( new DateTime( date ).toDate() ) ) );
+ event.getDataValues().add( new DataValue( "fWIAEtYVEGk", modeDischargeOptionSet.get( new Random().nextInt( 4 ) ).getCode() ) );
+ event.getDataValues().add( new DataValue( "K6uUAvq500H", icd10OptionSet.get( new Random().nextInt( 12000 ) ).getCode() ) );
+
+ events.add( event );
+ }
+
+ eventService.addEvents( events, new ImportOptions() );
+ }
+}
=== modified file 'tools/dhis-adhoc/src/main/resources/META-INF/dhis/beans.xml'
--- tools/dhis-adhoc/src/main/resources/META-INF/dhis/beans.xml 2014-10-23 07:14:17 +0000
+++ tools/dhis-adhoc/src/main/resources/META-INF/dhis/beans.xml 2015-02-17 21:39:32 +0000
@@ -5,6 +5,8 @@
<bean id="exampleCommand" class="org.hisp.dhis.adhoc.command.ExampleCommand" />
<bean id="randomDataPopulator" class="org.hisp.dhis.adhoc.command.RandomDataPopulator" />
+
+ <bean id="randomEventPopulator" class="org.hisp.dhis.adhoc.command.RandomEventPopulator" />
<bean id="analyticsTableGenerator" class="org.hisp.dhis.adhoc.command.AnalyticsTableGenerator" />
</beans>