diff --git a/redaction-report-service-v1/redaction-report-service-server-v1/src/main/java/com/iqser/red/service/redaction/report/v1/server/service/RSSPoc2Service.java b/redaction-report-service-v1/redaction-report-service-server-v1/src/main/java/com/iqser/red/service/redaction/report/v1/server/service/RSSPoc2Service.java index 37240e3..48e1366 100644 --- a/redaction-report-service-v1/redaction-report-service-server-v1/src/main/java/com/iqser/red/service/redaction/report/v1/server/service/RSSPoc2Service.java +++ b/redaction-report-service-v1/redaction-report-service-server-v1/src/main/java/com/iqser/red/service/redaction/report/v1/server/service/RSSPoc2Service.java @@ -5,11 +5,11 @@ import java.util.ArrayList; import java.util.Comparator; import java.util.HashMap; import java.util.Iterator; +import java.util.LinkedHashMap; import java.util.List; import java.util.Locale; import java.util.Map; import java.util.Set; -import java.util.TreeMap; import java.util.stream.Collectors; import javax.annotation.PostConstruct; @@ -32,6 +32,46 @@ import lombok.RequiredArgsConstructor; @RequiredArgsConstructor public class RSSPoc2Service { + public static final String STUDY_TYPE_NUMBER = "Study_Type_Number"; + public static final String STUDY_TITLE = "Study_Title"; + public static final String REPORT_NUMBER = "Report_Number"; + public static final String PERFORMING_LABORATORY = "Performing_Laboratory"; + public static final String EXPERIMENTAL_STARTING_DATE = "Experimental_Starting_Date"; + public static final String EXPERIMENTAL_COMPLETION_DATE = "Experimental_Completion_Date"; + public static final String GLP_STUDY = "GLP_Study"; + public static final String CERTIFICATE_OF_ANALYSIS_BATCH_IDENTIFICATION = "Certificate_of_Analysis_Batch_Identification"; + public static final String TEST_GUIDELINE_1 = "Test_Guideline_1"; + public static final String TEST_GUIDELINE_2 = "Test_Guideline_2"; + public static final String STUDY_CONCLUSION = "Study_Conclusion"; + public static final String DEVIATION_FROM_THE_GUIDELINE_SENTENCE = "Deviation_from_the_Guideline_"; + public static final String SPECIES = "Species"; + public static final String STRAIN = "Strain"; + public static final String CONCLUSION_LD_50_MG_PER_MG = "Conclusion_LD50_mg_per_mg"; + public static final String CONCLUSION_LD_50_GREATER_THAN = "Conclusion_LD50_Greater_than"; + public static final String CONCLUSION_MINIMUM_CONFIDENCE = "Conclusion_Minimum_Confidence"; + public static final String CONCLUSION_MAXIMUM_CONFIDENCE = "Conclusion_Maximum_Confidence"; + public static final String NECROPSY_FINDINGS = "Necropsy_Findings"; + public static final String NECROPSY_FINDINGS_SENTENCE = "Necropsy_findings_"; + public static final String CONDUCTED_WITHIN_4_HOURS_OF_EXPOSURE = "Conducted_within_4_Hours_of_Exposure"; + public static final String STUDY_DESIGN = "Study_Design"; + public static final String RESULTS_AND_CONCLUSIONS = "Results_and_Conclusions"; + public static final String WEIGHT_BEHAVIOR_CHANGES_SENTENCE = "Weight_Behavior_Changes_"; + public static final String MORTALITY_STATEMENT = "Mortality_Statement"; + public static final String CLINICAL_OBSERVATIONS_SENTENCE = "Clinical_Observations_"; + public static final String BODY_WEIGHT_CHANGES_SENTENCE = "Body_Weight_Changes_"; + public static final String DETAILING_OF_REPORTED_CHANGES = "Detailing_of_Reported_Changes"; + public static final String SEX = "Sex"; + public static final String NUMBER_OF_ANIMALS = "Number_of_Animals"; + public static final String CLINCAL_SIGNS_SENTENCE = "Clincal_Signs_"; + public static final String MORTALITY = "Mortality"; + public static final String DOSAGES = "Dosages"; + public static final String PRELIMINARY_TEST_RESULTS_SENTENCE = "Preliminary_Test_Results_"; + public static final String TEST_RESULTS = "Test_Results"; + public static final String WAS_THE_DEFINITIVE_STUDY_CONDUCTED_WITH_POSITIVE_CONTROL = "Was_the_definitive_study_conducted_with_positive_control"; + public static final String DOSE_MORTALITY_SENTENCE = "Dose_Mortality_"; + public static final String RESULTS_MAIN_STUDY = "Results_Main_Study"; + public static final String WHAT_WAS_THE_APPROACH_USED = "What_was_the_approach_used"; + private final RedactionLogClient redactionLogClient; private final FileStatusClient statusClient; @@ -90,53 +130,53 @@ public class RSSPoc2Service { String oecd = getOecdNumber(file); - Map resultMap = new TreeMap<>(); + Map resultMap = new LinkedHashMap<>(); var redactionLog = redactionLogClient.getRedactionLog(dossierId, file.getId(), new ArrayList<>(), true, false); sortRedactionLog(redactionLog); redactionLog.getRedactionLogEntry().removeIf(r -> !r.isRedacted() || r.getChanges().get(r.getChanges().size() - 1).getType().equals(ChangeType.REMOVED)); - resultMap.put("Study_Type_Number", oecd); + resultMap.put(STUDY_TYPE_NUMBER, oecd); - resultMap.put("Study_Title", getTitle(redactionLog)); - resultMap.put("Report_Number", getReportNumber(redactionLog)); - resultMap.put("Performing_Laboratory", getPerformingLaboratory(redactionLog)); - resultMap.put("Experimental_Starting_Date", getExperimentalStartDate(redactionLog)); - resultMap.put("Experimental_Completion_Date", getExperimentalEndDate(redactionLog)); - resultMap.put("GLP_Study", getGlpStudy(redactionLog)); - resultMap.put("Certificate_of_Analysis_Batch_Identification", getBatchNumber(redactionLog)); - resultMap.put("Test_Guideline_1", getTestGuideline1(redactionLog)); + resultMap.put(STUDY_TITLE, getTitle(redactionLog)); + resultMap.put(REPORT_NUMBER, getReportNumber(redactionLog)); + resultMap.put(PERFORMING_LABORATORY, getPerformingLaboratory(redactionLog)); + resultMap.put(EXPERIMENTAL_STARTING_DATE, getExperimentalStartDate(redactionLog)); + resultMap.put(EXPERIMENTAL_COMPLETION_DATE, getExperimentalEndDate(redactionLog)); + resultMap.put(GLP_STUDY, getGlpStudy(redactionLog)); + resultMap.put(CERTIFICATE_OF_ANALYSIS_BATCH_IDENTIFICATION, getBatchNumber(redactionLog)); + resultMap.put(TEST_GUIDELINE_1, getTestGuideline1(redactionLog)); var testGuideline2 = getTestGuideline2(redactionLog); - resultMap.put("Test_Guideline_2", testGuideline2 == null ? "" : testGuideline2); + resultMap.put(TEST_GUIDELINE_2, testGuideline2 == null ? "" : testGuideline2); if (oecdIn(oecd, Set.of("402", "403", "404", "405", "425", "429", "436", "471"))) { - resultMap.put("Study_Conclusion", getStudyConclusion(redactionLog)); + resultMap.put(STUDY_CONCLUSION, getStudyConclusion(redactionLog)); var guidelineDeviationSentences = getAsSentences(redactionLog, "guideline_deviation"); int i = 1; for (String guidelineDeviationSentence : guidelineDeviationSentences) { - resultMap.put("Deviation_from_the_Guideline_" + i, guidelineDeviationSentence); + resultMap.put(DEVIATION_FROM_THE_GUIDELINE_SENTENCE + i, guidelineDeviationSentence); i++; } } - if (oecdIn(oecd, Set.of("402", "403", "404", "405", "425", "429", "436"))) { + if (oecdIn(oecd, Set.of("402", "403", "404", "405", "425", "429", "436", "471"))) { - resultMap.put("Species", getSpecies(redactionLog)); - resultMap.put("Strain", getStrain(redactionLog)); + resultMap.put(SPECIES, getSpecies(redactionLog)); + resultMap.put(STRAIN, getStrain(redactionLog)); } if (oecdIn(oecd, Set.of("402", "403", "425", "436"))) { - resultMap.put("Conclusion_LD50_mg_per_mg", getLd50Value(redactionLog)); - resultMap.put("Conclusion_LD50_Greater_than", getLd50GreaterThan(redactionLog)); - resultMap.put("Conclusion_Minimum_Confidence", getConfidenceMinimal(redactionLog)); - resultMap.put("Conclusion_Maximum_Confidence", getConfidenceMaximal(redactionLog)); + resultMap.put(CONCLUSION_LD_50_MG_PER_MG, getLd50Value(redactionLog)); + resultMap.put(CONCLUSION_LD_50_GREATER_THAN, getLd50GreaterThan(redactionLog)); + resultMap.put(CONCLUSION_MINIMUM_CONFIDENCE, getConfidenceMinimal(redactionLog)); + resultMap.put(CONCLUSION_MAXIMUM_CONFIDENCE, getConfidenceMaximal(redactionLog)); } if (oecdIn(oecd, Set.of("402"))) { - resultMap.put("Necropsy_Findings", getLongestBlock(redactionLog, "necropsy_findings")); + resultMap.put(NECROPSY_FINDINGS, getLongestBlock(redactionLog, "necropsy_findings")); } if (oecdIn(oecd, Set.of("403", "436"))) { @@ -144,32 +184,32 @@ public class RSSPoc2Service { var sentences = getAsSentences(redactionLog, "necropsy_findings"); int i = 1; for (String sentence : sentences) { - resultMap.put("Necropsy_findings_" + i, sentence); + resultMap.put(NECROPSY_FINDINGS_SENTENCE + i, sentence); i++; } } if (oecdIn(oecd, Set.of("403", "436"))) { - resultMap.put("Conducted_within_4_Hours_of_Exposure", getAsOneBlock(redactionLog, "4h_exposure")); + resultMap.put(CONDUCTED_WITHIN_4_HOURS_OF_EXPOSURE, getAsOneBlock(redactionLog, "4h_exposure")); } - if (oecdIn(oecd, Set.of("404","405", "429" ,"406", "428", "438", "439", "474", "487"))) { - resultMap.put("Study_Design", getAsOneBlock(redactionLog, "study_design")); + if (oecdIn(oecd, Set.of("404", "405", "429", "406", "428", "438", "439", "474", "487"))) { + resultMap.put(STUDY_DESIGN, getAsOneBlock(redactionLog, "study_design")); } if (oecdIn(oecd, Set.of("406", "428", "438", "439", "474", "487"))) { - resultMap.put("Results_and_Conclusions", getJoinedValues(redactionLog, "results_and_conclusion", " ")); + resultMap.put(RESULTS_AND_CONCLUSIONS, getJoinedValues(redactionLog, "results_and_conclusion", " ")); } if (oecdIn(oecd, Set.of("402"))) { var weightBehaviorChangesSentences = getAsSentences(redactionLog, "weight_behavior_changes"); int i = 1; for (String sentence : weightBehaviorChangesSentences) { - resultMap.put("Weight_Behavior_Changes" + i, sentence); + resultMap.put(WEIGHT_BEHAVIOR_CHANGES_SENTENCE + i, sentence); i++; } - resultMap.put("Mortality_Statement", getAsOneBlock(redactionLog, "mortality_statement")); + resultMap.put(MORTALITY_STATEMENT, getAsOneBlock(redactionLog, "mortality_statement")); } if (oecdIn(oecd, Set.of("403"))) { @@ -188,14 +228,14 @@ public class RSSPoc2Service { var sentences = getAsSentences(redactionLog, "clinical_observations"); int i = 1; for (String sentence : sentences) { - resultMap.put("Clinical_Observations_" + i, sentence); + resultMap.put(CLINICAL_OBSERVATIONS_SENTENCE + i, sentence); i++; } sentences = getAsSentences(redactionLog, "bodyweight_changes"); i = 1; for (String sentence : sentences) { - resultMap.put("Body_Weight_Changes_" + i, sentence); + resultMap.put(BODY_WEIGHT_CHANGES_SENTENCE + i, sentence); i++; } } @@ -206,12 +246,12 @@ public class RSSPoc2Service { // } if (oecdIn(oecd, Set.of("404", "405"))) { - resultMap.put("Detailing_of_Reported_Changes", getAsOneBlock(redactionLog, "detailing")); + resultMap.put(DETAILING_OF_REPORTED_CHANGES, getAsOneBlock(redactionLog, "detailing")); } if (oecdIn(oecd, Set.of("405", "429"))) { - resultMap.put("Sex", getJoinedUniqueValues(redactionLog, "sex", ", ")); - resultMap.put("Number_of_Animals", getNumberOfAnimals(redactionLog)); + resultMap.put(SEX, getJoinedUniqueValues(redactionLog, "sex", ", ")); + resultMap.put(NUMBER_OF_ANIMALS, getNumberOfAnimals(redactionLog)); } if (oecdIn(oecd, Set.of("425"))) { @@ -219,28 +259,39 @@ public class RSSPoc2Service { var clinicalSignsSentences = getAsSentences(redactionLog, "clinical_signs"); int i = 1; for (String clinicalSignsSentence : clinicalSignsSentences) { - resultMap.put("Clincal_Signs_" + i, clinicalSignsSentence); + resultMap.put(CLINCAL_SIGNS_SENTENCE + i, clinicalSignsSentence); i++; } - resultMap.put("Mortality", getAsOneBlock(redactionLog, "mortality")); + var doseMortalitySentences = getDoseMortality(redactionLog); + i = 1; + for (String sentence : doseMortalitySentences) { + resultMap.put(DOSE_MORTALITY_SENTENCE + i, sentence); + i++; + } - resultMap.put("Dosages", getDosages(redactionLog)); + resultMap.put(MORTALITY, getAsOneBlock(redactionLog, "mortality")); + + resultMap.put(DOSAGES, getDosages(redactionLog)); } if (oecdIn(oecd, Set.of("429"))) { var sentences = getAsSentences(redactionLog, "preliminary_test_results"); int i = 1; for (String sentence : sentences) { - resultMap.put("Preliminary_Test_Results_" + i, sentence); + resultMap.put(PRELIMINARY_TEST_RESULTS_SENTENCE + i, sentence); i++; } - resultMap.put("Test_Results", getAsOneBlock(redactionLog, "test_results")); - resultMap.put("Was_the_definitive_study_conducted_with_positive_control", getAsOneBlock(redactionLog, "positive_control")); + resultMap.put(TEST_RESULTS, getAsOneBlock(redactionLog, "test_results")); + resultMap.put(WAS_THE_DEFINITIVE_STUDY_CONDUCTED_WITH_POSITIVE_CONTROL, getAsOneBlock(redactionLog, "positive_control")); + + resultMap.put(RESULTS_MAIN_STUDY, getAsOneBlock(redactionLog, "results_(main_study)")); + resultMap.put(WHAT_WAS_THE_APPROACH_USED, getWhatWasTheApproachUsed(redactionLog)); + } - rssFileResponses.add(new RSSFileResponse(file.getFilename(), resultMap)); + rssFileResponses.add(new RSSFileResponse(file.getFilename(), sortInFloraFormOrder(resultMap))); } rssFileResponses.sort(Comparator.comparing(RSSFileResponse::getFilename)); @@ -249,6 +300,168 @@ public class RSSPoc2Service { } + private Map sortInFloraFormOrder(Map components) { + + Map resultMap = new LinkedHashMap<>(); + + resultMap.put(STUDY_TITLE, components.get(STUDY_TITLE)); + resultMap.put(PERFORMING_LABORATORY, components.get(PERFORMING_LABORATORY)); + resultMap.put(REPORT_NUMBER, components.get(REPORT_NUMBER)); + resultMap.put(GLP_STUDY, components.get(GLP_STUDY)); + resultMap.put(TEST_GUIDELINE_1, components.get(TEST_GUIDELINE_1)); + resultMap.put(TEST_GUIDELINE_2, components.get(TEST_GUIDELINE_2)); + resultMap.put(EXPERIMENTAL_STARTING_DATE, components.get(EXPERIMENTAL_STARTING_DATE)); + resultMap.put(EXPERIMENTAL_COMPLETION_DATE, components.get(EXPERIMENTAL_COMPLETION_DATE)); + resultMap.put(CERTIFICATE_OF_ANALYSIS_BATCH_IDENTIFICATION, components.get(CERTIFICATE_OF_ANALYSIS_BATCH_IDENTIFICATION)); + + String oecd = components.get(STUDY_TYPE_NUMBER); + + if (oecd == null || oecd.isEmpty()) { + return resultMap; + } + + resultMap.put(STUDY_TYPE_NUMBER, oecd); + + switch (oecd) { + + case "439": + case "406": + case "428": + case "438": + case "474": + case "487": + resultMap.put(STUDY_DESIGN, components.get(STUDY_DESIGN)); + resultMap.put(RESULTS_AND_CONCLUSIONS, components.get(RESULTS_AND_CONCLUSIONS)); + break; + case "425": + resultMap.put(SPECIES, components.get(SPECIES)); + resultMap.put(STRAIN, components.get(STRAIN)); + resultMap.put(DOSAGES, components.get(DOSAGES)); + resultMap.put(MORTALITY, components.get(MORTALITY)); + resultMap.putAll(getKeyContains(components, DOSE_MORTALITY_SENTENCE)); + resultMap.putAll(getKeyContains(components, CLINCAL_SIGNS_SENTENCE)); + resultMap.putAll(getKeyContains(components, DEVIATION_FROM_THE_GUIDELINE_SENTENCE)); + resultMap.put(CONCLUSION_LD_50_GREATER_THAN, components.get(CONCLUSION_LD_50_GREATER_THAN)); + resultMap.put(CONCLUSION_LD_50_MG_PER_MG, components.get(CONCLUSION_LD_50_MG_PER_MG)); + resultMap.put(CONCLUSION_MINIMUM_CONFIDENCE, components.get(CONCLUSION_MINIMUM_CONFIDENCE)); + resultMap.put(CONCLUSION_MAXIMUM_CONFIDENCE, components.get(CONCLUSION_MAXIMUM_CONFIDENCE)); + resultMap.put(STUDY_CONCLUSION, components.get(STUDY_CONCLUSION)); + break; + case "402": + resultMap.put(SPECIES, components.get(SPECIES)); + resultMap.put(STRAIN, components.get(STRAIN)); +// resultMap.put(D, components.get(STRAIN)); 402-Dose(s) (mg/Kg bw) TODO + resultMap.put(MORTALITY_STATEMENT, components.get(MORTALITY_STATEMENT)); + resultMap.putAll(getKeyContains(components, WEIGHT_BEHAVIOR_CHANGES_SENTENCE)); + resultMap.put(NECROPSY_FINDINGS, components.get(NECROPSY_FINDINGS)); + resultMap.putAll(getKeyContains(components, DEVIATION_FROM_THE_GUIDELINE_SENTENCE)); + resultMap.put(CONCLUSION_LD_50_GREATER_THAN, components.get(CONCLUSION_LD_50_GREATER_THAN)); + resultMap.put(CONCLUSION_LD_50_MG_PER_MG, components.get(CONCLUSION_LD_50_MG_PER_MG)); + resultMap.put(CONCLUSION_MINIMUM_CONFIDENCE, components.get(CONCLUSION_MINIMUM_CONFIDENCE)); + resultMap.put(CONCLUSION_MAXIMUM_CONFIDENCE, components.get(CONCLUSION_MAXIMUM_CONFIDENCE)); + resultMap.put(STUDY_CONCLUSION, components.get(STUDY_CONCLUSION)); + break; + case "403": + case "436": + resultMap.put(SPECIES, components.get(SPECIES)); + resultMap.put(STRAIN, components.get(STRAIN)); + resultMap.put(CONDUCTED_WITHIN_4_HOURS_OF_EXPOSURE, components.get(CONDUCTED_WITHIN_4_HOURS_OF_EXPOSURE)); + resultMap.putAll(getKeyContains(components, CLINICAL_OBSERVATIONS_SENTENCE)); + resultMap.putAll(getKeyContains(components, BODY_WEIGHT_CHANGES_SENTENCE)); + resultMap.putAll(getKeyContains(components, NECROPSY_FINDINGS_SENTENCE)); + resultMap.putAll(getKeyContains(components, DEVIATION_FROM_THE_GUIDELINE_SENTENCE)); + resultMap.put(CONCLUSION_LD_50_GREATER_THAN, components.get(CONCLUSION_LD_50_GREATER_THAN)); + resultMap.put(CONCLUSION_LD_50_MG_PER_MG, components.get(CONCLUSION_LD_50_MG_PER_MG)); + resultMap.put(CONCLUSION_MINIMUM_CONFIDENCE, components.get(CONCLUSION_MINIMUM_CONFIDENCE)); + resultMap.put(CONCLUSION_MAXIMUM_CONFIDENCE, components.get(CONCLUSION_MAXIMUM_CONFIDENCE)); + resultMap.put(STUDY_CONCLUSION, components.get(STUDY_CONCLUSION)); + break; + case "405": + resultMap.put(SPECIES, components.get(SPECIES)); + resultMap.put(STRAIN, components.get(STRAIN)); + resultMap.put(SEX, components.get(SEX)); + resultMap.put(NUMBER_OF_ANIMALS, components.get(NUMBER_OF_ANIMALS)); + resultMap.put(STUDY_DESIGN, components.get(STUDY_DESIGN)); + resultMap.put(DETAILING_OF_REPORTED_CHANGES, components.get(DETAILING_OF_REPORTED_CHANGES)); + resultMap.putAll(getKeyContains(components, DEVIATION_FROM_THE_GUIDELINE_SENTENCE)); + resultMap.put(STUDY_CONCLUSION, components.get(STUDY_CONCLUSION)); + break; + case "429": + resultMap.put(SPECIES, components.get(SPECIES)); + resultMap.put(STRAIN, components.get(STRAIN)); + resultMap.put(WAS_THE_DEFINITIVE_STUDY_CONDUCTED_WITH_POSITIVE_CONTROL, components.get(WAS_THE_DEFINITIVE_STUDY_CONDUCTED_WITH_POSITIVE_CONTROL)); + resultMap.put(STUDY_DESIGN, components.get(STUDY_DESIGN)); + resultMap.put(RESULTS_MAIN_STUDY, components.get(RESULTS_MAIN_STUDY)); + resultMap.putAll(getKeyContains(components, PRELIMINARY_TEST_RESULTS_SENTENCE)); + resultMap.put(WHAT_WAS_THE_APPROACH_USED, components.get(WHAT_WAS_THE_APPROACH_USED)); + resultMap.put(SEX, components.get(SEX)); + resultMap.put(NUMBER_OF_ANIMALS, components.get(NUMBER_OF_ANIMALS)); + resultMap.put(TEST_RESULTS, components.get(TEST_RESULTS)); + resultMap.putAll(getKeyContains(components, DEVIATION_FROM_THE_GUIDELINE_SENTENCE)); + resultMap.put(STUDY_CONCLUSION, components.get(STUDY_CONCLUSION)); + break; + case "404": + resultMap.put(SPECIES, components.get(SPECIES)); + resultMap.put(STRAIN, components.get(STRAIN)); + resultMap.put(STUDY_DESIGN, components.get(STUDY_DESIGN)); + resultMap.put(DETAILING_OF_REPORTED_CHANGES, components.get(DETAILING_OF_REPORTED_CHANGES)); + resultMap.putAll(getKeyContains(components, DEVIATION_FROM_THE_GUIDELINE_SENTENCE)); + resultMap.put(STUDY_CONCLUSION, components.get(STUDY_CONCLUSION)); + break; + case "471": + resultMap.put(STRAIN, components.get(STRAIN)); + resultMap.putAll(getKeyContains(components, DEVIATION_FROM_THE_GUIDELINE_SENTENCE)); + resultMap.put(STUDY_CONCLUSION, components.get(STUDY_CONCLUSION)); + break; + } + + return resultMap; + } + + + private Map getKeyContains(Map components, String compontentName) { + + Map resultMap = new LinkedHashMap<>(); + + for (Map.Entry entry : components.entrySet()) { + if (entry.getKey().contains(compontentName)) { + resultMap.put(entry.getKey(), entry.getValue()); + } + } + + return resultMap; + } + + + private String getWhatWasTheApproachUsed(RedactionLog redactionLog) { + + var approachUsed = redactionLog.getRedactionLogEntry().stream().filter(r -> r.getType().equals("approach_used")).map(RedactionLogEntry::getValue).findFirst(); + if (approachUsed.isPresent()) { + return "Group"; + } + return "Individual"; + } + + + private List getDoseMortality(RedactionLog redactionLog) { + + var doseMortalityEntries = redactionLog.getRedactionLogEntry().stream().filter(r -> r.getType().equals("dose_mortality")).collect(Collectors.toList()); + + Map> perYValue = new HashMap<>(); + + for (var entry : doseMortalityEntries) { + perYValue.computeIfAbsent(Math.round(entry.getPositions().get(0).getTopLeft().getY()), (x) -> new ArrayList<>()).add(entry.getValue()); + } + + List result = new ArrayList<>(); + for (Map.Entry> entry : perYValue.entrySet()) { + result.add(entry.getValue().stream().collect(Collectors.joining(", "))); + } + + return result; + } + + private String getJoinedValues(RedactionLog redactionLog, String type, String seperator) { return redactionLog.getRedactionLogEntry().stream().filter(r -> r.getType().equals(type)).map(RedactionLogEntry::getValue).collect(Collectors.joining(seperator)).trim(); @@ -337,7 +550,6 @@ public class RSSPoc2Service { return String.valueOf(uniqueAnimalNumbers.size()); } - // private String getDoseMlPerAnimal(RedactionLog redactionLog) { // // var doseMlPerAnimal = redactionLog.getRedactionLogEntry().stream().filter(r -> r.getType().equals("dose_(ml_per_animal)")).map(RedactionLogEntry::getValue).findFirst(); @@ -345,7 +557,6 @@ public class RSSPoc2Service { // return doseMlPerAnimal.orElse(""); // } - // private Set getEffectiveConcentrations(RedactionLog redactionLog) { // // return redactionLog.getRedactionLogEntry().stream().filter(r -> r.getType().equals("effective_concentration")).map(RedactionLogEntry::getValue).collect(Collectors.toSet()); @@ -484,12 +695,25 @@ public class RSSPoc2Service { private String getPerformingLaboratory(RedactionLog redactionLog) { - var laboratoryName = redactionLog.getRedactionLogEntry().stream().filter(r -> r.getType().equals("laboratory_name")).map(RedactionLogEntry::getValue).findFirst(); - var laboratoryCountry = redactionLog.getRedactionLogEntry().stream().filter(r -> r.getType().equals("laboratory_country")).map(RedactionLogEntry::getValue).findFirst(); +// LAB_NAME = "y": 418.50415 GERMANY_ "y": 390.90417 UNITED_K "y": 253.02429 --> GErmany, not unitedK + + var laboratoryEntry = redactionLog.getRedactionLogEntry().stream().filter(r -> r.getType().equals("laboratory_name")).findFirst(); + if (!laboratoryEntry.isPresent()) { + return ""; + } + + var laboratoryCountry = redactionLog.getRedactionLogEntry() + .stream() + .filter(r -> r.getType().equals("laboratory_country") && laboratoryEntry.get().getPositions().get(0).getTopLeft().getY() - r.getPositions() + .get(0) + .getTopLeft() + .getY() < 80) + .map(RedactionLogEntry::getValue) + .findFirst(); StringBuilder sb = new StringBuilder(); - if (laboratoryName.isPresent()) { - sb.append(laboratoryName.get()); + if (laboratoryEntry.isPresent()) { + sb.append(laboratoryEntry.get().getValue()); } if (laboratoryCountry.isPresent()) { sb.append(", ").append(laboratoryCountry.get());