Attention une mise à jour du serveur va être effectuée le lundi 17 mai entre 13h et 13h30. Cette mise à jour va générer une interruption du service de quelques minutes.

Commit 87f7e9d3 authored by luc chatty's avatar luc chatty

PATREG-33 | code review

parent 582b5ee3
Pipeline #138647 passed with stages
in 7 minutes and 47 seconds
......@@ -11,6 +11,9 @@ import javax.persistence.criteria.*;
import java.util.ArrayList;
import java.util.List;
/**
* DAO for Identifier Objects.
*/
public class IdentifierDAOImpl implements IdentifierDAO {
private EntityManager entityManager;
......
......@@ -350,115 +350,93 @@ public class SearchExecutionStepDefinition {
*/
@Then("all received patients verify one")
public void allReceiverPatientsVerifyOne(List<Map<String, String>> patientDataList) {
List<Patient> checkedPatients = new ArrayList<>();
if (patientDataList != null) {
for (Map<String, String> criterionMap : patientDataList) {
String parameter = criterionMap.get("parameter");
String verb = criterionMap.get("verb");
String value = criterionMap.get("value");
if (parameter == null || verb == null || value == null) {
fail(String.format("Criterion shall always have a parameter, verb and value : %s, %s, %s", parameter, verb, value));
}
getPatientsWhoVerify(parameter, verb, value).forEach(patient -> {
if (!checkedPatients.contains(patient)) {
checkedPatients.add(patient);
boolean allReceiverPatientsVerifyOne = true;
for (Patient patient : searchedPatients) {
boolean patientVerifyAtLeastOne = false;
for (Map<String, String> criterionMap : patientDataList) {
String parameter = criterionMap.get("parameter");
String verb = criterionMap.get("verb");
String value = criterionMap.get("value");
if (parameter == null || verb == null || value == null) {
fail(String.format("Criterion shall always have a parameter, verb and value : %s, %s, %s", parameter, verb, value));
}
});
patientVerifyAtLeastOne = patientVerifyAtLeastOne || patientVerify(patient, parameter, verb, value);
}
allReceiverPatientsVerifyOne = allReceiverPatientsVerifyOne && patientVerifyAtLeastOne;
}
assertTrue(allReceiverPatientsVerifyOne, "All patients should match at least one criterion");
}
assertEquals(searchedPatients.size(), checkedPatients.size(), "All patients should match at least one criterion");
}
/**
* Checks that some patient verify all Criterion in a list and store them in the checkerdPatients property.
*
* @param patientDataList
* @param patientDataList List of criterion that received patients may verify
*/
@Then("some patient verifies all")
public void somePatientsVerifyAll(List<Map<String, String>> patientDataList) {
if (patientDataList != null) {
List<Patient> somePatients = new ArrayList<>();
for (Map<String, String> criterionMap : patientDataList) {
String parameter = criterionMap.get("parameter");
String verb = criterionMap.get("verb");
String value = criterionMap.get("value");
if (parameter == null || verb == null || value == null) {
fail(String.format("Criterion shall always have a parameter, verb and value : %s, %s, %s", parameter, verb, value));
}
List<Patient> verifyPatients = getPatientsWhoVerify(parameter, verb, value);
verifyPatients.forEach(patient -> {
if (!somePatients.contains(patient)) {
somePatients.add(patient);
boolean somePatientsVerifyAll = false;
for (Patient patient : searchedPatients) {
for (Map<String, String> criterionMap : patientDataList) {
String parameter = criterionMap.get("parameter");
String verb = criterionMap.get("verb");
String value = criterionMap.get("value");
if (parameter == null || verb == null || value == null) {
fail(String.format("Criterion shall always have a parameter, verb and value : %s, %s, %s", parameter, verb, value));
}
});
somePatients.forEach(patient -> {
if (!verifyPatients.contains(patient)) {
verifyPatients.remove(patient);
}
});
}
somePatients.forEach(patient -> {
if (!this.checkedPatients.contains(patient)) {
this.checkedPatients.add(patient);
somePatientsVerifyAll = somePatientsVerifyAll || patientVerify(patient, parameter, verb, value);
}
});
}
assertTrue(somePatientsVerifyAll, "Some patients shall verify all criteria");
}
}
/**
* Checks that all returned patients have been checked correct.
* Checks that all retualways have a parameter, verb and value : always have a parameter, verb and value : rned patients have been checked correct.
*/
@Then("all return patients match criteria")
public void allReturnedPatientsMatchCriteria() {
assertEquals(searchedPatients.size(), checkedPatients.size(), "All patients should verify criteria.");
}
/**
* Checks some of the received patients verify asked criterion
*
* @param parameter name of the criterion
* * @param value value to search
* * @param verb operator to use
* assert that a patient verify a criterion
* @param patient the patient to check
* @param parameter the parameter if the criterion
* @param verb the verb of the criterion
* @param value the value of the criterion
* @return true is the patient verify the criterion
*/
private List<Patient> getPatientsWhoVerify(String parameter, String verb, String value) {
private boolean patientVerify(Patient patient , String parameter, String verb, String value) {
if (parameter != null) {
List<Patient> checkedPatients = new ArrayList<>();
if (parameter.equals("tmpuuid")) {
for (Patient patient : searchedPatients) {
if (checkStringValueWithOperator(verb, uuidOfFedPatients.get(value), patient.getUuid()) && !checkedPatients.contains(patient)) {
checkedPatients.add(patient);
}
}
} else if (parameter.equals("uuid")) {
for (Patient patient : searchedPatients) {
if (checkStringValueWithOperator(verb, value, patient.getUuid()) && !checkedPatients.contains(patient)) {
checkedPatients.add(patient);
}
}
} else if (parameter.equals("identifier.value")) {
for (Patient patient : searchedPatients) {
switch (parameter) {
case "tmpuuid":
return checkStringValueWithOperator(verb, uuidOfFedPatients.get(value), patient.getUuid()) && !checkedPatients.contains(patient);
case "uuid":
return checkStringValueWithOperator(verb, value, patient.getUuid()) && !checkedPatients.contains(patient);
case "identifier.value": {
List<String> identifierList = new ArrayList<>();
patient.getIdentifiers().forEach(identifier -> identifierList.add(identifier.getValue()));
if (checkStringListWithOperator(verb, value, identifierList) && !checkedPatients.contains(patient)) {
checkedPatients.add(patient);
}
return checkStringListWithOperator(verb, value, identifierList);
}
} else if (parameter.equals("identifier.systemIdentifier")) {
for (Patient patient : searchedPatients) {
case "identifier.systemIdentifier": {
List<String> identifierList = new ArrayList<>();
patient.getIdentifiers().forEach(identifier -> identifierList.add(identifier.getSystemIdentifier()));
if (checkStringListWithOperator(verb, value, identifierList) && !checkedPatients.contains(patient)) {
checkedPatients.add(patient);
}
return checkStringListWithOperator(verb, value, identifierList) && !checkedPatients.contains(patient);
}
} else {
fail(String.format("Unsupported criteria %s", parameter));
default:
fail(String.format("Unsupported criteria %s", parameter));
break;
}
return checkedPatients;
return false;
} else {
fail("Criterion name shall not be null !");
}
return null;
return false;
}
......
......@@ -412,58 +412,46 @@ public class SearchExecutionStepDefinition {
*/
@Then("all received patients verify one")
public void allReceiverPatientsVerifyOne(List<Map<String, String>> patientDataList) {
List<Patient> checkedPatients = new ArrayList<>();
if (patientDataList != null) {
for (Map<String, String> criterionMap : patientDataList) {
String parameter = criterionMap.get("parameter");
String verb = criterionMap.get("verb");
String value = criterionMap.get("value");
if (parameter == null || verb == null || value == null) {
fail(String.format("Criterion shall always have a parameter, verb and value : %s, %s, %s", parameter, verb, value));
}
getPatientsWhoVerify(parameter, verb, value).forEach(patient -> {
if (!checkedPatients.contains(patient)) {
checkedPatients.add(patient);
boolean allReceiverPatientsVerifyOne = true;
for (Patient patient : searchedPatients) {
boolean patientVerifyAtLeastOne = false;
for (Map<String, String> criterionMap : patientDataList) {
String parameter = criterionMap.get("parameter");
String verb = criterionMap.get("verb");
String value = criterionMap.get("value");
if (parameter == null || verb == null || value == null) {
fail(String.format("Criterion shall always have a parameter, verb and value : %s, %s, %s", parameter, verb, value));
}
});
patientVerifyAtLeastOne = patientVerifyAtLeastOne || patientVerify(patient, parameter, verb, value);
}
allReceiverPatientsVerifyOne = allReceiverPatientsVerifyOne && patientVerifyAtLeastOne;
}
assertTrue(allReceiverPatientsVerifyOne, "All patients should match at least one criterion");
}
assertEquals(searchedPatients.size(), checkedPatients.size(), "All patients should match at least one criterion");
}
/**
* Checks that some patient verify all Criterion in a list and store them in the checkerdPatients property.
*
* @param patientDataList
* @param patientDataList List of criterion that received patients may verify
*/
@Then("some patient verifies all")
public void somePatientsVerifyAll(List<Map<String, String>> patientDataList) {
if (patientDataList != null) {
List<Patient> somePatients = new ArrayList<>();
for (Map<String, String> criterionMap : patientDataList) {
String parameter = criterionMap.get("parameter");
String verb = criterionMap.get("verb");
String value = criterionMap.get("value");
if (parameter == null || verb == null || value == null) {
fail(String.format("Criterion shall always have a parameter, verb and value : %s, %s, %s", parameter, verb, value));
}
List<Patient> verifyPatients = getPatientsWhoVerify(parameter, verb, value);
verifyPatients.forEach(patient -> {
if (!somePatients.contains(patient)) {
somePatients.add(patient);
boolean somePatientsVerifyAll = false;
for (Patient patient : searchedPatients) {
for (Map<String, String> criterionMap : patientDataList) {
String parameter = criterionMap.get("parameter");
String verb = criterionMap.get("verb");
String value = criterionMap.get("value");
if (parameter == null || verb == null || value == null) {
fail(String.format("Criterion shall always have a parameter, verb and value : %s, %s, %s", parameter, verb, value));
}
});
somePatients.forEach(patient -> {
if (!verifyPatients.contains(patient)) {
verifyPatients.remove(patient);
}
});
}
somePatients.forEach(patient -> {
if (!this.checkedPatients.contains(patient)) {
this.checkedPatients.add(patient);
somePatientsVerifyAll = somePatientsVerifyAll || patientVerify(patient, parameter, verb, value);
}
});
}
assertTrue(somePatientsVerifyAll, "Some patients shall verify all criteria");
}
}
......@@ -476,51 +464,40 @@ public class SearchExecutionStepDefinition {
}
/**
* Checks some of the received patients verify asked criterion
*
* @param parameter name of the criterion
* * @param value value to search
* * @param verb operator to use
* assert that a patient verify a criterion
* @param patient the patient to check
* @param parameter the parameter if the criterion
* @param verb the verb of the criterion
* @param value the value of the criterion
* @return true is the patient verify the criterion
*/
private List<Patient> getPatientsWhoVerify(String parameter, String verb, String value) {
private boolean patientVerify(Patient patient , String parameter, String verb, String value) {
if (parameter != null) {
List<Patient> checkedPatients = new ArrayList<>();
if (parameter.equals("tmpuuid")) {
for (Patient patient : searchedPatients) {
if (checkStringValueWithOperator(verb, uuidOfFedPatients.get(value), patient.getUuid()) && !checkedPatients.contains(patient)) {
checkedPatients.add(patient);
}
}
} else if (parameter.equals("uuid")) {
for (Patient patient : searchedPatients) {
if (checkStringValueWithOperator(verb, value, patient.getUuid()) && !checkedPatients.contains(patient)) {
checkedPatients.add(patient);
}
}
} else if (parameter.equals("identifier.value")) {
for (Patient patient : searchedPatients) {
switch (parameter) {
case "tmpuuid":
return checkStringValueWithOperator(verb, uuidOfFedPatients.get(value), patient.getUuid()) && !checkedPatients.contains(patient);
case "uuid":
return checkStringValueWithOperator(verb, value, patient.getUuid()) && !checkedPatients.contains(patient);
case "identifier.value": {
List<String> identifierList = new ArrayList<>();
patient.getIdentifiers().forEach(identifier -> identifierList.add(identifier.getValue()));
if (checkStringListWithOperator(verb, value, identifierList) && !checkedPatients.contains(patient)) {
checkedPatients.add(patient);
}
return checkStringListWithOperator(verb, value, identifierList);
}
} else if (parameter.equals("identifier.systemIdentifier")) {
for (Patient patient : searchedPatients) {
case "identifier.systemIdentifier": {
List<String> identifierList = new ArrayList<>();
patient.getIdentifiers().forEach(identifier -> identifierList.add(identifier.getSystemIdentifier()));
if (checkStringListWithOperator(verb, value, identifierList) && !checkedPatients.contains(patient)) {
checkedPatients.add(patient);
}
return checkStringListWithOperator(verb, value, identifierList) && !checkedPatients.contains(patient);
}
} else {
fail(String.format("Unsupported criteria %s", parameter));
default:
fail(String.format("Unsupported criteria %s", parameter));
break;
}
return checkedPatients;
return false;
} else {
fail("Criterion name shall not be null !");
}
return null;
return false;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment