Sunday, August 17, 2014

GSoC 2014: My Final Blog post !!!

Hi all,

So time has flew and the Google Summer of Code 2014 has come to an end. Since i had already completed the planned coding work, this week i mostly spent on writing the unit tests and adding the documentation for the module. Therefore i completed that work this week. In the next few days i will be releasing the final 1.1.0 version of the module and will deploy the artifacts and hence can finish the GSoC period with a success note.

Since this is my last blog post in the i would like to thank my awesome mentors Pascal and Jan for all the guide they gave me during this time. When i started i had a little programming knowledge on OpenMRS but they helped me a lot in catching up the speed. Also i should thank Micheal,Daniel,Wyclif and Harsha too for all the help they gave me in answering queries for me to know well on the project.

My mentor Pascal is on vacation this week so we didn't get time to call this week. He had given me all the guides before the vacation and i was able to finish the tasks as per his advice. In the next week i will be updating OpenMRS developers list with the final state of the project. Looking forward to the final evaluation.



Sunday, August 10, 2014

GSoC Final Coding Week : Adding the 'Created Encounters' Application Indicator

After 12 weeks of hard work, this week i finished the coding of the module 'System Performance and Utilization'. The final indicator that is added was 'Encounter Created' which listens on the created encounters (on the other hand, entered forms) and displays the created encounters per hour and per day.

In addition to that i completed a short video of the final state of the module so far, added a demo on how to add the module, invoke the indicators and observe the displayed data graphs there. By the time of creating the video, the 'Created encounters' indicator was in progress therefore the demo doesn't include the graph for that. However i will be updating it on the module documentation.

The post on the final presentation posted into OpenMRS talk can be found in the below link.

Final demo video:
https://talk.openmrs.org/t/gsoc-2014-system-performance-and-utilization-module-final-presentation/488

Final Presentation Slides:
https://wiki.openmrs.org/display/projects/Final+Evaluation+Resources

Therefore the next week i hope to spend on writing the test cases as well as complete all the testing on the module source code. After that the final week can be spent on adding the documentation and releasing the version 1.1.0 of the module to conclude this great summer !!

Sunday, August 3, 2014

GSOC Week 11: Finishing the User Login Indicator

Time has flew so fast and it is one more coding week in the GSoC. This week i finished the logged in users indicator with completing both graphs for the Logged In Users Count as ell as created listeners, deletion thread for the indicator.

In order to enable user log in tracking when the module is started, it is needed to invoke the 'Enable User Login Tracking' button from the module home page as below.

After that when you go to User Logins: section the below is the view of the charts for logged in users per each 30 second and for each 5 minutes.



Since the coming week is the final coding week for GSoC as agreed with my mentor Pascal, i will be working on getting one more application indicator done, which is 'completed forms per hour/day'.

In addition this week i also spent time on working on my final evaluation video for the project which will be added into OpenMRS talk page in the coming days after i finalize it with my mentor.

Below are the commits for the feature this week.
[1] https://github.com/openmrs/openmrs-module-systemmetrics/commit/96acbd28d31134cf0dbaa4589b13033205b537cd
[2] https://github.com/openmrs/openmrs-module-systemmetrics/commit/af7ae56fae686a5077b34a10a3ff7baa8749d4c3

Thursday, July 24, 2014

GSoC Week 10: Application Indicators - Getting user log in count chart


Since my previous attemp of getting logging in users through a SessionListener failed, this week i started back with two alternatives.

1. As suggested by my mentor Pascal, i tried to use a scheduler task for this. But since the task also doesn't have HTTPSession infomation this was not successful.

2. Created a new UI button to enable user login data tracking. When it is tirggerred the HTTPSession of the servlet request is passed to the Collector thread and logged in user count is retirved and stored into the databse from here onwards.

Below is how it is done.

I added a button to UI to click to enable login indicator. When user clicks this button it starts the LoggedInUsersCountCollectorThread with the session as below.


@RequestMapping(value = "/module/systemmetrics/track", method = RequestMethod.GET)
public void track(HttpServletRequest request)
{
loggedInUsersCountCollectorThread = new LoggedInUsersCountCollectorThread(request.getSession());
Thread loginThread = new Thread(loggedInUsersCountCollectorThread);
loginThread.start();
}


