Skip to content

Commit

Permalink
fix obtaining operational area
Browse files Browse the repository at this point in the history
  • Loading branch information
hilpitome committed Jan 16, 2024
1 parent 5b23603 commit e5adb39
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<artifactId>opensrp-server-core</artifactId>
<packaging>jar</packaging>
<version>2.14.7-SNAPSHOT</version>
<version>2.14.9-DEV1-SNAPSHOT</version>
<name>opensrp-server-core</name>
<description>OpenSRP Server Core module</description>
<url>https://github.com/OpenSRP/opensrp-server-core</url>
Expand Down
31 changes: 25 additions & 6 deletions src/main/java/org/opensrp/service/StockService.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,14 @@
import java.text.ParseException;
import java.util.*;

import com.google.gson.Gson;

Check notice on line 6 in src/main/java/org/opensrp/service/StockService.java

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

src/main/java/org/opensrp/service/StockService.java#L6

Unused import - com.google.gson.Gson.
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.joda.time.DateTime;
import org.json.JSONObject;

Check notice on line 10 in src/main/java/org/opensrp/service/StockService.java

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

src/main/java/org/opensrp/service/StockService.java#L10

Unused import - org.json.JSONObject.
import org.opensrp.domain.postgres.Structure;
import org.opensrp.domain.postgres.StructureMetadataExample;
import org.opensrp.repository.postgres.mapper.custom.CustomStructureMetadataMapper;
import org.smartregister.domain.Inventory;
import org.smartregister.domain.ProductCatalogue;
import org.smartregister.domain.PhysicalLocation;
Expand Down Expand Up @@ -54,6 +59,9 @@ public class StockService {
private PlanService planService;
@Autowired
private TaskGenerator taskGenerator;

@Autowired
private CustomStructureMetadataMapper structureMetadataMapper;

private static Logger logger = LogManager.getLogger(StockService.class.toString());

Expand Down Expand Up @@ -185,18 +193,29 @@ public void addInventory(Inventory inventory, String userName) {
allStocks.add(stock);
// Go up the location tree to get the operational area.
//TODO Make process configurable
PhysicalLocation servicePoint = physicalLocationService.getLocation(stock.getLocationId(), false, false);
if(servicePoint == null || servicePoint.getProperties() == null || servicePoint.getProperties().getParentId() == null) return;
logger.info("Service Point %s"+servicePoint.getProperties().getName());
logger.info("Init updating tasks after adding stock");
StructureMetadataExample structureMetadataExample = new StructureMetadataExample();
structureMetadataExample.createCriteria().andGeojsonIdEqualTo(stock.getId());
Structure structure = structureMetadataMapper.findById(stock.getLocationId(), true);
PhysicalLocation servicePoint = (PhysicalLocation) structure.getJson();

if(structure.getJson() == null || servicePoint.getProperties().getParentId() == null)
return;;
logger.info("Fetching parent location for servicepoint "+servicePoint.getProperties().getUid());
String servicePointParentId = servicePoint.getProperties().getParentId();

PhysicalLocation servicePointLocation = physicalLocationService.getLocation(servicePointParentId, false, false);

if(servicePointLocation == null || servicePointLocation.getProperties() == null || servicePointLocation.getProperties().getParentId() == null) return;
logger.info("Service Point parent "+servicePointLocation.getProperties().getName()+" location id "+servicePointParentId);

PhysicalLocation district = physicalLocationService.getLocation(servicePoint.getProperties().getParentId(), false, false);
if(district == null || district.getProperties() == null || district.getProperties().getParentId() == null) return;

logger.info("District %s"+district.getProperties().getName());
String regionId = district.getProperties().getParentId();
if(regionId==null) return;
logger.info("District "+district.getProperties().getName());
logger.info("RegionID "+regionId);

logger.info("RegionID %s"+regionId);
List<PlanDefinition> plans = planService.getPlanRepository().getPlansByServerVersionAndOperationalAreasAndStatus(0L,
Collections.singletonList(regionId), false, PlanDefinition.PlanStatus.ACTIVE);
for (PlanDefinition plan :
Expand Down

0 comments on commit e5adb39

Please sign in to comment.