Summary Table
Categories |
Total Count |
PII |
0 |
URL |
0 |
DNS |
1 |
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.HashSet;
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.WebDataBinder;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.PostMapping;
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.RestController;
import gov.va.med.ars.exceptions.GenericException;
import gov.va.med.ars.model.request.GenericRequest;
import gov.va.med.ars.model.request.JsonArrayModel;
import gov.va.med.ars.model.response.GenericJsonResponse;
import gov.va.med.ars.service.ICodeAndModifierService;
import net.minidev.json.JSONObject;
/**
* @author
DNS
*
*/
@RestController
@RequestMapping("api/v1/populate")
public class CodeAndModifiersController {
private static final Logger logger = LogManager.getLogger(CodeAndModifiersController.class);
@Autowired
ICodeAndModifierService codeAndModiferService;
/**
*
*/
@PostMapping(value = { "/loinc", "/loincMod", "/hccs" })
public ResponseEntity<?> getCodes(@RequestBody JsonArrayModel acceptedValues, HttpServletRequest request)
throws GenericException {
JSONObject response = null;
String currentUrl = request.getRequestURI().toString();
try {
if (acceptedValues.getAcceptedValues().size() > 0) {
List<?> returnedResponse = codeAndModiferService.getCodeAndModifier(currentUrl,
acceptedValues.getAcceptedValues());
if (returnedResponse.size() > 0) {
return new ResponseEntity<>(returnedResponse, HttpStatus.OK);
} else {
response = new JSONObject();
logger.warn("getCodes : wrong input ");
response.put("errorCode", "Un-Authorized");
response.put("message", "The entered user has given wrong input to the application");
return new ResponseEntity<>(response, HttpStatus.NOT_FOUND);
}
} else {
response = new JSONObject();
logger.warn("getCodes : wrong input ");
response.put("errorCode", "Un-Authorized");
response.put("message", "The entered user has given wrong input to the application");
return new ResponseEntity<>(response, HttpStatus.NOT_FOUND);
}
} catch (Exception e) {
logger.error("PopulateCodeAndModifiersController:getCodes() exception occured for claim index : "
+ e.getMessage());
throw e;
}
}
@RequestMapping(value = { "/add" }, method = { RequestMethod.POST, RequestMethod.PUT })
public ResponseEntity<?> addOrModifyCodes(@Valid @RequestBody GenericRequest codeAndModifierRequest,
HttpServletRequest request) throws GenericException {
JSONObject jsonResponse = null;
GenericJsonResponse genericJsonResponse = null;
try {
if (codeAndModifierRequest != null) {
List<String> duplicateCheck = codeAndModiferService
.checkSubmittedModificationsForDupes(codeAndModifierRequest);
if (!duplicateCheck.isEmpty()) {
logger.warn("Found Duplicates in Request");
JSONObject entity = new JSONObject();
entity.put("errorCode", "Update Codes Not Complete: Duplicates Found");
entity.put("message", duplicateCheck);
return new ResponseEntity<>(entity, HttpStatus.BAD_REQUEST);
}
List<String> redundantCodes = codeAndModiferService.getArchivedCodes(codeAndModifierRequest);
HashSet<Object> seen = new HashSet<>();
if (redundantCodes.size() > 0) {
if (codeAndModifierRequest.getHccList() != null && !codeAndModifierRequest.getHccList().isEmpty()) {
codeAndModifierRequest.getHccList().removeIf(e -> !seen.add(redundantCodes));
}
if (codeAndModifierRequest.getLoincList() != null
&& !codeAndModifierRequest.getLoincList().isEmpty()) {
codeAndModifierRequest.getLoincList().removeIf(e -> !seen.add(redundantCodes));
}
if (codeAndModifierRequest.getLoincList() != null
&& !codeAndModifierRequest.getLoincModList().isEmpty()) {
codeAndModifierRequest.getLoincModList().removeIf(e -> !seen.add(redundantCodes));
}
}
boolean response = codeAndModiferService.addOrModifyCodeAndModifier(codeAndModifierRequest);
genericJsonResponse = new GenericJsonResponse();
genericJsonResponse.setResult(response);
genericJsonResponse.setAlreadyArchivedCodes(redundantCodes);
return new ResponseEntity<>(genericJsonResponse, HttpStatus.OK);
} else {
jsonResponse = new JSONObject();
logger.warn("getClaim : no information was passed");
jsonResponse.put("errorCode", "Un-Authorized");
jsonResponse.put("message", "The entered user has no access to the add the codes");
return new ResponseEntity<>(jsonResponse, HttpStatus.NOT_FOUND);
}
} catch (Exception e) {
logger.error("PopulateCodeAndModifiersController:getCodes() exception occured for claim index : "
+ e.getMessage());
throw e;
}
}
@RequestMapping(value = { "/archive" }, method = { RequestMethod.POST, RequestMethod.PUT })
public ResponseEntity<?> archiveCodes(@Valid @RequestBody GenericRequest codeAndModifierRequest,
HttpServletRequest request) throws GenericException {
JSONObject jsonResponse = null;
try {
if (codeAndModifierRequest != null) {
List<String> duplicateCheck = codeAndModiferService
.checkSubmittedModificationsForDupes(codeAndModifierRequest);
if (!duplicateCheck.isEmpty()) {
logger.warn("Found Duplicates in Request");
JSONObject entity = new JSONObject();
entity.put("errorCode", "Update Codes Not Complete: Duplicates Found");
entity.put("message", duplicateCheck);
return new ResponseEntity<>(entity, HttpStatus.BAD_REQUEST);
}
boolean response = codeAndModiferService.addOrModifyCodeAndModifier(codeAndModifierRequest);
JSONObject entity = new JSONObject();
entity.put("result", response);
return new ResponseEntity<>(entity, HttpStatus.OK);
} else {
jsonResponse = new JSONObject();
logger.warn("getClaim : no information was passed");
jsonResponse.put("errorCode", "Un-Authorized");
jsonResponse.put("message", "The entered user has no access to the add the codes");
return new ResponseEntity<>(jsonResponse, HttpStatus.NOT_FOUND);
}
} catch (Exception e) {
logger.error("PopulateCodeAndModifiersController:getCodes() exception occured for claim index : "
+ e.getMessage());
throw e;
}
}
@InitBinder()
public void customizeBinding (WebDataBinder binder) {
binder.setDisallowedFields(new String[]{});
}
}