After that i can use the current session and get logged in users from time to time. This is similar to how the OpenMRS Core --> Administration --> Maintenance --> View logged in users section is also getting the users list.

Below is the chart view of the stored data which is calculated every 30 seconds.



Here are the commits i made for the feature within this week. 
  • https://github.com/openmrs/openmrs-module-systemmetrics/commit/e9a36740f2eddf35e6d5e435c13286735aecf0be
Since there is a new JIRA project is created for our project now i created the first feature entry there.
  • https://issues.openmrs.org/browse/SPU-1

Sunday, July 20, 2014

GSoC Week 09 - Starting with Application Indicators

This week i started with application indicators and as discussed previously with Pascal and Jan my first indicator to work on is Logged-in users count. Therefore i tried to record data on Logged In users.


However currently i have blocked a bit in that in by this week.


I first created the relevant table structure, DAO objects etc. for LoginValue DAO where we can store [timestamp, metric_id, logged in user count] records. Then in order to retrieve data on user log-ins i created a collector thread and implemented it with HTTPSessionListener class. So when the system starts the login data collector thread would run in each 30 seconds and create LoginValue entry and add it into data table. Then we can retrieve data from this table and draw the graph.


My intention was that when a user logs in, the sessionCreated() event will be triggered in this LoggedInUsersCountCollectorThread collector class which is given below.


public class LoggedInUsersCountCollectorThread implements Runnable, HttpSessionListener {


private boolean start;
LoginValue loginValue;
List<String> currentUsers = new ArrayList<String>();


PerformanceMonitoringService performanceMonitoringService;

public LoggedInUsersCountCollectorThread() {
           startLoggedInUsersCountCollectorThread();
}

@Override
public void run() {
Context.openSession();
performanceMonitoringService = Context.getService(PerformanceMonitoringService.class);
while (start){
int userCount = currentUsers.size();
loginValue = new LoginValue(System.currentTimeMillis(),3,userCount);
performanceMonitoringService.addLoginValue(loginValue);
try {
System.out.println("Users count " + userCount + " - sleeping 30s now");
Thread.sleep(30000);
} catch (InterruptedException e) 
{ /* ignore*/  }
    }
}

private boolean isStarted(){
return start;
}

public void startLoggedInUsersCountCollectorThread(){
start = true;
}

public void stopLoggedInUsersCountCollectorThread(){
start = false;
}

@Override
public void sessionCreated(HttpSessionEvent httpSessionEvent) {
currentUsers = CurrentUsers.getCurrentUsernames(httpSessionEvent.getSession());
System.out.println("User logged in " + currentUsers.size());
}


@Override
public void sessionDestroyed(HttpSessionEvent httpSessionEvent) {
System.out.println("User logged out " + currentUsers.size());
}



However this listener doesn't trigger when i started the module. My other functions works as expected and it updates the table etc. however since this thread always returns currentUsers list size as zero ( as sessionCreated event never triggered), the count is always recorded as 0 so i am unable to proceed to draw tables. I also tried with adding a listener entry into override-web.xml file in OpenMRS/test/resource directory as this but no luck.


<listener>
<listener-class>org.openmrs.module.systemmetrics.api.collectors.LoggedInUsersCountCollectorThread</listener-class>
</listener>



I will be discussing this with Pascal on the weekly update call this Monday and will get his advice. Based on that i hope i can correct if there is any issue or else i will be moving to try an alternative way.

Sunday, July 13, 2014

GSoC Week 08: System Performance and Utilization Module v1.0.0 Released !!

This week i released the first public available version of System Performance and Utilization Module. The  'systemmetrics-1.0.omod' is now available in the OpenMRS module repository and i created the corresponding Git tags v1.0.0 as well as the module documentation.

Below i would like to mention the useful references that helped me in releasing a module against github.


1. Releasing a module

https://wiki.openmrs.org/display/docs/Module+Tagging+and+Releasing

Once you follow the given instructions github will be automatically having the release tag in the git hub repo as below.

https://github.com/openmrs/openmrs-module-systemmetrics/releases

However i still need to deploy the module artifacts into remote nexus repository as i currently don't have access for it. I have submitted an access request and awaiting response on it.

2. Module Repository Location

https://modules.openmrs.org/#/show/162/system-performance-and-utilization-module

3. Module Documentation

https://wiki.openmrs.org/display/docs/System+Performance+and+Utilization+Module

4. Module Source Repository


There are few tasks for me to getting done with the 1.0.0 version. First one is deploying the artifacts into nexus. then create a JIRA project and also upload a video on using the module. While working on these things getting done, i hope to move into Application Indicators Implementation from next week too.

Sunday, July 6, 2014

GSoC Week 07 - Ready for the first release !!

This week i mostly worked on getting used memory indicator finalized for the very first 1.0.0 release of OpenMRS-SystemMetrics module. The final agreement for the release between me and my mentors was get the Memory indicator finalized with Service API and the Graph and releasing it out by the next week.

I was able to work on towards this and complete the memory data during this week and covered the tasks below.

1. Modified the per second memory value graph.

2. Added the next graph on per minute memory values for the Used Memory.

3. Added schedulers to delete the data from per second and per minute data tables in the database periodically. The current time duration is per second data will be deleted in every 30 minutes and per minute data will be cleared in every 5 hours to avoid these tables getting flooded. Evetually these values will be make configurable using global properties so users have the freedom of configuring those as they need.

4. Modified the Module home page and provided links to view the charts and tables.

Module Home Page:



Used Memory Charts page:




For the next week i hope to finish the documentation so far, create the JIRA project and create the first video of the System Performance and Utilization Module and release 1.0.0 version of the module.

Once we get the release out the next task would be start on Application indicators and get the data on logged in users statistics and display it in the module.



















Friday, June 27, 2014

GSoC Week 06 - Mid-term Evaluations :)

