Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DRM-09 : startOfPeriod and endOfPeriod not there exception should be handled properly #61

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -184,8 +184,18 @@ public String evaluateDataValueTemplate( DataValueTemplate dvt, Period period, L
{
query.setParameter( "locationId", location.getId().toString() );
}
query.setParameter( "startOfPeriod", period.getStartDate() );
query.setParameter( "endOfPeriod", period.getEndDate() );
if ( parameters.contains( "startOfPeriod" ) )
{
query.setParameter( "startOfPeriod", period.getStartDate() );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add some unit tests for these changes?

}
if ( parameters.contains( "endOfPeriod" ) )
{
query.setParameter( "endOfPeriod", period.getEndDate() );
}
if ( !parameters.contains( "startOfPeriod" ) && !parameters.contains( "endOfPeriod" ) )
{
return "NoParam";
}
return query.uniqueResult().toString();
}

Expand Down
Expand Up @@ -86,6 +86,18 @@ public void shouldevaluateDataValueTemplate()
assertEquals("3", dvs);
}
}

for ( ReportDefinition rd : rds )
{
for ( DataValueTemplate r : rd.getDataValueTemplates() )
{
String query = "select count(distinct p.person_id) from person p inner join obs o on o.person_id = p.person_id\n"
+ "where p.voided = 0 and o.voided = 0 and o.concept_id = 1425 and o.value_numeric = 4";
r.setQuery( query );
String dvs = dao.evaluateDataValueTemplate( r, period, location );
assertEquals( "NoParam", dvs );
}
}
}

@Test
Expand Down
Expand Up @@ -444,8 +444,16 @@ AdxType getAdxType( DataValueSet dvs, String timeperiod )
{
DataValueType dvtype = new DataValueType();
dvtype.setDataElement( dv.getDataElement() );
dvtype.setValue( new BigDecimal( dv.getValue() ) );
try
{
BigDecimal bd = new BigDecimal( dv.getValue() );
dvtype.setValue( bd );
dvTypeList.add( dvtype );
}
catch ( NumberFormatException e )
{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not recommended to catch exceptions and do nothing. You would rather leave them to bubble through.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You seem to have nothing to do in the exception handler. Can't you just remove the try and catch to let it bubble up?

dvTypeList.add( null );
}
}
gt.getDataValue().addAll( dvTypeList );
gt.setOrgUnit( dvs.getOrgUnit() );
Expand Down
3 changes: 2 additions & 1 deletion omod/src/main/resources/messages.properties
Expand Up @@ -100,4 +100,5 @@ ${project.parent.artifactId}.openMRSLocationMapped = OpenMRS Location is Mapped
${project.parent.artifactId}.openMRSLocationDoesNotExist = OpenMRS Location Does Not Exists.
${project.parent.artifactId}.orgUnitCodeDoesNotExist = "Code" Attribute in DHIS2 ORG UNIT is not set. Please set it and then try Mapping.

${project.parent.artifactId}.editReportMapping = Edit Report Mapping
${project.parent.artifactId}.editReportMapping = Edit Report Mapping
${project.parent.artifactId}.missingParameters = Parameters missing
7 changes: 6 additions & 1 deletion omod/src/main/webapp/executeReport.jsp
Expand Up @@ -36,7 +36,12 @@
<tr>
<td>${dvm.key.name}</td>
<td>${dvm.key.code}</td>
<td>${dvm.value}</td>
<c:if test="${dvm.value!='NoParam'}">
<td>${dvm.value}</td>
</c:if>
<c:if test="${dvm.value=='NoParam'}">
<td><div id="openmrs_msg"><spring:message code="dhisreport.missingParameters" /> </div></td>
</c:if>
</tr>
<tr>
</c:forEach>
Expand Down