<commit_before>﻿The DHIS2 Reporting Module
=========
An OpenMRS module that posts aggregate reports to DHIS2 based on dataelements bound to sql queries. The module works with OpenMRS 1.8.2 and higher. It is licensed under GNU GPL License, details of which can be found in the LICENSE.txt file.

The module configuration requires 2 things:

  - A report template which is uploaded into the module.
  - A DHIS2 instance (url, username and password)

Report template example:
-
This is the definition using which data will be POST'ed to a DHIS2 instance. The dataElements tag encompasses all the dataElements and their unique codes that are used in the report to be sent. Similarly, the disaggregations tag encompasses all the categoryOptionsCombo code and uid that are part of the dataElements to be reported.

The annotation contains the query used to generate the dataValue for the dataElement and its disaggregation.

    <?xml version="1.0"?>
    <reportTemplates xmlns:d2="http://dhis2.org/schema/dxf/2.0">
         <dataElements>
             <dataElement uid="nvVDDkfbbhf" code="ANC1" name="ANC1" type="int"/>
             <dataElement uid="OWeOBFxrvrv" code="ANC4" name="ANC4" type="int"/>
             <dataElement uid="xX6RDH6AZTK" code="POP" name="Population" type="int"/>
         </dataElements>
         <disaggregations>
             <disaggregation uid="YtbnZipIBx3" code="YtbnZipIBx3" name="(default)"/>
             <disaggregation uid="HgRodT2oZlq" code="HgRodT2oZlq" name="(Male)"/>
             <disaggregation uid="PfaFHAfpd2X" code="PfaFHAfpd2X" name="(Female)"/>
         </disaggregations>
         <reportTemplate>
             <name>Maternal and Child Health</name>
             <uid>sI82CctvS1A</uid>
             <code>MNCH</code>
             <periodType>Monthly</periodType>
             <dataValueTemplates>
                 <dataValueTemplate dataElement="ANC4" disaggregation="YtbnZipIBx3">
                 <annotation>
                     select count(distinct p.person_id)
                     from person p
                     inner join obs o on o.person_id = p.person_id
                     where p.voided = 0 and o.voided = 0
                     and o.concept_id = 1425 
                     and o.value_numeric = 4
                     and o.obs_datetime >= :startOfPeriod
                     and o.obs_datetime &lt;= :endOfPeriod
                     and o.location_id = :locationId
                 </annotation>
                 </dataValueTemplate>
             </dataValueTemplates>
        </reportTemplate>
    </reportTemplates>
    
DHIS2 instance information
-