The good news from GSoC office came today and it said i had passed the mid-term evaluation. :) Few more step to go now ...

This week at the start i had a mail discussion with pascal and we discussed on getting the first release for the System Monitoring module out by the 2nd week of July.

Then it was back to drawing the graph based on memory data. After struggling several times with NVD3 js i finally decided to look for alternatives as it was not easy for me to get the NVD3 based graph working. There were not enough examples, documents on getting this etc. When looking at other available options i found the Google Chart API [1] which was amazing and did my job !!

Google chart API has a rich documentation support and  a good API reference guide which helped me in creating a line chart by retrieving data from the metric value table and populate them as a graph. The syntax was easy to understand. So finally i was able to draw my first graph with real time memory data as shown in the image below. 

This is how the week went so far. Now i am going to work on furnishing the graphs and finalize the current implementation by next week so we can meet up the release deadline right at the time.

Sunday, June 22, 2014

GSoC Week 5 : Generated my first graph with Memory Usage

Since i have got lot of progress in listening to memory usage previous week this week my main target was getting started with NVD3 js and try to generate the graphs.

NVD3 js is a tool for build re-usable charts and chart components for using d3.js which is a JavaScript library for manipulating documents based on data using HTML, SVG and CSS. 

This is the first time i was working with NVD3 js and therefore it took me a few days to get it learnt and try out few basic examples. After that i started with creating the first graph in the module for the used memory data values. I first tried with using sample data and populating X and Y axises of the graph with reading and iterating  data using a json file where i stored {"timestamp": "memory value"} pairs. However it didn't work as each time i got D3.js error as it is not able to find my data.json file when called using,

d3.json('file path', callbacks); method.

Therefore to get the graph using i used some mock memory values inside my chart.jsp file and by populating those data i was able to draw the graph as below.




Therefore for the next week my biggest challenge is getting more used to NVD3 js API and to javascript and get this graph populated with real time memory data.

In addition since the coming week is the mid term evaluation, i worked on creating my project update presentation and added in the below locations.


[1] https://talk.openmrs.org/t/gsoc-2014-system-performance-and-utilization-module-midterm-presentation/313

[2] https://wiki.openmrs.org/display/projects/System+Performance+and+Utilization+Module

