Skip to content

Commit

Permalink
AMM-1140 | API for fetching unallocated grievance record count for al…
Browse files Browse the repository at this point in the history
…location screen (#152)

* adding changes related to encryption and decryption

* making final field static

* making enclosing method static

* adding beneficiaryConsent param to createFeedback API

* Update src/main/java/com/iemr/common/data/feedback/FeedbackDetails.java

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

* adding beneficiary consent param feedbacklist response

* adding space

* adding code for schedule for grievance data sync

* adding code rabbit code suggestions

* adding code rabbit suggestions

* code rabbit suggested changes to Model classes

* adding sonar quality changes

* adding sonar quality code suggestions

* adding sonar quality check suggestions

* adding code rabbit suggestions

* adding constant instead of duplicate literals

* adding cod changs to fetch unallocated grievance count

* adding changes suggested by sonar quality check

* adding code rabbit suggested changes

* fixing config file

* fixing space

* fixing space issue

* adding package for PrimaryDBConfig

---------

Co-authored-by: SR20290919 <SR20290919@APL-PG02PW8B>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Jan 22, 2025
1 parent a89a605 commit 27a71ab
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/main/java/com/iemr/common/config/PrimaryDBConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
@Configuration
@EnableTransactionManagement
@EnableJpaRepositories(entityManagerFactoryRef = "entityManagerFactory", basePackages = { "com.iemr.common.repository",
"com.iemr.common.repo", "com.iemr.common.notification.agent", "com.iemr.common.covidVaccination", "com.iemr.common.repository.everwell.*", " com.iemr.common.repository.users" })
"com.iemr.common.repo", "com.iemr.common.notification.agent", "com.iemr.common.covidVaccination", "com.iemr.common.repository.everwell.*", "com.iemr.common.data.grievance", "com.iemr.common.repository.users" })
public class PrimaryDBConfig {

Logger logger = LoggerFactory.getLogger(this.getClass().getName());
Expand Down Expand Up @@ -83,7 +83,7 @@ public DataSource dataSource() {
public LocalContainerEntityManagerFactoryBean entityManagerFactory(EntityManagerFactoryBuilder builder,
@Qualifier("dataSource") DataSource dataSource) {
return builder.dataSource(dataSource).packages("com.iemr.common.data", "com.iemr.common.notification",
"com.iemr.common.model", "com.iemr.common.covidVaccination", "com.iemr.common.data.everwell", "com.iemr.common.data.users").persistenceUnit("db_iemr").build();
"com.iemr.common.model", "com.iemr.common.covidVaccination", "com.iemr.common.data.everwell", "com.iemr.common.data.grievance", "com.iemr.common.data.users").persistenceUnit("db_iemr").build();
}

@Primary
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package com.iemr.common.controller.grievance;


import com.iemr.common.service.grievance.GrievanceDataSync;
import com.iemr.common.utils.exception.IEMRException;
import com.iemr.common.utils.response.OutputResponse;

import io.swagger.v3.oas.annotations.Operation;


import javax.ws.rs.core.MediaType;

import org.json.JSONException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class GrievanceController {
final Logger logger = LoggerFactory.getLogger(this.getClass().getName());


private GrievanceDataSync grievanceDataSync;

@Autowired
public GrievanceController(GrievanceDataSync grievanceDataSync) {
this.grievanceDataSync = grievanceDataSync;
}

@CrossOrigin()
@Operation(summary = "/unallocatedGrievanceCount")
@PostMapping(value = "/unallocatedGrievanceCount", consumes = MediaType.APPLICATION_JSON, produces = MediaType.APPLICATION_JSON, headers = "Authorization")
public String fetchUnallocatedGrievanceCount() {
OutputResponse responseData = new OutputResponse();
try {
responseData.setResponse(grievanceDataSync.fetchUnallocatedGrievanceCount());
}
catch (IEMRException e) {
logger.error("Business logic error in UnallocatedGrievanceCount" + e.getMessage(), e);
responseData.setError(e);
}
catch (JSONException e) {
logger.error("JSON processing error in UnallocatedGrievanceCount" + e.getMessage(), e);
responseData.setError(e);
}
catch (Exception e) {
logger.error("UnallocatedGrievanceCount failed with error" + e.getMessage(), e);
responseData.setError(e);
}
return responseData.toString();

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;



import com.iemr.common.data.grievance.GrievanceDetails;

@Repository
Expand All @@ -18,6 +15,8 @@ public interface GrievanceDataRepo extends CrudRepository<GrievanceDetails, Lon
@Query("SELECT COUNT(g) > 0 FROM GrievanceDetails g WHERE g.complaintId = :complaintId")
boolean existsByComplaintId(@Param("complaintId") String complaintId);


@Query("select count(request) "
+ "from GrievanceDetails request where request.isAllocated = false")
public Long fetchUnallocatedGrievanceCount();

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@
import java.util.List;
import java.util.Map;

import org.json.JSONException;

import com.iemr.common.utils.exception.IEMRException;

public interface GrievanceDataSync {
public List<Map<String, Object>> dataSyncToGrievance();

public String fetchUnallocatedGrievanceCount() throws IEMRException, JSONException;

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
import java.util.List;
import java.util.Map;

import org.json.JSONObject;
import org.json.JSONException;
import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -37,7 +38,8 @@
import com.iemr.common.repository.grievance.GrievanceFetchBenDetailsRepo;
import com.iemr.common.repository.grievance.GrievanceTransactionRepo;
import com.iemr.common.repository.location.LocationStateRepository;
import com.iemr.common.utils.mapper.InputMapper;
import com.iemr.common.utils.exception.IEMRException;
import com.iemr.common.utils.mapper.InputMapper;

@Service
@PropertySource("classpath:application.properties")
Expand Down Expand Up @@ -371,5 +373,19 @@ private void generateGrievanceAuthToken() {
}
}
}

public String fetchUnallocatedGrievanceCount() throws IEMRException, JSONException {
logger.debug("Request received for fetchUnallocatedGrievanceCount");

Long unallocatedCount = grievanceDataRepo.fetchUnallocatedGrievanceCount();

if (unallocatedCount == null) {
throw new IEMRException("Failed to fetch unallocated grievance count");
}

JSONObject result = new JSONObject();
result.put("count", unallocatedCount);
return result.toString();
}

}

0 comments on commit 27a71ab

Please sign in to comment.