Skip to content

Commit

Permalink
Added location to getClientFormAnswers
Browse files Browse the repository at this point in the history
  • Loading branch information
echo-liang committed Oct 11, 2023
1 parent 1eee790 commit 8a21258
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public String getClientFormAnswersUsingGET(BigDecimal clientFormId, String clien

logger.info("Client Form Answers Request");

return clientDataService.getClientFormAnswers(clientNumber, clientFormId);
return clientDataService.getClientFormAnswers(clientNumber, clientFormId, xLocationId);

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,10 @@ public interface ClientDataService {
* Get client form answers
* @param clientNumber
* @param clientFormId
* @param location
* @return {@link String} JSON answer object
*/
String getClientFormAnswers(String clientNumber, BigDecimal clientFormId);
String getClientFormAnswers(String clientNumber, BigDecimal clientFormId, String location);

List<ClientFormSummary> clientFormSearch(String clientNum, boolean currentPeriod, boolean mostRecent, String formTypeCd, String location);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ public List<ClientFormSummary> clientFormSearch(String clientNum, boolean curren
form.setSupervisionRating(form.getRatings().get(0).getText());
}
if (form.getModule().equalsIgnoreCase(OVERALL_FORM_TYPE)) {
formsMerged.add(populateRatings(form, clientNum));
formsMerged.add(populateRatings(form, clientNum, location));
} else {
formsMerged.add(form);
}
Expand All @@ -250,7 +250,7 @@ public List<ClientFormSummary> clientFormSearch(String clientNum, boolean curren
} else if ((formTypeCd.equalsIgnoreCase(OVERALL_FORM_TYPE) && form.getModule().equalsIgnoreCase(OVERALL_FORM_TYPE)) && hasSMOEarlyAdopter) {
logger.info("adding form {}", form.getModule());

formsMerged.add(populateRatings(form, clientNum));
formsMerged.add(populateRatings(form, clientNum, location));
}
}
//Add sorting on update date when implemented
Expand Down Expand Up @@ -293,9 +293,9 @@ public void deleteInterventionsExcept(String clientNumber, BigDecimal clientForm


@Override
public String getClientFormAnswers(String clientNumber,BigDecimal clientFormId) {
public String getClientFormAnswers(String clientNumber,BigDecimal clientFormId, String location) {
logger.debug("Getting form answers {}", clientFormId);
return obridgeClientService.getClientFormAnswers(clientNumber,clientFormId);
return obridgeClientService.getClientFormAnswers(clientNumber,clientFormId, new BigDecimal(location));
}

@Override
Expand Down Expand Up @@ -449,10 +449,10 @@ private Boolean hasSMOEarlyAdopter() {
* @return the form
* NOTE this can be done in a void but is clearer with a return
*/
private ClientFormSummary populateRatings(ClientFormSummary form, String clientNumber) {
private ClientFormSummary populateRatings(ClientFormSummary form, String clientNumber, String location) {
//Get Answers From CRNA/SARA
try {
String answers = getClientFormAnswers(clientNumber, form.getId());
String answers = getClientFormAnswers(clientNumber, form.getId(), location);

String crnaRatingAnswer = FormUtils.findAnswerByKey(answers, OVERALL_CRNA_RATING);
String saraRatingAnswer = FormUtils.findAnswerByKey(answers, OVERALL_SARA_RATING);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,43 +147,43 @@ public void editForm(UpdateForm updateForm, String location) {

if (updateForm.getComplete()) {
if (clientFormSummary.getModule().equalsIgnoreCase(CRNA_FORM_TYPE)) {
ValidationResult result = validationService.validateCRNA(obridgeClientService.getClientFormAnswers(updateForm.getUpdateFormInput().getClientNumber(), updateForm.getUpdateFormInput().getClientFormId()), updateForm.getInterventionKeys());
ValidationResult result = validationService.validateCRNA(obridgeClientService.getClientFormAnswers(updateForm.getUpdateFormInput().getClientNumber(), updateForm.getUpdateFormInput().getClientFormId(), new BigDecimal(location)), updateForm.getInterventionKeys());
if (!result.getErrors().isEmpty()) {
throw new CCCMException("CRNA form validation failed:", CCCMErrorCode.VALIDATIONERRORWITHRESULT, result);
}

if (updateForm.getUpdateFormInput().getLinkedClientFormId() != null) {
ValidationResult saraResult = validationService.validateSARA(obridgeClientService.getClientFormAnswers(updateForm.getUpdateFormInput().getClientNumber(), updateForm.getUpdateFormInput().getLinkedClientFormId()));
ValidationResult saraResult = validationService.validateSARA(obridgeClientService.getClientFormAnswers(updateForm.getUpdateFormInput().getClientNumber(), updateForm.getUpdateFormInput().getLinkedClientFormId(), new BigDecimal(location)));
if (!saraResult.getErrors().isEmpty()) {
throw new CCCMException("SARA form validation failed:", CCCMErrorCode.VALIDATIONERRORWITHRESULT, saraResult);
}
}
}

if (clientFormSummary.getModule().equalsIgnoreCase(SARA_FORM_TYPE)) {
ValidationResult result = validationService.validateSARA(obridgeClientService.getClientFormAnswers(updateForm.getUpdateFormInput().getClientNumber(), updateForm.getUpdateFormInput().getClientFormId()));
ValidationResult result = validationService.validateSARA(obridgeClientService.getClientFormAnswers(updateForm.getUpdateFormInput().getClientNumber(), updateForm.getUpdateFormInput().getClientFormId(), new BigDecimal(location)));
if (!result.getErrors().isEmpty()) {
throw new CCCMException("SARA form validation failed:", CCCMErrorCode.VALIDATIONERRORWITHRESULT, result);
}

if (updateForm.getUpdateFormInput().getLinkedClientFormId() != null) {
ValidationResult crnaResult = validationService.validateCRNA(obridgeClientService.getClientFormAnswers(updateForm.getUpdateFormInput().getClientNumber(), updateForm.getUpdateFormInput().getLinkedClientFormId()), updateForm.getInterventionKeys());
ValidationResult crnaResult = validationService.validateCRNA(obridgeClientService.getClientFormAnswers(updateForm.getUpdateFormInput().getClientNumber(), updateForm.getUpdateFormInput().getLinkedClientFormId(), new BigDecimal(location)), updateForm.getInterventionKeys());
if (!crnaResult.getErrors().isEmpty()) {
throw new CCCMException("CRNA form validation failed:", CCCMErrorCode.VALIDATIONERRORWITHRESULT, crnaResult);
}
}
}

if (clientFormSummary.getModule().equalsIgnoreCase(ACUTE_FORM_TYPE)) {
ValidationResult result = validationService.validateACUTE(obridgeClientService.getClientFormAnswers(updateForm.getUpdateFormInput().getClientNumber(), updateForm.getUpdateFormInput().getClientFormId()));
ValidationResult result = validationService.validateACUTE(obridgeClientService.getClientFormAnswers(updateForm.getUpdateFormInput().getClientNumber(), updateForm.getUpdateFormInput().getClientFormId(), new BigDecimal(location)));
if (!result.getErrors().isEmpty()) {
throw new CCCMException("ACUTE form validation failed:", CCCMErrorCode.VALIDATIONERRORWITHRESULT, result);
}
requiresNew = requiresNewForm(updateForm, clientFormSummary, location);
}

if (clientFormSummary.getModule().equalsIgnoreCase(STATIC99R_FORM_TYPE)) {
ValidationResult result = validationService.validateStatic99r(obridgeClientService.getClientFormAnswers(updateForm.getUpdateFormInput().getClientNumber(), updateForm.getUpdateFormInput().getClientFormId()));
ValidationResult result = validationService.validateStatic99r(obridgeClientService.getClientFormAnswers(updateForm.getUpdateFormInput().getClientNumber(), updateForm.getUpdateFormInput().getClientFormId(), new BigDecimal(location)));
if (!result.getErrors().isEmpty()) {
throw new CCCMException("Static-99R form validation failed:", CCCMErrorCode.VALIDATIONERRORWITHRESULT, result);
}
Expand All @@ -192,14 +192,14 @@ public void editForm(UpdateForm updateForm, String location) {

if (clientFormSummary.getModule().equalsIgnoreCase(STABLE_FORM_TYPE)) {
//TODO: Add validation rule to "An Acute and a Static have been completed in the current period of supervision."
ValidationResult result = validationService.validateStable(obridgeClientService.getClientFormAnswers(updateForm.getUpdateFormInput().getClientNumber(), updateForm.getUpdateFormInput().getClientFormId()));
ValidationResult result = validationService.validateStable(obridgeClientService.getClientFormAnswers(updateForm.getUpdateFormInput().getClientNumber(), updateForm.getUpdateFormInput().getClientFormId(), new BigDecimal(location)));
if (!result.getErrors().isEmpty()) {
throw new CCCMException("Stable form validation failed:", CCCMErrorCode.VALIDATIONERRORWITHRESULT, result);
}
}

if (clientFormSummary.getModule().equalsIgnoreCase(OVERALL_FORM_TYPE)) {
ValidationResult result = validationService.validateSOOverall(obridgeClientService.getClientFormAnswers(updateForm.getUpdateFormInput().getClientNumber(), updateForm.getUpdateFormInput().getClientFormId()));
ValidationResult result = validationService.validateSOOverall(obridgeClientService.getClientFormAnswers(updateForm.getUpdateFormInput().getClientNumber(), updateForm.getUpdateFormInput().getClientFormId(), new BigDecimal(location)));
if (!result.getErrors().isEmpty()) {
throw new CCCMException("Overall form validation failed:", CCCMErrorCode.VALIDATIONERRORWITHRESULT, result);
}
Expand Down Expand Up @@ -352,7 +352,7 @@ private BigDecimal cloneFormAndAnswers(ClientFormSummary clientFormSummary, Clon
BigDecimal clientFormId = obridgeClientService.createForm(formInput);

//Get Answers
String answers = obridgeClientService.getClientFormAnswers(cloneFormRequest.getClientNumber(), clientFormSummary.getId());
String answers = obridgeClientService.getClientFormAnswers(cloneFormRequest.getClientNumber(), clientFormSummary.getId(), new BigDecimal(location));
//Insert Answers Use Clone Config for ignore
String strippedAnswers = stripAnswers(answers, cloneConfig.getForms().stream().filter(cloneForm -> cloneForm.getFormType().equalsIgnoreCase(clientFormSummary.getModule())).findFirst().get());
obridgeClientService.saveClientFormAnswers(cloneFormRequest.getClientNumber(), clientFormId, strippedAnswers, false, new BigDecimal(location));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,8 @@ String updateClientFormInterventions(@PathParam("clientNumber") String clientNum
@GET
@Path("/forms/client/answers/{clientNumber}/{clientFormId}")
String getClientFormAnswers(@PathParam("clientNumber") String clientNumber,
@PathParam("clientFormId") BigDecimal clientFormId);
@PathParam("clientFormId") BigDecimal clientFormId,
@QueryParam("location") BigDecimal location);

@GET
@Path("/forms/client/summary/answers/{clientNumber}/{clientFormId}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public class GetClientFormAnswersUsingGETTest {
@DisplayName("200: should return answers")
public void testGetAnswersEndpoint() {

Mockito.when(clientDataService.getClientFormAnswers(Mockito.any(), Mockito.any())).thenReturn("ANSWERS");
Mockito.when(clientDataService.getClientFormAnswers(Mockito.any(), Mockito.any(), Mockito.any())).thenReturn("ANSWERS");

String result = sut.getClientFormAnswersUsingGET(BigDecimal.ONE,"TEST", null);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public class ClientFormSearchTest {
public void testGetClientFormsNoMerge() {

Mockito.when(obridgeClientService.getClientForms(Mockito.anyString(), Mockito.anyBoolean(), Mockito.anyString(), Mockito.any(BigDecimal.class))).thenReturn(createRelatedList());
Mockito.when(obridgeClientService.getClientFormAnswers(Mockito.anyString(), Mockito.any(BigDecimal.class))).thenReturn(answersJson);
Mockito.when(obridgeClientService.getClientFormAnswers(Mockito.anyString(), Mockito.any(BigDecimal.class), Mockito.any())).thenReturn(answersJson);

Mockito.when(jsonWebTokenMock.claim(Mockito.anyString())).thenReturn(Optional.of(getRolesWithSMO()));

Expand All @@ -71,7 +71,7 @@ public void testGetClientFormsNoMerge() {
public void testGetClientFormsAllNoMerge() {

Mockito.when(obridgeClientService.getClientForms(Mockito.anyString(), Mockito.anyBoolean(), Mockito.anyString(), Mockito.any(BigDecimal.class))).thenReturn(createNonRelatedList());
Mockito.when(obridgeClientService.getClientFormAnswers(Mockito.anyString(), Mockito.any(BigDecimal.class))).thenReturn(answersJson);
Mockito.when(obridgeClientService.getClientFormAnswers(Mockito.anyString(), Mockito.any(BigDecimal.class), Mockito.any())).thenReturn(answersJson);

Mockito.when(jsonWebTokenMock.claim(Mockito.anyString())).thenReturn(Optional.of(getRolesWithSMO()));

Expand All @@ -87,7 +87,7 @@ public void testGetClientFormsMerge() {

Mockito.when(obridgeClientService.getClientForms(Mockito.anyString(), Mockito.anyBoolean(), Mockito.anyString(), Mockito.any(BigDecimal.class))).thenReturn(createRelatedList());
Mockito.when(jsonWebTokenMock.claim(Mockito.anyString())).thenReturn(Optional.of(getRolesWithSMO()));
Mockito.when(obridgeClientService.getClientFormAnswers(Mockito.anyString(), Mockito.any(BigDecimal.class))).thenReturn(answersJson);
Mockito.when(obridgeClientService.getClientFormAnswers(Mockito.anyString(), Mockito.any(BigDecimal.class), Mockito.any())).thenReturn(answersJson);

List<ClientFormSummary> result = sut.clientFormSearch("", false, false,"All", "1");

Expand Down Expand Up @@ -181,7 +181,7 @@ public void testGetAllClientFormsOverall() {

Mockito.when(obridgeClientService.getClientForms(Mockito.anyString(), Mockito.anyBoolean(), Mockito.anyString(), Mockito.any(BigDecimal.class))).thenReturn(createRelatedList());
Mockito.when(jsonWebTokenMock.claim(Mockito.anyString())).thenReturn(Optional.of(getRolesWithSMO()));
Mockito.when(obridgeClientService.getClientFormAnswers(Mockito.anyString(), Mockito.any(BigDecimal.class))).thenReturn(answersJson);
Mockito.when(obridgeClientService.getClientFormAnswers(Mockito.anyString(), Mockito.any(BigDecimal.class), Mockito.any())).thenReturn(answersJson);

List<ClientFormSummary> result = sut.clientFormSearch("", false, true,"SMO_OVERALL", "1");

Expand Down
Loading

0 comments on commit 8a21258

Please sign in to comment.