Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,18 @@ public String getDesignatedPhi(@RequestParam(value = "villageId", required = fal
}
return response.toStringWithSerialization();
}

@Operation(summary = "Get all designated PHI mappings; activeOnly=true leaves out inactive rows")
@GetMapping(value = "/getAll", produces = "application/json", headers = "Authorization")
public String getAllDesignatedPhi(
@RequestParam(value = "activeOnly", required = false, defaultValue = "false") Boolean activeOnly) {
OutputResponse response = new OutputResponse();
try {
response.setResponse(GSON.toJson(nikshayDesignatedPhiService.getAllDesignatedPhi(activeOnly)));
} catch (Exception e) {
logger.error("getAllDesignatedPhi failed: " + e.getMessage(), e);
response.setError(e);
}
return response.toStringWithSerialization();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ public String setDeviceActive(@RequestBody NikshayActivateRequest request) {
return respond("setDeviceActive", () -> nikshayDeviceService.setDeviceActive(request));
}

@Operation(summary = "List devices (without password), optionally by device name (NAAT / XRAY) and active flag")
@Operation(summary = "List devices (without password), each with its active villages, "
+ "optionally by device name (NAAT / XRAY) and active flag")
@GetMapping(value = "/list", produces = "application/json", headers = "Authorization")
public String listDevices(@RequestParam(value = "deviceName", required = false) String deviceName,
@RequestParam(value = "isActive", required = false) Boolean isActive) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,6 @@

List<Map<String, Object>> getDesignatedPhi(Integer villageId, Integer tbuId, Integer districtId,
Boolean activeOnly, Boolean unmappedOnly) throws Exception;

List<Map<String, Object>> getAllDesignatedPhi(Boolean activeOnly) throws Exception;

Check warning on line 22 in src/main/java/com/iemr/admin/service/nikshay/NikshayDesignatedPhiService.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Replace generic exceptions with specific library exceptions or a custom exception.

See more on https://sonarcloud.io/project/issues?id=PSMRI_Admin-API&issues=AaF4FkwUOarpksLXJlhO&open=AaF4FkwUOarpksLXJlhO&pullRequest=158
}
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,8 @@ public List<Map<String, Object>> getDesignatedPhi(Integer villageId, Integer tbu
if (villageId == null && tbuId == null && districtId == null) {
throw new IllegalArgumentException("Village, TBU or district is required");
}
List<Map<String, Object>> result = new ArrayList<>();
if (Boolean.TRUE.equals(unmappedOnly)) {
List<Map<String, Object>> result = new ArrayList<>();
// row layout: see NikshayTransferOutPhiRepo.findVillagesWithoutDesignatedPhi
for (Object[] row : transferOutPhiRepo.findVillagesWithoutDesignatedPhi(villageId, tbuId, districtId)) {
Map<String, Object> m = new LinkedHashMap<>();
Expand All @@ -168,8 +168,19 @@ public List<Map<String, Object>> getDesignatedPhi(Integer villageId, Integer tbu
}
return result;
}
// row layout: see NikshayTransferOutPhiRepo.search
for (Object[] row : transferOutPhiRepo.search(villageId, tbuId, districtId, !Boolean.FALSE.equals(activeOnly))) {
return toSearchRows(transferOutPhiRepo.search(villageId, tbuId, districtId, !Boolean.FALSE.equals(activeOnly)));
}

// Every designated PHI mapping, with no village / TBU / district filter
@Override
public List<Map<String, Object>> getAllDesignatedPhi(Boolean activeOnly) throws Exception {
return toSearchRows(transferOutPhiRepo.search(null, null, null, Boolean.TRUE.equals(activeOnly)));
}

// row layout: see NikshayTransferOutPhiRepo.search
private List<Map<String, Object>> toSearchRows(List<Object[]> rows) {
List<Map<String, Object>> result = new ArrayList<>();
for (Object[] row : rows) {
Map<String, Object> m = new LinkedHashMap<>();
m.put("id", toInt(row[0]));
m.put("villageId", toInt(row[1]));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,9 @@ public List<NikshayDeviceResponse> listDevices(String deviceName, Boolean isActi
NikshayDeviceName name = trimToNull(deviceName) == null ? null : NikshayDeviceName.from(deviceName);
List<NikshayDeviceResponse> result = new ArrayList<>();
for (NikshayDeviceConfiguration device : deviceRepo.search(name, isActive)) {
result.add(toResponse(device));
NikshayDeviceResponse response = toResponse(device);
response.setVillages(getVillagesOfDevice(device.getId(), true));
result.add(response);
}
return result;
}
Expand Down
Loading