Saturday, June 14, 2014

GSoC Week 4: Extracting memory data values

In this week i started on reading memory values from the system and storing it in memory values table in System Performance and Utilization  module.

Querying the used memory for this is done using the Java Management beans where it expose both use memory and free memory values with MemoryMXBean. The following link is explaining about the structure of the beans API.

http://docs.oracle.com/javase/7/docs/api/java/lang/management/ManagementFactory.html

Once we read memory values from the beans, we store them in the metric_values table. This operation is called in each 10 seconds where it reads used memory value and them sleeps for 10 seconds.

After every one minute the used memory values which was recorded for the previous minute is taken and we get the average used memory value for that minute using these. Then there is another table named per_minute_value_table. The new average used memory value will be recorded in this table in every minute.

Below is the structure of the metric_value table of the new module and how the data entered there looks like for now.



The next step would be read these entries from DB and display them in graphs in the UI.

Saturday, June 7, 2014

GSOC Week 3 : Adding new tables for system indicators

In this week i worked on creating Hibernate mappings and adding the newly designed tables system_metric_types and system_metric_values into OpenMRS database. I first created HibernateDAO objects for MetricType object then called that in PerformanceMonitoringServiceImpl service to add/remove/modify MetricType values. 

However when i then added MetricType.hbm.xml file and name in config.xml it gave me this error.

org.hibernate.MappingException: Unknown entity: org.openmrs.module.systemmetrics.MetricType at org.hibernate.impl.SessionFactoryImpl.getEntityPersister(SessionFactoryImpl.java:693) at org.hibernate.impl.SessionImpl.getEntityPersister(SessionImpl.java:1485) 

 It seemed that hibernate didn't pick up my mapping file entry. With the help of my mentor i finally figured out a way to get rid of it as below. Instead of mapping, i used JPA annoatations. 

 First create MetricType object and annotate it with Table and column annotations as below. As we define table name, primary key, column names here there is no need to refer a .hbm.xml file Also the class needed to implement Serializable in order to define Id, which is primary key. 

  @Entity @Table(name = "systemmetrics_metric_type") 
public class MetricType implements Serializable { 

 @Id @Column(name = "metric_id") 
 private int metricId; 

 @Id @Column(name = "metric_name", length = 255) 
 private String metricName; 

 @Id @Column(name = "metric_type", length = 255) 
 private String metricType; 


 After that modify config.xml file to use annotated classes. You can comment out mapping-files entry there. 

 <!-- Maps hibernate file's, if present -->
    <!--<mappingFiles></mappingFiles>-->

 <!-- Packages that will be scanned for JPA annotations -->
<packagesWithMappedClasses>
        org.openmrs.module.systemmetrics
</packagesWithMappedClasses>


Then it is needed to change liquibase.xml file and add the changeset entry there with entries for each our tables as below. A list of supported elements and attributed as given in http://www.liquibase.org/manual/home#available_database_refactorings 

<changeSet id="system-metrics-1" author="milinda-ruk">
        <createTable tableName="systemmetrics_metric_type">
            <column name="metric_id" type="int" autoIncrement="true">
                <constraints primaryKey="true" nullable="false"/>
            </column>
            <column name="metric_name" type="varchar(255)">
                <constraints nullable="false"/>
            </column>
            <column name="metric_type" type="varchar(255)">
                <constraints nullable="false"/>
            </column>
        </createTable>
  </changeSet>

When the module is loaded the new table is created now and you can add data there using DAO objects. 

For the next week i hope to complete adding used memory data periodically into metric_value table and moving them into used_memory_minute table.

Friday, May 30, 2014

GSoC Week 2: Designing database schema for store module data

In this week i had the weekly call with Pascal as usual. As discussed in that, i was mainly working on designing the database schemas for the new module data to be stored. As the first steps i have come up with the following schema for the new tables that will be used in storing system indicators as used memory, heap memory, free memory etc. Since it is bad practice to define a separate table to each indicator and as it is hard to scale that with time the following design is agreed. We first store metic_name with an id called  metric_id in seperate table for all metics. Then another table is used to store real data values against metirc name and id as below.

Metircs Types Table
[ metric_id, time_stamp, metric_value ]

Metic Values Table

[ metric_id, metric_name, metric_type ]

I am now going to follow this way and create the first set of tables and try to store memory data here.

In addition we discussed on handling historical data. As we can't store previous data forever since database is growing, we are going to have a periodical call to calculate the aggregate value of each metric and it will be moved to a seperate table.

I also sent a request to add my new module into OpenMRS reporsitory this week.


Friday, May 23, 2014

Beginning coding with GSoC - Adding a new module

This week started the coding for Google Summer of Code project. As the first task i started writing the new module structure using maven archetype document reference in [1]. Also i discussed with my mentors Pascal and Jan through mail about the first set of indicators to implement and how to do that. Since this is the first week i still didn't start coding for the indicators but focused on creating the now module and adding it to github. As agreed by three of us the new module will be named as openmrs-module-metrics. 

Below are few snapshots from the module home page. I will be adding this to github soon and will be starting the coding from next week as planned.