The DHIS2 instance to which data is being reported should expose the [Web-API](http://dhis2.org/doc/snapshot/en/user/html/ch23.html). The data is sent as XML to the [dataValueSets](http://dhis2.org/doc/snapshot/en/user/html/ch23s05.html) resource, but relying on human-readable "code field" instead of the more obscure uid.<commit_msg>Update Status of Project<commit_after>﻿The DHIS2 Reporting Module
=========
An OpenMRS module that posts aggregate reports to DHIS2 based on dataelements bound to sql queries. The module works with OpenMRS 1.8.2 and higher. It is licensed under GNU GPL License, details of which can be found in the LICENSE.txt file.

### Module requirements:
* Able to support multiple DHIS2 instances
* Integrated with DHIS2 WebAPI
* Able to Sync new changes (of datasets and organization units) in the Dhis2 Instance
* Support [ADX](http://wiki.ihe.net/index.php/Aggregate_Data_Exchange)

## DHIS2 Model

<img src="https://github.com/maurya/openmrs-module-dhis2reporter/blob/master/omod/src/main/resources/images/dhis2core_diagram.jpg" alt="DHIS2 Model"/>


## Module Model

* DHIS2 Server - id, url, username, password
* DataSet - id, dhis2server, uid, name, code, period
* OrgUnit - id, dhis2server, uid, name, code, Location
* DataElement - id, dhis2server, uid, name, code
* Disaggregation - id, name, uid, dhis2server
* DataValueTemplate - id, DataSet, DataElement, Disaggregation

Input:
-

The dataElements tag encompasses all the dataElements and their unique codes that are used in the report to be sent. Similarly, the disaggregations tag encompasses all the categoryOptionsCombo code and uid that are part of the dataElements to be reported.

    <?xml version="1.0"?>
    <reportTemplates xmlns:d2="http://dhis2.org/schema/dxf/2.0">
         <dataElements>
             <dataElement uid="nvVDDkfbbhf" code="ANC1" name="ANC1" type="int"/>
             <dataElement uid="OWeOBFxrvrv" code="ANC4" name="ANC4" type="int"/>
             <dataElement uid="xX6RDH6AZTK" code="POP" name="Population" type="int"/>
         </dataElements>
         <disaggregations>
             <disaggregation uid="YtbnZipIBx3" code="YtbnZipIBx3" name="(default)"/>
             <disaggregation uid="HgRodT2oZlq" code="HgRodT2oZlq" name="(Male)"/>
             <disaggregation uid="PfaFHAfpd2X" code="PfaFHAfpd2X" name="(Female)"/>
         </disaggregations>
         <reportTemplate>
             <name>Maternal and Child Health</name>
             <uid>sI82CctvS1A</uid>
             <code>MNCH</code>
             <periodType>Monthly</periodType>
             <dataValueTemplates>
                 <dataValueTemplate dataElement="ANC4" disaggregation="YtbnZipIBx3"/>
             </dataValueTemplates>
        </reportTemplate>
    </reportTemplates>
    
    
#### ADX Data Output

[ADX](http://wiki.ihe.net/index.php/Aggregate_Data_Exchange)Sample has been taken from https://github.com/dhis2/adx/tree/master/IHE/samples
```
<?xml version="1.0" encoding="UTF-8"?>
<adx xmlns="urn:ihe:qrph:adx:2015"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="urn:ihe:qrph:adx:2015 ../schema/adx_sample_generated.xsd"
     exported="2015-02-08T19:30:00Z">
    
    <group orgUnit="342" period="2015-01-01/P1M" dataSetComplete="true" mechanism="PEPFAR">
        <dataValue dataElement="MAL01" value="32" />
        <dataValue dataElement="MAL02" value="20" />
        <dataValue dataElement="MAL04" value="10" ageGroup="under5" sex="M" />
        <dataValue dataElement="MAL04" value="10" ageGroup="under5" sex="F"/>
        <dataValue dataElement="MAL04" value="10" ageGroup="5andOver" sex="M"/>
        <dataValue dataElement="MAL04" value="10" ageGroup="5andOver" sex="F"/>
    </group>
    <group orgUnit="342" period="2015-01-01/P1M" mechanism="OTHER" comment="Imported from facility system">
        <dataValue dataElement="MAL01" value="32" />
        <dataValue dataElement="MAL02" value="20" />
        <dataValue dataElement="MAL03" value="0" >
            <annotation>Some qualifying text here on the datavalue</annotation>
        </dataValue>
        <dataValue dataElement="MAL04" value="10" ageGroup="under5" sex="M" />
        <dataValue dataElement="MAL04" value="10" ageGroup="under5" sex="F"/>
        <dataValue dataElement="MAL04" value="10" ageGroup="5andOver" sex="M"/>
        <dataValue dataElement="MAL04" value="10" ageGroup="5andOver" sex="F"/>
    </group>
</adx>
```


DHIS2 instance information
-

The DHIS2 instance to which data is being reported should support ADX - DHIS2 2.21 or later. The data is sent to the [dataValueSets](http://dhis2.org/doc/snapshot/en/user/html/ch23s05.html) resource.


Implemented:

  - [x] Configure DHIS2 Server
  - [x] Get Metadata From DHIS2 Web API 
  - [x] Being able to generate ADX using SQL for base Indicators
  - [x] Being able to generate ADX using Reporting Module for base Indicators
  - [x] Send Data for Multiple locations/OrgUnits

TODO:
 -  [ ] Store Additional Metadata in OpenMRS - Category, CategoryCombo, CategoryOption
 -  [ ] Generate Disaggregations for ADX output
 -  [ ] Support Multiple DHIS2 Instances
 -  [ ] Support Disaggregation with Reporting Module Reports 

{'fraction_non_alphanumeric': 0.11435523114355231, 'fraction_numerical': 0.027660391855551286, 'mean_word_length': 3.141039236479321, 'pattern_counts': {'":': 0, '<': 82, '<?xml version=': 3, '>': 83, 'https://': 2, 'lorem ipsum': 0, 'www.': 1, 'xml': 7}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3763688', 'n_tokens_mistral': 2574, 'n_tokens_neox': 2376, 'n_words': 665}