Skip to content

Commit

Permalink
Merge pull request #1176 from mozzy11/develop
Browse files Browse the repository at this point in the history
Update Patient History Provider
  • Loading branch information
mozzy11 authored Jul 11, 2024
2 parents 67c4de4 + 562af4e commit ca7085e
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@
import org.openelisglobal.common.rest.provider.bean.patientHistory.TestDisplay;
import org.openelisglobal.dictionary.service.DictionaryService;
import org.openelisglobal.dictionary.valueholder.Dictionary;
import org.openelisglobal.panel.valueholder.Panel;
import org.openelisglobal.result.service.ResultService;
import org.openelisglobal.result.valueholder.Result;
import org.openelisglobal.sample.valueholder.Sample;
import org.openelisglobal.samplehuman.service.SampleHumanService;
import org.openelisglobal.test.service.TestService;
import org.openelisglobal.test.valueholder.Test;
import org.openelisglobal.test.valueholder.TestSection;
import org.openelisglobal.typeofsample.valueholder.TypeOfSample;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
Expand Down Expand Up @@ -57,50 +57,52 @@ public List<ResultTree> getResultTreeArray(@RequestParam String patientId) {
});

List<Analysis> analyses = new ArrayList<>();
Map<Panel, Set<Result>> panelResultMap = new HashMap<>();
Map<TestSection, Set<Panel>> testSectionPanelMap = new HashMap<>();

Set<Panel> filteredPanels;
Set<Result> filteredResults;
TestSection testSection = null;
Panel panel = null;
Map<TypeOfSample, Map<TestSection, Set<Result>>> sampleResultMap = new HashMap<>();
Map<TestSection, Set<TypeOfSample>> testSectionPanelMap = new HashMap<>();

for (Result result : results) {
analyses.add(result.getAnalysis());
testSection = result.getAnalysis().getTestSection();
panel = result.getAnalysis().getPanel() != null ? result.getAnalysis().getPanel()
: createDummyPanel(result.getAnalysis().getTestSection().getId());

TestSection testSection = result.getAnalysis().getTest().getTestSection();
TypeOfSample sampleType = result.getAnalysis().getSampleItem().getTypeOfSample();
if (testSectionPanelMap.containsKey(testSection)) {
testSectionPanelMap.get(testSection).add(panel);
testSectionPanelMap.get(testSection).add(sampleType);
} else {
filteredPanels = new HashSet<>();
filteredPanels.add(panel);
testSectionPanelMap.put(testSection, filteredPanels);
Set<TypeOfSample> filteredSamples = new HashSet<>();
filteredSamples.add(sampleType);
testSectionPanelMap.put(testSection, filteredSamples);
}

if (panelResultMap.containsKey(panel)) {
panelResultMap.get(panel).add(result);
if (sampleResultMap.containsKey(sampleType)) {
if (sampleResultMap.get(sampleType).containsKey(testSection)) {
sampleResultMap.get(sampleType).get(testSection).add(result);
} else {
Set<Result> filteredResults = new HashSet<>();
filteredResults.add(result);
sampleResultMap.get(sampleType).put(testSection, filteredResults);
}
} else {
filteredResults = new HashSet<>();
Map<TestSection, Set<Result>> unitResultMap = new HashMap<>();
Set<Result> filteredResults = new HashSet<>();
filteredResults.add(result);
panelResultMap.put(panel, filteredResults);
unitResultMap.put(testSection, filteredResults);
sampleResultMap.put(sampleType, unitResultMap);
}
}

List<ResultTree> resultTrees = new ArrayList<>();

for (Map.Entry<TestSection, Set<Panel>> entry : testSectionPanelMap.entrySet()) {
for (Map.Entry<TestSection, Set<TypeOfSample>> entry : testSectionPanelMap.entrySet()) {
List<PanelDisplay> panelDisplays = new ArrayList<>();

for (Panel panelEntry : entry.getValue()) {
for (TypeOfSample sampleEntry : entry.getValue()) {
Map<Test, Set<Result>> testResultMap = new HashMap<>();

for (Result resultEntry : panelResultMap.get(panelEntry)) {
for (Result resultEntry : sampleResultMap.get(sampleEntry).get(entry.getKey())) {

Test test = resultEntry.getAnalysis().getTest();

if (!testResultMap.containsKey(test)) {
filteredResults = new HashSet<>();
Set<Result> filteredResults = new HashSet<>();
filteredResults.add(resultEntry);
testResultMap.put(test, filteredResults);
} else {
Expand Down Expand Up @@ -156,7 +158,7 @@ public List<ResultTree> getResultTreeArray(@RequestParam String patientId) {
}

PanelDisplay panelDisplay = new PanelDisplay();
panelDisplay.setDisplay(panelEntry.getPanelName().contains("NEW") ? "" : panelEntry.getLocalizedName());
panelDisplay.setDisplay(sampleEntry.getLocalizedName());
panelDisplay.setSubSets(testDisplays);
panelDisplays.add(panelDisplay);
}
Expand All @@ -170,13 +172,6 @@ public List<ResultTree> getResultTreeArray(@RequestParam String patientId) {
return resultTrees;
}

private Panel createDummyPanel(String id) {
Panel panel = new Panel();
panel.setId("NEW" + id);
panel.setPanelName("NEW" + id);
return panel;
}

@GetMapping(value = "test-result-tree", produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
public PanelDisplay getTestResultTree(@RequestParam String patientId, @RequestParam String testId) {
Expand Down
16 changes: 16 additions & 0 deletions src/main/java/org/openelisglobal/result/valueholder/Result.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
package org.openelisglobal.result.valueholder;

import com.fasterxml.jackson.annotation.JsonIgnore;
import java.util.Objects;
import java.util.UUID;
import org.openelisglobal.analysis.valueholder.Analysis;
import org.openelisglobal.analyte.valueholder.Analyte;
Expand Down Expand Up @@ -220,4 +221,19 @@ public Integer getVirralloadLowLimit() {
public void setVirralloadLowLimit(Integer virralloadLowLimit) {
this.virralloadLowLimit = virralloadLowLimit;
}

@Override
public boolean equals(Object o) {
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
return false;
Result that = (Result) o;
return id.equals(that.id);
}

@Override
public int hashCode() {
return Objects.hash(id);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package org.openelisglobal.typeofsample.valueholder;

import java.util.Objects;
import org.openelisglobal.common.valueholder.BaseObject;
import org.openelisglobal.common.valueholder.ValueHolder;
import org.openelisglobal.localization.valueholder.Localization;
Expand Down Expand Up @@ -113,4 +114,19 @@ public Localization getLocalization() {
public void setLocalization(Localization localization) {
this.localization.setValue(localization);
}

@Override
public boolean equals(Object o) {
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
return false;
TypeOfSample that = (TypeOfSample) o;
return id.equals(that.id);
}

@Override
public int hashCode() {
return Objects.hash(id);
}
}

0 comments on commit ca7085e

Please sign in to comment.