|
29 | 29 | import java.util.stream.Collectors; |
30 | 30 |
|
31 | 31 | import de.symeda.sormas.api.DiseaseHelper; |
| 32 | +import de.symeda.sormas.api.event.EventReferenceDto; |
32 | 33 | import de.symeda.sormas.api.sample.PathogenTestType; |
33 | 34 | import org.apache.commons.collections4.CollectionUtils; |
34 | 35 |
|
@@ -119,10 +120,25 @@ public CommitDiscardWrapperComponent<PathogenTestForm> getPathogenTestCreateComp |
119 | 120 | int caseSampleCount, |
120 | 121 | Consumer<PathogenTestDto> onSavedPathogenTest, |
121 | 122 | boolean suppressNavigateToCase) { |
122 | | - CaseDataDto caseDataDto = FacadeProvider.getCaseFacade().getByUuid(sampleDto.getAssociatedCase().getUuid()); |
123 | | - PathogenTestForm createForm = new PathogenTestForm(sampleDto, true, caseSampleCount, false, true, caseDataDto.getDisease()); // Valid because jurisdiction doesn't matter for entities that are about to be created |
| 123 | + // Pathogen tests can be created for a sample that is associated with a case, event participant or contact. |
| 124 | + Disease associatedEventOrCaseOrContactDisease = null; |
| 125 | + if (sampleDto.getAssociatedCase() != null) { |
| 126 | + CaseDataDto caseDataDto = FacadeProvider.getCaseFacade().getByUuid(sampleDto.getAssociatedCase().getUuid()); |
| 127 | + associatedEventOrCaseOrContactDisease = caseDataDto.getDisease(); |
| 128 | + } |
| 129 | + if (associatedEventOrCaseOrContactDisease == null && sampleDto.getAssociatedEventParticipant() != null) { |
| 130 | + EventParticipantDto eventParticipant = FacadeProvider.getEventParticipantFacade().getEventParticipantByUuid(sampleDto.getAssociatedEventParticipant().getUuid()); |
| 131 | + EventReferenceDto eventDto = eventParticipant.getEvent(); |
| 132 | + EventDto participantEvent = FacadeProvider.getEventFacade().getEventByUuid(eventDto.getUuid(), false); |
| 133 | + associatedEventOrCaseOrContactDisease = participantEvent.getDisease(); |
| 134 | + } |
| 135 | + if (associatedEventOrCaseOrContactDisease == null && sampleDto.getAssociatedContact() != null) { |
| 136 | + ContactDto contact = FacadeProvider.getContactFacade().getByUuid(sampleDto.getAssociatedContact().getUuid()); |
| 137 | + associatedEventOrCaseOrContactDisease = contact.getDisease(); |
| 138 | + } |
| 139 | + PathogenTestForm createForm = new PathogenTestForm(sampleDto, true, caseSampleCount, false, true, associatedEventOrCaseOrContactDisease); // Valid because jurisdiction doesn't matter for entities that are about to be created |
124 | 140 | // Defaulting the case disease as tested disease |
125 | | - pathogenTest.setTestedDisease(caseDataDto.getDisease()); |
| 141 | + pathogenTest.setTestedDisease(associatedEventOrCaseOrContactDisease); |
126 | 142 | createForm.setValue(pathogenTest); |
127 | 143 | final CommitDiscardWrapperComponent<PathogenTestForm> editView = |
128 | 144 | new CommitDiscardWrapperComponent<>(createForm, UiUtil.permitted(UserRight.PATHOGEN_TEST_CREATE), createForm.getFieldGroup()); |
|
0 commit comments