Summary Table

Categories Total Count
PII 0
URL 0
DNS 0
EKL 0
IP 0
PORT 0
VsID 0
CF 0
AI 0
VPD 0
PL 0
Other 0

File Content

package gov.va.med.ars.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import gov.va.med.ars.exceptions.GenericException;
import gov.va.med.ars.model.request.PayerInfoListRequest;
import gov.va.med.ars.model.response.GenericJsonResponse;
import gov.va.med.ars.model.response.PayerInfoResponse;
import gov.va.med.ars.service.IPayerInfoService;
import net.minidev.json.JSONObject;

@RestController
@RequestMapping("api/v1/populate")
public class PayerInfoController {
@Autowired
IPayerInfoService payerInfoService;

private static final Logger logger = LogManager.getLogger(PayerInfoController.class);

@GetMapping(value = "/payerInfo")
public ResponseEntity<?> getPayerInfo(
@RequestParam(value = "includeArchived", required = false) Boolean includeArchived) {
JSONObject response = null;
try {
List<PayerInfoResponse> payerInfoList = null;
if (includeArchived == null || !includeArchived) {
payerInfoList = payerInfoService.getActivePayerInfo();
} else {
payerInfoList = payerInfoService.getAllPayerInfo();
}

if (payerInfoList.size() > 0) {
return new ResponseEntity<>(payerInfoList, HttpStatus.OK);
} else {
response = new JSONObject();
response.put("errorCode", "Not found");
response.put("message", "No payer exists in the database.");
return new ResponseEntity<>(response, HttpStatus.NOT_FOUND);
}

} catch (Exception e) {
logger.error("PayerInfoController:getPayerInfo() exception occured: " + e.getMessage());
throw e;
}
}

@RequestMapping(value = { "/addPayerInfo" }, method = { RequestMethod.POST, RequestMethod.PUT })
public ResponseEntity<?> addOrModifyPayer(@Valid @RequestBody PayerInfoListRequest payerInfoRequest,
HttpServletRequest request) throws GenericException {
JSONObject jsonResponse = null;
GenericJsonResponse genericJsonResponse = null;
try {
if (payerInfoRequest != null) {

List<String> duplicateCheck = payerInfoService.checkSubmittedModificationsForDupes(payerInfoRequest);

if (!duplicateCheck.isEmpty()) {
logger.warn("Found Duplicates in Request");
JSONObject entity = new JSONObject();
entity.put("errorCode",
"Could not add the payer as the payer with same payer Id already exsists: Duplicates Found");
entity.put("message", duplicateCheck);
return new ResponseEntity<>(entity, HttpStatus.BAD_REQUEST);
}

payerInfoService.addOrModifyPayerInfo(payerInfoRequest);
genericJsonResponse = new GenericJsonResponse();
genericJsonResponse.setResult(true);

return new ResponseEntity<>(genericJsonResponse, HttpStatus.OK);
} else {
jsonResponse = new JSONObject();
jsonResponse.put("errorCode", "Un-Authorized");
jsonResponse.put("message", "The entered user has no access to add the payer information");
return new ResponseEntity<>(jsonResponse, HttpStatus.NOT_FOUND);
}

} catch (Exception e) {
logger.error("Adding Payer info: error occured : " + e.getMessage());
throw e;
}
}

@RequestMapping(value = { "/payerInfoarchive" }, method = { RequestMethod.POST, RequestMethod.PUT })
public ResponseEntity<?> archiveCodes(@Valid @RequestBody PayerInfoListRequest payerInfoRequest,
HttpServletRequest request) throws GenericException {
JSONObject jsonResponse = null;
try {
if (payerInfoRequest != null) {
List<String> duplicateCheck = payerInfoService.checkSubmittedModificationsForDupes(payerInfoRequest);
if (!duplicateCheck.isEmpty()) {
logger.warn("Found Duplicates in Request");
JSONObject entity = new JSONObject();
entity.put("errorCode", "Update Payer Info Not Complete: Duplicates Found");
entity.put("message", duplicateCheck);
return new ResponseEntity<>(entity, HttpStatus.BAD_REQUEST);
}
boolean response = payerInfoService.addOrModifyPayerInfo(payerInfoRequest);
JSONObject entity = new JSONObject();
entity.put("result", response);
return new ResponseEntity<>(entity, HttpStatus.OK);
} else {
jsonResponse = new JSONObject();
jsonResponse.put("errorCode", "Un-Authorized");
jsonResponse.put("message", "The entered user has no access to the archive the Payer Information");
return new ResponseEntity<>(jsonResponse, HttpStatus.NOT_FOUND);
}

} catch (Exception e) {
logger.error("PopulatePayerInfoController:archiveCodes() exception occured: " + e.getMessage());
throw e;
}
}
}