Skip to content

Commit

Permalink
Changed healthblock select query from (taluka, code) to (district, code)
Browse files Browse the repository at this point in the history
  • Loading branch information
sree21go committed Jul 23, 2018
1 parent f74d8db commit 4358f76
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@

public interface HealthBlockService {
HealthBlock findByTalukaAndCode(Taluka taluka, Long code);

HealthBlock findByDistrictAndCode(District district, Long code);

HealthBlock create(HealthBlock healthBlock);
HealthBlock update(HealthBlock healthBlock);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,36 @@ public HealthBlock execute(Query query) {
return healthBlockDataService.executeSQLQuery(queryExecution);
}

@Override
public HealthBlock findByDistrictAndCode(final District district, final Long code) {
if (district == null) { return null; }

SqlQueryExecution<HealthBlock> queryExecution = new SqlQueryExecution<HealthBlock>() {

@Override
public String getSqlQuery() {
return "select * " +
"from nms_health_blocks " +
"where code = ? and district_id_OID = ?";
}

@Override
public HealthBlock execute(Query query) {
query.setClass(HealthBlock.class);
ForwardQueryResult fqr = (ForwardQueryResult) query.execute(code, district.getId());
if (fqr.isEmpty()) {
return null;
}
if (fqr.size() == 1) {
return (HealthBlock) fqr.get(0);
}
throw new IllegalStateException("More than one row returned!");
}
};

return healthBlockDataService.executeSQLQuery(queryExecution);
}

@Override
public HealthBlock create(HealthBlock healthBlock) {
return healthBlockDataService.create(healthBlock);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ public Map<String, Object> getLocations(Map<String, Object> map, boolean createI
if (!isValidID(map, HEALTHBLOCK_ID)) {
return locations;
}
HealthBlock healthBlock = healthBlockService.findByTalukaAndCode(taluka, (Long) map.get(HEALTHBLOCK_ID));

This comment has been minimized.

Copy link
@gudipatiharitha

gudipatiharitha Jul 23, 2018

Contributor

If findby taluka is buggy - we should add a comment saying so

HealthBlock healthBlock = healthBlockService.findByDistrictAndCode(district, (Long) map.get(HEALTHBLOCK_ID));
if (healthBlock == null && createIfNotExists) {
healthBlock = new HealthBlock();
healthBlock.addTaluka(taluka);
Expand Down

0 comments on commit 4358f76

Please sign in to comment.