 [Module Link from OpenMRS Home]




                                                [Module Home Page]

[1] https://wiki.openmrs.org/display/docs/Creating+Your+First+Module

Sunday, May 18, 2014

Community Bonding Period of GSoC

During the community bonding period, i had two calls with my mentors Pascal and Jan. In first one we introduced ourselves and discussed about project requirements. As per my mentors guidance, i created a google doc where we will be discussing and adding project requirements and added it into OpenMRS wiki here.

GSoC Project Requirements:

https://wiki.openmrs.org/display/projects/System+Performance+and+Utilization+Module+Requirements

In the second week we identified few main indicators that needed to be searched and tried to implement as first phase and my mentor, pascal requested me to find out how that data can be captured and presented therefore i spent the week on them. Also learnt on how to write a new OpenMRS module as below since it will be my first task to get started with project.

How t write a new module:

https://wiki.openmrs.org/display/docs/Creating+Your+First+Module

Wednesday, May 7, 2014

Beginning GSoC 2014 with OpenMRS


It was a wonderful news that after months of hard work i have been selected to Google Summer of Code with OpenMRS. This is my first time in the GSoC. Here is a short description about my project as it will be a help for you to understand that how it works in OpenMRS.

My project is to develop a system performance and utilization module [1]. It's a new OpenMRS module which can supply information on system performance and utilization in order to monitor reliability and impact of the electronic medical record system installation.This module can be used to monitor OpenMRS and transfer specific system indications.

So far, I have already started creating mock GUI's and now I'm going to start the cording part from mid of this month.I have already fixed some bugs in the code earlier. Last week I addressed the GSoC 2014 developer forum to introduce myself to others.

In this week I started the project discussion with my primary mentor Pascal Brandt and backup mentor Jan Flower. We agreed to have this conversation on every week. I hope it will be a good help for make my way to success.
                                  
Finally i would like to make a note here that  I consider working with OpenMRS community is a big merit for me.

                                                                     
                                                            
                    

Tuesday, March 18, 2014

My first Point of Sale Software Application


Point of Sale software has a high demand in the current market where many vendors like to make their sales business convenient with using a Electronic mechanism in order to track sales, orders, refunds etc. LeafPOS is a project which is developed by myself to provide POS operations targeting retails and restaurants business.

The functions of the application is:

1. Stock Management
2. Orders and Refunds Management
3. User Management
4. Provide daily/monthly Reports
5. Print the bill with Thermal Printer
6. Show the Order Items, Balance etc. in Custom Display

The application is written with Java and MySQL database. Here are few of the snapshots from the project.

1. Log in window




 2. Main window





3. Start order window



4. Items search window



5. Pay window



6. Add stock window



















..............................................................................................................................................................


Paint Delivery System

The main use of the application is keeping track of the paint products sold by the sales  representatives. The various functions of application includes Order handling, Distributors handling, Items and Stock handling etc. The source code of back end and UI is written in C#  and MySQL is used for the database. We have done this as a group project during my second year of university.

Sample UI portal screenshot is,


The hosted source code can be downloaded from here .