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
/*
* SeocControllerIntTest.java
* Copyright (c) 2017 Veterans Affairs.
*/
package gov.va.oneconsult.seoc.api.controller;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import org.apache.log4j.Logger;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.embedded.LocalServerPort;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.web.client.TestRestTemplate;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.test.context.junit4.SpringRunner;
import gov.va.oneconsult.seoc.api.Application;
import gov.va.oneconsult.seoc.api.json.CheckNameRequest;
import gov.va.oneconsult.seoc.api.json.CreateBillingCodeRequest;
import gov.va.oneconsult.seoc.api.json.CreateServiceRequest;
import gov.va.oneconsult.seoc.api.json.SeocActivateRequest;
import gov.va.oneconsult.seoc.api.json.SeocCreateRequest;
import gov.va.oneconsult.seoc.api.json.SeocCreateResponse;
import gov.va.oneconsult.seoc.api.json.SeocGenericRequest;
import gov.va.oneconsult.seoc.api.json.SeocGenericResponse;
import gov.va.oneconsult.seoc.api.model.CategoryOfCare;
import gov.va.oneconsult.seoc.api.model.ChangeLog;
import gov.va.oneconsult.seoc.api.model.Qasp;
import gov.va.oneconsult.seoc.api.model.Seoc;
import gov.va.oneconsult.seoc.api.model.ServiceLine;
import gov.va.oneconsult.seoc.api.repository.CategoryOfCareRepository;
import gov.va.oneconsult.seoc.api.repository.ClinicalServiceRepository;
import gov.va.oneconsult.seoc.api.repository.QaspRepository;
import gov.va.oneconsult.seoc.api.repository.SeocRepository;
import gov.va.oneconsult.seoc.api.repository.ServiceLineRepository;
import gov.va.oneconsult.seoc.api.service.LogService;
import gov.va.oneconsult.seoc.api.service.SeocService;
import gov.va.oneconsult.seoc.api.service.impl.SeocServiceHelper;
import gov.va.oneconsult.seoc.api.util.Constants;
import gov.va.oneconsult.seoc.api.util.DeserializeTest;
import gov.va.oneconsult.seoc.api.util.EncodeLoggerFactory;
import gov.va.oneconsult.seoc.api.util.TestUtil;
/**
* Integration Test Cases
*
* @author AbleVets
*/
@RunWith(SpringRunner.class)
@SpringBootTest(classes = Application.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class SeocControllerIntTest {
@LocalServerPort
private int port;
private TestRestTemplate restTemplate = new TestRestTemplate();
private HttpHeaders headers = new HttpHeaders();
public static final Logger logger = EncodeLoggerFactory.getLogger(SeocControllerIntTest.class);
public static final DeserializeTest deserialize = new DeserializeTest();
@Autowired
public SeocRepository seocRepository;
@Autowired
public ServiceLineRepository serviceLineRepository;
@Autowired
public CategoryOfCareRepository categoryOfCareRepository;
@Autowired
public QaspRepository qaspRepository;
@Autowired
public ClinicalServiceRepository clinicalServiceRepository;
@Autowired
private LogService logService;
@Autowired
private SeocService seocService;
public static final String USER_ROOT = "/v1/user/";
public static final String ROOT = "/v1/seoc/";
public static final String ALL = "all/";
public static final String ACTIVE = "active/";
public static final String SEOC_KEY = "seocKey/";
public static final String CHECK_SEOC_NAME = "checkseocexists/";
public static final String ACTIVATE_SEOC = "activate/";
public static final String BILLINGCODES = "active/billingcodes";
public static final String VALID_ACTIVATE_SEOC = "validActivate/";
public static final String PENDING_REVISION = "createPendingRevision/";
public static final String VALID_PENDING_REVISION = "validPendingRevision/";
public static final String DELETE_SEOC = "delete/";
public static final String DISCONTINUE_SEOC = "discontinue/";
public static final String REVERSE_SEOC = "reverse/";
public static final String MAINTENANCE = "maint/";
public static final String RETRIEVE_SEOC_BC = "seocsByBillingCode/";
public static final String MANAGE_BC = "manageBillingCode/";
public static final String vaUserId = "System";
@Before
public void setup() {
setHeaders();
}
/**
* Description:Test read all seocs successful scenario
*/
@Test
public void readAllSeocs() {
HttpEntity<String> request = new HttpEntity<String>(null, headers);
ResponseEntity<String> response = restTemplate.exchange(createURLWithPort(ROOT + ALL), HttpMethod.GET, request,
String.class);
assertEquals(HttpStatus.OK, response.getStatusCode());
String responseJson = response.getBody();
assertTrue(responseJson.contains("id"));
assertTrue(responseJson.contains("seocId"));
assertTrue(responseJson.contains("seocKey"));
assertTrue(responseJson.contains("serviceLine"));
assertTrue(responseJson.contains("name"));
assertTrue(responseJson.contains("versionNumber"));
assertTrue(responseJson.contains("effectiveDate"));
assertTrue(responseJson.contains("endDate"));
assertThat(responseJson).doesNotContain("services");
assertThat(responseJson).doesNotContain("hptcs");
assertThat(responseJson).doesNotContain("billingCodes");
assertThat(responseJson).doesNotContain("serviceHptcs");
}
/**
* Description:Test read active seocs successful scenario
*/
@Test
public void readActiveSeocs() {
HttpEntity<String> request = new HttpEntity<String>(null, headers);
ResponseEntity<String> response = restTemplate.exchange(createURLWithPort(ROOT + ACTIVE), HttpMethod.GET,
request, String.class);
assertEquals(HttpStatus.OK, response.getStatusCode());
String responseJson = SeocObjectGenerator.asJsonString(response.getBody());
assertThat(responseJson).doesNotContain("services");
assertThat(responseJson).doesNotContain("hptcs");
// Should not have invalid characters
assertThat(responseJson).doesNotContain(Character.toString((char) 1));
assertThat(responseJson).doesNotContain(Character.toString((char) 2));
assertThat(responseJson).doesNotContain(Character.toString((char) 3));
assertThat(responseJson).doesNotContain(Character.toString((char) 4));
assertThat(responseJson).doesNotContain(Character.toString((char) 5));
assertThat(responseJson).doesNotContain(Character.toString((char) 6));
assertThat(responseJson).doesNotContain(Character.toString((char) 21));
assertThat(responseJson).doesNotContain(Character.toString((char) 23));
assertThat(responseJson).doesNotContain(Character.toString((char) 160));
assertThat(responseJson).doesNotContain("‘");
assertThat(responseJson).doesNotContain("’");
assertThat(responseJson).doesNotContain("“");
assertThat(responseJson).doesNotContain("”");
assertThat(responseJson).doesNotContain("–");
}
/**
* Description:Test read active seocs with associated billing codes
*/
@Test
public void readActiveSeocsWithBillingCodes() {
HttpEntity<String> request = new HttpEntity<String>(null, headers);
ResponseEntity<String> response = restTemplate.exchange(createURLWithPort(ROOT + BILLINGCODES), HttpMethod.GET,
request, String.class);
assertEquals(HttpStatus.OK, response.getStatusCode());
String responseJson = SeocObjectGenerator.asJsonString(response.getBody());
assertThat(responseJson).doesNotContain("seocId");
assertThat(responseJson).doesNotContain("seocKey");
assertThat(responseJson).doesNotContain("effectiveDate");
assertThat(responseJson).doesNotContain("endDate");
assertThat(responseJson).doesNotContain("disclaimer");
assertThat(responseJson).doesNotContain("duration");
assertThat(responseJson).doesNotContain("description");
assertThat(responseJson).doesNotContain("REV");
assertThat(responseJson).doesNotContain("PRCT");
assertThat(responseJson).doesNotContain("proceduralOverview");
assertThat(responseJson).doesNotContain("status");
assertThat(responseJson).doesNotContain("serviceLine");
assertThat(responseJson).doesNotContain("categoryOfCare");
assertThat(responseJson).doesNotContain("QASP");
assertThat(responseJson).doesNotContain("previewText");
assertThat(responseJson).doesNotContain("maxAllowableVisits");
assertThat(responseJson).doesNotContain("activatedTimestamp");
assertThat(responseJson).doesNotContain("activatedBy");
assertThat(responseJson).doesNotContain("discontinuedTimestamp");
assertThat(responseJson).doesNotContain("discontinuedBy");
assertThat(responseJson).doesNotContain("services");
assertThat(responseJson).doesNotContain("hptcs");
// Checking for data in JSON
assertTrue(responseJson.contains("precertRequired"));
assertTrue(responseJson.contains("billingCode"));
assertTrue(responseJson.contains("codeType"));
assertTrue(responseJson.contains("versionNumber"));
assertTrue(responseJson.contains("name"));
assertTrue(responseJson.contains("billingCodes"));
assertTrue(responseJson.contains("id"));
}
/**
* Description:Test read published seocs successful scenario
*/
@Test
public void readPublishedSeoc() {
Set<String> billingCodes = new HashSet<String>();
billingCodes.add("code101");
billingCodes.add("code102");
Set<String> clinicalServices = new HashSet<String>();
clinicalServices.add("12-Pulmonary");
CreateServiceRequest serviceRequest = CreateServiceRequest.Builder.create().withDescription("service1")
.withCodeRequired("YES").withVisits(5).withClinicalServices(clinicalServices)
.withBillingCodes(billingCodes).build();
List<CreateServiceRequest> serviceList = new ArrayList<CreateServiceRequest>();
serviceList.add(serviceRequest);
Set<String> hptcs = new HashSet<String>();
hptcs.add("hptc101");
String requestJson = SeocObjectGenerator.asJsonString(SeocCreateRequest.Builder.create("SeocTest1", "Radiology")
.withServiceList(serviceList).withDescription("Description").withDisclaimer("Disclaimer")
.withDuration(5).withMaxVisits(5).withRev(false).withProceduralOverview("Procedural Overview")
.withCategoryOfCare("Acupuncture12").withQasp("QASP1").withHptcs(hptcs).build());
HttpEntity<String> request = new HttpEntity<String>(requestJson, headers);
// Create SEOC
ResponseEntity<String> response = restTemplate.exchange(createURLWithPort(ROOT), HttpMethod.POST, request,
String.class);
assertThat(HttpStatus.CREATED).isEqualTo(response.getStatusCode());
int id = deserialize.createResponse(response.getBody()).getUniqueId();
String etagHash = response.getHeaders().getETag();
// Activate SEOC
headers.setIfMatch(etagHash);
requestJson = SeocObjectGenerator
.asJsonString(SeocActivateRequest.Builder.create(id, TestUtil.getEffectiveDateString()).build());
request = new HttpEntity<String>(requestJson, headers);
response = restTemplate.exchange(createURLWithPort(ROOT + ACTIVATE_SEOC), HttpMethod.POST, request,
String.class);
SeocGenericResponse seocGenericResponse = deserialize.genericResponse(response.getBody());
String actualStatus = seocGenericResponse.getStatus();
assertThat(actualStatus).isEqualTo(Constants.SUCCESS);
assertThat(HttpStatus.OK).isEqualTo(response.getStatusCode());
etagHash = response.getHeaders().getETag();
request = new HttpEntity<String>(null, headers);
response = restTemplate.exchange(createURLWithPort(ROOT), HttpMethod.GET, request, String.class);
assertEquals(HttpStatus.OK, response.getStatusCode());
String responseJson = response.getBody();
assertTrue(responseJson.contains("services"));
assertTrue(responseJson.contains("hptcs"));
assertThat(responseJson).contains("serviceHptcs");
assertThat(responseJson).doesNotContain("In-Progress");
assertThat(responseJson).contains("Date Hold");
assertThat(responseJson).contains("Active");
assertThat(responseJson).contains("Discontinued");
assertThat(responseJson).contains(
"\"services\":[{\"id\":5,\"description\":\"Service5\",\"frequency\":5,\"frequencytype\":\"days\",\"visits\":4,\"coderequired\":\"YES\",\"codedBy\":\"AV\",\"codedtimestamp\":\"01-17-2018\",\"clinicalService\":\"15-General Medicine\",\"billingCodes\":[{\"id\":5,\"description\":\"description5\",\"precertRequired\":true,\"billingCode\":\"code105\",\"codeType\":\"CPT\",\"deactivated\":false}],\"serviceHptcs\":[{\"HPTC\":\"hptc106\"},{\"HPTC\":\"hptc105\"},{\"HPTC\":\"hptc101\"}]}]");
// Reverse and Delete the Date Hold SEOC to clean up the data
headers.setIfMatch(etagHash);
request = new HttpEntity<>(headers);
response = restTemplate.exchange(createURLWithPort(ROOT + REVERSE_SEOC + id), HttpMethod.GET, request,
String.class);
assertThat(HttpStatus.OK).isEqualTo(response.getStatusCode());
etagHash = response.getHeaders().getETag();
headers.setIfMatch(etagHash);
request = new HttpEntity<>(headers);
response = restTemplate.exchange(createURLWithPort(ROOT + DELETE_SEOC + id), HttpMethod.GET, request,
String.class);
assertThat(HttpStatus.OK).isEqualTo(response.getStatusCode());
}
/**
* Description:Test read seocs by key successful scenario
*/
@Test
public void readSeocsByKey() {
HttpEntity<String> request = new HttpEntity<String>(null, headers);
ResponseEntity<String> response = restTemplate.exchange(createURLWithPort(ROOT + SEOC_KEY + "1"),
HttpMethod.GET, request, String.class);
assertEquals(HttpStatus.OK, response.getStatusCode());
String responseJson = response.getBody();
assertTrue(responseJson.contains("services"));
assertTrue(responseJson.contains("hptcs"));
assertThat(responseJson)
.contains("\"clinicalServices\":[{\"discontinued\":null,\"description\":\"14-Acupuncture\"}]");
}
/**
* Description:Test read seoc by id successful scenario
*/
@Test
public void readSeocsById() {
HttpEntity<String> request = new HttpEntity<String>(null, headers);
ResponseEntity<String> response = restTemplate.exchange(createURLWithPort(ROOT + "3"), HttpMethod.GET, request,
String.class);
assertEquals(HttpStatus.OK, response.getStatusCode());
String responseJson = response.getBody();
assertTrue(responseJson.contains("services"));
assertTrue(responseJson.contains("hptcs"));
assertThat(responseJson).contains(
"\"clinicalServices\":[{\"discontinued\":null,\"description\":\"15-General Medicine\"},{\"discontinued\":null,\"description\":\"14-Acupuncture\"}]");
}
/**
* Description:Test creation of Seoc successful scenario
*/
@Test
public void createSeoc_successHtmlEncoding() {
Set<String> billingCodes = new HashSet<String>();
billingCodes.add("code101");
billingCodes.add("code102");
CreateServiceRequest serviceRequest = CreateServiceRequest.Builder.create().withDescription("service1")
.withCodeRequired("YES").withBillingCodes(billingCodes).build();
List<CreateServiceRequest> serviceList = new ArrayList<CreateServiceRequest>();
serviceList.add(serviceRequest);
String requestJson = SeocObjectGenerator.asJsonString(SeocCreateRequest.Builder
.create("SeocTest#123", "Medical Specialty Care").withServiceList(serviceList).build());
HttpEntity<String> request = new HttpEntity<String>(requestJson, headers);
ResponseEntity<String> response = restTemplate.exchange(createURLWithPort(ROOT), HttpMethod.POST, request,
String.class);
String responseJson = SeocObjectGenerator.asJsonString(response.getBody());
assertTrue(responseJson.contains("SeocTest#123"));
assertTrue(responseJson.contains("Created"));
assertEquals(HttpStatus.CREATED, response.getStatusCode());
}
/**
* Description:Test creation of Seoc successful scenario
*/
@Test
public void createSeoc_success() {
Set<String> billingCodes = new HashSet<String>();
billingCodes.add("code101");
billingCodes.add("code102");
CreateServiceRequest serviceRequest = CreateServiceRequest.Builder.create().withDescription("service1")
.withCodeRequired("YES").withBillingCodes(billingCodes).build();
List<CreateServiceRequest> serviceList = new ArrayList<CreateServiceRequest>();
serviceList.add(serviceRequest);
Set<String> hptcs = new HashSet<String>();
hptcs.add("hptc101");
String expectedName = "SeocTest1";
int expectedMaxVisits = 5;
int expectedDuration = 0;
String requestJson = SeocObjectGenerator.asJsonString(SeocCreateRequest.Builder
.create(expectedName, "Medical Specialty Care").withMaxVisits(expectedMaxVisits)
.withDuration(expectedDuration).withServiceList(serviceList).withHptcs(hptcs).build());
HttpEntity<String> request = new HttpEntity<String>(requestJson, headers);
ResponseEntity<String> response = restTemplate.exchange(createURLWithPort(ROOT), HttpMethod.POST, request,
String.class);
int id = deserialize.createResponse(response.getBody()).getUniqueId();
List<ChangeLog> logs = logService.getChangeLogBySeocId(id, Constants.EVENT_ACTION_SAVE);
// Assert that save is recorded in the log
assertThat(logs).isNotEmpty();
assertThat(logs.size()).isEqualTo(1);
assertThat(logs.get(0).getUser().getVaUserId()).contains(vaUserId);
String responseJson = SeocObjectGenerator.asJsonString(response.getBody());
assertTrue(responseJson.contains(expectedName));
assertTrue(responseJson.contains("Created"));
assertEquals(HttpStatus.CREATED, response.getStatusCode());
request = new HttpEntity<>(headers);
response = restTemplate.exchange(createURLWithPort(ROOT + id), HttpMethod.GET, request, String.class);
String actualMaxVisits = deserialize.seocResponse(response.getBody(), "maxAllowableVisits");
String actualDuration = deserialize.seocResponse(response.getBody(), "duration");
String actualName = deserialize.seocResponse(response.getBody(), "name");
String actualHptcs = deserialize.seocResponse(response.getBody(), "hptcs");
assertThat(actualName).isEqualTo(expectedName);
assertThat(actualMaxVisits).isEqualTo(String.valueOf(expectedMaxVisits));
assertThat(actualDuration).isEqualTo(String.valueOf(expectedDuration));
assertThat(actualHptcs).isEqualTo(
"[{\"hptc\":\"hptc101\",\"specialization\":\"\",\"classification\":\"TYPE1\",\"grouping\":\"GROUP1\"}]");
}
/**
* Description:Test creation of Seoc successful scenario
*/
@Test
public void updateSeoc_success() {
Set<String> billingCodes = new HashSet<String>();
billingCodes.add("code101");
billingCodes.add("code102");
CreateServiceRequest serviceRequest = CreateServiceRequest.Builder.create().withDescription("service1")
.withCodeRequired("YES").withBillingCodes(billingCodes).build();
List<CreateServiceRequest> serviceList = new ArrayList<CreateServiceRequest>();
serviceList.add(serviceRequest);
Set<String> hptcs = new HashSet<String>();
hptcs.add("hptc101");
String expectedName = "SeocTest1";
int expectedMaxVisits = 5;
int expectedDuration = 0;
String requestJson = SeocObjectGenerator.asJsonString(SeocCreateRequest.Builder
.create(expectedName, "Medical Specialty Care").withMaxVisits(expectedMaxVisits)
.withDuration(expectedDuration).withServiceList(serviceList).withHptcs(hptcs).build());
HttpEntity<String> request = new HttpEntity<String>(requestJson, headers);
// Create Seoc
ResponseEntity<String> response = restTemplate.exchange(createURLWithPort(ROOT), HttpMethod.POST, request,
String.class);
int id = deserialize.createResponse(response.getBody()).getUniqueId();
String responseJson = SeocObjectGenerator.asJsonString(response.getBody());
assertTrue(responseJson.contains(expectedName));
assertTrue(responseJson.contains("Created"));
assertEquals(HttpStatus.CREATED, response.getStatusCode());
// Get after create Seoc
request = new HttpEntity<>(headers);
response = restTemplate.exchange(createURLWithPort(ROOT + id), HttpMethod.GET, request, String.class);
String actualMaxVisits = deserialize.seocResponse(response.getBody(), "maxAllowableVisits");
String actualDuration = deserialize.seocResponse(response.getBody(), "duration");
String actualName = deserialize.seocResponse(response.getBody(), "name");
String actualHptcs = deserialize.seocResponse(response.getBody(), "hptcs");
String seocKey = deserialize.seocResponse(response.getBody(), "seocKey");
assertThat(actualName).isEqualTo(expectedName);
assertThat(actualMaxVisits).isEqualTo(String.valueOf(expectedMaxVisits));
assertThat(actualDuration).isEqualTo(String.valueOf(expectedDuration));
assertThat(actualHptcs).isEqualTo(
"[{\"hptc\":\"hptc101\",\"specialization\":\"\",\"classification\":\"TYPE1\",\"grouping\":\"GROUP1\"}]");
String eTagAfterCreate = response.getHeaders().getETag();
// Update Seoc - remove services, update hptc
headers = new HttpHeaders();
headers.setIfMatch(eTagAfterCreate);
setHeaders();
// Remove earlier hptc "hptc1" and add new hptc "hptc2"
hptcs = new HashSet<String>();
hptcs.add("hptc102");
requestJson = SeocObjectGenerator
.asJsonString(SeocCreateRequest.Builder.create(expectedName, "Medical Specialty Care").withSeocId(id)
.withSeocKey(Integer.parseInt(seocKey)).withMaxVisits(expectedMaxVisits)
.withDuration(expectedDuration).withServiceList(serviceList).withHptcs(hptcs).build());
request = new HttpEntity<String>(requestJson, headers);
// Update
restTemplate.exchange(createURLWithPort(ROOT), HttpMethod.POST, request, String.class);
List<ChangeLog> logs = logService.getChangeLogBySeocId(id, Constants.EVENT_ACTION_SAVE);
assertThat(logs).isNotEmpty();
assertThat(logs.size()).isEqualTo(2);
// Get after Seoc Update
response = restTemplate.exchange(createURLWithPort(ROOT + id), HttpMethod.GET, request, String.class);
actualName = deserialize.seocResponse(response.getBody(), "name");
actualHptcs = deserialize.seocResponse(response.getBody(), "hptcs");
assertThat(actualName).isEqualTo(expectedName);
// assert hptc2 is available
assertThat(actualHptcs).isEqualTo(
"[{\"hptc\":\"hptc102\",\"specialization\":\"SPEC1\",\"classification\":\"TYPE1\",\"grouping\":\"GROUP1\"}]");
}
/**
* Description:Test creation of Seoc successful scenario
*/
@Test
public void createSeoc_withEmptyMaxVisitsAndDuration() {
Set<String> billingCodes = new HashSet<String>();
billingCodes.add("code101");
billingCodes.add("code102");
CreateServiceRequest serviceRequest = CreateServiceRequest.Builder.create().withDescription("service1")
.withCodeRequired("YES").withBillingCodes(billingCodes).build();
List<CreateServiceRequest> serviceList = new ArrayList<CreateServiceRequest>();
serviceList.add(serviceRequest);
String expectedName = "SeocTest1";
String expectedCoc = "Medical Specialty Care";
String requestJson = SeocObjectGenerator
.asJsonString(SeocCreateRequest.Builder.create(expectedName, expectedCoc).withMaxVisits(null)
.withDuration(null).withServiceList(serviceList).build());
HttpEntity<String> request = new HttpEntity<String>(requestJson, headers);
ResponseEntity<String> response = restTemplate.exchange(createURLWithPort(ROOT), HttpMethod.POST, request,
String.class);
String responseJson = SeocObjectGenerator.asJsonString(response.getBody());
assertTrue(responseJson.contains(expectedName));
assertTrue(responseJson.contains("Created"));
assertEquals(HttpStatus.CREATED, response.getStatusCode());
int id = deserialize.createResponse(response.getBody()).getUniqueId();
request = new HttpEntity<>(headers);
response = restTemplate.exchange(createURLWithPort(ROOT + id), HttpMethod.GET, request, String.class);
String actualMaxVisits = deserialize.seocResponse(response.getBody(), "maxAllowableVisits");
String actualDuration = deserialize.seocResponse(response.getBody(), "duration");
String actualName = deserialize.seocResponse(response.getBody(), "name");
assertThat(actualName).isEqualTo(expectedName);
assertThat(actualMaxVisits).isNull();
assertThat(actualDuration).isNull();
}
/**
* Description: Test creation of new Seoc success scenario
*/
@Test
public void createSeoc_seocExists() {
String requestJson = SeocObjectGenerator.asJsonString(
new CheckNameRequest.Builder("Acupuncture Initial SEOC 1.0.1").withSeocKey(1).withSeocId(1).build());
HttpEntity<String> request = new HttpEntity<String>(requestJson, headers);
ResponseEntity<String> response = restTemplate.exchange(createURLWithPort(ROOT + CHECK_SEOC_NAME),
HttpMethod.POST, request, String.class);
SeocGenericResponse seocGenericResponse = deserialize.genericResponse(response.getBody());
String actualStatus = seocGenericResponse.getStatus();
assertThat(actualStatus).isEqualTo(Constants.SUCCESS);
assertEquals(HttpStatus.OK, response.getStatusCode());
}
/**
* Description: Test update Seoc with discontinued Service Line
*/
@Test
public void updateSeoc_discontinuedServiceLine() {
Set<String> billingCodes = new HashSet<String>();
billingCodes.add("code101");
billingCodes.add("code102");
Set<String> clinicalServices = new HashSet<String>();
clinicalServices.add("12-Pulmonary");
CreateServiceRequest serviceRequest = CreateServiceRequest.Builder.create().withDescription("service1")
.withCodeRequired("YES").withVisits(5).withClinicalServices(clinicalServices)
.withBillingCodes(billingCodes).build();
List<CreateServiceRequest> serviceList = new ArrayList<CreateServiceRequest>();
serviceList.add(serviceRequest);
Set<String> hptcs = new HashSet<String>();
hptcs.add("hptc101");
String requestJson = SeocObjectGenerator.asJsonString(SeocCreateRequest.Builder.create("SeocTest1", "Radiology")
.withServiceList(serviceList).withDescription("Description").withDisclaimer("Disclaimer")
.withDuration(5).withMaxVisits(5).withRev(false).withProceduralOverview("Procedural Overview")
.withCategoryOfCare("Acupuncture12").withQasp("QASP1").withHptcs(hptcs).build());
// Create SEOC
HttpEntity<String> request = new HttpEntity<String>(requestJson, headers);
ResponseEntity<String> response = restTemplate.exchange(createURLWithPort(ROOT), HttpMethod.POST, request,
String.class);
assertThat(HttpStatus.CREATED).isEqualTo(response.getStatusCode());
int id = deserialize.createResponse(response.getBody()).getUniqueId();
request = new HttpEntity<>(headers);
response = restTemplate.exchange(createURLWithPort(ROOT + id), HttpMethod.GET, request, String.class);
String etagHash = response.getHeaders().getETag();
String seocKey = deserialize.seocResponse(response.getBody(), "seocKey");
headers.setIfMatch(etagHash);
requestJson = SeocObjectGenerator.asJsonString(SeocCreateRequest.Builder.create("SeocTest1", "Psychology")
.withSeocId(id).withSeocKey(Integer.parseInt(seocKey)).withServiceList(serviceList)
.withDescription("Description").withDisclaimer("Disclaimer").withDuration(5).withMaxVisits(5)
.withRev(false).withProceduralOverview("Procedural Overview").withCategoryOfCare("Psychology")
.withQasp("QASP1").withHptcs(hptcs).build());
// Update with discontinued Service Line
request = new HttpEntity<String>(requestJson, headers);
response = restTemplate.exchange(createURLWithPort(ROOT), HttpMethod.POST, request, String.class);
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.BAD_REQUEST);
SeocCreateResponse seocResponse = deserialize.createResponse(response.getBody());
assertThat(seocResponse.getStatus()).isEqualTo(Constants.FAILURE);
assertThat(seocResponse.getComments()).isEqualTo(
"The Service Line value Psychology has been discontinued. A valid Service Line must be selected.");
}
/**
* Description: Test update Seoc with discontinued Category of Care
*/
@Test
public void updateSeoc_discontinuedCategoryOfCare() {
Set<String> billingCodes = new HashSet<String>();
billingCodes.add("code101");
billingCodes.add("code102");
Set<String> clinicalServices = new HashSet<String>();
clinicalServices.add("12-Pulmonary");
CreateServiceRequest serviceRequest = CreateServiceRequest.Builder.create().withDescription("service1")
.withCodeRequired("YES").withVisits(5).withClinicalServices(clinicalServices)
.withBillingCodes(billingCodes).build();
List<CreateServiceRequest> serviceList = new ArrayList<CreateServiceRequest>();
serviceList.add(serviceRequest);
Set<String> hptcs = new HashSet<String>();
hptcs.add("hptc101");
String requestJson = SeocObjectGenerator.asJsonString(SeocCreateRequest.Builder.create("SeocTest1", "Radiology")
.withServiceList(serviceList).withDescription("Description").withDisclaimer("Disclaimer")
.withDuration(5).withMaxVisits(5).withRev(false).withProceduralOverview("Procedural Overview")
.withCategoryOfCare("Acupuncture12").withQasp("QASP1").withHptcs(hptcs).build());
// Create SEOC
HttpEntity<String> request = new HttpEntity<String>(requestJson, headers);
ResponseEntity<String> response = restTemplate.exchange(createURLWithPort(ROOT), HttpMethod.POST, request,
String.class);
assertThat(HttpStatus.CREATED).isEqualTo(response.getStatusCode());
int id = deserialize.createResponse(response.getBody()).getUniqueId();
request = new HttpEntity<>(headers);
response = restTemplate.exchange(createURLWithPort(ROOT + id), HttpMethod.GET, request, String.class);
String etagHash = response.getHeaders().getETag();
String seocKey = deserialize.seocResponse(response.getBody(), "seocKey");
headers.setIfMatch(etagHash);
requestJson = SeocObjectGenerator.asJsonString(SeocCreateRequest.Builder.create("SeocTest1", "Dental")
.withSeocId(id).withSeocKey(Integer.parseInt(seocKey)).withServiceList(serviceList)
.withDescription("Description").withDisclaimer("Disclaimer").withDuration(5).withMaxVisits(5)
.withRev(false).withProceduralOverview("Procedural Overview").withCategoryOfCare("Dental Care")
.withQasp("QASP1").withHptcs(hptcs).build());
// Update with discontinued Category of Care
request = new HttpEntity<String>(requestJson, headers);
response = restTemplate.exchange(createURLWithPort(ROOT), HttpMethod.POST, request, String.class);
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.CREATED);
etagHash = response.getHeaders().getETag();
headers.setIfMatch(etagHash);
request = new HttpEntity<>(headers);
response = restTemplate.exchange(createURLWithPort(ROOT + id), HttpMethod.GET, request, String.class);
String actualCategoryOfCare = deserialize.seocResponse(response.getBody(), "categoryOfCare");
assertThat(actualCategoryOfCare).isEqualTo(null);
}
/**
* Description: Test update Seoc with discontinued QASP
*/
@Test
public void updateSeoc_discontinuedQASP() {
Set<String> billingCodes = new HashSet<String>();
billingCodes.add("code101");
billingCodes.add("code102");
Set<String> clinicalServices = new HashSet<String>();
clinicalServices.add("12-Pulmonary");
CreateServiceRequest serviceRequest = CreateServiceRequest.Builder.create().withDescription("service1")
.withCodeRequired("YES").withVisits(5).withClinicalServices(clinicalServices)
.withBillingCodes(billingCodes).build();
List<CreateServiceRequest> serviceList = new ArrayList<CreateServiceRequest>();
serviceList.add(serviceRequest);
Set<String> hptcs = new HashSet<String>();
hptcs.add("hptc101");
String requestJson = SeocObjectGenerator.asJsonString(SeocCreateRequest.Builder.create("SeocTest1", "Radiology")
.withServiceList(serviceList).withDescription("Description").withDisclaimer("Disclaimer")
.withDuration(5).withMaxVisits(5).withRev(false).withProceduralOverview("Procedural Overview")
.withCategoryOfCare("Acupuncture12").withQasp("QASP1").withHptcs(hptcs).build());
// Create SEOC
HttpEntity<String> request = new HttpEntity<String>(requestJson, headers);
ResponseEntity<String> response = restTemplate.exchange(createURLWithPort(ROOT), HttpMethod.POST, request,
String.class);
assertThat(HttpStatus.CREATED).isEqualTo(response.getStatusCode());
int id = deserialize.createResponse(response.getBody()).getUniqueId();
request = new HttpEntity<>(headers);
response = restTemplate.exchange(createURLWithPort(ROOT + id), HttpMethod.GET, request, String.class);
String etagHash = response.getHeaders().getETag();
String seocKey = deserialize.seocResponse(response.getBody(), "seocKey");
headers.setIfMatch(etagHash);
requestJson = SeocObjectGenerator.asJsonString(SeocCreateRequest.Builder.create("SeocTest1", "Radiology")
.withSeocId(id).withSeocKey(Integer.parseInt(seocKey)).withServiceList(serviceList)
.withDescription("Description").withDisclaimer("Disclaimer").withDuration(5).withMaxVisits(5)
.withRev(false).withProceduralOverview("Procedural Overview").withCategoryOfCare("Acupuncture12")
.withQasp("QASP4").withHptcs(hptcs).build());
// Update with discontinued QASP
request = new HttpEntity<String>(requestJson, headers);
response = restTemplate.exchange(createURLWithPort(ROOT), HttpMethod.POST, request, String.class);
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.CREATED);
etagHash = response.getHeaders().getETag();
headers.setIfMatch(etagHash);
request = new HttpEntity<>(headers);
response = restTemplate.exchange(createURLWithPort(ROOT + id), HttpMethod.GET, request, String.class);
String actualQasp = deserialize.seocResponse(response.getBody(), "qasp");
assertThat(actualQasp).isEqualTo(null);
}
/**
* Description: Test update Seoc with discontinued Clinical Service
*/
@Test
public void updateSeoc_discontinuedClinicalService() throws JSONException {
Set<String> billingCodes = new HashSet<String>();
billingCodes.add("code101");
billingCodes.add("code102");
Set<String> clinicalServices = new HashSet<String>();
clinicalServices.add("12-Pulmonary");
CreateServiceRequest serviceRequest = CreateServiceRequest.Builder.create().withDescription("service1")
.withCodeRequired("YES").withVisits(5).withClinicalServices(clinicalServices)
.withBillingCodes(billingCodes).build();
List<CreateServiceRequest> serviceList = new ArrayList<CreateServiceRequest>();
serviceList.add(serviceRequest);
Set<String> hptcs = new HashSet<String>();
hptcs.add("hptc101");
String requestJson = SeocObjectGenerator.asJsonString(SeocCreateRequest.Builder.create("SeocTest1", "Radiology")
.withServiceList(serviceList).withDescription("Description").withDisclaimer("Disclaimer")
.withDuration(5).withMaxVisits(5).withRev(false).withProceduralOverview("Procedural Overview")
.withCategoryOfCare("Acupuncture12").withQasp("QASP1").withHptcs(hptcs).build());
// Create SEOC
HttpEntity<String> request = new HttpEntity<String>(requestJson, headers);
ResponseEntity<String> response = restTemplate.exchange(createURLWithPort(ROOT), HttpMethod.POST, request,
String.class);
assertThat(HttpStatus.CREATED).isEqualTo(response.getStatusCode());
int id = deserialize.createResponse(response.getBody()).getUniqueId();
request = new HttpEntity<>(headers);
response = restTemplate.exchange(createURLWithPort(ROOT + id), HttpMethod.GET, request, String.class);
String etagHash = response.getHeaders().getETag();
String seocKey = deserialize.seocResponse(response.getBody(), "seocKey");
headers.setIfMatch(etagHash);
clinicalServices.add("16-Psychiatry");
serviceRequest = CreateServiceRequest.Builder.create().withDescription("service1").withCodeRequired("YES")
.withVisits(5).withClinicalServices(clinicalServices).withBillingCodes(billingCodes).build();
serviceList = new ArrayList<CreateServiceRequest>();
serviceList.add(serviceRequest);
requestJson = SeocObjectGenerator.asJsonString(SeocCreateRequest.Builder.create("SeocTest1", "Radiology")
.withSeocId(id).withSeocKey(Integer.parseInt(seocKey)).withServiceList(serviceList)
.withDescription("Description").withDisclaimer("Disclaimer").withDuration(5).withMaxVisits(5)
.withRev(false).withProceduralOverview("Procedural Overview").withCategoryOfCare("Acupuncture12")
.withQasp("QASP1").withHptcs(hptcs).build());
// Update with discontinued Clinical Service
request = new HttpEntity<String>(requestJson, headers);
response = restTemplate.exchange(createURLWithPort(ROOT), HttpMethod.POST, request, String.class);
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.CREATED);
etagHash = response.getHeaders().getETag();
headers.setIfMatch(etagHash);
request = new HttpEntity<>(headers);
response = restTemplate.exchange(createURLWithPort(ROOT + id), HttpMethod.GET, request, String.class);
JSONObject actualService = new JSONArray(deserialize.seocResponse(response.getBody(), "services"))
.getJSONObject(0);
String actualClinicalServices = actualService.getString("clinicalServices");
assertThat(actualClinicalServices).isEqualTo("[{\"description\":\"12-Pulmonary\",\"discontinued\":null}]");
}
/**
* Description: Test update Seoc with deactivated Billing Code
*/
@Test
public void updateSeoc_deactivatedBillingCode() throws JSONException {
Set<String> billingCodes = new HashSet<String>();
billingCodes.add("code101");
billingCodes.add("code102");
Set<String> clinicalServices = new HashSet<String>();
clinicalServices.add("12-Pulmonary");
CreateServiceRequest serviceRequest = CreateServiceRequest.Builder.create().withDescription("service1")
.withCodeRequired("YES").withVisits(5).withClinicalServices(clinicalServices)
.withBillingCodes(billingCodes).build();
List<CreateServiceRequest> serviceList = new ArrayList<CreateServiceRequest>();
serviceList.add(serviceRequest);
Set<String> hptcs = new HashSet<String>();
hptcs.add("hptc101");
String requestJson = SeocObjectGenerator.asJsonString(SeocCreateRequest.Builder.create("SeocTest1", "Radiology")
.withServiceList(serviceList).withDescription("Description").withDisclaimer("Disclaimer")
.withDuration(5).withMaxVisits(5).withRev(false).withProceduralOverview("Procedural Overview")
.withCategoryOfCare("Acupuncture12").withQasp("QASP1").withHptcs(hptcs).build());
// Create SEOC
HttpEntity<String> request = new HttpEntity<String>(requestJson, headers);
ResponseEntity<String> response = restTemplate.exchange(createURLWithPort(ROOT), HttpMethod.POST, request,
String.class);
assertThat(HttpStatus.CREATED).isEqualTo(response.getStatusCode());
int id = deserialize.createResponse(response.getBody()).getUniqueId();
request = new HttpEntity<>(headers);
response = restTemplate.exchange(createURLWithPort(ROOT + id), HttpMethod.GET, request, String.class);
String etagHash = response.getHeaders().getETag();
String seocKey = deserialize.seocResponse(response.getBody(), "seocKey");
headers.setIfMatch(etagHash);
billingCodes.add("code109");
serviceRequest = CreateServiceRequest.Builder.create().withDescription("service1").withCodeRequired("YES")
.withVisits(5).withClinicalServices(clinicalServices).withBillingCodes(billingCodes).build();
serviceList = new ArrayList<CreateServiceRequest>();
serviceList.add(serviceRequest);
requestJson = SeocObjectGenerator.asJsonString(SeocCreateRequest.Builder.create("SeocTest1", "Radiology")
.withSeocId(id).withSeocKey(Integer.parseInt(seocKey)).withServiceList(serviceList)
.withDescription("Description").withDisclaimer("Disclaimer").withDuration(5).withMaxVisits(5)
.withRev(false).withProceduralOverview("Procedural Overview").withCategoryOfCare("Acupuncture12")
.withQasp("QASP1").withHptcs(hptcs).build());
// Update with discontinued Clinical Service
request = new HttpEntity<String>(requestJson, headers);
response = restTemplate.exchange(createURLWithPort(ROOT), HttpMethod.POST, request, String.class);
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.CREATED);
etagHash = response.getHeaders().getETag();
headers.setIfMatch(etagHash);
request = new HttpEntity<>(headers);
response = restTemplate.exchange(createURLWithPort(ROOT + id), HttpMethod.GET, request, String.class);
JSONObject actualService = new JSONArray(deserialize.seocResponse(response.getBody(), "services"))
.getJSONObject(0);
String actualBillingCodes = actualService.getString("billingCodes");
assertThat(actualBillingCodes).isEqualTo(
"[{\"billingCode\":\"code101\",\"codeType\":\"CPT\",\"precertRequired\":false,\"description\":\"description1\",\"id\":1,\"deactivated\":false},{\"billingCode\":\"code102\",\"codeType\":\"CPT\",\"precertRequired\":false,\"description\":\"description2\",\"id\":2,\"deactivated\":false}]");
}
/**
* Description: Test validation of seoc actvation
*/
@Test
public void validSeocActivate_success() {
Set<String> billingCodes = new HashSet<String>();
billingCodes.add("code101");
billingCodes.add("code102");
Set<String> clinicalServices = new HashSet<String>();
clinicalServices.add("12-Pulmonary");
CreateServiceRequest serviceRequest = CreateServiceRequest.Builder.create().withDescription("service1")
.withCodeRequired("YES").withVisits(5).withClinicalServices(clinicalServices)
.withBillingCodes(billingCodes).build();
List<CreateServiceRequest> serviceList = new ArrayList<CreateServiceRequest>();
serviceList.add(serviceRequest);
Set<String> hptcs = new HashSet<String>();
hptcs.add("hptc101");
String requestJson = SeocObjectGenerator
.asJsonString(SeocCreateRequest.Builder.create("SeocTest1", "Medical Specialty Care")
.withServiceList(serviceList).withDescription("Description").withDisclaimer("Disclaimer")
.withDuration(5).withMaxVisits(5).withRev(false).withProceduralOverview("Procedural Overview")
.withCategoryOfCare("Pulmonary").withQasp("QASP1").withHptcs(hptcs).build());
HttpEntity<String> request = new HttpEntity<String>(requestJson, headers);
ResponseEntity<String> response = restTemplate.exchange(createURLWithPort(ROOT), HttpMethod.POST, request,
String.class);
int id = deserialize.createResponse(response.getBody()).getUniqueId();
request = new HttpEntity<>(headers);
response = restTemplate.exchange(createURLWithPort(ROOT + VALID_ACTIVATE_SEOC + id), HttpMethod.GET, request,
String.class);
String actualStatus = deserialize.genericResponse(response.getBody()).getStatus();
assertThat(actualStatus).isEqualTo(Constants.SUCCESS);
assertThat(HttpStatus.OK).isEqualTo(response.getStatusCode());
}
/**
* Description: Validate SEOC Activation succeeds - REV is true PRCT is true
*/
@Test
public void validSeocActivateSuccessREVTruePRCTTrue() {
Set<String> billingCodes = new HashSet<String>();
billingCodes.add("code101");
billingCodes.add("code102");
billingCodes.add("code103");
Set<String> clinicalServices = new HashSet<String>();
clinicalServices.add("12-Pulmonary");
CreateServiceRequest serviceRequest = CreateServiceRequest.Builder.create().withDescription("service1")
.withCodeRequired("YES").withVisits(5).withClinicalServices(clinicalServices)
.withBillingCodes(billingCodes).build();
List<CreateServiceRequest> serviceList = new ArrayList<CreateServiceRequest>();
serviceList.add(serviceRequest);
Set<String> hptcs = new HashSet<String>();
hptcs.add("hptc101");
String requestJson = SeocObjectGenerator
.asJsonString(SeocCreateRequest.Builder.create("SeocTest1", "Medical Specialty Care")
.withServiceList(serviceList).withDescription("Description").withDisclaimer("Disclaimer")
.withDuration(5).withMaxVisits(5).withRev(true).withProceduralOverview("Procedural Overview")
.withCategoryOfCare("Pulmonary").withQasp("QASP1").withHptcs(hptcs).build());
HttpEntity<String> request = new HttpEntity<String>(requestJson, headers);
ResponseEntity<String> response = restTemplate.exchange(createURLWithPort(ROOT), HttpMethod.POST, request,
String.class);
int id = deserialize.createResponse(response.getBody()).getUniqueId();
request = new HttpEntity<>(headers);
response = restTemplate.exchange(createURLWithPort(ROOT + VALID_ACTIVATE_SEOC + id), HttpMethod.GET, request,
String.class);
String actualStatus = deserialize.genericResponse(response.getBody()).getStatus();
assertThat(actualStatus).isEqualTo(Constants.SUCCESS);
assertThat(HttpStatus.OK).isEqualTo(response.getStatusCode());
}
/**
* Description: Validate SEOC Activation succeeds - REV is true PRCT is true, No
* Code Required
*/
@Test
public void validSeocActivateSuccessREVTruePRCTTrueNoCodeRequired() {
Set<String> billingCodes = new HashSet<String>();
billingCodes.add("code101");
billingCodes.add("code102");
Set<String> clinicalServices = new HashSet<String>();
clinicalServices.add("12-Pulmonary");
CreateServiceRequest serviceRequest = CreateServiceRequest.Builder.create().withDescription("service1")
.withCodeRequired("YES").withVisits(5).withClinicalServices(clinicalServices)
.withBillingCodes(billingCodes).build();
CreateServiceRequest serviceRequest2 = CreateServiceRequest.Builder.create().withDescription("service2")
.withCodeRequired("NO").withVisits(5).withClinicalServices(clinicalServices).build();
List<CreateServiceRequest> serviceList = new ArrayList<CreateServiceRequest>();
serviceList.add(serviceRequest);
serviceList.add(serviceRequest2);
Set<String> hptcs = new HashSet<String>();
hptcs.add("hptc101");
String requestJson = SeocObjectGenerator
.asJsonString(SeocCreateRequest.Builder.create("SeocTest1", "Medical Specialty Care")
.withServiceList(serviceList).withDescription("Description").withDisclaimer("Disclaimer")
.withDuration(5).withMaxVisits(5).withRev(true).withProceduralOverview("Procedural Overview")
.withCategoryOfCare("Pulmonary").withQasp("QASP1").withHptcs(hptcs).build());
HttpEntity<String> request = new HttpEntity<String>(requestJson, headers);
ResponseEntity<String> response = restTemplate.exchange(createURLWithPort(ROOT), HttpMethod.POST, request,
String.class);
int id = deserialize.createResponse(response.getBody()).getUniqueId();
request = new HttpEntity<>(headers);
response = restTemplate.exchange(createURLWithPort(ROOT + VALID_ACTIVATE_SEOC + id), HttpMethod.GET, request,
String.class);
String actualStatus = deserialize.genericResponse(response.getBody()).getStatus();
assertThat(actualStatus).isEqualTo(Constants.SUCCESS);
assertThat(HttpStatus.OK).isEqualTo(response.getStatusCode());
}
/**
* Description: Validate SEOC Activation succeeds - REV is true PRCT is true,
* Any Code Accepted
*/
@Test
public void validSeocActivateSuccessREVTruePRCTTrueAnyCodeAccepted() {
Set<String> billingCodes = new HashSet<String>();
billingCodes.add("code101");
billingCodes.add("code102");
Set<String> clinicalServices = new HashSet<String>();
clinicalServices.add("12-Pulmonary");
CreateServiceRequest serviceRequest = CreateServiceRequest.Builder.create().withDescription("service1")
.withCodeRequired("YES").withVisits(5).withClinicalServices(clinicalServices)
.withBillingCodes(billingCodes).build();
CreateServiceRequest serviceRequest2 = CreateServiceRequest.Builder.create().withDescription("service2")
.withCodeRequired("ANY").withVisits(5).withClinicalServices(clinicalServices).build();
List<CreateServiceRequest> serviceList = new ArrayList<CreateServiceRequest>();
serviceList.add(serviceRequest);
serviceList.add(serviceRequest2);
Set<String> hptcs = new HashSet<String>();
hptcs.add("hptc101");
String requestJson = SeocObjectGenerator
.asJsonString(SeocCreateRequest.Builder.create("SeocTest1", "Medical Specialty Care")
.withServiceList(serviceList).withDescription("Description").withDisclaimer("Disclaimer")
.withDuration(5).withMaxVisits(5).withRev(true).withProceduralOverview("Procedural Overview")
.withCategoryOfCare("Pulmonary").withQasp("QASP1").withHptcs(hptcs).build());
HttpEntity<String> request = new HttpEntity<String>(requestJson, headers);
ResponseEntity<String> response = restTemplate.exchange(createURLWithPort(ROOT), HttpMethod.POST, request,
String.class);
int id = deserialize.createResponse(response.getBody()).getUniqueId();
request = new HttpEntity<>(headers);
response = restTemplate.exchange(createURLWithPort(ROOT + VALID_ACTIVATE_SEOC + id), HttpMethod.GET, request,
String.class);
String actualStatus = deserialize.genericResponse(response.getBody()).getStatus();
assertThat(actualStatus).isEqualTo(Constants.SUCCESS);
assertThat(HttpStatus.OK).isEqualTo(response.getStatusCode());
}
/**
* Description: Validate SEOC Activation failed - REV is true PRCT is false
*/
@Test
public void validSeocActivateFailedREVTruePRCTFalse() {
Set<String> billingCodes = new HashSet<String>();
billingCodes.add("code101");
billingCodes.add("code102");
Set<String> clinicalServices = new HashSet<String>();
clinicalServices.add("12-Pulmonary");
CreateServiceRequest serviceRequest = CreateServiceRequest.Builder.create().withDescription("service1")
.withCodeRequired("YES").withVisits(5).withClinicalServices(clinicalServices)
.withBillingCodes(billingCodes).build();
List<CreateServiceRequest> serviceList = new ArrayList<CreateServiceRequest>();
serviceList.add(serviceRequest);
Set<String> hptcs = new HashSet<String>();
hptcs.add("hptc101");
String requestJson = SeocObjectGenerator
.asJsonString(SeocCreateRequest.Builder.create("SeocTest1", "Medical Specialty Care")
.withServiceList(serviceList).withDescription("Description").withDisclaimer("Disclaimer")
.withDuration(5).withMaxVisits(5).withRev(true).withProceduralOverview("Procedural Overview")
.withCategoryOfCare("Pulmonary").withQasp("QASP1").withHptcs(hptcs).build());
HttpEntity<String> request = new HttpEntity<String>(requestJson, headers);
ResponseEntity<String> response = restTemplate.exchange(createURLWithPort(ROOT), HttpMethod.POST, request,
String.class);
int id = deserialize.createResponse(response.getBody()).getUniqueId();
request = new HttpEntity<>(headers);
response = restTemplate.exchange(createURLWithPort(ROOT + VALID_ACTIVATE_SEOC + id), HttpMethod.GET, request,
String.class);
assertThat(HttpStatus.BAD_REQUEST).isEqualTo(response.getStatusCode());
}
/**
* Description: Validate SEOC Activation failed - Service Line is discontinued
*/
@Test
public void validSeocActivateFailedServiceLineDiscontinued() {
Set<String> billingCodes = new HashSet<String>();
billingCodes.add("code101");
billingCodes.add("code102");
Set<String> clinicalServices = new HashSet<String>();
clinicalServices.add("12-Pulmonary");
CreateServiceRequest serviceRequest = CreateServiceRequest.Builder.create().withDescription("service1")
.withCodeRequired("YES").withVisits(5).withClinicalServices(clinicalServices)
.withBillingCodes(billingCodes).build();
List<CreateServiceRequest> serviceList = new ArrayList<CreateServiceRequest>();
serviceList.add(serviceRequest);
Set<String> hptcs = new HashSet<String>();
hptcs.add("hptc101");
String requestJson = SeocObjectGenerator
.asJsonString(SeocCreateRequest.Builder.create("SeocTest1", "Medical Specialty Care")
.withServiceList(serviceList).withDescription("Description").withDisclaimer("Disclaimer")
.withDuration(5).withMaxVisits(5).withRev(false).withProceduralOverview("Procedural Overview")
.withCategoryOfCare("Pulmonary").withQasp("QASP1").withHptcs(hptcs).build());
HttpEntity<String> request = new HttpEntity<String>(requestJson, headers);
ResponseEntity<String> response = restTemplate.exchange(createURLWithPort(ROOT), HttpMethod.POST, request,
String.class);
int id = deserialize.createResponse(response.getBody()).getUniqueId();
// Discontinue the Service Line
ServiceLine serviceLine = serviceLineRepository.findByDescription("Medical Specialty Care");
serviceLine.setDiscontinued(true);
serviceLineRepository.save(serviceLine);
request = new HttpEntity<>(headers);
response = restTemplate.exchange(createURLWithPort(ROOT + VALID_ACTIVATE_SEOC + id), HttpMethod.GET, request,
String.class);
assertThat(HttpStatus.BAD_REQUEST).isEqualTo(response.getStatusCode());
// Re-activate the Service Line to clean up the data
serviceLine = serviceLineRepository.findByDescription("Medical Specialty Care");
serviceLine.setDiscontinued(null);
serviceLineRepository.save(serviceLine);
}
/**
* Description: Validate SEOC Activation failed - Category of Care is
* discontinued
*/
@Test
public void validSeocActivateFailedCategoryOfCareDiscontinued() {
Set<String> billingCodes = new HashSet<String>();
billingCodes.add("code101");
billingCodes.add("code102");
Set<String> clinicalServices = new HashSet<String>();
clinicalServices.add("12-Pulmonary");
CreateServiceRequest serviceRequest = CreateServiceRequest.Builder.create().withDescription("service1")
.withCodeRequired("YES").withVisits(5).withClinicalServices(clinicalServices)
.withBillingCodes(billingCodes).build();
List<CreateServiceRequest> serviceList = new ArrayList<CreateServiceRequest>();
serviceList.add(serviceRequest);
Set<String> hptcs = new HashSet<String>();
hptcs.add("hptc101");
String requestJson = SeocObjectGenerator
.asJsonString(SeocCreateRequest.Builder.create("SeocTest1", "Medical Specialty Care")
.withServiceList(serviceList).withDescription("Description").withDisclaimer("Disclaimer")
.withDuration(5).withMaxVisits(5).withRev(false).withProceduralOverview("Procedural Overview")
.withCategoryOfCare("Pulmonary").withQasp("QASP1").withHptcs(hptcs).build());
HttpEntity<String> request = new HttpEntity<String>(requestJson, headers);
ResponseEntity<String> response = restTemplate.exchange(createURLWithPort(ROOT), HttpMethod.POST, request,
String.class);
int id = deserialize.createResponse(response.getBody()).getUniqueId();
// Discontinue the Category of Care
CategoryOfCare categoryOfCare = categoryOfCareRepository.findByDescription("Pulmonary");
categoryOfCare.setDiscontinued(true);
categoryOfCareRepository.save(categoryOfCare);
request = new HttpEntity<>(headers);
response = restTemplate.exchange(createURLWithPort(ROOT + VALID_ACTIVATE_SEOC + id), HttpMethod.GET, request,
String.class);
assertThat(HttpStatus.BAD_REQUEST).isEqualTo(response.getStatusCode());
// Re-activate the Category of Care to clean up the data
categoryOfCare = categoryOfCareRepository.findByDescription("Pulmonary");
categoryOfCare.setDiscontinued(null);
categoryOfCareRepository.save(categoryOfCare);
}
/**
* Description: Validate SEOC Activation failed - QASP is discontinued
*/
@Test
public void validSeocActivateFailedQASPDiscontinued() {
Set<String> billingCodes = new HashSet<String>();
billingCodes.add("code101");
billingCodes.add("code102");
Set<String> clinicalServices = new HashSet<String>();
clinicalServices.add("12-Pulmonary");
CreateServiceRequest serviceRequest = CreateServiceRequest.Builder.create().withDescription("service1")
.withCodeRequired("YES").withVisits(5).withClinicalServices(clinicalServices)
.withBillingCodes(billingCodes).build();
List<CreateServiceRequest> serviceList = new ArrayList<CreateServiceRequest>();
serviceList.add(serviceRequest);
Set<String> hptcs = new HashSet<String>();
hptcs.add("hptc101");
String requestJson = SeocObjectGenerator
.asJsonString(SeocCreateRequest.Builder.create("SeocTest1", "Medical Specialty Care")
.withServiceList(serviceList).withDescription("Description").withDisclaimer("Disclaimer")
.withDuration(5).withMaxVisits(5).withRev(false).withProceduralOverview("Procedural Overview")
.withCategoryOfCare("Pulmonary").withQasp("QASP1").withHptcs(hptcs).build());
HttpEntity<String> request = new HttpEntity<String>(requestJson, headers);
ResponseEntity<String> response = restTemplate.exchange(createURLWithPort(ROOT), HttpMethod.POST, request,
String.class);
int id = deserialize.createResponse(response.getBody()).getUniqueId();
// Discontinue the QASP
Qasp qasp = qaspRepository.findByDescription("QASP1");
qasp.setDiscontinued(true);
qaspRepository.save(qasp);
request = new HttpEntity<>(headers);
response = restTemplate.exchange(createURLWithPort(ROOT + VALID_ACTIVATE_SEOC + id), HttpMethod.GET, request,
String.class);
assertThat(HttpStatus.BAD_REQUEST).isEqualTo(response.getStatusCode());
// Re-activate the QASP to clean up the data
qasp = qaspRepository.findByDescription("QASP1");
qasp.setDiscontinued(null);
qaspRepository.save(qasp);
}
// NOTE: Due to the validation on the Clinical Service class, it isn't possible
// at this time to add an integration test for a Discontinued Clinical Service
/**
* Description: Test Seoc Activation success scenario
*/
@Test
public void seocActivate_success() {
Set<String> billingCodes = new HashSet<String>();
billingCodes.add("code101");
billingCodes.add("code102");
Set<String> clinicalServices = new HashSet<String>();
clinicalServices.add("12-Pulmonary");
CreateServiceRequest serviceRequest = CreateServiceRequest.Builder.create().withDescription("service1")
.withCodeRequired("YES").withVisits(5).withClinicalServices(clinicalServices)
.withBillingCodes(billingCodes).build();
List<CreateServiceRequest> serviceList = new ArrayList<CreateServiceRequest>();
serviceList.add(serviceRequest);
Set<String> hptcs = new HashSet<String>();
hptcs.add("hptc101");
String requestJson = SeocObjectGenerator.asJsonString(SeocCreateRequest.Builder.create("SeocTest1", "Radiology")
.withServiceList(serviceList).withDescription("Description").withDisclaimer("Disclaimer")
.withDuration(5).withMaxVisits(5).withRev(false).withProceduralOverview("Procedural Overview")
.withCategoryOfCare("Acupuncture12").withQasp("QASP1").withHptcs(hptcs).build());
HttpEntity<String> request = new HttpEntity<String>(requestJson, headers);
ResponseEntity<String> response = restTemplate.exchange(createURLWithPort(ROOT), HttpMethod.POST, request,
String.class);
int id = deserialize.createResponse(response.getBody()).getUniqueId();
String eTagHash = response.getHeaders().getETag();
// Activate
headers.setIfMatch(eTagHash);
requestJson = SeocObjectGenerator
.asJsonString(SeocActivateRequest.Builder.create(id, TestUtil.getEffectiveDateString()).build());
request = new HttpEntity<String>(requestJson, headers);
response = restTemplate.exchange(createURLWithPort(ROOT + ACTIVATE_SEOC), HttpMethod.POST, request,
String.class);
List<ChangeLog> logs = logService.getChangeLogBySeocId(id, Constants.EVENT_ACTION_ACTIVATE);
// Assert ChangeLog records inserted after activation
assertThat(logs.size()).isEqualTo(1);
assertThat(logs.get(0).getUser().getVaUserId()).contains(vaUserId);
String actualStatus = deserialize.genericResponse(response.getBody()).getStatus();
assertThat(actualStatus).isEqualTo(Constants.SUCCESS);
assertThat(HttpStatus.OK).isEqualTo(response.getStatusCode());
// Get seoc by ID
request = new HttpEntity<>(headers);
response = restTemplate.exchange(createURLWithPort(ROOT + id), HttpMethod.GET, request, String.class);
String actStatus = deserialize.seocResponse(response.getBody(), "status");
String activatedBy = deserialize.seocResponse(response.getBody(), "activatedBy");
String versionNumber = deserialize.seocResponse(response.getBody(), "versionNumber");
String[] versionParts = SeocServiceHelper.getPartsOfVersion(versionNumber);
assertThat(versionParts[1]).isEqualTo("4");
assertThat(actStatus).isEqualTo(Constants.STATUS_DATEHOLD);
assertThat(activatedBy).isEqualTo(vaUserId);
}
/**
* Description: Test Seoc Activation success - pending revision
*/
@Test
public void seocActivateSuccessPendingRevision() {
int id = 3;
// Seoc1 - Get existing Active Seoc
HttpEntity<String> request = new HttpEntity<>(headers);
ResponseEntity<String> response = restTemplate.exchange(createURLWithPort(ROOT + id), HttpMethod.GET, request,
String.class);
String etagHash = response.getHeaders().getETag();
// Create Pending revision
headers.setIfMatch(etagHash);
String requestJson = SeocObjectGenerator.asJsonString(SeocGenericRequest.Builder.create(id).build());
request = new HttpEntity<String>(requestJson, headers);
response = restTemplate.exchange(createURLWithPort(ROOT + PENDING_REVISION), HttpMethod.POST, request,
String.class);
SeocCreateResponse createResponse = deserialize.createResponse(response.getBody());
int pendingRevId = createResponse.getUniqueId();
assertThat(createResponse.getStatus()).isEqualTo(Constants.CREATED);
response = restTemplate.exchange(createURLWithPort(ROOT + pendingRevId), HttpMethod.GET, request, String.class);
etagHash = response.getHeaders().getETag();
// Activate the newly created pending revision
headers.setIfMatch(etagHash);
requestJson = SeocObjectGenerator.asJsonString(
SeocActivateRequest.Builder.create(pendingRevId, TestUtil.getEffectiveDateString()).build());
request = new HttpEntity<String>(requestJson, headers);
response = restTemplate.exchange(createURLWithPort(ROOT + ACTIVATE_SEOC), HttpMethod.POST, request,
String.class);
String actualStatus = deserialize.genericResponse(response.getBody()).getStatus();
assertThat(actualStatus).isEqualTo(Constants.SUCCESS);
assertThat(HttpStatus.OK).isEqualTo(response.getStatusCode());
List<ChangeLog> logs = logService.getChangeLogBySeocId(pendingRevId, Constants.EVENT_ACTION_ACTIVATE);
// Assert ChangeLog records inserted after activation
assertThat(logs.size()).isEqualTo(1);
assertThat(logs.get(0).getUser().getVaUserId()).contains(vaUserId);
// Get seoc by ID
request = new HttpEntity<>(headers);
response = restTemplate.exchange(createURLWithPort(ROOT + pendingRevId), HttpMethod.GET, request, String.class);
String actStatus = deserialize.seocResponse(response.getBody(), "status");
String activatedBy = deserialize.seocResponse(response.getBody(), "activatedBy");
String versionNumber = deserialize.seocResponse(response.getBody(), "versionNumber");
String[] versionParts = SeocServiceHelper.getPartsOfVersion(versionNumber);
assertThat(versionParts[1]).isEqualTo("1");
assertThat(actStatus).isEqualTo(Constants.STATUS_DATEHOLD);
assertThat(activatedBy).isEqualTo(vaUserId);
etagHash = response.getHeaders().getETag();
// Get previous seoc by ID
request = new HttpEntity<>(headers);
response = restTemplate.exchange(createURLWithPort(ROOT + id), HttpMethod.GET, request, String.class);
String discontinuedTimestamp = deserialize.seocResponse(response.getBody(), "discontinuedTimestamp");
String discontinuedBy = deserialize.seocResponse(response.getBody(), "discontinuedBy");
String endDate = deserialize.seocResponse(response.getBody(), "endDate");
assertThat(discontinuedTimestamp).isEqualTo(TestUtil.getEffectiveDateString());
assertThat(discontinuedBy).isEqualTo(vaUserId);
assertThat(endDate).isEqualTo(TestUtil.getEffectiveDateString());
// Reverse and delete the Pending Revision to clean up the data
headers.setIfMatch(etagHash);
request = new HttpEntity<>(headers);
response = restTemplate.exchange(createURLWithPort(ROOT + REVERSE_SEOC + pendingRevId), HttpMethod.GET, request,
String.class);
assertThat(HttpStatus.OK).isEqualTo(response.getStatusCode());
etagHash = response.getHeaders().getETag();
headers.setIfMatch(etagHash);
request = new HttpEntity<>(headers);
response = restTemplate.exchange(createURLWithPort(ROOT + DELETE_SEOC + pendingRevId), HttpMethod.GET, request,
String.class);
assertThat(HttpStatus.OK).isEqualTo(response.getStatusCode());
}
/**
* Description: Test Seoc Activation failure - incomplete SEOC
*/
@Test
public void seocActivate_failure() {
Set<String> billingCodes = new HashSet<String>();
billingCodes.add("testBC1");
billingCodes.add("testBC2");
CreateServiceRequest serviceRequest = CreateServiceRequest.Builder.create().withDescription("service1")
.withCodeRequired("YES").withVisits(0).withBillingCodes(billingCodes).build();
List<CreateServiceRequest> serviceList = new ArrayList<CreateServiceRequest>();
serviceList.add(serviceRequest);
String requestJson = SeocObjectGenerator.asJsonString(SeocCreateRequest.Builder
.create("SeocTest1", "Medical Specialty Care").withServiceList(serviceList)
.withDescription("Description").withDisclaimer("Disclaimer").withDuration(5).withMaxVisits(5)
.withRev(false).withProceduralOverview("Procedural Overview").withCategoryOfCare("Pulmonary").build());
HttpEntity<String> request = new HttpEntity<String>(requestJson, headers);
ResponseEntity<String> response = restTemplate.exchange(createURLWithPort(ROOT), HttpMethod.POST, request,
String.class);
int id = deserialize.createResponse(response.getBody()).getUniqueId();
String eTagHash = response.getHeaders().getETag();
headers.setIfMatch(eTagHash);
requestJson = SeocObjectGenerator
.asJsonString(SeocActivateRequest.Builder.create(id, TestUtil.getEffectiveDateString()).build());
request = new HttpEntity<String>(requestJson, headers);
response = restTemplate.exchange(createURLWithPort(ROOT + ACTIVATE_SEOC), HttpMethod.POST, request,
String.class);
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.BAD_REQUEST);
}
/**
* Description:Test Seoc Activation failure - empty request
*/
@Test
public void seocActivate_failureEmptyRequest() {
Set<String> billingCodes = new HashSet<String>();
billingCodes.add("code101");
billingCodes.add("code102");
Set<String> clinicalServices = new HashSet<String>();
clinicalServices.add("12-Pulmonary");
CreateServiceRequest serviceRequest = CreateServiceRequest.Builder.create().withDescription("service1")
.withCodeRequired("YES").withVisits(5).withClinicalServices(clinicalServices)
.withBillingCodes(billingCodes).build();
List<CreateServiceRequest> serviceList = new ArrayList<CreateServiceRequest>();
serviceList.add(serviceRequest);
Set<String> hptcs = new HashSet<String>();
hptcs.add("hptc101");
String requestJson = SeocObjectGenerator.asJsonString(SeocCreateRequest.Builder.create("SeocTest1", "Radiology")
.withServiceList(serviceList).withDescription("Description").withDisclaimer("Disclaimer")
.withDuration(5).withMaxVisits(5).withRev(false).withProceduralOverview("Procedural Overview")
.withCategoryOfCare("Acupuncture12").withQasp("QASP1").withHptcs(hptcs).build());
HttpEntity<String> request = new HttpEntity<String>(requestJson, headers);
ResponseEntity<String> response = restTemplate.exchange(createURLWithPort(ROOT), HttpMethod.POST, request,
String.class);
int id = deserialize.createResponse(response.getBody()).getUniqueId();
String eTagHash = response.getHeaders().getETag();
headers.setIfMatch(eTagHash);
requestJson = SeocObjectGenerator
.asJsonString(SeocActivateRequest.Builder.create(id, TestUtil.getEffectiveDateString()).build());
request = new HttpEntity<>(headers);
response = restTemplate.exchange(createURLWithPort(ROOT + ACTIVATE_SEOC), HttpMethod.POST, request,
String.class);
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.BAD_REQUEST);
}
/**
* Description: Test Seoc Activation failure - missing id
*/
@Test
public void seocActivate_failureMissingId() {
Set<String> billingCodes = new HashSet<String>();
billingCodes.add("code101");
billingCodes.add("code102");
Set<String> clinicalServices = new HashSet<String>();
clinicalServices.add("12-Pulmonary");
CreateServiceRequest serviceRequest = CreateServiceRequest.Builder.create().withDescription("service1")
.withCodeRequired("YES").withVisits(5).withClinicalServices(clinicalServices)
.withBillingCodes(billingCodes).build();
List<CreateServiceRequest> serviceList = new ArrayList<CreateServiceRequest>();
serviceList.add(serviceRequest);
Set<String> hptcs = new HashSet<String>();
hptcs.add("hptc101");
String requestJson = SeocObjectGenerator.asJsonString(SeocCreateRequest.Builder.create("SeocTest1", "Radiology")
.withServiceList(serviceList).withDescription("Description").withDisclaimer("Disclaimer")
.withDuration(5).withMaxVisits(5).withRev(false).withProceduralOverview("Procedural Overview")
.withCategoryOfCare("Acupuncture12").withQasp("QASP1").withHptcs(hptcs).build());
HttpEntity<String> request = new HttpEntity<String>(requestJson, headers);
ResponseEntity<String> response = restTemplate.exchange(createURLWithPort(ROOT), HttpMethod.POST, request,
String.class);
String eTagHash = response.getHeaders().getETag();
// Activate
headers.setIfMatch(eTagHash);
requestJson = SeocObjectGenerator.asJsonString(
SeocActivateRequest.Builder.create().withEffectiveDate(TestUtil.getEffectiveDateString()).build());
request = new HttpEntity<String>(requestJson, headers);
response = restTemplate.exchange(createURLWithPort(ROOT + ACTIVATE_SEOC), HttpMethod.POST, request,
String.class);
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.BAD_REQUEST);
}
/**
* Description: Test Seoc Activation failure - missing effectiveDate
*/
@Test
public void seocActivate_failure_missingEffectiveDate() {
Set<String> billingCodes = new HashSet<String>();
billingCodes.add("code101");
billingCodes.add("code102");
Set<String> clinicalServices = new HashSet<String>();
clinicalServices.add("12-Pulmonary");
CreateServiceRequest serviceRequest = CreateServiceRequest.Builder.create().withDescription("service1")
.withCodeRequired("YES").withVisits(5).withClinicalServices(clinicalServices)
.withBillingCodes(billingCodes).build();
List<CreateServiceRequest> serviceList = new ArrayList<CreateServiceRequest>();
serviceList.add(serviceRequest);
Set<String> hptcs = new HashSet<String>();
hptcs.add("hptc101");
String requestJson = SeocObjectGenerator.asJsonString(SeocCreateRequest.Builder.create("SeocTest1", "Radiology")
.withServiceList(serviceList).withDescription("Description").withDisclaimer("Disclaimer")
.withDuration(5).withMaxVisits(5).withRev(false).withProceduralOverview("Procedural Overview")
.withCategoryOfCare("Acupuncture12").withQasp("QASP1").withHptcs(hptcs).build());
HttpEntity<String> request = new HttpEntity<String>(requestJson, headers);
ResponseEntity<String> response = restTemplate.exchange(createURLWithPort(ROOT), HttpMethod.POST, request,
String.class);
int id = deserialize.createResponse(response.getBody()).getUniqueId();
String eTagHash = response.getHeaders().getETag();
// Activate
headers.setIfMatch(eTagHash);
requestJson = SeocObjectGenerator.asJsonString(SeocActivateRequest.Builder.create().withSeocId(id).build());
request = new HttpEntity<String>(requestJson, headers);
response = restTemplate.exchange(createURLWithPort(ROOT + ACTIVATE_SEOC), HttpMethod.POST, request,
String.class);
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.BAD_REQUEST);
}
/**
* Description: Test Seoc Activation failure - past effectiveDate
*/
@Test
public void seocActivate_failurePastEffectiveDate() {
Set<String> billingCodes = new HashSet<String>();
billingCodes.add("code101");
billingCodes.add("code102");
Set<String> clinicalServices = new HashSet<String>();
clinicalServices.add("12-Pulmonary");
CreateServiceRequest serviceRequest = CreateServiceRequest.Builder.create().withDescription("service1")
.withCodeRequired("YES").withVisits(5).withClinicalServices(clinicalServices)
.withBillingCodes(billingCodes).build();
List<CreateServiceRequest> serviceList = new ArrayList<CreateServiceRequest>();
serviceList.add(serviceRequest);
Set<String> hptcs = new HashSet<String>();
hptcs.add("hptc101");
String requestJson = SeocObjectGenerator.asJsonString(SeocCreateRequest.Builder.create("SeocTest1", "Radiology")
.withServiceList(serviceList).withDescription("Description").withDisclaimer("Disclaimer")
.withDuration(5).withMaxVisits(5).withRev(false).withProceduralOverview("Procedural Overview")
.withCategoryOfCare("Acupuncture12").withQasp("QASP1").withHptcs(hptcs).build());
HttpEntity<String> request = new HttpEntity<String>(requestJson, headers);
ResponseEntity<String> response = restTemplate.exchange(createURLWithPort(ROOT), HttpMethod.POST, request,
String.class);
int id = deserialize.createResponse(response.getBody()).getUniqueId();
String eTagHash = response.getHeaders().getETag();
// Activate
headers.setIfMatch(eTagHash);
requestJson = SeocObjectGenerator
.asJsonString(SeocActivateRequest.Builder.create(id, TestUtil.getEffectiveDateStringPast()).build());
request = new HttpEntity<String>(requestJson, headers);
response = restTemplate.exchange(createURLWithPort(ROOT + ACTIVATE_SEOC), HttpMethod.POST, request,
String.class);
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.BAD_REQUEST);
}
/**
* Description: Test Seoc Activation failure - missing vaUserId in the header
*/
@Test
public void seocActivate_failure_missingVaUserId() {
Set<String> billingCodes = new HashSet<String>();
billingCodes.add("code101");
billingCodes.add("code102");
Set<String> clinicalServices = new HashSet<String>();
clinicalServices.add("12-Pulmonary");
CreateServiceRequest serviceRequest = CreateServiceRequest.Builder.create().withDescription("service1")
.withCodeRequired("YES").withVisits(5).withClinicalServices(clinicalServices)
.withBillingCodes(billingCodes).build();
List<CreateServiceRequest> serviceList = new ArrayList<CreateServiceRequest>();
serviceList.add(serviceRequest);
Set<String> hptcs = new HashSet<String>();
hptcs.add("hptc101");
String requestJson = SeocObjectGenerator.asJsonString(SeocCreateRequest.Builder.create("SeocTest1", "Radiology")
.withServiceList(serviceList).withDescription("Description").withDisclaimer("Disclaimer")
.withDuration(5).withMaxVisits(5).withRev(false).withProceduralOverview("Procedural Overview")
.withCategoryOfCare("Acupuncture12").withQasp("QASP1").withHptcs(hptcs).build());
HttpEntity<String> request = new HttpEntity<String>(requestJson, headers);
ResponseEntity<String> response = restTemplate.exchange(createURLWithPort(ROOT), HttpMethod.POST, request,
String.class);
String eTagHash = response.getHeaders().getETag();
// Activate
HttpHeaders headers = new HttpHeaders();
headers.setIfMatch(eTagHash);
headers.setContentType(MediaType.APPLICATION_JSON_UTF8);
requestJson = SeocObjectGenerator.asJsonString(
SeocActivateRequest.Builder.create().withEffectiveDate(TestUtil.getEffectiveDateString()).build());
request = new HttpEntity<String>(requestJson, headers);
response = restTemplate.exchange(createURLWithPort(ROOT + ACTIVATE_SEOC), HttpMethod.POST, request,
String.class);
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.BAD_REQUEST);
}
/**
* Description: Test validation of pending revision - failure since the SEOC is
* in Progress
*/
@Test
public void validPendingRevision_failure_inProgressSeoc() {
Set<String> billingCodes = new HashSet<String>();
billingCodes.add("testBC1");
billingCodes.add("testBC2");
Set<String> clinicalServices = new HashSet<String>();
clinicalServices.add("12-Pulmonary");
CreateServiceRequest serviceRequest = CreateServiceRequest.Builder.create().withDescription("service1")
.withCodeRequired("YES").withVisits(5).withClinicalServices(clinicalServices)
.withBillingCodes(billingCodes).build();
List<CreateServiceRequest> serviceList = new ArrayList<CreateServiceRequest>();
serviceList.add(serviceRequest);
String requestJson = SeocObjectGenerator
.asJsonString(SeocCreateRequest.Builder.create("SeocTest1", "Medical Specialty Care")
.withServiceList(serviceList).withDescription("Description").withDisclaimer("Disclaimer")
.withDuration(5).withMaxVisits(5).withRev(false).withProceduralOverview("Procedural Overview")
.withCategoryOfCare("Pulmonary").withQasp("QASP1").build());
// Create SEOC
HttpEntity<String> request = new HttpEntity<String>(requestJson, headers);
ResponseEntity<String> response = restTemplate.exchange(createURLWithPort(ROOT), HttpMethod.POST, request,
String.class);
int id = deserialize.createResponse(response.getBody()).getUniqueId();
// Check to see if Pending Revision can be created
request = new HttpEntity<>(headers);
response = restTemplate.exchange(createURLWithPort(ROOT + VALID_PENDING_REVISION + id), HttpMethod.GET, request,
String.class);
SeocGenericResponse genericResponse = deserialize.genericResponse(response.getBody());
String actualStatus = genericResponse.getStatus();
String message = genericResponse.getMessage();
assertThat(actualStatus).isEqualTo(Constants.FAILURE);
assertThat(message).isEqualTo(
"Seoc is not eligible for Pending revision. Current status of SEOC is " + Constants.STATUS_INPROGRESS);
assertThat(HttpStatus.OK).isEqualTo(response.getStatusCode());
}
/**
* Description: Test validation of pending revision - failure since the SEOC is
* in Date Hold
*/
@Test
public void validPendingRevision_failure_dateHold() {
Set<String> billingCodes = new HashSet<String>();
billingCodes.add("code101");
billingCodes.add("code102");
Set<String> clinicalServices = new HashSet<String>();
clinicalServices.add("12-Pulmonary");
CreateServiceRequest serviceRequest = CreateServiceRequest.Builder.create().withDescription("service1")
.withCodeRequired("YES").withVisits(5).withClinicalServices(clinicalServices)
.withBillingCodes(billingCodes).build();
List<CreateServiceRequest> serviceList = new ArrayList<CreateServiceRequest>();
serviceList.add(serviceRequest);
Set<String> hptcs = new HashSet<String>();
hptcs.add("hptc101");
String requestJson = SeocObjectGenerator
.asJsonString(SeocCreateRequest.Builder.create("SeocTest1", "Medical Specialty Care")
.withServiceList(serviceList).withDescription("Description").withDisclaimer("Disclaimer")
.withDuration(5).withMaxVisits(5).withRev(false).withProceduralOverview("Procedural Overview")
.withCategoryOfCare("Pulmonary").withQasp("QASP1").withHptcs(hptcs).build());
// Create SEOC
HttpEntity<String> request = new HttpEntity<String>(requestJson, headers);
ResponseEntity<String> response = restTemplate.exchange(createURLWithPort(ROOT), HttpMethod.POST, request,
String.class);
int id = deserialize.createResponse(response.getBody()).getUniqueId();
String eTagHash = response.getHeaders().getETag();
// Activate SEOC
headers.setIfMatch(eTagHash);
requestJson = SeocObjectGenerator
.asJsonString(SeocActivateRequest.Builder.create(id, TestUtil.getEffectiveDateStringFuture()).build());
request = new HttpEntity<String>(requestJson, headers);
response = restTemplate.exchange(createURLWithPort(ROOT + ACTIVATE_SEOC), HttpMethod.POST, request,
String.class);
String actualStatus = deserialize.genericResponse(response.getBody()).getStatus();
assertThat(actualStatus).isEqualTo(Constants.SUCCESS);
assertThat(HttpStatus.OK).isEqualTo(response.getStatusCode());
// Check to see if Pending Revision can be created
request = new HttpEntity<>(headers);
response = restTemplate.exchange(createURLWithPort(ROOT + VALID_PENDING_REVISION + id), HttpMethod.GET, request,
String.class);
SeocGenericResponse genericResponse = deserialize.genericResponse(response.getBody());
actualStatus = genericResponse.getStatus();
String message = genericResponse.getMessage();
assertThat(actualStatus).isEqualTo(Constants.FAILURE);
assertThat(message).isEqualTo(
"Seoc is not eligible for Pending revision. Current status of SEOC is " + Constants.STATUS_DATEHOLD);
assertThat(HttpStatus.OK).isEqualTo(response.getStatusCode());
}
/**
* Description: Test validation of pending revision - failure since the SEOC is
* Discontinued
*/
@Test
public void validPendingRevision_failure_discontinued() {
Set<String> billingCodes = new HashSet<String>();
billingCodes.add("code101");
billingCodes.add("code102");
Set<String> clinicalServices = new HashSet<String>();
clinicalServices.add("12-Pulmonary");
CreateServiceRequest serviceRequest = CreateServiceRequest.Builder.create().withDescription("service1")
.withCodeRequired("YES").withVisits(5).withClinicalServices(clinicalServices)
.withBillingCodes(billingCodes).build();
List<CreateServiceRequest> serviceList = new ArrayList<CreateServiceRequest>();
serviceList.add(serviceRequest);
Set<String> hptcs = new HashSet<String>();
hptcs.add("hptc101");
String requestJson = SeocObjectGenerator
.asJsonString(SeocCreateRequest.Builder.create("SeocTest1", "Medical Specialty Care")
.withServiceList(serviceList).withDescription("Description").withDisclaimer("Disclaimer")
.withDuration(5).withMaxVisits(5).withRev(false).withProceduralOverview("Procedural Overview")
.withCategoryOfCare("Pulmonary").withQasp("QASP1").withHptcs(hptcs).build());
// Create SEOC
HttpEntity<String> request = new HttpEntity<String>(requestJson, headers);
ResponseEntity<String> response = restTemplate.exchange(createURLWithPort(ROOT), HttpMethod.POST, request,
String.class);
int id = deserialize.createResponse(response.getBody()).getUniqueId();
String eTagHash = response.getHeaders().getETag();
// Activate SEOC
headers.setIfMatch(eTagHash);
requestJson = SeocObjectGenerator
.asJsonString(SeocActivateRequest.Builder.create(id, TestUtil.getEffectiveDateString()).build());
request = new HttpEntity<String>(requestJson, headers);
response = restTemplate.exchange(createURLWithPort(ROOT + ACTIVATE_SEOC), HttpMethod.POST, request,
String.class);
String actualStatus = deserialize.genericResponse(response.getBody()).getStatus();
assertThat(actualStatus).isEqualTo(Constants.SUCCESS);
assertThat(HttpStatus.OK).isEqualTo(response.getStatusCode());
// Set Effective Date and End Date to the past
Seoc foundSeoc = seocRepository.findById(id);
foundSeoc.setEffectiveDate(TestUtil.getEffectiveDatePast());
foundSeoc.setEndDate(TestUtil.getEffectiveDatePast());
seocRepository.save(foundSeoc);
// Check to see if Pending Revision can be created
request = new HttpEntity<>(headers);
response = restTemplate.exchange(createURLWithPort(ROOT + VALID_PENDING_REVISION + id), HttpMethod.GET, request,
String.class);
SeocGenericResponse genericResponse = deserialize.genericResponse(response.getBody());
actualStatus = genericResponse.getStatus();
String message = genericResponse.getMessage();
assertThat(actualStatus).isEqualTo(Constants.FAILURE);
assertThat(message).isEqualTo("Seoc is not eligible for Pending revision. Current status of SEOC is "
+ Constants.STATUS_DISCONTINUED);
assertThat(HttpStatus.OK).isEqualTo(response.getStatusCode());
}
/**
* Description: Test validation of pending revision - success
*/
@Test
public void validPendingRevision_success() {
Set<String> billingCodes = new HashSet<String>();
billingCodes.add("code101");
billingCodes.add("code102");
Set<String> clinicalServices = new HashSet<String>();
clinicalServices.add("12-Pulmonary");
CreateServiceRequest serviceRequest = CreateServiceRequest.Builder.create().withDescription("service1")
.withCodeRequired("YES").withVisits(5).withClinicalServices(clinicalServices)
.withBillingCodes(billingCodes).build();
List<CreateServiceRequest> serviceList = new ArrayList<CreateServiceRequest>();
serviceList.add(serviceRequest);
Set<String> hptcs = new HashSet<String>();
hptcs.add("hptc101");
String requestJson = SeocObjectGenerator
.asJsonString(SeocCreateRequest.Builder.create("SeocTest1", "Medical Specialty Care")
.withServiceList(serviceList).withDescription("Description").withDisclaimer("Disclaimer")
.withDuration(5).withMaxVisits(5).withRev(false).withProceduralOverview("Procedural Overview")
.withCategoryOfCare("Pulmonary").withQasp("QASP1").withHptcs(hptcs).build());
// Create SEOC
HttpEntity<String> request = new HttpEntity<String>(requestJson, headers);
ResponseEntity<String> response = restTemplate.exchange(createURLWithPort(ROOT), HttpMethod.POST, request,
String.class);
int id = deserialize.createResponse(response.getBody()).getUniqueId();
String eTagHash = response.getHeaders().getETag();
// Activate SEOC
headers.setIfMatch(eTagHash);
requestJson = SeocObjectGenerator
.asJsonString(SeocActivateRequest.Builder.create(id, TestUtil.getEffectiveDateString()).build());
request = new HttpEntity<String>(requestJson, headers);
response = restTemplate.exchange(createURLWithPort(ROOT + ACTIVATE_SEOC), HttpMethod.POST, request,
String.class);
String actualStatus = deserialize.genericResponse(response.getBody()).getStatus();
assertThat(actualStatus).isEqualTo(Constants.SUCCESS);
assertThat(HttpStatus.OK).isEqualTo(response.getStatusCode());
// Set Effective Date to the past
Seoc foundSeoc = seocRepository.findById(id);
foundSeoc.setEffectiveDate(TestUtil.getEffectiveDatePast());
seocRepository.save(foundSeoc);
// Check to see if Pending Revision can be created
request = new HttpEntity<>(headers);
response = restTemplate.exchange(createURLWithPort(ROOT + VALID_PENDING_REVISION + id), HttpMethod.GET, request,
String.class);
SeocGenericResponse genericResponse = deserialize.genericResponse(response.getBody());
actualStatus = genericResponse.getStatus();
String message = genericResponse.getMessage();
assertThat(actualStatus).isEqualTo(Constants.SUCCESS);
assertThat(message).isEqualTo("Pending revision can be created.");
assertThat(HttpStatus.OK).isEqualTo(response.getStatusCode());
}
/**
* Description: Test delete seoc when a seoc is successfully deleted and logs
* the delete activity in the change log
*/
@Test
public void deleteSeoc_success() {
Set<String> billingCodes = new HashSet<String>();
billingCodes.add("testBC1");
billingCodes.add("testBC2");
Set<String> clinicalServices = new HashSet<String>();
clinicalServices.add("12-Pulmonary");
CreateServiceRequest serviceRequest = CreateServiceRequest.Builder.create().withDescription("service1")
.withCodeRequired("YES").withVisits(0).withClinicalServices(clinicalServices)
.withBillingCodes(billingCodes).build();
List<CreateServiceRequest> serviceList = new ArrayList<CreateServiceRequest>();
serviceList.add(serviceRequest);
String requestJson = SeocObjectGenerator.asJsonString(SeocCreateRequest.Builder
.create("SeocTest1", "Medical Specialty Care").withServiceList(serviceList)
.withDescription("Description").withDisclaimer("Disclaimer").withDuration(5).withMaxVisits(5)
.withRev(false).withProceduralOverview("Procedural Overview").withCategoryOfCare("Pulmonary").build());
HttpEntity<String> request = new HttpEntity<String>(requestJson, headers);
// Create Seoc
ResponseEntity<String> response = restTemplate.exchange(createURLWithPort(ROOT), HttpMethod.POST, request,
String.class);
// get the uniqueId
int id = deserialize.createResponse(response.getBody()).getUniqueId();
String eTagAfterCreate = response.getHeaders().getETag();
headers = new HttpHeaders();
headers.setIfMatch(eTagAfterCreate);
setHeaders();
// Delete the Seoc
request = new HttpEntity<>(headers);
response = restTemplate.exchange(createURLWithPort(ROOT + DELETE_SEOC + id), HttpMethod.GET, request,
String.class);
// Assert that delete operation returns with success status
String actualStatus = deserialize.genericResponse(response.getBody()).getStatus();
assertThat(actualStatus).isEqualTo(Constants.SUCCESS);
// Assert that a change log for delete has been recorded
List<ChangeLog> logs = logService.getChangeLogBySeocId(id, Constants.EVENT_ACTION_DELETE);
assertThat(logs).isNotEmpty();
assertThat(logs.size()).isEqualTo(1);
assertThat(logs.get(0).getUser().getVaUserId()).contains(vaUserId);
// Assert that the seoc record no longer exists in the DB
Seoc seocAfterDeletion = seocService.getSeocById(id);
assertThat(seocAfterDeletion).isNull();
}
/**
* Description: Test the scenario where a pending revision has been created and
* try to create pending revision for the second time on parent seoc. This test
* case can be executed only if custom activation date can be provided which is
* a future requirement.
*/
@Test
public void createPendingRevision_failure() {
int id = 3;
// Seoc1 - Get existing Active Seoc
HttpEntity<String> request = new HttpEntity<>(headers);
ResponseEntity<String> response = restTemplate.exchange(createURLWithPort(ROOT + id), HttpMethod.GET, request,
String.class);
String eTagHash = response.getHeaders().getETag();
// Create Pending revision
headers.setIfMatch(eTagHash);
String requestJson = SeocObjectGenerator.asJsonString(SeocGenericRequest.Builder.create(id).build());
request = new HttpEntity<String>(requestJson, headers);
response = restTemplate.exchange(createURLWithPort(ROOT + PENDING_REVISION), HttpMethod.POST, request,
String.class);
SeocCreateResponse createResponse = deserialize.createResponse(response.getBody());
int pendingRevId = createResponse.getUniqueId();
assertThat(createResponse.getStatus()).isEqualTo(Constants.CREATED);
response = restTemplate.exchange(createURLWithPort(ROOT + pendingRevId), HttpMethod.GET, request, String.class);
eTagHash = response.getHeaders().getETag();
// Activate the newly created pending revision
headers.setIfMatch(eTagHash);
requestJson = SeocObjectGenerator.asJsonString(
SeocActivateRequest.Builder.create(pendingRevId, TestUtil.getEffectiveDateString()).build());
request = new HttpEntity<String>(requestJson, headers);
response = restTemplate.exchange(createURLWithPort(ROOT + ACTIVATE_SEOC), HttpMethod.POST, request,
String.class);
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK);
eTagHash = response.getHeaders().getETag();
// Try to check valid Pending revision on parent seoc
request = new HttpEntity<>(headers);
response = restTemplate.exchange(createURLWithPort(ROOT + VALID_PENDING_REVISION + id), HttpMethod.GET, request,
String.class);
String actualStatus = deserialize.genericResponse(response.getBody()).getStatus();
assertThat(actualStatus).isEqualTo(Constants.FAILURE);
assertThat(HttpStatus.OK).isEqualTo(response.getStatusCode());
// Try to create another Pending revision
headers.setIfMatch(eTagHash);
requestJson = SeocObjectGenerator.asJsonString(SeocGenericRequest.Builder.create(id).build());
request = new HttpEntity<String>(requestJson, headers);
response = restTemplate.exchange(createURLWithPort(ROOT + PENDING_REVISION), HttpMethod.POST, request,
String.class);
actualStatus = deserialize.createResponse(response.getBody()).getStatus();
assertThat(actualStatus).isEqualTo(Constants.FAILURE);
assertThat(HttpStatus.OK).isEqualTo(response.getStatusCode());
// Reverse and Delete the Pending Revision to clean up the data
headers.setIfMatch(eTagHash);
request = new HttpEntity<>(headers);
response = restTemplate.exchange(createURLWithPort(ROOT + REVERSE_SEOC + pendingRevId), HttpMethod.GET, request,
String.class);
assertThat(HttpStatus.OK).isEqualTo(response.getStatusCode());
eTagHash = response.getHeaders().getETag();
headers.setIfMatch(eTagHash);
request = new HttpEntity<>(headers);
response = restTemplate.exchange(createURLWithPort(ROOT + DELETE_SEOC + pendingRevId), HttpMethod.GET, request,
String.class);
assertThat(HttpStatus.OK).isEqualTo(response.getStatusCode());
}
/**
* Description: Test create pending revision for a In Progress SEOC
*/
@Test
public void createPendingRevision_failure_inProgress() {
Set<String> billingCodes = new HashSet<String>();
billingCodes.add("code101");
billingCodes.add("code102");
Set<String> clinicalServices = new HashSet<String>();
clinicalServices.add("12-Pulmonary");
CreateServiceRequest serviceRequest = CreateServiceRequest.Builder.create().withDescription("service1")
.withCodeRequired("YES").withVisits(5).withClinicalServices(clinicalServices)
.withBillingCodes(billingCodes).build();
List<CreateServiceRequest> serviceList = new ArrayList<CreateServiceRequest>();
serviceList.add(serviceRequest);
Set<String> hptcs = new HashSet<String>();
hptcs.add("hptc101");
String requestJson = SeocObjectGenerator
.asJsonString(SeocCreateRequest.Builder.create("SeocTest1", "Medical Specialty Care")
.withServiceList(serviceList).withDescription("Description").withDisclaimer("Disclaimer")
.withDuration(5).withMaxVisits(5).withRev(false).withProceduralOverview("Procedural Overview")
.withCategoryOfCare("Pulmonary").withQasp("QASP1").withHptcs(hptcs).build());
HttpEntity<String> request = new HttpEntity<String>(requestJson, headers);
// Create SEOC
ResponseEntity<String> response = restTemplate.exchange(createURLWithPort(ROOT), HttpMethod.POST, request,
String.class);
String actualStatus = deserialize.createResponse(response.getBody()).getStatus();
assertThat(actualStatus).isEqualTo(Constants.CREATED);
assertThat(HttpStatus.CREATED).isEqualTo(response.getStatusCode());
int id = deserialize.createResponse(response.getBody()).getUniqueId();
// Try to create a Pending Revision
requestJson = SeocObjectGenerator.asJsonString(SeocGenericRequest.Builder.create(id).build());
request = new HttpEntity<String>(requestJson, headers);
response = restTemplate.exchange(createURLWithPort(ROOT + PENDING_REVISION), HttpMethod.POST, request,
String.class);
SeocCreateResponse createResponse = deserialize.createResponse(response.getBody());
actualStatus = createResponse.getStatus();
String message = createResponse.getMessage();
assertThat(actualStatus).isEqualTo(Constants.FAILURE);
assertThat(message).isEqualTo(
"Seoc is not eligible for Pending revision. Current status of SEOC is " + Constants.STATUS_INPROGRESS);
assertThat(HttpStatus.OK).isEqualTo(response.getStatusCode());
}
/**
* Description: Test create pending revision for a Date Hold SEOC
*/
@Test
public void createPendingRevision_failure_dateHold() {
Set<String> billingCodes = new HashSet<String>();
billingCodes.add("code101");
billingCodes.add("code102");
Set<String> clinicalServices = new HashSet<String>();
clinicalServices.add("12-Pulmonary");
CreateServiceRequest serviceRequest = CreateServiceRequest.Builder.create().withDescription("service1")
.withCodeRequired("YES").withVisits(5).withClinicalServices(clinicalServices)
.withBillingCodes(billingCodes).build();
List<CreateServiceRequest> serviceList = new ArrayList<CreateServiceRequest>();
serviceList.add(serviceRequest);
Set<String> hptcs = new HashSet<String>();
hptcs.add("hptc101");
String requestJson = SeocObjectGenerator
.asJsonString(SeocCreateRequest.Builder.create("SeocTest1", "Medical Specialty Care")
.withServiceList(serviceList).withDescription("Description").withDisclaimer("Disclaimer")
.withDuration(5).withMaxVisits(5).withRev(false).withProceduralOverview("Procedural Overview")
.withCategoryOfCare("Pulmonary").withQasp("QASP1").withHptcs(hptcs).build());
HttpEntity<String> request = new HttpEntity<String>(requestJson, headers);
// Create SEOC
ResponseEntity<String> response = restTemplate.exchange(createURLWithPort(ROOT), HttpMethod.POST, request,
String.class);
String actualStatus = deserialize.createResponse(response.getBody()).getStatus();
assertThat(actualStatus).isEqualTo(Constants.CREATED);
assertThat(HttpStatus.CREATED).isEqualTo(response.getStatusCode());
int id = deserialize.createResponse(response.getBody()).getUniqueId();
String eTagHash = response.getHeaders().getETag();
// Activate SEOC
headers.setIfMatch(eTagHash);
requestJson = SeocObjectGenerator
.asJsonString(SeocActivateRequest.Builder.create(id, TestUtil.getEffectiveDateStringFuture()).build());
request = new HttpEntity<String>(requestJson, headers);
response = restTemplate.exchange(createURLWithPort(ROOT + ACTIVATE_SEOC), HttpMethod.POST, request,
String.class);
actualStatus = deserialize.genericResponse(response.getBody()).getStatus();
assertThat(actualStatus).isEqualTo(Constants.SUCCESS);
assertThat(HttpStatus.OK).isEqualTo(response.getStatusCode());
eTagHash = response.getHeaders().getETag();
headers.setIfMatch(eTagHash);
// Try to create a Pending Revision
requestJson = SeocObjectGenerator.asJsonString(SeocGenericRequest.Builder.create(id).build());
request = new HttpEntity<String>(requestJson, headers);
response = restTemplate.exchange(createURLWithPort(ROOT + PENDING_REVISION), HttpMethod.POST, request,
String.class);
SeocCreateResponse createResponse = deserialize.createResponse(response.getBody());
actualStatus = createResponse.getStatus();
String message = createResponse.getMessage();
assertThat(actualStatus).isEqualTo(Constants.FAILURE);
assertThat(message).isEqualTo(
"Seoc is not eligible for Pending revision. Current status of SEOC is " + Constants.STATUS_DATEHOLD);
assertThat(HttpStatus.OK).isEqualTo(response.getStatusCode());
}
/**
* Description: Test create pending revision for a Discontinued SEOC
*/
@Test
public void createPendingRevision_failure_discontinued() {
Set<String> billingCodes = new HashSet<String>();
billingCodes.add("code101");
billingCodes.add("code102");
Set<String> clinicalServices = new HashSet<String>();
clinicalServices.add("12-Pulmonary");
CreateServiceRequest serviceRequest = CreateServiceRequest.Builder.create().withDescription("service1")
.withCodeRequired("YES").withVisits(5).withClinicalServices(clinicalServices)
.withBillingCodes(billingCodes).build();
List<CreateServiceRequest> serviceList = new ArrayList<CreateServiceRequest>();
serviceList.add(serviceRequest);
Set<String> hptcs = new HashSet<String>();
hptcs.add("hptc101");
String requestJson = SeocObjectGenerator
.asJsonString(SeocCreateRequest.Builder.create("SeocTest1", "Medical Specialty Care")
.withServiceList(serviceList).withDescription("Description").withDisclaimer("Disclaimer")
.withDuration(5).withMaxVisits(5).withRev(false).withProceduralOverview("Procedural Overview")
.withCategoryOfCare("Pulmonary").withQasp("QASP1").withHptcs(hptcs).build());
HttpEntity<String> request = new HttpEntity<String>(requestJson, headers);
// Create SEOC
ResponseEntity<String> response = restTemplate.exchange(createURLWithPort(ROOT), HttpMethod.POST, request,
String.class);
String actualStatus = deserialize.createResponse(response.getBody()).getStatus();
assertThat(actualStatus).isEqualTo(Constants.CREATED);
assertThat(HttpStatus.CREATED).isEqualTo(response.getStatusCode());
int id = deserialize.createResponse(response.getBody()).getUniqueId();
String eTagHash = response.getHeaders().getETag();
// Activate SEOC
headers.setIfMatch(eTagHash);
requestJson = SeocObjectGenerator
.asJsonString(SeocActivateRequest.Builder.create(id, TestUtil.getEffectiveDateStringFuture()).build());
request = new HttpEntity<String>(requestJson, headers);
response = restTemplate.exchange(createURLWithPort(ROOT + ACTIVATE_SEOC), HttpMethod.POST, request,
String.class);
actualStatus = deserialize.genericResponse(response.getBody()).getStatus();
assertThat(actualStatus).isEqualTo(Constants.SUCCESS);
assertThat(HttpStatus.OK).isEqualTo(response.getStatusCode());
eTagHash = response.getHeaders().getETag();
// Set Effective Date and End Date to the past
Seoc foundSeoc = seocRepository.findById(id);
foundSeoc.setEffectiveDate(TestUtil.getEffectiveDatePast());
foundSeoc.setEndDate(TestUtil.getEffectiveDatePast());
seocRepository.save(foundSeoc);
// Try to create a Pending Revision
headers.setIfMatch(eTagHash);
requestJson = SeocObjectGenerator.asJsonString(SeocGenericRequest.Builder.create(id).build());
request = new HttpEntity<String>(requestJson, headers);
response = restTemplate.exchange(createURLWithPort(ROOT + PENDING_REVISION), HttpMethod.POST, request,
String.class);
SeocCreateResponse createResponse = deserialize.createResponse(response.getBody());
actualStatus = createResponse.getStatus();
String message = createResponse.getMessage();
assertThat(actualStatus).isEqualTo(Constants.FAILURE);
assertThat(message).isEqualTo("Seoc is not eligible for Pending revision. Current status of SEOC is "
+ Constants.STATUS_DISCONTINUED);
assertThat(HttpStatus.OK).isEqualTo(response.getStatusCode());
}
/**
* Description: Test Seoc Discontinue success scenario. Delete a pending
* revision and discontinue active seoc
*/
@Ignore
public void seocDiscontinue_success() {
Set<String> billingCodes = new HashSet<String>();
billingCodes.add("testBC1");
billingCodes.add("testBC2");
Set<String> clinicalServices = new HashSet<String>();
clinicalServices.add("12-Pulmonary");
CreateServiceRequest serviceRequest = CreateServiceRequest.Builder.create().withDescription("service1")
.withCodeRequired("YES").withVisits(5).withBillingCodes(billingCodes)
.withClinicalServices(clinicalServices).build();
List<CreateServiceRequest> serviceList = new ArrayList<CreateServiceRequest>();
serviceList.add(serviceRequest);
String requestJson = SeocObjectGenerator
.asJsonString(SeocCreateRequest.Builder.create("SeocTest1", "Medical Specialty Care")
.withServiceList(serviceList).withDescription("Description").withDisclaimer("Disclaimer")
.withDuration(5).withMaxVisits(5).withRev(false).withProceduralOverview("Procedural Overview")
.withCategoryOfCare("Pulmonary").withQasp("QASP1").build());
HttpEntity<String> request = new HttpEntity<String>(requestJson, headers);
// Create SEOC
ResponseEntity<String> response = restTemplate.exchange(createURLWithPort(ROOT), HttpMethod.POST, request,
String.class);
int id = deserialize.createResponse(response.getBody()).getUniqueId();
String eTagHash = response.getHeaders().getETag();
// Activate SEOC
headers.setIfMatch(eTagHash);
requestJson = SeocObjectGenerator
.asJsonString(SeocActivateRequest.Builder.create(id, TestUtil.getEffectiveDateString()).build());
request = new HttpEntity<String>(requestJson, headers);
response = restTemplate.exchange(createURLWithPort(ROOT + ACTIVATE_SEOC), HttpMethod.POST, request,
String.class);
String actualStatus = deserialize.genericResponse(response.getBody()).getStatus();
assertThat(actualStatus).isEqualTo(Constants.SUCCESS);
assertThat(HttpStatus.OK).isEqualTo(response.getStatusCode());
// Create Pending revision
requestJson = SeocObjectGenerator.asJsonString(SeocGenericRequest.Builder.create(id).build());
request = new HttpEntity<String>(requestJson, headers);
response = restTemplate.exchange(createURLWithPort(ROOT + PENDING_REVISION), HttpMethod.POST, request,
String.class);
int pendingRevId = deserialize.createResponse(response.getBody()).getUniqueId();
assertThat(deserialize.createResponse(response.getBody()).getStatus()).isEqualTo(Constants.CREATED);
// Discontinue parent seoc
response = restTemplate.exchange(createURLWithPort(ROOT + DISCONTINUE_SEOC + id), HttpMethod.GET, request,
String.class);
List<ChangeLog> logs = logService.getChangeLogBySeocId(id, Constants.EVENT_ACTION_DISCONTINUE);
// Assert ChangeLog records inserted after discontinue
assertThat(logs.size()).isEqualTo(1);
assertThat(logs.get(0).getUser().getVaUserId()).contains(vaUserId);
Seoc discontinuedSeoc = seocService.getSeocById(id);
assertThat(discontinuedSeoc.getCalculatedStatus()).isEqualTo(Constants.STATUS_DISCONTINUED);
assertThat(discontinuedSeoc.getEndDate()).isNotNull();
actualStatus = deserialize.genericResponse(response.getBody()).getStatus();
assertThat(actualStatus).isEqualTo(Constants.SUCCESS);
assertThat(HttpStatus.OK).isEqualTo(response.getStatusCode());
// Assert Pending revision is deleted
Seoc pendingRev = seocService.getSeocById(pendingRevId);
assertThat(pendingRev).isNull();
}
/**
* Description: User1 and User2 trying to update the SEOC .User1 succeeds and
* User2 fails due to race condition.
*
* @throws ExecutionException
* @throws InterruptedException
*/
@Test
public void updateSeoc_firstUserSucceedsRaceCondition() throws ExecutionException, InterruptedException {
// create a new Seoc
String requestJson = SeocObjectGenerator.asJsonString(
SeocCreateRequest.Builder.create("SeocTest1", "Medical Specialty Care").withDescription("Description")
.withDisclaimer("Disclaimer").withDuration(5).withMaxVisits(5).withRev(false)
.withProceduralOverview("Procedural Overview").withCategoryOfCare("Pulmonary").build());
HttpEntity<String> request = new HttpEntity<String>(requestJson, headers);
// Create Request
ResponseEntity<String> response = restTemplate.exchange(createURLWithPort(ROOT), HttpMethod.POST, request,
String.class);
int id = deserialize.createResponse(response.getBody()).getUniqueId();
int seocKey = deserialize.createResponse(response.getBody()).getUniqueId();
// Get etag after creation
String eTagAfterCreate = response.getHeaders().getETag();
// Get Seoc object of the newly created seoc
String requestJsonForUser1 = SeocObjectGenerator
.asJsonString(SeocCreateRequest.Builder.create("SeocTest1", "Medical Specialty Care").withSeocId(id)
.withSeocKey(seocKey).withDescription("Modified description by User-1")
.withDisclaimer("Disclaimer").withDuration(5).withMaxVisits(5).withRev(false)
.withProceduralOverview("Procedural Overview").withCategoryOfCare("Pulmonary").build());
String requestJsonForUser2 = SeocObjectGenerator
.asJsonString(SeocCreateRequest.Builder.create("SeocTest1", "Medical Specialty Care").withSeocId(id)
.withSeocKey(seocKey).withDescription("Modified description by User-2")
.withDisclaimer("Disclaimer").withDuration(5).withMaxVisits(5).withRev(false)
.withProceduralOverview("Procedural Overview").withCategoryOfCare("Pulmonary").build());
// Set the etag in GET request to retrieve
headers.setIfMatch(eTagAfterCreate);
// Try Update Seoc with two users
ScheduledExecutorService executorService = Executors.newSingleThreadScheduledExecutor();
Future<ResponseEntity<String>> user1Response = executorService.submit(() -> {
ResponseEntity<String> firstResponse = restTemplate.exchange(createURLWithPort(ROOT + "/"), HttpMethod.POST,
new HttpEntity<String>(requestJsonForUser1, headers), String.class);
return firstResponse;
});
Future<ResponseEntity<String>> user2Response = executorService.schedule(() -> {
ResponseEntity<String> secondResponse = restTemplate.exchange(createURLWithPort(ROOT + "/"),
HttpMethod.POST, new HttpEntity<String>(requestJsonForUser2, headers), String.class);
return secondResponse;
}, 50, TimeUnit.MILLISECONDS);
executorService.shutdown();
// Assert first user's request successfully went thru
assertThat(deserialize.createResponse(user1Response.get().getBody()).getStatus()).isEqualTo(Constants.UPDATED);
assertThat(deserialize.createResponse(user2Response.get().getBody()).getStatus())
.isNotEqualTo(Constants.UPDATED);
assertThat(user2Response.get().getStatusCode()).isEqualTo(HttpStatus.PRECONDITION_FAILED);
}
/**
* Description: User1 and User2 trying to update the SEOC .User1 failed due to
* pre-condition failure and User2 succeeds.
*
* @throws ExecutionException
* @throws InterruptedException
*/
@Test
public void updateSeoc_raceConditionSecondUserSucceeds() throws ExecutionException, InterruptedException {
// create a new Seoc
String requestJson = SeocObjectGenerator.asJsonString(
SeocCreateRequest.Builder.create("SeocTest1", "Medical Specialty Care").withDescription("Description")
.withDisclaimer("Disclaimer").withDuration(5).withMaxVisits(5).withRev(false)
.withProceduralOverview("Procedural Overview").withCategoryOfCare("Pulmonary").build());
HttpEntity<String> request = new HttpEntity<String>(requestJson, headers);
// Create Request
ResponseEntity<String> response = restTemplate.exchange(createURLWithPort(ROOT), HttpMethod.POST, request,
String.class);
int id = deserialize.createResponse(response.getBody()).getUniqueId();
int seocKey = deserialize.createResponse(response.getBody()).getSeocKey();
// Get etag after creation
String eTagAfterCreate = response.getHeaders().getETag();
// Get Seoc object of the newly created seoc
String requestJsonForUser1 = SeocObjectGenerator
.asJsonString(SeocCreateRequest.Builder.create("SeocTest1", "Medical Specialty Care").withSeocId(id)
.withSeocKey(seocKey).withDescription("Modified description by User-1")
.withDisclaimer("Disclaimer").withDuration(5).withMaxVisits(5).withRev(false)
.withProceduralOverview("Procedural Overview").withCategoryOfCare("Pulmonary").build());
String requestJsonForUser2 = SeocObjectGenerator
.asJsonString(SeocCreateRequest.Builder.create("SeocTest1", "Medical Specialty Care").withSeocId(id)
.withSeocKey(seocKey).withDescription("Modified description by User-2")
.withDisclaimer("Disclaimer").withDuration(5).withMaxVisits(5).withRev(false)
.withProceduralOverview("Procedural Overview").withCategoryOfCare("Pulmonary").build());
// Make first request fail the validation for eTag
HttpHeaders headersUser1 = new HttpHeaders();
headersUser1.setIfMatch("00" + eTagAfterCreate.substring(2));
headersUser1.setContentType(MediaType.APPLICATION_JSON_UTF8);
headersUser1.set(Constants.USERID, vaUserId);
headersUser1.set(Constants.CLIENT_KEY, TestUtil.CLIENT_KEY);
// Try Update Seoc with two users
ScheduledExecutorService executorService = Executors.newSingleThreadScheduledExecutor();
Future<ResponseEntity<String>> user1Response = executorService.submit(() -> {
ResponseEntity<String> firstResponse = restTemplate.exchange(createURLWithPort(ROOT), HttpMethod.POST,
new HttpEntity<String>(requestJsonForUser1, headersUser1), String.class);
return firstResponse;
});
// Set the etag in GET request to retrieve
headers = new HttpHeaders();
setHeaders();
headers.setIfMatch(eTagAfterCreate);
Future<ResponseEntity<String>> user2Response = executorService.schedule(() -> {
ResponseEntity<String> secondResponse = restTemplate.exchange(createURLWithPort(ROOT), HttpMethod.POST,
new HttpEntity<String>(requestJsonForUser2, headers), String.class);
return secondResponse;
}, 25, TimeUnit.MILLISECONDS);
executorService.shutdown();
// Assert first user's request successfully went thru
assertThat(user1Response.get().getStatusCode()).isEqualTo(HttpStatus.PRECONDITION_FAILED);
assertThat(deserialize.createResponse(user2Response.get().getBody()).getStatus()).isEqualTo(Constants.UPDATED);
}
/**
* Description: Check if eTag coming from the SEOC create response is same as
* the one obtained from get SEOC.
*/
@Test
public void checkEtag_afterCreate() {
// create a new Seoc
Set<String> billingCodes = new HashSet<String>();
billingCodes.add("testBC1");
billingCodes.add("testBC2");
CreateServiceRequest serviceRequest = CreateServiceRequest.Builder.create().withDescription("service1")
.withCodeRequired("YES").withVisits(0).withBillingCodes(billingCodes)
.withClinicalServices(new HashSet<String>()).build();
List<CreateServiceRequest> serviceList = new ArrayList<CreateServiceRequest>();
serviceList.add(serviceRequest);
String requestJson = SeocObjectGenerator.asJsonString(SeocCreateRequest.Builder
.create("SeocTest1", "Medical Specialty Care").withServiceList(serviceList)
.withDescription("Description").withDisclaimer("Disclaimer").withDuration(5).withMaxVisits(5)
.withRev(false).withProceduralOverview("Procedural Overview").withCategoryOfCare("Pulmonary").build());
HttpEntity<String> request = new HttpEntity<String>(requestJson, headers);
// Create Request
ResponseEntity<String> response = restTemplate.exchange(createURLWithPort(ROOT), HttpMethod.POST, request,
String.class);
int id = deserialize.createResponse(response.getBody()).getUniqueId();
String eTagFromCreate = response.getHeaders().getETag();
// Get seoc by Id
request = new HttpEntity<String>(null, headers);
response = restTemplate.exchange(createURLWithPort(ROOT + "/" + id), HttpMethod.GET, request, String.class);
String eTagFromGet = response.getHeaders().getETag();
// Assert that eTag is same for seoc for created and retrieved by get operation
assertThat(SeocServiceHelper.unpadEtag(eTagFromGet)).isEqualTo(SeocServiceHelper.unpadEtag(eTagFromCreate));
}
/**
* Description: Check if eTag is updated when the SEOC is updated.
*/
@Test
public void checkEtag_afterUpdate() {
// create a new Seoc
String requestJson = SeocObjectGenerator.asJsonString(
SeocCreateRequest.Builder.create("SeocTest1", "Medical Specialty Care").withDescription("Description")
.withDisclaimer("Disclaimer").withDuration(5).withMaxVisits(5).withRev(false)
.withProceduralOverview("Procedural Overview").withCategoryOfCare("Pulmonary").build());
HttpEntity<String> request = new HttpEntity<String>(requestJson, headers);
// Create Request
ResponseEntity<String> response = restTemplate.exchange(createURLWithPort(ROOT), HttpMethod.POST, request,
String.class);
int id = deserialize.createResponse(response.getBody()).getUniqueId();
int seocKey = deserialize.createResponse(response.getBody()).getSeocKey();
// Get Before Doing another update
request = new HttpEntity<String>(null, headers);
response = restTemplate.exchange(createURLWithPort(ROOT + "/" + id), HttpMethod.GET, request, String.class);
String eTagFromGet = response.getHeaders().getETag();
// Update the same Seoc
requestJson = SeocObjectGenerator.asJsonString(SeocCreateRequest.Builder
.create("SeocTest1", "Medical Specialty Care").withSeocId(id).withSeocKey(seocKey)
.withDescription("Description Changed").withDisclaimer("Disclaimer").withDuration(5).withMaxVisits(5)
.withRev(false).withProceduralOverview("Procedural Overview").withCategoryOfCare("Pulmonary").build());
headers.setIfMatch(eTagFromGet);
request = new HttpEntity<String>(requestJson, headers);
// Update Request
response = restTemplate.exchange(createURLWithPort(ROOT), HttpMethod.POST, request, String.class);
String eTagFromUpdate = response.getHeaders().getETag();
// Assert that eTag changed after doing update on the same seoc
assertThat(SeocServiceHelper.unpadEtag(eTagFromUpdate)).isNotEqualTo(SeocServiceHelper.unpadEtag(eTagFromGet));
}
/**
* Description: Etag missing in the if-Match. Response - PreConditionFailed
*/
@Test
public void etagMissing_ifMatchFailed() {
// Create a new Seoc
String requestJson = SeocObjectGenerator.asJsonString(
SeocCreateRequest.Builder.create("SeocTest1", "Medical Specialty Care").withDescription("Description")
.withDisclaimer("Disclaimer").withDuration(5).withMaxVisits(5).withRev(false)
.withProceduralOverview("Procedural Overview").withCategoryOfCare("Pulmonary").build());
HttpEntity<String> request = new HttpEntity<String>(requestJson, headers);
// Create Request
ResponseEntity<String> response = restTemplate.exchange(createURLWithPort(ROOT), HttpMethod.POST, request,
String.class);
int id = deserialize.createResponse(response.getBody()).getUniqueId();
int seocKey = deserialize.createResponse(response.getBody()).getSeocKey();
// Get Before Doing another update
request = new HttpEntity<String>(null, headers);
response = restTemplate.exchange(createURLWithPort(ROOT + "/" + id), HttpMethod.GET, request, String.class);
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK);
// Update the same Seoc
requestJson = SeocObjectGenerator.asJsonString(SeocCreateRequest.Builder
.create("SeocTest1", "Medical Specialty Care").withSeocId(id).withSeocKey(seocKey)
.withDescription("Description Changed").withDisclaimer("Disclaimer").withDuration(5).withMaxVisits(5)
.withRev(false).withProceduralOverview("Procedural Overview").withCategoryOfCare("Pulmonary").build());
request = new HttpEntity<String>(requestJson, headers);
// Update Request
response = restTemplate.exchange(createURLWithPort(ROOT), HttpMethod.POST, request, String.class);
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.BAD_REQUEST);
}
/**
* Description: User1 is trying to activate, User2 tries to update. User1
* succeeds and User2 fails with PreConditionFailed.
*
* @throws ExecutionException
* @throws InterruptedException
*/
@Test
public void activateUpdate_raceConditionUser1Succeeds() throws ExecutionException, InterruptedException {
// create a new Seoc
Set<String> billingCodes = new HashSet<String>();
billingCodes.add("code101");
billingCodes.add("code102");
Set<String> clinicalServices = new HashSet<String>();
clinicalServices.add("12-Pulmonary");
CreateServiceRequest serviceRequest = CreateServiceRequest.Builder.create().withDescription("service1")
.withCodeRequired("YES").withVisits(5).withClinicalServices(clinicalServices)
.withBillingCodes(billingCodes).build();
List<CreateServiceRequest> serviceList = new ArrayList<CreateServiceRequest>();
serviceList.add(serviceRequest);
Set<String> hptcs = new HashSet<String>();
hptcs.add("hptc103");
String requestJson = SeocObjectGenerator
.asJsonString(SeocCreateRequest.Builder.create("SeocTest1", "Medical Specialty Care")
.withDescription("Description").withDisclaimer("Disclaimer").withDuration(5).withMaxVisits(5)
.withRev(false).withProceduralOverview("Procedural Overview").withCategoryOfCare("Pulmonary")
.withServiceList(serviceList).withQasp("QASP1").withHptcs(hptcs).build());
HttpEntity<String> request = new HttpEntity<String>(requestJson, headers);
// Create Request
ResponseEntity<String> response = restTemplate.exchange(createURLWithPort(ROOT), HttpMethod.POST, request,
String.class);
int id = deserialize.createResponse(response.getBody()).getUniqueId();
int seocKey = deserialize.createResponse(response.getBody()).getSeocKey();
// Get etag after creation
String eTagAfterCreate = response.getHeaders().getETag();
// Get Seoc object of the newly created seoc
String requestJsonForUser2 = SeocObjectGenerator
.asJsonString(SeocCreateRequest.Builder.create("SeocTest1", "Medical Specialty Care").withSeocId(id)
.withSeocKey(seocKey).withDescription("Modified description by User-2")
.withDisclaimer("Disclaimer").withDuration(5).withMaxVisits(5).withRev(false)
.withProceduralOverview("Procedural Overview").withCategoryOfCare("Pulmonary")
.withServiceList(serviceList).withQasp("QASP1").withHptcs(hptcs).build());
// Make first request fail the validation for eTag
HttpHeaders headersUser1 = new HttpHeaders();
headersUser1.setIfMatch(eTagAfterCreate);
headersUser1.setContentType(MediaType.APPLICATION_JSON_UTF8);
headersUser1.set(Constants.USERID, vaUserId);
headersUser1.set(Constants.CLIENT_KEY, TestUtil.CLIENT_KEY);
// User1 tries to Activate and User2 tries to Update
ScheduledExecutorService executorService = Executors.newSingleThreadScheduledExecutor();
Future<ResponseEntity<String>> user1Response = executorService.submit(() -> {
String activateRequestJson = SeocObjectGenerator
.asJsonString(SeocActivateRequest.Builder.create(id, TestUtil.getEffectiveDateString()).build());
HttpEntity<String> firstRequest = new HttpEntity<String>(activateRequestJson, headersUser1);
ResponseEntity<String> firstResponse = restTemplate.exchange(createURLWithPort(ROOT + ACTIVATE_SEOC),
HttpMethod.POST, firstRequest, String.class);
return firstResponse;
});
// Set the etag in GET request to retrieve
headers = new HttpHeaders();
setHeaders();
headers.setIfMatch(eTagAfterCreate);
Future<ResponseEntity<String>> user2Response = executorService.schedule(() -> {
ResponseEntity<String> secondResponse = restTemplate.exchange(createURLWithPort(ROOT + "/"),
HttpMethod.POST, new HttpEntity<String>(requestJsonForUser2, headers), String.class);
return secondResponse;
}, 25, TimeUnit.MILLISECONDS);
executorService.shutdown();
// Assert first user's request successfully went thru
assertThat(user1Response.get().getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat(user2Response.get().getStatusCode()).isEqualTo(HttpStatus.PRECONDITION_FAILED);
}
/**
* Description: User1 trying to Activate and User2 trying to update. User1
* failed due to validation error hence User2 succeeds
*
* @throws ExecutionException
* @throws InterruptedException
*/
@Test
public void activateUpdate_raceConditionUser2Succeeds() throws ExecutionException, InterruptedException {
// create a new Seoc
Set<String> billingCodes = new HashSet<String>();
billingCodes.add("testBC1");
billingCodes.add("testBC2");
Set<String> clinicalServices = new HashSet<String>();
clinicalServices.add("12-Pulmonary");
CreateServiceRequest serviceRequest = CreateServiceRequest.Builder.create().withDescription("service1")
.withCodeRequired("YES").withVisits(5).withClinicalServices(clinicalServices)
.withBillingCodes(billingCodes).build();
List<CreateServiceRequest> serviceList = new ArrayList<CreateServiceRequest>();
serviceList.add(serviceRequest);
Set<String> hptcs = new HashSet<String>();
hptcs.add("hptc103");
String requestJson = SeocObjectGenerator
.asJsonString(SeocCreateRequest.Builder.create("SeocTest1", "Medical Specialty Care")
.withDescription("Description").withDisclaimer("Disclaimer").withDuration(5).withMaxVisits(5)
.withRev(false).withProceduralOverview("Procedural Overview").withCategoryOfCare("Pulmonary")
.withServiceList(serviceList).withHptcs(hptcs).build());
HttpEntity<String> request = new HttpEntity<String>(requestJson, headers);
// Create Request
ResponseEntity<String> response = restTemplate.exchange(createURLWithPort(ROOT), HttpMethod.POST, request,
String.class);
int id = deserialize.createResponse(response.getBody()).getUniqueId();
int seocKey = deserialize.createResponse(response.getBody()).getSeocKey();
// Get etag after creation
String eTagAfterCreate = response.getHeaders().getETag();
// Get Seoc object of the newly created seoc
String requestJsonForUser2 = SeocObjectGenerator
.asJsonString(SeocCreateRequest.Builder.create("SeocTest1", "Medical Specialty Care").withSeocId(id)
.withSeocKey(seocKey).withDescription("Modified description by User-2")
.withDisclaimer("Disclaimer").withDuration(5).withMaxVisits(5).withRev(false)
.withProceduralOverview("Procedural Overview").withCategoryOfCare("Pulmonary")
.withServiceList(serviceList).withQasp("QASP1").withHptcs(hptcs).build());
// Make first request fail the validation for eTag
HttpHeaders headersUser1 = new HttpHeaders();
headersUser1.setIfMatch(eTagAfterCreate);
headersUser1.setContentType(MediaType.APPLICATION_JSON_UTF8);
headersUser1.set(Constants.USERID, vaUserId);
// User1 tries to Activate and User2 tries to Update
ScheduledExecutorService executorService = Executors.newSingleThreadScheduledExecutor();
Future<ResponseEntity<String>> user1Response = executorService.submit(() -> {
String activateRequestJson = SeocObjectGenerator
.asJsonString(SeocActivateRequest.Builder.create(id, TestUtil.getEffectiveDateString()).build());
HttpEntity<String> firstRequest = new HttpEntity<String>(activateRequestJson, headers);
ResponseEntity<String> firstResponse = restTemplate.exchange(createURLWithPort(ROOT + ACTIVATE_SEOC),
HttpMethod.POST, firstRequest, String.class);
return firstResponse;
});
// Set the etag in GET request to retrieve
headers = new HttpHeaders();
setHeaders();
headers.setIfMatch(eTagAfterCreate);
Future<ResponseEntity<String>> user2Response = executorService.schedule(() -> {
ResponseEntity<String> secondResponse = restTemplate.exchange(createURLWithPort(ROOT + "/"),
HttpMethod.POST, new HttpEntity<String>(requestJsonForUser2, headers), String.class);
return secondResponse;
}, 25, TimeUnit.MILLISECONDS);
executorService.shutdown();
// Assert first user's request successfully went thru
assertThat(user1Response.get().getStatusCode()).isEqualTo(HttpStatus.BAD_REQUEST);
assertThat(deserialize.createResponse(user2Response.get().getBody()).getStatus()).isEqualTo(Constants.UPDATED);
}
/**
* Description: User1 trying to delete and User2 trying to update. User1
* succeeds and User2 fails with NO_CONTENT message.
*
* @throws ExecutionException
* @throws InterruptedException
*/
@Test
public void deleteUpdate_raceConditionUser1Succeeds() throws ExecutionException, InterruptedException {
// create a new Seoc
Set<String> billingCodes = new HashSet<String>();
billingCodes.add("testBC1");
billingCodes.add("testBC2");
Set<String> clinicalServices = new HashSet<String>();
clinicalServices.add("12-Pulmonary");
CreateServiceRequest serviceRequest = CreateServiceRequest.Builder.create().withDescription("service1")
.withCodeRequired("YES").withVisits(5).withClinicalServices(clinicalServices)
.withBillingCodes(billingCodes).build();
List<CreateServiceRequest> serviceList = new ArrayList<CreateServiceRequest>();
serviceList.add(serviceRequest);
Set<String> hptcs = new HashSet<String>();
hptcs.add("hptc103");
String requestJson = SeocObjectGenerator
.asJsonString(SeocCreateRequest.Builder.create("SeocTest1", "Medical Specialty Care")
.withDescription("Description").withDisclaimer("Disclaimer").withDuration(5).withMaxVisits(5)
.withRev(false).withProceduralOverview("Procedural Overview").withCategoryOfCare("Pulmonary")
.withServiceList(serviceList).withQasp("QASP1").withHptcs(hptcs).build());
HttpEntity<String> request = new HttpEntity<String>(requestJson, headers);
// Create Request
ResponseEntity<String> response = restTemplate.exchange(createURLWithPort(ROOT), HttpMethod.POST, request,
String.class);
int id = deserialize.createResponse(response.getBody()).getUniqueId();
int seocKey = deserialize.createResponse(response.getBody()).getSeocKey();
// Get etag after creation
String eTagAfterCreate = response.getHeaders().getETag();
// Get Seoc object of the newly created seoc
String requestJsonForUser2 = SeocObjectGenerator
.asJsonString(SeocCreateRequest.Builder.create("SeocTest1", "Medical Specialty Care").withSeocId(id)
.withSeocKey(seocKey).withDescription("Modified description by User-1")
.withDisclaimer("Disclaimer").withDuration(5).withMaxVisits(5).withRev(false)
.withProceduralOverview("Procedural Overview").withCategoryOfCare("Pulmonary")
.withServiceList(serviceList).withQasp("QASP1").withHptcs(hptcs).build());
// Make first request fail the validation for eTag
HttpHeaders headersUser1 = new HttpHeaders();
headersUser1.setIfMatch(eTagAfterCreate);
headersUser1.setContentType(MediaType.APPLICATION_JSON_UTF8);
headersUser1.set(Constants.USERID, vaUserId);
headersUser1.set(Constants.CLIENT_KEY, TestUtil.CLIENT_KEY);
// User1 tries to Activate and User2 tries to Update
ScheduledExecutorService executorService = Executors.newSingleThreadScheduledExecutor();
Future<ResponseEntity<String>> user1Response = executorService.submit(() -> {
HttpEntity<String> firstRequest = new HttpEntity<>(headers);
ResponseEntity<String> firstResponse = restTemplate.exchange(createURLWithPort(ROOT + DELETE_SEOC + id),
HttpMethod.GET, firstRequest, String.class);
return firstResponse;
});
// Set the etag in GET request to retrieve
headers = new HttpHeaders();
setHeaders();
headers.setIfMatch(eTagAfterCreate);
Future<ResponseEntity<String>> user2Response = executorService.schedule(() -> {
ResponseEntity<String> secondResponse = restTemplate.exchange(createURLWithPort(ROOT + "/"),
HttpMethod.POST, new HttpEntity<String>(requestJsonForUser2, headersUser1), String.class);
return secondResponse;
}, 25, TimeUnit.MILLISECONDS);
executorService.shutdown();
// Assert first user's request successfully went thru
assertThat(user1Response.get().getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat(user2Response.get().getStatusCode()).isEqualTo(HttpStatus.NO_CONTENT);
}
/**
* Description: User1 trying to update and User2 trying to delete. User1
* succeeds and User2 fails with PRECONDITIONFAILED
*
* @throws ExecutionException
* @throws InterruptedException
*/
@Test
public void deleteUpdate_raceConditionUser2Succeeds() throws ExecutionException, InterruptedException {
// create a new Seoc
Set<String> billingCodes = new HashSet<String>();
billingCodes.add("testBC1");
billingCodes.add("testBC2");
Set<String> clinicalServices = new HashSet<String>();
clinicalServices.add("12-Pulmonary");
CreateServiceRequest serviceRequest = CreateServiceRequest.Builder.create().withDescription("service1")
.withCodeRequired("YES").withVisits(5).withClinicalServices(clinicalServices)
.withBillingCodes(billingCodes).build();
List<CreateServiceRequest> serviceList = new ArrayList<CreateServiceRequest>();
serviceList.add(serviceRequest);
Set<String> hptcs = new HashSet<String>();
hptcs.add("hptc103");
String requestJson = SeocObjectGenerator
.asJsonString(SeocCreateRequest.Builder.create("SeocTest1", "Medical Specialty Care")
.withDescription("Description").withDisclaimer("Disclaimer").withDuration(5).withMaxVisits(5)
.withRev(false).withProceduralOverview("Procedural Overview").withCategoryOfCare("Pulmonary")
.withServiceList(serviceList).withQasp("QASP1").withHptcs(hptcs).build());
HttpEntity<String> request = new HttpEntity<String>(requestJson, headers);
// Create Request
ResponseEntity<String> response = restTemplate.exchange(createURLWithPort(ROOT), HttpMethod.POST, request,
String.class);
int id = deserialize.createResponse(response.getBody()).getUniqueId();
int seocKey = deserialize.createResponse(response.getBody()).getSeocKey();
// Get etag after creation
String eTagAfterCreate = response.getHeaders().getETag();
// User1 updating the service data
serviceRequest = CreateServiceRequest.Builder.create().withDescription("service1").withCodeRequired("NO")
.withVisits(5).withClinicalServices(clinicalServices).build();
List<CreateServiceRequest> serviceListUpdated = new ArrayList<CreateServiceRequest>();
serviceListUpdated.add(serviceRequest);
// Get Seoc object of the newly created seoc
String requestJsonForUser1 = SeocObjectGenerator
.asJsonString(SeocCreateRequest.Builder.create("SeocTest1", "Medical Specialty Care").withSeocId(id)
.withSeocKey(seocKey).withDescription("Modified description by User-1")
.withDisclaimer("Disclaimer").withDuration(5).withMaxVisits(5).withRev(false)
.withProceduralOverview("Procedural Overview").withCategoryOfCare("Pulmonary")
.withServiceList(serviceListUpdated).withQasp("QASP1").withHptcs(hptcs).build());
// Make first request fail the validation for eTag
HttpHeaders headersUser1 = new HttpHeaders();
headersUser1.setIfMatch(eTagAfterCreate);
headersUser1.setContentType(MediaType.APPLICATION_JSON_UTF8);
headersUser1.set(Constants.USERID, vaUserId);
headersUser1.set(Constants.CLIENT_KEY, TestUtil.CLIENT_KEY);
// User1 tries to Activate and User2 tries to Update
ScheduledExecutorService executorService = Executors.newSingleThreadScheduledExecutor();
Future<ResponseEntity<String>> user1Response = executorService.submit(() -> {
ResponseEntity<String> firstResponse = restTemplate.exchange(createURLWithPort(ROOT + "/"), HttpMethod.POST,
new HttpEntity<String>(requestJsonForUser1, headersUser1), String.class);
return firstResponse;
});
// Set the etag in GET request to retrieve
headers = new HttpHeaders();
setHeaders();
headers.setIfMatch(eTagAfterCreate);
Future<ResponseEntity<String>> user2Response = executorService.schedule(() -> {
HttpEntity<String> secondRequest = new HttpEntity<>(headers);
ResponseEntity<String> secondResponse = restTemplate.exchange(createURLWithPort(ROOT + DELETE_SEOC + id),
HttpMethod.GET, secondRequest, String.class);
return secondResponse;
}, 25, TimeUnit.MILLISECONDS);
executorService.shutdown();
// Assert first user's request successfully went thru
assertThat(user1Response.get().getStatusCode()).isEqualTo(HttpStatus.CREATED);
assertThat(user2Response.get().getStatusCode()).isEqualTo(HttpStatus.PRECONDITION_FAILED);
}
/**
* Description:User1 trying to activate and User2 trying to delete. User1
* succeeds and User2 fails with PRECONDITIONFAILED
*
* @throws ExecutionException
* @throws InterruptedException
*/
@Test
public void activateDelete_raceConditionActivateSucceeds() throws ExecutionException, InterruptedException {
// create a new Seoc
Set<String> billingCodes = new HashSet<String>();
billingCodes.add("code101");
billingCodes.add("code102");
Set<String> clinicalServices = new HashSet<String>();
clinicalServices.add("12-Pulmonary");
CreateServiceRequest serviceRequest = CreateServiceRequest.Builder.create().withDescription("service1")
.withCodeRequired("YES").withVisits(5).withClinicalServices(clinicalServices)
.withBillingCodes(billingCodes).build();
List<CreateServiceRequest> serviceList = new ArrayList<CreateServiceRequest>();
serviceList.add(serviceRequest);
Set<String> hptcs = new HashSet<String>();
hptcs.add("hptc103");
String requestJson = SeocObjectGenerator
.asJsonString(SeocCreateRequest.Builder.create("SeocTest1", "Medical Specialty Care")
.withDescription("Description").withDisclaimer("Disclaimer").withDuration(5).withMaxVisits(5)
.withRev(false).withProceduralOverview("Procedural Overview").withCategoryOfCare("Pulmonary")
.withServiceList(serviceList).withQasp("QASP1").withHptcs(hptcs).build());
HttpEntity<String> request = new HttpEntity<String>(requestJson, headers);
// Create Request
ResponseEntity<String> response = restTemplate.exchange(createURLWithPort(ROOT), HttpMethod.POST, request,
String.class);
int id = deserialize.createResponse(response.getBody()).getUniqueId();
// Get etag after creation
String eTagAfterCreate = response.getHeaders().getETag();
HttpHeaders headersUser1 = new HttpHeaders();
headersUser1.setIfMatch(eTagAfterCreate);
headersUser1.setContentType(MediaType.APPLICATION_JSON_UTF8);
headersUser1.set(Constants.USERID, vaUserId);
// User1 tries to Activate and User2 tries to Delete
ScheduledExecutorService executorService = Executors.newSingleThreadScheduledExecutor();
Future<ResponseEntity<String>> user1Response = executorService.submit(() -> {
String activateRequestJson = SeocObjectGenerator
.asJsonString(SeocActivateRequest.Builder.create(id, TestUtil.getEffectiveDateString()).build());
HttpEntity<String> firstRequest = new HttpEntity<String>(activateRequestJson, headers);
ResponseEntity<String> firstResponse = restTemplate.exchange(createURLWithPort(ROOT + ACTIVATE_SEOC),
HttpMethod.POST, firstRequest, String.class);
return firstResponse;
});
// Set the etag in GET request to retrieve
headers = new HttpHeaders();
setHeaders();
headers.setIfMatch(eTagAfterCreate);
Future<ResponseEntity<String>> user2Response = executorService.schedule(() -> {
HttpEntity<String> secondRequest = new HttpEntity<>(headers);
ResponseEntity<String> secondResponse = restTemplate.exchange(createURLWithPort(ROOT + DELETE_SEOC + id),
HttpMethod.GET, secondRequest, String.class);
return secondResponse;
}, 25, TimeUnit.MILLISECONDS);
executorService.shutdown();
// Assert first user's request successfully went thru
assertThat(user1Response.get().getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat(user2Response.get().getStatusCode()).isEqualTo(HttpStatus.PRECONDITION_FAILED);
}
/**
* Description: User1 trying to Delete, User2 trying to Activate. User1 succeeds
* and User2 gets NO_CONTENT
*
* @throws ExecutionException
* @throws InterruptedException
*/
@Test
public void deleteActivate_raceConditionDeletionSucceeds() throws ExecutionException, InterruptedException {
// create a new Seoc
Set<String> billingCodes = new HashSet<String>();
billingCodes.add("testBC1");
billingCodes.add("testBC2");
Set<String> clinicalServices = new HashSet<String>();
clinicalServices.add("12-Pulmonary");
CreateServiceRequest serviceRequest = CreateServiceRequest.Builder.create().withDescription("service1")
.withCodeRequired("YES").withVisits(5).withClinicalServices(clinicalServices)
.withBillingCodes(billingCodes).build();
List<CreateServiceRequest> serviceList = new ArrayList<CreateServiceRequest>();
serviceList.add(serviceRequest);
Set<String> hptcs = new HashSet<String>();
hptcs.add("hptc103");
String requestJson = SeocObjectGenerator
.asJsonString(SeocCreateRequest.Builder.create("SeocTest1", "Medical Specialty Care")
.withDescription("Description").withDisclaimer("Disclaimer").withDuration(5).withMaxVisits(5)
.withRev(false).withProceduralOverview("Procedural Overview").withCategoryOfCare("Pulmonary")
.withServiceList(serviceList).withQasp("QASP1").withHptcs(hptcs).build());
HttpEntity<String> request = new HttpEntity<String>(requestJson, headers);
// Create Request
ResponseEntity<String> response = restTemplate.exchange(createURLWithPort(ROOT), HttpMethod.POST, request,
String.class);
int id = deserialize.createResponse(response.getBody()).getUniqueId();
// Get etag after creation
String eTagAfterCreate = response.getHeaders().getETag();
HttpHeaders headersUser1 = new HttpHeaders();
headersUser1.setIfMatch(eTagAfterCreate);
headersUser1.setContentType(MediaType.APPLICATION_JSON_UTF8);
headersUser1.set(Constants.USERID, vaUserId);
// User1 tries to Delete and User2 tries to Activate
ScheduledExecutorService executorService = Executors.newSingleThreadScheduledExecutor();
Future<ResponseEntity<String>> user1Response = executorService.submit(() -> {
HttpEntity<String> firstRequest = new HttpEntity<>(headers);
ResponseEntity<String> firstResponse = restTemplate.exchange(createURLWithPort(ROOT + DELETE_SEOC + id),
HttpMethod.GET, firstRequest, String.class);
return firstResponse;
});
// Set the etag in GET request to retrieve
headers = new HttpHeaders();
setHeaders();
headers.setIfMatch(eTagAfterCreate);
Future<ResponseEntity<String>> user2Response = executorService.schedule(() -> {
String activateRequestJson = SeocObjectGenerator
.asJsonString(SeocActivateRequest.Builder.create(id, TestUtil.getEffectiveDateString()).build());
HttpEntity<String> secondRequest = new HttpEntity<String>(activateRequestJson, headers);
ResponseEntity<String> secondResponse = restTemplate.exchange(createURLWithPort(ROOT + ACTIVATE_SEOC),
HttpMethod.POST, secondRequest, String.class);
return secondResponse;
}, 25, TimeUnit.MILLISECONDS);
executorService.shutdown();
// Assert first user's request successfully went thru
assertThat(user1Response.get().getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat(user2Response.get().getStatusCode()).isEqualTo(HttpStatus.NO_CONTENT);
}
/**
* Description: Successfully reverse Date Hold SEOC
*/
@Test
public void reverseSeoc_success() {
Set<String> billingCodes = new HashSet<String>();
billingCodes.add("code101");
billingCodes.add("code102");
Set<String> clinicalServices = new HashSet<String>();
clinicalServices.add("12-Pulmonary");
CreateServiceRequest serviceRequest = CreateServiceRequest.Builder.create().withDescription("service1")
.withCodeRequired("YES").withVisits(5).withClinicalServices(clinicalServices)
.withBillingCodes(billingCodes).build();
List<CreateServiceRequest> serviceList = new ArrayList<CreateServiceRequest>();
serviceList.add(serviceRequest);
Set<String> hptcs = new HashSet<String>();
hptcs.add("hptc101");
String requestJson = SeocObjectGenerator.asJsonString(SeocCreateRequest.Builder.create("SeocTest1", "Radiology")
.withServiceList(serviceList).withDescription("Description").withDisclaimer("Disclaimer")
.withDuration(5).withMaxVisits(5).withRev(false).withProceduralOverview("Procedural Overview")
.withCategoryOfCare("Acupuncture12").withQasp("QASP1").withHptcs(hptcs).build());
HttpEntity<String> request = new HttpEntity<String>(requestJson, headers);
// Create SEOC
ResponseEntity<String> response = restTemplate.exchange(createURLWithPort(ROOT), HttpMethod.POST, request,
String.class);
assertThat(HttpStatus.CREATED).isEqualTo(response.getStatusCode());
int id = deserialize.createResponse(response.getBody()).getUniqueId();
String etagHash = response.getHeaders().getETag();
// Activate SEOC
headers.setIfMatch(etagHash);
requestJson = SeocObjectGenerator
.asJsonString(SeocActivateRequest.Builder.create(id, TestUtil.getEffectiveDateString()).build());
request = new HttpEntity<String>(requestJson, headers);
response = restTemplate.exchange(createURLWithPort(ROOT + ACTIVATE_SEOC), HttpMethod.POST, request,
String.class);
SeocGenericResponse seocGenericResponse = deserialize.genericResponse(response.getBody());
String actualStatus = seocGenericResponse.getStatus();
assertThat(actualStatus).isEqualTo(Constants.SUCCESS);
assertThat(HttpStatus.OK).isEqualTo(response.getStatusCode());
etagHash = response.getHeaders().getETag();
// Reverse SEOC
headers.setIfMatch(etagHash);
request = new HttpEntity<>(headers);
response = restTemplate.exchange(createURLWithPort(ROOT + REVERSE_SEOC + id), HttpMethod.GET, request,
String.class);
List<ChangeLog> logs = logService.getChangeLogBySeocId(id, Constants.EVENT_ACTION_REVERSE);
// Assert ChangeLog records inserted after reverse
assertThat(logs.size()).isEqualTo(1);
assertThat(logs.get(0).getUser().getVaUserId()).contains(vaUserId);
Seoc reversedSeoc = seocService.getSeocById(id);
assertThat(reversedSeoc.getCalculatedStatus()).isEqualTo(Constants.STATUS_INPROGRESS);
assertThat(reversedSeoc.getVersionNumber()).isNull();
assertThat(reversedSeoc.getEffectiveDate()).isNull();
assertThat(reversedSeoc.getActivatedTimestamp()).isNull();
assertThat(reversedSeoc.getActivatedBy()).isNull();
seocGenericResponse = deserialize.genericResponse(response.getBody());
assertThat(seocGenericResponse.getSeocId()).isEqualTo(reversedSeoc.getId());
assertThat(seocGenericResponse.getSeocKey()).isEqualTo(reversedSeoc.getSeocKey());
assertThat(seocGenericResponse.getStatus()).isEqualTo(Constants.SUCCESS);
assertThat(HttpStatus.OK).isEqualTo(response.getStatusCode());
}
/**
* Description: Successfully reverse Revision Date Hold SEOC
*/
@Test
public void reverseSeoc_success_pendingRevision() {
int id = 3;
// Seoc1 - Get existing Active Seoc
HttpEntity<String> request = new HttpEntity<>(headers);
ResponseEntity<String> response = restTemplate.exchange(createURLWithPort(ROOT + id), HttpMethod.GET, request,
String.class);
String etagHash = response.getHeaders().getETag();
// Create Pending revision
headers.setIfMatch(etagHash);
String requestJson = SeocObjectGenerator.asJsonString(SeocGenericRequest.Builder.create(id).build());
request = new HttpEntity<String>(requestJson, headers);
response = restTemplate.exchange(createURLWithPort(ROOT + PENDING_REVISION), HttpMethod.POST, request,
String.class);
SeocCreateResponse createResponse = deserialize.createResponse(response.getBody());
int pendingRevId = createResponse.getUniqueId();
assertThat(createResponse.getStatus()).isEqualTo(Constants.CREATED);
response = restTemplate.exchange(createURLWithPort(ROOT + pendingRevId), HttpMethod.GET, request, String.class);
etagHash = response.getHeaders().getETag();
// Activate the newly created pending revision
headers.setIfMatch(etagHash);
requestJson = SeocObjectGenerator.asJsonString(
SeocActivateRequest.Builder.create(pendingRevId, TestUtil.getEffectiveDateString()).build());
request = new HttpEntity<String>(requestJson, headers);
response = restTemplate.exchange(createURLWithPort(ROOT + ACTIVATE_SEOC), HttpMethod.POST, request,
String.class);
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK);
etagHash = response.getHeaders().getETag();
// Reverse SEOC
headers.setIfMatch(etagHash);
request = new HttpEntity<>(headers);
response = restTemplate.exchange(createURLWithPort(ROOT + REVERSE_SEOC + pendingRevId), HttpMethod.GET, request,
String.class);
List<ChangeLog> logs = logService.getChangeLogBySeocId(pendingRevId, Constants.EVENT_ACTION_REVERSE);
// Assert ChangeLog records inserted after reverse
assertThat(logs.size()).isEqualTo(1);
assertThat(logs.get(0).getUser().getVaUserId()).contains(vaUserId);
Seoc reversedSeoc = seocService.getSeocById(pendingRevId);
Seoc previousSeoc = seocService.getSeocById(id);
assertThat(reversedSeoc.getCalculatedStatus()).isEqualTo(Constants.STATUS_INPROGRESS);
assertThat(reversedSeoc.getVersionNumber()).isEqualTo(Constants.VERSION_PENDING_REVISION);
assertThat(reversedSeoc.getEffectiveDate()).isNull();
assertThat(reversedSeoc.getActivatedTimestamp()).isNull();
assertThat(reversedSeoc.getActivatedBy()).isNull();
assertThat(previousSeoc.getEndDate()).isNull();
assertThat(previousSeoc.getDiscontinuedTimestamp()).isNull();
assertThat(previousSeoc.getDiscontinuedBy()).isNull();
SeocGenericResponse seocGenericResponse = deserialize.genericResponse(response.getBody());
assertThat(seocGenericResponse.getSeocId()).isEqualTo(reversedSeoc.getId());
assertThat(seocGenericResponse.getSeocKey()).isEqualTo(reversedSeoc.getSeocKey());
assertThat(seocGenericResponse.getStatus()).isEqualTo(Constants.SUCCESS);
assertThat(HttpStatus.OK).isEqualTo(response.getStatusCode());
// Delete the Pending Revision to clean up the data
etagHash = response.getHeaders().getETag();
headers.setIfMatch(etagHash);
request = new HttpEntity<>(headers);
response = restTemplate.exchange(createURLWithPort(ROOT + DELETE_SEOC + pendingRevId), HttpMethod.GET, request,
String.class);
assertThat(HttpStatus.OK).isEqualTo(response.getStatusCode());
}
/**
* Description: Successful SEOC Reversal should update the ETag
*/
@Test
public void reverseSeoc_success_changeETag() {
Set<String> billingCodes = new HashSet<String>();
billingCodes.add("code101");
billingCodes.add("code102");
Set<String> clinicalServices = new HashSet<String>();
clinicalServices.add("12-Pulmonary");
CreateServiceRequest serviceRequest = CreateServiceRequest.Builder.create().withDescription("service1")
.withCodeRequired("YES").withVisits(5).withClinicalServices(clinicalServices)
.withBillingCodes(billingCodes).build();
List<CreateServiceRequest> serviceList = new ArrayList<CreateServiceRequest>();
serviceList.add(serviceRequest);
Set<String> hptcs = new HashSet<String>();
hptcs.add("hptc101");
String requestJson = SeocObjectGenerator.asJsonString(SeocCreateRequest.Builder.create("SeocTest1", "Radiology")
.withServiceList(serviceList).withDescription("Description").withDisclaimer("Disclaimer")
.withDuration(5).withMaxVisits(5).withRev(false).withProceduralOverview("Procedural Overview")
.withCategoryOfCare("Acupuncture12").withQasp("QASP1").withHptcs(hptcs).build());
HttpEntity<String> request = new HttpEntity<String>(requestJson, headers);
// Create SEOC
ResponseEntity<String> response = restTemplate.exchange(createURLWithPort(ROOT), HttpMethod.POST, request,
String.class);
assertThat(HttpStatus.CREATED).isEqualTo(response.getStatusCode());
int id = deserialize.createResponse(response.getBody()).getUniqueId();
String etagHash = response.getHeaders().getETag();
// Activate SEOC
headers.setIfMatch(etagHash);
requestJson = SeocObjectGenerator
.asJsonString(SeocActivateRequest.Builder.create(id, TestUtil.getEffectiveDateString()).build());
request = new HttpEntity<String>(requestJson, headers);
response = restTemplate.exchange(createURLWithPort(ROOT + ACTIVATE_SEOC), HttpMethod.POST, request,
String.class);
SeocGenericResponse seocGenericResponse = deserialize.genericResponse(response.getBody());
String actualStatus = seocGenericResponse.getStatus();
assertThat(actualStatus).isEqualTo(Constants.SUCCESS);
assertThat(HttpStatus.OK).isEqualTo(response.getStatusCode());
String eTagHash = response.getHeaders().getETag();
// Reverse SEOC
headers.setIfMatch(eTagHash);
request = new HttpEntity<>(headers);
response = restTemplate.exchange(createURLWithPort(ROOT + REVERSE_SEOC + id), HttpMethod.GET, request,
String.class);
assertThat(response.getHeaders().getETag()).isNotEqualTo(eTagHash);
}
/**
* Description: Reverse SEOC - IfMatch header is missing
*/
@Test
public void reverseSeoc_failure_missingIfMatch() {
Set<String> billingCodes = new HashSet<String>();
billingCodes.add("code101");
billingCodes.add("code102");
Set<String> clinicalServices = new HashSet<String>();
clinicalServices.add("12-Pulmonary");
CreateServiceRequest serviceRequest = CreateServiceRequest.Builder.create().withDescription("service1")
.withCodeRequired("YES").withVisits(5).withClinicalServices(clinicalServices)
.withBillingCodes(billingCodes).build();
List<CreateServiceRequest> serviceList = new ArrayList<CreateServiceRequest>();
serviceList.add(serviceRequest);
Set<String> hptcs = new HashSet<String>();
hptcs.add("hptc101");
String requestJson = SeocObjectGenerator.asJsonString(SeocCreateRequest.Builder.create("SeocTest1", "Radiology")
.withServiceList(serviceList).withDescription("Description").withDisclaimer("Disclaimer")
.withDuration(5).withMaxVisits(5).withRev(false).withProceduralOverview("Procedural Overview")
.withCategoryOfCare("Acupuncture12").withQasp("QASP1").withHptcs(hptcs).build());
HttpEntity<String> request = new HttpEntity<String>(requestJson, headers);
// Create SEOC
ResponseEntity<String> response = restTemplate.exchange(createURLWithPort(ROOT), HttpMethod.POST, request,
String.class);
assertThat(HttpStatus.CREATED).isEqualTo(response.getStatusCode());
int id = deserialize.createResponse(response.getBody()).getUniqueId();
String eTagHash = response.getHeaders().getETag();
// Activate SEOC
headers.setIfMatch(eTagHash);
requestJson = SeocObjectGenerator
.asJsonString(SeocActivateRequest.Builder.create(id, TestUtil.getEffectiveDateString()).build());
request = new HttpEntity<String>(requestJson, headers);
response = restTemplate.exchange(createURLWithPort(ROOT + ACTIVATE_SEOC), HttpMethod.POST, request,
String.class);
SeocGenericResponse seocGenericResponse = deserialize.genericResponse(response.getBody());
String actualStatus = seocGenericResponse.getStatus();
assertThat(actualStatus).isEqualTo(Constants.SUCCESS);
assertThat(HttpStatus.OK).isEqualTo(response.getStatusCode());
HttpHeaders reverseHeaders = new HttpHeaders();
reverseHeaders.setContentType(MediaType.APPLICATION_JSON_UTF8);
reverseHeaders.set(Constants.USERID, vaUserId);
reverseHeaders.set(Constants.CLIENT_KEY, TestUtil.CLIENT_KEY);
request = new HttpEntity<>(reverseHeaders);
response = restTemplate.exchange(createURLWithPort(ROOT + REVERSE_SEOC + id), HttpMethod.GET, request,
String.class);
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.BAD_REQUEST);
assertThat(response.getBody())
.isEqualTo("Reverse is not initiated. IfMatch tag missing in the request headers");
}
/**
* Description: Reverse SEOC - vaUserId header is missing
*/
@Test
public void reverseSeoc_failure_missingUserId() {
Set<String> billingCodes = new HashSet<String>();
billingCodes.add("code101");
billingCodes.add("code102");
Set<String> clinicalServices = new HashSet<String>();
clinicalServices.add("12-Pulmonary");
CreateServiceRequest serviceRequest = CreateServiceRequest.Builder.create().withDescription("service1")
.withCodeRequired("YES").withVisits(5).withClinicalServices(clinicalServices)
.withBillingCodes(billingCodes).build();
List<CreateServiceRequest> serviceList = new ArrayList<CreateServiceRequest>();
serviceList.add(serviceRequest);
Set<String> hptcs = new HashSet<String>();
hptcs.add("hptc101");
String requestJson = SeocObjectGenerator.asJsonString(SeocCreateRequest.Builder.create("SeocTest1", "Radiology")
.withServiceList(serviceList).withDescription("Description").withDisclaimer("Disclaimer")
.withDuration(5).withMaxVisits(5).withRev(false).withProceduralOverview("Procedural Overview")
.withCategoryOfCare("Acupuncture12").withQasp("QASP1").withHptcs(hptcs).build());
HttpEntity<String> request = new HttpEntity<String>(requestJson, headers);
// Create SEOC
ResponseEntity<String> response = restTemplate.exchange(createURLWithPort(ROOT), HttpMethod.POST, request,
String.class);
assertThat(HttpStatus.CREATED).isEqualTo(response.getStatusCode());
int id = deserialize.createResponse(response.getBody()).getUniqueId();
String eTagHash = response.getHeaders().getETag();
// Activate SEOC
headers.setIfMatch(eTagHash);
requestJson = SeocObjectGenerator
.asJsonString(SeocActivateRequest.Builder.create(id, TestUtil.getEffectiveDateString()).build());
request = new HttpEntity<String>(requestJson, headers);
response = restTemplate.exchange(createURLWithPort(ROOT + ACTIVATE_SEOC), HttpMethod.POST, request,
String.class);
SeocGenericResponse seocGenericResponse = deserialize.genericResponse(response.getBody());
String actualStatus = seocGenericResponse.getStatus();
assertThat(actualStatus).isEqualTo(Constants.SUCCESS);
assertThat(HttpStatus.OK).isEqualTo(response.getStatusCode());
HttpHeaders reverseHeaders = new HttpHeaders();
reverseHeaders.setContentType(MediaType.APPLICATION_JSON_UTF8);
reverseHeaders.setIfMatch(response.getHeaders().getETag());
reverseHeaders.set(Constants.CLIENT_KEY, TestUtil.CLIENT_KEY);
request = new HttpEntity<>(reverseHeaders);
response = restTemplate.exchange(createURLWithPort(ROOT + REVERSE_SEOC + id), HttpMethod.GET, request,
String.class);
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.BAD_REQUEST);
assertThat(response.getBody()).isEqualTo("Reverse is not initiated. UserId is missing in the request headers");
}
/**
* Description: Reverse SEOC - SEOC Id is invalid
*/
@Test
public void reverseSeoc_failure_invalidSeocId() {
Set<String> billingCodes = new HashSet<String>();
billingCodes.add("code101");
billingCodes.add("code102");
Set<String> clinicalServices = new HashSet<String>();
clinicalServices.add("12-Pulmonary");
CreateServiceRequest serviceRequest = CreateServiceRequest.Builder.create().withDescription("service1")
.withCodeRequired("YES").withVisits(5).withClinicalServices(clinicalServices)
.withBillingCodes(billingCodes).build();
List<CreateServiceRequest> serviceList = new ArrayList<CreateServiceRequest>();
serviceList.add(serviceRequest);
Set<String> hptcs = new HashSet<String>();
hptcs.add("hptc101");
String requestJson = SeocObjectGenerator.asJsonString(SeocCreateRequest.Builder.create("SeocTest1", "Radiology")
.withServiceList(serviceList).withDescription("Description").withDisclaimer("Disclaimer")
.withDuration(5).withMaxVisits(5).withRev(false).withProceduralOverview("Procedural Overview")
.withCategoryOfCare("Acupuncture12").withQasp("QASP1").withHptcs(hptcs).build());
HttpEntity<String> request = new HttpEntity<String>(requestJson, headers);
// Create SEOC
ResponseEntity<String> response = restTemplate.exchange(createURLWithPort(ROOT), HttpMethod.POST, request,
String.class);
assertThat(HttpStatus.CREATED).isEqualTo(response.getStatusCode());
int id = deserialize.createResponse(response.getBody()).getUniqueId();
String eTagHash = response.getHeaders().getETag();
// Activate SEOC
headers.setIfMatch(eTagHash);
requestJson = SeocObjectGenerator
.asJsonString(SeocActivateRequest.Builder.create(id, TestUtil.getEffectiveDateString()).build());
request = new HttpEntity<String>(requestJson, headers);
response = restTemplate.exchange(createURLWithPort(ROOT + ACTIVATE_SEOC), HttpMethod.POST, request,
String.class);
SeocGenericResponse seocGenericResponse = deserialize.genericResponse(response.getBody());
String actualStatus = seocGenericResponse.getStatus();
assertThat(actualStatus).isEqualTo(Constants.SUCCESS);
assertThat(HttpStatus.OK).isEqualTo(response.getStatusCode());
eTagHash = response.getHeaders().getETag();
headers.setIfMatch(eTagHash);
request = new HttpEntity<>(headers);
response = restTemplate.exchange(createURLWithPort(ROOT + REVERSE_SEOC + 0), HttpMethod.GET, request,
String.class);
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.BAD_REQUEST);
assertThat(response.getBody()).isEqualTo("Reverse is not initiated. SEOC Id is missing in the request");
}
/**
* Description: User1 and User2 are trying to reverse a SEOC User1 succeeds and
* User2 fails with PRECONDITIONFAILED
*
* @throws ExecutionException
* @throws InterruptedException
*/
@Test
public void reverseSeoc_raceCondition() throws ExecutionException, InterruptedException {
Set<String> billingCodes = new HashSet<String>();
billingCodes.add("code101");
billingCodes.add("code102");
Set<String> clinicalServices = new HashSet<String>();
clinicalServices.add("12-Pulmonary");
CreateServiceRequest serviceRequest = CreateServiceRequest.Builder.create().withDescription("service1")
.withCodeRequired("YES").withVisits(5).withClinicalServices(clinicalServices)
.withBillingCodes(billingCodes).build();
List<CreateServiceRequest> serviceList = new ArrayList<CreateServiceRequest>();
serviceList.add(serviceRequest);
Set<String> hptcs = new HashSet<String>();
hptcs.add("hptc101");
String requestJson = SeocObjectGenerator.asJsonString(SeocCreateRequest.Builder.create("SeocTest1", "Radiology")
.withServiceList(serviceList).withDescription("Description").withDisclaimer("Disclaimer")
.withDuration(5).withMaxVisits(5).withRev(false).withProceduralOverview("Procedural Overview")
.withCategoryOfCare("Acupuncture12").withQasp("QASP1").withHptcs(hptcs).build());
HttpEntity<String> request = new HttpEntity<String>(requestJson, headers);
// Create SEOC
ResponseEntity<String> response = restTemplate.exchange(createURLWithPort(ROOT), HttpMethod.POST, request,
String.class);
assertThat(HttpStatus.CREATED).isEqualTo(response.getStatusCode());
int id = deserialize.createResponse(response.getBody()).getUniqueId();
String eTagHash = response.getHeaders().getETag();
// Activate SEOC
headers.setIfMatch(eTagHash);
requestJson = SeocObjectGenerator
.asJsonString(SeocActivateRequest.Builder.create(id, TestUtil.getEffectiveDateString()).build());
request = new HttpEntity<String>(requestJson, headers);
response = restTemplate.exchange(createURLWithPort(ROOT + ACTIVATE_SEOC), HttpMethod.POST, request,
String.class);
SeocGenericResponse seocGenericResponse = deserialize.genericResponse(response.getBody());
String actualStatus = seocGenericResponse.getStatus();
assertThat(actualStatus).isEqualTo(Constants.SUCCESS);
assertThat(HttpStatus.OK).isEqualTo(response.getStatusCode());
eTagHash = response.getHeaders().getETag();
headers.setIfMatch(eTagHash);
// User1 and User2 try to reverse the SEOC
ScheduledExecutorService executorService = Executors.newSingleThreadScheduledExecutor();
Future<ResponseEntity<String>> user1Response = executorService.submit(() -> {
HttpEntity<String> firstRequest = new HttpEntity<>(headers);
ResponseEntity<String> firstResponse = restTemplate.exchange(createURLWithPort(ROOT + REVERSE_SEOC + id),
HttpMethod.GET, firstRequest, String.class);
return firstResponse;
});
Future<ResponseEntity<String>> user2Response = executorService.schedule(() -> {
HttpEntity<String> secondRequest = new HttpEntity<>(headers);
ResponseEntity<String> secondResponse = restTemplate.exchange(createURLWithPort(ROOT + REVERSE_SEOC + id),
HttpMethod.GET, secondRequest, String.class);
return secondResponse;
}, 25, TimeUnit.MILLISECONDS);
executorService.shutdown();
// Assert first user's request successfully went through
assertThat(user1Response.get().getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat(user2Response.get().getStatusCode()).isEqualTo(HttpStatus.PRECONDITION_FAILED);
}
/**
* Description: User1 is trying to reverse a Date Hold SEOC, User 2 reverses and
* deletes the Date Hold SEOC
*
* @throws ExecutionException
* @throws InterruptedException
*/
@Test
public void reverseDeleteSeoc_raceCondition() throws ExecutionException, InterruptedException {
Set<String> billingCodes = new HashSet<String>();
billingCodes.add("code101");
billingCodes.add("code102");
Set<String> clinicalServices = new HashSet<String>();
clinicalServices.add("12-Pulmonary");
CreateServiceRequest serviceRequest = CreateServiceRequest.Builder.create().withDescription("service1")
.withCodeRequired("YES").withVisits(5).withClinicalServices(clinicalServices)
.withBillingCodes(billingCodes).build();
List<CreateServiceRequest> serviceList = new ArrayList<CreateServiceRequest>();
serviceList.add(serviceRequest);
Set<String> hptcs = new HashSet<String>();
hptcs.add("hptc101");
String requestJson = SeocObjectGenerator.asJsonString(SeocCreateRequest.Builder.create("SeocTest1", "Radiology")
.withServiceList(serviceList).withDescription("Description").withDisclaimer("Disclaimer")
.withDuration(5).withMaxVisits(5).withRev(false).withProceduralOverview("Procedural Overview")
.withCategoryOfCare("Acupuncture12").withQasp("QASP1").withHptcs(hptcs).build());
HttpEntity<String> request = new HttpEntity<String>(requestJson, headers);
// Create SEOC
ResponseEntity<String> response = restTemplate.exchange(createURLWithPort(ROOT), HttpMethod.POST, request,
String.class);
assertThat(HttpStatus.CREATED).isEqualTo(response.getStatusCode());
int id = deserialize.createResponse(response.getBody()).getUniqueId();
String eTagHash = response.getHeaders().getETag();
// Activate SEOC
headers.setIfMatch(eTagHash);
requestJson = SeocObjectGenerator
.asJsonString(SeocActivateRequest.Builder.create(id, TestUtil.getEffectiveDateString()).build());
request = new HttpEntity<String>(requestJson, headers);
response = restTemplate.exchange(createURLWithPort(ROOT + ACTIVATE_SEOC), HttpMethod.POST, request,
String.class);
SeocGenericResponse seocGenericResponse = deserialize.genericResponse(response.getBody());
String actualStatus = seocGenericResponse.getStatus();
assertThat(actualStatus).isEqualTo(Constants.SUCCESS);
assertThat(HttpStatus.OK).isEqualTo(response.getStatusCode());
final String activateHash = response.getHeaders().getETag();
headers.setIfMatch(activateHash);
// User 1 tries to reverse the SEOC, User 2 reverses and deletes the SEOC
ScheduledExecutorService executorService = Executors.newSingleThreadScheduledExecutor();
Future<ResponseEntity<String>> user1Response = executorService.schedule(() -> {
HttpEntity<String> firstRequest = new HttpEntity<>(headers);
ResponseEntity<String> firstResponse = restTemplate.exchange(createURLWithPort(ROOT + REVERSE_SEOC + id),
HttpMethod.GET, firstRequest, String.class);
return firstResponse;
}, 100, TimeUnit.MILLISECONDS);
Future<ResponseEntity<String>> user2Response = executorService.submit(() -> {
HttpHeaders user2Headers = new HttpHeaders();
user2Headers.setContentType(MediaType.APPLICATION_JSON_UTF8);
user2Headers.set(Constants.USERID, vaUserId);
user2Headers.setIfMatch(activateHash);
user2Headers.set(Constants.CLIENT_KEY, TestUtil.CLIENT_KEY);
HttpEntity<String> secondRequest = new HttpEntity<>(user2Headers);
ResponseEntity<String> secondResponse = restTemplate.exchange(createURLWithPort(ROOT + REVERSE_SEOC + id),
HttpMethod.GET, secondRequest, String.class);
user2Headers.setIfMatch(secondResponse.getHeaders().getETag());
secondRequest = new HttpEntity<>(user2Headers);
secondResponse = restTemplate.exchange(createURLWithPort(ROOT + DELETE_SEOC + id), HttpMethod.GET,
secondRequest, String.class);
return secondResponse;
});
assertThat(user1Response.get().getStatusCode()).isEqualTo(HttpStatus.BAD_REQUEST);
assertThat(user2Response.get().getStatusCode()).isEqualTo(HttpStatus.OK);
}
/**
* Description: User1 is trying to reverse a Date Hold SEOC, User 2 reverses,
* updates, and activates the SEOC
*
* @throws ExecutionException
* @throws InterruptedException
*/
@Test
public void reverseUpdateSeoc_raceCondition() throws ExecutionException, InterruptedException {
Set<String> billingCodes = new HashSet<String>();
billingCodes.add("code101");
billingCodes.add("code102");
Set<String> clinicalServices = new HashSet<String>();
clinicalServices.add("12-Pulmonary");
CreateServiceRequest serviceRequest = CreateServiceRequest.Builder.create().withDescription("service1")
.withCodeRequired("YES").withVisits(5).withClinicalServices(clinicalServices)
.withBillingCodes(billingCodes).build();
List<CreateServiceRequest> serviceList = new ArrayList<CreateServiceRequest>();
serviceList.add(serviceRequest);
Set<String> hptcs = new HashSet<String>();
hptcs.add("hptc101");
String requestJson = SeocObjectGenerator.asJsonString(SeocCreateRequest.Builder.create("SeocTest1", "Radiology")
.withServiceList(serviceList).withDescription("Description").withDisclaimer("Disclaimer")
.withDuration(5).withMaxVisits(5).withRev(false).withProceduralOverview("Procedural Overview")
.withCategoryOfCare("Acupuncture12").withQasp("QASP1").withHptcs(hptcs).build());
HttpEntity<String> request = new HttpEntity<String>(requestJson, headers);
// Create SEOC
ResponseEntity<String> response = restTemplate.exchange(createURLWithPort(ROOT), HttpMethod.POST, request,
String.class);
assertThat(HttpStatus.CREATED).isEqualTo(response.getStatusCode());
SeocCreateResponse createResponse = deserialize.createResponse(response.getBody());
int id = createResponse.getUniqueId();
int seocKey = createResponse.getSeocKey();
String eTagHash = response.getHeaders().getETag();
// Activate SEOC
headers.setIfMatch(eTagHash);
requestJson = SeocObjectGenerator
.asJsonString(SeocActivateRequest.Builder.create(id, TestUtil.getEffectiveDateString()).build());
request = new HttpEntity<String>(requestJson, headers);
response = restTemplate.exchange(createURLWithPort(ROOT + ACTIVATE_SEOC), HttpMethod.POST, request,
String.class);
SeocGenericResponse seocGenericResponse = deserialize.genericResponse(response.getBody());
String actualStatus = seocGenericResponse.getStatus();
assertThat(actualStatus).isEqualTo(Constants.SUCCESS);
assertThat(HttpStatus.OK).isEqualTo(response.getStatusCode());
final String activateHash = response.getHeaders().getETag();
headers.setIfMatch(activateHash);
// User 1 tries to reverse the SEOC, User 2 reverses, updates, and activates the
// SEOC
ScheduledExecutorService executorService = Executors.newSingleThreadScheduledExecutor();
Future<ResponseEntity<String>> user1Response = executorService.schedule(() -> {
HttpEntity<String> firstRequest = new HttpEntity<>(headers);
ResponseEntity<String> firstResponse = restTemplate.exchange(createURLWithPort(ROOT + REVERSE_SEOC + id),
HttpMethod.GET, firstRequest, String.class);
return firstResponse;
}, 100, TimeUnit.MILLISECONDS);
Future<ResponseEntity<String>> user2Response = executorService.submit(() -> {
HttpHeaders user2Headers = new HttpHeaders();
user2Headers.setContentType(MediaType.APPLICATION_JSON_UTF8);
user2Headers.set(Constants.USERID, vaUserId);
user2Headers.setIfMatch(activateHash);
user2Headers.set(Constants.CLIENT_KEY, TestUtil.CLIENT_KEY);
HttpEntity<String> secondRequest = new HttpEntity<>(user2Headers);
ResponseEntity<String> secondResponse = restTemplate.exchange(createURLWithPort(ROOT + REVERSE_SEOC + id),
HttpMethod.GET, secondRequest, String.class);
user2Headers.setIfMatch(secondResponse.getHeaders().getETag());
String requestJsonForUser2 = SeocObjectGenerator
.asJsonString(SeocCreateRequest.Builder.create("SeocTest1", "Medical Specialty Care").withSeocId(id)
.withSeocKey(seocKey).withDescription("Modified description by User-2")
.withDisclaimer("Disclaimer").withDuration(5).withMaxVisits(5).withRev(false)
.withProceduralOverview("Procedural Overview").withCategoryOfCare("Pulmonary")
.withServiceList(serviceList).withQasp("QASP1").withHptcs(hptcs).build());
secondRequest = new HttpEntity<String>(requestJsonForUser2, user2Headers);
secondResponse = restTemplate.exchange(createURLWithPort(ROOT + "/"), HttpMethod.POST, secondRequest,
String.class);
user2Headers.setIfMatch(secondResponse.getHeaders().getETag());
requestJsonForUser2 = SeocObjectGenerator
.asJsonString(SeocActivateRequest.Builder.create(id, TestUtil.getEffectiveDateString()).build());
secondRequest = new HttpEntity<String>(requestJsonForUser2, user2Headers);
secondResponse = restTemplate.exchange(createURLWithPort(ROOT + ACTIVATE_SEOC), HttpMethod.POST,
secondRequest, String.class);
return secondResponse;
});
assertThat(user1Response.get().getStatusCode()).isEqualTo(HttpStatus.PRECONDITION_FAILED);
assertThat(user2Response.get().getStatusCode()).isEqualTo(HttpStatus.OK);
}
/**
* Description: Reverse SEOC - SEOC not valid for reversal
*/
@Test
public void reverseSeoc_failure_invalidSeoc() {
Set<String> billingCodes = new HashSet<String>();
billingCodes.add("code101");
billingCodes.add("code102");
Set<String> clinicalServices = new HashSet<String>();
clinicalServices.add("12-Pulmonary");
CreateServiceRequest serviceRequest = CreateServiceRequest.Builder.create().withDescription("service1")
.withCodeRequired("YES").withVisits(5).withClinicalServices(clinicalServices)
.withBillingCodes(billingCodes).build();
List<CreateServiceRequest> serviceList = new ArrayList<CreateServiceRequest>();
serviceList.add(serviceRequest);
Set<String> hptcs = new HashSet<String>();
hptcs.add("hptc101");
String requestJson = SeocObjectGenerator.asJsonString(SeocCreateRequest.Builder.create("SeocTest1", "Radiology")
.withServiceList(serviceList).withDescription("Description").withDisclaimer("Disclaimer")
.withDuration(5).withMaxVisits(5).withRev(false).withProceduralOverview("Procedural Overview")
.withCategoryOfCare("Acupuncture12").withQasp("QASP1").withHptcs(hptcs).build());
HttpEntity<String> request = new HttpEntity<String>(requestJson, headers);
// Create SEOC
ResponseEntity<String> response = restTemplate.exchange(createURLWithPort(ROOT), HttpMethod.POST, request,
String.class);
assertThat(HttpStatus.CREATED).isEqualTo(response.getStatusCode());
int id = deserialize.createResponse(response.getBody()).getUniqueId();
String eTagHash = response.getHeaders().getETag();
headers.setIfMatch(eTagHash);
request = new HttpEntity<>(headers);
response = restTemplate.exchange(createURLWithPort(ROOT + REVERSE_SEOC + id), HttpMethod.GET, request,
String.class);
SeocGenericResponse seocGenericResponse = deserialize.genericResponse(response.getBody());
assertThat(seocGenericResponse.getStatus()).isEqualTo(Constants.FAILURE);
assertThat(seocGenericResponse.getMessage()).isEqualTo(
"Seoc is not eligible for reversal. Current status of SEOC is " + Constants.STATUS_INPROGRESS);
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.BAD_REQUEST);
}
/**
* Description: Successfully create billing code
*/
@Test
public void testCreateBillingCodeSuccess() {
CreateBillingCodeRequest billingCodeRequest = CreateBillingCodeRequest.Builder.create().withBillingCode("bc1")
.withCodeType("CT").withDescription("BC1 Desc").withPrecertRequired(false).build();
String requestJson = SeocObjectGenerator.asJsonString(billingCodeRequest);
HttpEntity<String> request = new HttpEntity<String>(requestJson, headers);
ResponseEntity<String> response = restTemplate.exchange(createURLWithPort(ROOT + "createBillingCode"),
HttpMethod.POST, request, String.class);
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.CREATED);
}
/**
* Description:Failed to create new billing code due to a pre-existing billing
* code
*/
@Test
public void createBillingCode_failure() {
CreateBillingCodeRequest billingCodeRequest = CreateBillingCodeRequest.Builder.create()
.withBillingCode(" code101 ").withCodeType("CT").withDescription(" BC1 Desc ")
.withPrecertRequired(false).build();
String requestJson = SeocObjectGenerator.asJsonString(billingCodeRequest);
HttpEntity<String> request = new HttpEntity<String>(requestJson, headers);
ResponseEntity<String> response = restTemplate.exchange(createURLWithPort(ROOT + "createBillingCode"),
HttpMethod.POST, request, String.class);
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.CONFLICT);
}
/**
* Description:Failed to create new Billing code due to failed validations
*/
@Test
public void createBillingCode_validationFails() {
CreateBillingCodeRequest billingCodeRequest = CreateBillingCodeRequest.Builder.create()
.withBillingCode("code101324#$^^**(*(*&&^%sd").withCodeType("code101324#$^^**(*(*&&^%sd")
.withDescription("BC1 Desc").withPrecertRequired(false).build();
String requestJson = SeocObjectGenerator.asJsonString(billingCodeRequest);
HttpEntity<String> request = new HttpEntity<String>(requestJson, headers);
ResponseEntity<String> response = restTemplate.exchange(createURLWithPort(ROOT + "createBillingCode"),
HttpMethod.POST, request, String.class);
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.BAD_REQUEST);
}
@Test
public void discontinueBillingCode_success() {
int activeId = 2;
HttpEntity<String> request = new HttpEntity<String>(null, headers);
int prevRevId = 6;
String billingCode = "code103";
// Seoc1 - Get existing Active Seoc
request = new HttpEntity<>(headers);
ResponseEntity<String> response = restTemplate.exchange(createURLWithPort(ROOT + prevRevId), HttpMethod.GET,
request, String.class);
String eTagHash = response.getHeaders().getETag();
// Create Pending revision
headers.setIfMatch(eTagHash);
String requestJson = SeocObjectGenerator.asJsonString(SeocGenericRequest.Builder.create(prevRevId).build());
request = new HttpEntity<String>(requestJson, headers);
response = restTemplate.exchange(createURLWithPort(ROOT + PENDING_REVISION), HttpMethod.POST, request,
String.class);
int pendingRevId = deserialize.createResponse(response.getBody()).getUniqueId();
assertThat(deserialize.createResponse(response.getBody()).getStatus()).isEqualTo(Constants.CREATED);
// Get Seoc after creation of pending revision
response = restTemplate.exchange(createURLWithPort(ROOT + pendingRevId), HttpMethod.GET, request, String.class);
// assert that the billing code is available before deletion
assertThat(response.getBody()).contains(
"{\"id\":3,\"description\":\"description3\",\"precertRequired\":true,\"billingCode\":\"code103\",\"codeType\":\"CPT\",\"deactivated\":false}");
// Seoc2 - Inprogress Seoc
Set<String> billingCodes = new HashSet<String>();
billingCodes.add(billingCode);
billingCodes.add("testBC2");
Set<String> clinicalServices = new HashSet<String>();
clinicalServices.add("12-Pulmonary");
CreateServiceRequest serviceRequest = CreateServiceRequest.Builder.create().withDescription("service1")
.withCodeRequired("YES").withVisits(5).withClinicalServices(clinicalServices)
.withBillingCodes(billingCodes).build();
List<CreateServiceRequest> serviceList = new ArrayList<CreateServiceRequest>();
serviceList.add(serviceRequest);
Set<String> hptcs = new HashSet<String>();
hptcs.add("hptc101");
requestJson = SeocObjectGenerator
.asJsonString(SeocCreateRequest.Builder.create("SeocInprogressTest1", "Radiology")
.withServiceList(serviceList).withDescription("Description").withDisclaimer("Disclaimer")
.withDuration(5).withMaxVisits(5).withRev(false).withProceduralOverview("Procedural Overview")
.withCategoryOfCare("Acupuncture12").withQasp("QASP1").withHptcs(hptcs).build());
request = new HttpEntity<String>(requestJson, headers);
response = restTemplate.exchange(createURLWithPort(ROOT), HttpMethod.POST, request, String.class);
int inProgressSeocId = deserialize.createResponse(response.getBody()).getUniqueId();
// Get Seoc after creation
response = restTemplate.exchange(createURLWithPort(ROOT + inProgressSeocId), HttpMethod.GET, request,
String.class);
// assert that the billing code is available before billing code deletion
assertThat(response.getBody()).contains(
"{\"id\":3,\"description\":\"description3\",\"precertRequired\":true,\"billingCode\":\"code103\",\"codeType\":\"CPT\",\"deactivated\":false}");
// Seoc3 - Activated and in DateHold. Still not activated
billingCodes = new HashSet<String>();
billingCodes.add("testBC1");
billingCodes.add(billingCode);
serviceRequest = CreateServiceRequest.Builder.create().withDescription("service1").withCodeRequired("YES")
.withVisits(5).withClinicalServices(clinicalServices).withBillingCodes(billingCodes).build();
serviceList = new ArrayList<CreateServiceRequest>();
serviceList.add(serviceRequest);
hptcs = new HashSet<String>();
hptcs.add("hptc101");
requestJson = SeocObjectGenerator
.asJsonString(SeocCreateRequest.Builder.create("SeocActivatedTest1", "Radiology")
.withServiceList(serviceList).withDescription("Description").withDisclaimer("Disclaimer")
.withDuration(5).withMaxVisits(5).withRev(false).withProceduralOverview("Procedural Overview")
.withCategoryOfCare("Acupuncture12").withQasp("QASP1").withHptcs(hptcs).build());
request = new HttpEntity<String>(requestJson, headers);
response = restTemplate.exchange(createURLWithPort(ROOT), HttpMethod.POST, request, String.class);
int idForDateHoldSeoc = deserialize.createResponse(response.getBody()).getUniqueId();
String createHashForDateHoldSeoc = response.getHeaders().getETag();
// Activate
headers.setIfMatch(createHashForDateHoldSeoc);
requestJson = SeocObjectGenerator.asJsonString(
SeocActivateRequest.Builder.create(idForDateHoldSeoc, TestUtil.getEffectiveDateString()).build());
request = new HttpEntity<String>(requestJson, headers);
response = restTemplate.exchange(createURLWithPort(ROOT + ACTIVATE_SEOC), HttpMethod.POST, request,
String.class);
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK);
// Get Seoc after activation
response = restTemplate.exchange(createURLWithPort(ROOT + idForDateHoldSeoc), HttpMethod.GET, request,
String.class);
// assert that the billing code is available and not deactivated before billing
// code discontinued
assertThat(response.getBody()).contains(
"{\"id\":3,\"description\":\"description3\",\"precertRequired\":true,\"billingCode\":\"code103\",\"codeType\":\"CPT\",\"deactivated\":false}");
// DISCONTINUE BILLING CODE
CreateBillingCodeRequest billingCodeRequest = CreateBillingCodeRequest.Builder.create()
.withPrevBillingCode(billingCode).build();
requestJson = SeocObjectGenerator.asJsonString(billingCodeRequest);
request = new HttpEntity<String>(requestJson, headers);
switchMaintenanceMode("true");
response = restTemplate.exchange(createURLWithPort(ROOT + MANAGE_BC), HttpMethod.PUT, request, String.class);
switchMaintenanceMode("false");
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK);
// Get Active Seoc after discontinuing billing code
response = restTemplate.exchange(createURLWithPort(ROOT + activeId), HttpMethod.GET, request, String.class);
// assert that billing code is not deleted
assertThat(response.getBody()).contains(
"{\"id\":3,\"description\":\"description3\",\"precertRequired\":true,\"billingCode\":\"code103\",\"codeType\":\"CPT\",\"deactivated\":true}");
// Get Pending Revision for the Active Seoc
Set<Seoc> seocVersions = seocService.getBySeocKey(2);
Seoc pendingRevision = seocVersions.stream().filter(s -> s.getEffectiveDate() == null)
.collect(Collectors.toSet()).toArray(new Seoc[1])[0];
response = restTemplate.exchange(createURLWithPort(ROOT + pendingRevision.getId()), HttpMethod.GET, request,
String.class);
// assert that billing code is deleted
assertThat(response.getBody()).doesNotContain(
"{\"id\":3,\"description\":\"description3\",\"precertRequired\":true,\"billingCode\":\"code103\",\"codeType\":\"CPT\",\"deactivated\":false}");
assertThat(response.getBody()).doesNotContain(
"{\"id\":3,\"description\":\"description3\",\"precertRequired\":true,\"billingCode\":\"code103\",\"codeType\":\"CPT\",\"deactivated\":true}");
// Get Previous revision Seoc after discontinuing billing code
response = restTemplate.exchange(createURLWithPort(ROOT + prevRevId), HttpMethod.GET, request, String.class);
// assert that billing code is not deleted
assertThat(response.getBody()).contains(
"{\"id\":3,\"description\":\"description3\",\"precertRequired\":true,\"billingCode\":\"code103\",\"codeType\":\"CPT\",\"deactivated\":true}");
// Get Pending revision Seoc after discontinuing billing code
response = restTemplate.exchange(createURLWithPort(ROOT + pendingRevId), HttpMethod.GET, request, String.class);
// assert that billing code is deleted
assertThat(response.getBody()).doesNotContain(
"{\"id\":3,\"description\":\"description3\",\"precertRequired\":true,\"billingCode\":\"code103\",\"codeType\":\"CPT\",\"deactivated\":false}");
assertThat(response.getBody()).doesNotContain(
"{\"id\":3,\"description\":\"description3\",\"precertRequired\":true,\"billingCode\":\"code103\",\"codeType\":\"CPT\",\"deactivated\":true}");
// Get Inprogress Seoc after discontinue billing code
response = restTemplate.exchange(createURLWithPort(ROOT + inProgressSeocId), HttpMethod.GET, request,
String.class);
// assert that the billing code is not available after billing code discontinued
assertThat(response.getBody()).doesNotContain(
"{\"id\":3,\"description\":\"description3\",\"precertRequired\":true,\"billingCode\":\"code103\",\"codeType\":\"CPT\",\"deactivated\":false}");
assertThat(response.getBody()).doesNotContain(
"{\"id\":3,\"description\":\"description3\",\"precertRequired\":true,\"billingCode\":\"code103\",\"codeType\":\"CPT\",\"deactivated\":true}");
// Get Active Seoc after discontinue billing code
response = restTemplate.exchange(createURLWithPort(ROOT + idForDateHoldSeoc), HttpMethod.GET, request,
String.class);
// assert that the billing code is available and deactivated after billing code
// discontinued
assertThat(response.getBody()).doesNotContain(
"{\"id\":3,\"description\":\"description3\",\"precertRequired\":true,\"billingCode\":\"code103\",\"codeType\":\"CPT\",\"deactivated\":false}");
assertThat(response.getBody()).doesNotContain(
"{\"id\":3,\"description\":\"description3\",\"precertRequired\":true,\"billingCode\":\"code103\",\"codeType\":\"CPT\",\"deactivated\":true}");
}
@Test
public void retrieveSeocsByBillingCode_success() {
HttpEntity<String> request = new HttpEntity<String>(null, headers);
int id = 3;
String billingCode = "code105";
// Check seocs for billing code before creating pending revision
ResponseEntity<String> response = restTemplate.exchange(
createURLWithPort(ROOT + RETRIEVE_SEOC_BC + billingCode), HttpMethod.GET, request, String.class);
assertThat(response.getBody()).contains(
"{\"name\":\"Pulmonary SEOC 1.0.1\",\"serviceLine\":\"Medical Specialty Care\",\"versionNumber\":\"1.1.2\",\"status\":\"Active\"}");
// Get after create Seoc
request = new HttpEntity<>(headers);
response = restTemplate.exchange(createURLWithPort(ROOT + id), HttpMethod.GET, request, String.class);
String eTagHash = response.getHeaders().getETag();
// Create Pending revision
headers.setIfMatch(eTagHash);
String requestJson = SeocObjectGenerator.asJsonString(SeocGenericRequest.Builder.create(id).build());
request = new HttpEntity<String>(requestJson, headers);
response = restTemplate.exchange(createURLWithPort(ROOT + PENDING_REVISION), HttpMethod.POST, request,
String.class);
int pendingRevId = deserialize.createResponse(response.getBody()).getUniqueId();
assertThat(deserialize.createResponse(response.getBody()).getStatus()).isEqualTo(Constants.CREATED);
eTagHash = response.getHeaders().getETag();
// Activate the newly created pending revision
headers.setIfMatch(eTagHash);
requestJson = SeocObjectGenerator
.asJsonString(SeocActivateRequest.Builder.create(pendingRevId, TestUtil.getEffectiveDateString()));
request = new HttpEntity<String>(requestJson, headers);
response = restTemplate.exchange(createURLWithPort(ROOT + ACTIVATE_SEOC), HttpMethod.POST, request,
String.class);
response = restTemplate.exchange(createURLWithPort(ROOT + RETRIEVE_SEOC_BC + billingCode), HttpMethod.GET,
request, String.class);
// After creation of pending revision. Only pending revision should show up in
// the Seocs list
assertThat(response.getBody()).contains(
"{\"name\":\"Pulmonary SEOC 1.0.1\",\"serviceLine\":\"Medical Specialty Care\",\"versionNumber\":\"Pending Revision\",\"status\":\"In-Progress\"}");
assertThat(response.getBody()).doesNotContain(
"{\"name\":\"Pulmonary SEOC 1.0.1\",\"serviceLine\":\"Medical Specialty Care\",\"versionNumber\":\"1.2.2\",\"status\":\"Active\"}");
// Delete the Pending Revision to clean up the data
response = restTemplate.exchange(createURLWithPort(ROOT + pendingRevId), HttpMethod.GET, request, String.class);
eTagHash = response.getHeaders().getETag();
headers.setIfMatch(eTagHash);
request = new HttpEntity<>(headers);
response = restTemplate.exchange(createURLWithPort(ROOT + DELETE_SEOC + pendingRevId), HttpMethod.GET, request,
String.class);
assertThat(HttpStatus.OK).isEqualTo(response.getStatusCode());
}
@Test
public void updateBillingCode_activeSeocSuccess() {
HttpEntity<String> request = new HttpEntity<String>(null, headers);
int activeSeocId = 7;
String billingCode = "code106";
// Pick an existing billing code which is active
ResponseEntity<String> response = restTemplate.exchange(
createURLWithPort("v1/lookup/billingcode/" + billingCode), HttpMethod.GET, request, String.class);
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat(response.getBody()).contains(
"[{\"id\":6,\"description\":\"description6\",\"precertRequired\":true,\"billingCode\":\"code106\",\"codeType\":\"CPT\",\"deactivated\":false}]");
// Pick an active seoc with the billing code - ACTIVE SEOC
request = new HttpEntity<>(headers);
response = restTemplate.exchange(createURLWithPort(ROOT + activeSeocId), HttpMethod.GET, request, String.class);
assertThat(response.getBody()).contains(
"[{\"id\":6,\"description\":\"description6\",\"precertRequired\":true,\"billingCode\":\"code106\",\"codeType\":\"CPT\",\"deactivated\":false}]");
// EDIT BILLING CODE
CreateBillingCodeRequest billingCodeRequest = CreateBillingCodeRequest.Builder.create()
.withBillingCode("code116").withCodeType("CPT").withDescription("description116")
.withPrecertRequired(true).withPrevBillingCode(billingCode).build();
String requestJson = SeocObjectGenerator.asJsonString(billingCodeRequest);
request = new HttpEntity<String>(requestJson, headers);
switchMaintenanceMode("true");
response = restTemplate.exchange(createURLWithPort(ROOT + MANAGE_BC), HttpMethod.PUT, request, String.class);
switchMaintenanceMode("false");
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK);
// check if the billing code is discontinued
response = restTemplate.exchange(createURLWithPort("v1/lookup/billingcode/" + billingCode), HttpMethod.GET,
request, String.class);
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat(response.getBody()).contains("");
// Previous billing code in ACTIVE Seoc
request = new HttpEntity<>(headers);
response = restTemplate.exchange(createURLWithPort(ROOT + activeSeocId), HttpMethod.GET, request, String.class);
assertThat(response.getBody()).contains(
"[{\"id\":6,\"description\":\"description6\",\"precertRequired\":true,\"billingCode\":\"code106\",\"codeType\":\"CPT\",\"deactivated\":true}]");
}
@Test
public void updateBillingCode_dateHoldSeocSuccess() {
HttpEntity<String> request = new HttpEntity<String>(null, headers);
String billingCode = "code107";
// Pick an existing billing code which is active
ResponseEntity<String> response = restTemplate.exchange(
createURLWithPort("v1/lookup/billingcode/" + billingCode), HttpMethod.GET, request, String.class);
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat(response.getBody()).contains(
"[{\"id\":7,\"description\":\"description7\",\"precertRequired\":true,\"billingCode\":\"code107\",\"codeType\":\"CPT\",\"deactivated\":false}]");
// Create a new seoc with the billing code - Preparing DATE HOLD SEOC
Set<String> billingCodes = new HashSet<String>();
billingCodes.add(billingCode);
Set<String> clinicalServices = new HashSet<String>();
clinicalServices.add("12-Pulmonary");
CreateServiceRequest serviceRequest = CreateServiceRequest.Builder.create().withDescription("service1")
.withCodeRequired("YES").withVisits(5).withClinicalServices(clinicalServices)
.withBillingCodes(billingCodes).build();
List<CreateServiceRequest> serviceList = new ArrayList<CreateServiceRequest>();
serviceList.add(serviceRequest);
Set<String> hptcs = new HashSet<String>();
hptcs.add("hptc103");
String requestJson = SeocObjectGenerator
.asJsonString(SeocCreateRequest.Builder.create("SeocTest1", "Medical Specialty Care")
.withDescription("Description").withDisclaimer("Disclaimer").withDuration(5).withMaxVisits(5)
.withRev(false).withProceduralOverview("Procedural Overview").withCategoryOfCare("Pulmonary")
.withServiceList(serviceList).withQasp("QASP1").withHptcs(hptcs).build());
request = new HttpEntity<String>(requestJson, headers);
response = restTemplate.exchange(createURLWithPort(ROOT), HttpMethod.POST, request, String.class);
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.CREATED);
int inprogressId = deserialize.createResponse(response.getBody()).getUniqueId();
String inprogressHash = response.getHeaders().getETag();
// activate that seoc - DATE HOLD
headers.setIfMatch(inprogressHash);
requestJson = SeocObjectGenerator.asJsonString(
SeocActivateRequest.Builder.create(inprogressId, TestUtil.getEffectiveDateString()).build());
request = new HttpEntity<String>(requestJson, headers);
response = restTemplate.exchange(createURLWithPort(ROOT + ACTIVATE_SEOC), HttpMethod.POST, request,
String.class);
String actualStatus = deserialize.genericResponse(response.getBody()).getStatus();
int dateHoldId = deserialize.createResponse(response.getBody()).getSeocId();
assertThat(actualStatus).isEqualTo(Constants.SUCCESS);
assertThat(HttpStatus.OK).isEqualTo(response.getStatusCode());
// EDIT BILLING CODE
CreateBillingCodeRequest billingCodeRequest = CreateBillingCodeRequest.Builder.create()
.withBillingCode("code116").withCodeType("CPT").withDescription("description116")
.withPrecertRequired(true).withPrevBillingCode(billingCode).build();
requestJson = SeocObjectGenerator.asJsonString(billingCodeRequest);
request = new HttpEntity<String>(requestJson, headers);
switchMaintenanceMode("true");
response = restTemplate.exchange(createURLWithPort(ROOT + MANAGE_BC), HttpMethod.PUT, request, String.class);
switchMaintenanceMode("false");
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK);
// check if the billing code value is updated in the In-progress, date hold and
// active seocs
response = restTemplate.exchange(createURLWithPort("v1/lookup/billingcode/" + billingCode), HttpMethod.GET,
request, String.class);
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat(response.getBody()).contains("");
request = new HttpEntity<>(headers);
response = restTemplate.exchange(createURLWithPort(ROOT + dateHoldId), HttpMethod.GET, request, String.class);
String responseBody = response.getBody();
// SEOC is reverted to In-Progress
assertThat(responseBody).contains("\"status\":\"In-Progress\"");
// Previous billing code is not in SEOC
assertThat(response.getBody()).doesNotContain(
"{\"id\":7,\"description\":\"description7\",\"precertRequired\":true,\"billingCode\":\"code107\",\"codeType\":\"CPT\",\"deactivated\":true}");
// New billing code is in SEOC
assertThat(response.getBody()).contains(
"\"description\":\"description116\",\"precertRequired\":true,\"billingCode\":\"code116\",\"codeType\":\"CPT\",\"deactivated\":false}");
}
@Test
public void updateBillingCode_InprogressSeocSuccess() {
HttpEntity<String> request = new HttpEntity<String>(null, headers);
String billingCode = "code108";
// Pick an existing billing code which is active
ResponseEntity<String> response = restTemplate.exchange(
createURLWithPort("v1/lookup/billingcode/" + billingCode), HttpMethod.GET, request, String.class);
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat(response.getBody()).contains(
"[{\"id\":8,\"description\":\"description8\",\"precertRequired\":true,\"billingCode\":\"code108\",\"codeType\":\"CPT\",\"deactivated\":false}]");
// create another seoc with the billing code - INPROGRESS
Set<String> billingCodes = new HashSet<String>();
billingCodes.add(billingCode);
Set<String> clinicalServices = new HashSet<String>();
clinicalServices.add("12-Pulmonary");
CreateServiceRequest serviceRequest = CreateServiceRequest.Builder.create().withDescription("service1")
.withCodeRequired("YES").withVisits(5).withClinicalServices(clinicalServices)
.withBillingCodes(billingCodes).build();
List<CreateServiceRequest> serviceList = new ArrayList<CreateServiceRequest>();
serviceList.add(serviceRequest);
Set<String> hptcs = new HashSet<String>();
hptcs.add("hptc103");
String requestJson = SeocObjectGenerator
.asJsonString(SeocCreateRequest.Builder.create("SeocTest1", "Medical Specialty Care")
.withDescription("Description").withDisclaimer("Disclaimer").withDuration(5).withMaxVisits(5)
.withRev(false).withProceduralOverview("Procedural Overview").withCategoryOfCare("Pulmonary")
.withServiceList(serviceList).withQasp("QASP1").withHptcs(hptcs).build());
request = new HttpEntity<String>(requestJson, headers);
response = restTemplate.exchange(createURLWithPort(ROOT), HttpMethod.POST, request, String.class);
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.CREATED);
int inprogressId = deserialize.createResponse(response.getBody()).getUniqueId();
// EDIT BILLING CODE
CreateBillingCodeRequest billingCodeRequest = CreateBillingCodeRequest.Builder.create()
.withBillingCode("code116").withCodeType("CPT").withDescription("description116")
.withPrecertRequired(true).withPrevBillingCode(billingCode).build();
requestJson = SeocObjectGenerator.asJsonString(billingCodeRequest);
request = new HttpEntity<String>(requestJson, headers);
switchMaintenanceMode("true");
response = restTemplate.exchange(createURLWithPort(ROOT + MANAGE_BC), HttpMethod.PUT, request, String.class);
switchMaintenanceMode("false");
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK);
// Updated billing code in INPROGRESS SEOC
request = new HttpEntity<>(headers);
response = restTemplate.exchange(createURLWithPort(ROOT + inprogressId), HttpMethod.GET, request, String.class);
assertThat(response.getBody()).contains(
"\"description\":\"description116\",\"precertRequired\":true,\"billingCode\":\"code116\",\"codeType\":\"CPT\",\"deactivated\":false}");
}
@Test
public void updateBillingCode_notValidEditRequest() {
HttpEntity<String> request = new HttpEntity<String>(null, headers);
String billingCode = "code106";
// Pick an existing billing code which is active
ResponseEntity<String> response = restTemplate.exchange(
createURLWithPort("v1/lookup/billingcode/" + billingCode), HttpMethod.GET, request, String.class);
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat(response.getBody()).contains(
"[{\"id\":6,\"description\":\"description6\",\"precertRequired\":true,\"billingCode\":\"code106\",\"codeType\":\"CPT\",\"deactivated\":false}]");
// EDIT BILLING CODE
CreateBillingCodeRequest billingCodeRequest = CreateBillingCodeRequest.Builder.create()
.withBillingCode("code116").withCodeType("CPT").withDescription("description116")
.withPrecertRequired(true).withPrevBillingCode("").build();
String requestJson = SeocObjectGenerator.asJsonString(billingCodeRequest);
request = new HttpEntity<String>(requestJson, headers);
switchMaintenanceMode("true");
response = restTemplate.exchange(createURLWithPort(ROOT + MANAGE_BC), HttpMethod.PUT, request, String.class);
switchMaintenanceMode("false");
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.BAD_REQUEST);
}
@Test
public void updateBillingCode_nullRequest() {
HttpEntity<String> request = new HttpEntity<String>(null, headers);
String billingCode = "code106";
// Pick an existing billing code which is active
ResponseEntity<String> response = restTemplate.exchange(
createURLWithPort("v1/lookup/billingcode/" + billingCode), HttpMethod.GET, request, String.class);
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat(response.getBody()).contains(
"[{\"id\":6,\"description\":\"description6\",\"precertRequired\":true,\"billingCode\":\"code106\",\"codeType\":\"CPT\",\"deactivated\":false}]");
// EDIT BILLING CODE
CreateBillingCodeRequest billingCodeRequest = null;
String requestJson = SeocObjectGenerator.asJsonString(billingCodeRequest);
request = new HttpEntity<String>(requestJson, headers);
switchMaintenanceMode("true");
response = restTemplate.exchange(createURLWithPort(ROOT + MANAGE_BC), HttpMethod.PUT, request, String.class);
switchMaintenanceMode("false");
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.BAD_REQUEST);
}
/**
*
* Description: Set the headers
*/
private void setHeaders() {
headers.setContentType(MediaType.APPLICATION_JSON_UTF8);
headers.set(Constants.USERID, vaUserId);
headers.set(Constants.CLIENT_KEY, TestUtil.CLIENT_KEY);
}
/**
* Description:
*/
private void switchMaintenanceMode(String requestJson) {
// Setting maintenance mode
HttpEntity<String> request = new HttpEntity<String>(requestJson, headers);
ResponseEntity<String> response = restTemplate.exchange(createURLWithPort(USER_ROOT + MAINTENANCE),
HttpMethod.PUT, request, String.class);
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK);
}
/**
* Description: Test url
*
* @param uri
* @return returns test url
*/
private String createURLWithPort(String uri) {
return "http://localhost:" + port + uri;
}
}