From 6359f3c770b722833bd57a96175d7ca1ae493a64 Mon Sep 17 00:00:00 2001 From: MOHANKUMAR T <31698165+mohan-13@users.noreply.github.com> Date: Fri, 12 Jul 2024 12:35:33 +0530 Subject: [PATCH] BAH-4026 | Raise Sample event when the concept class is Specimen (#267) --- .../labconcepts/contract/Sample.java | 5 +++-- .../labconcepts/mapper/AllSamplesMapper.java | 4 ++-- .../model/event/SaleableTypeEvent.java | 5 +++-- .../labconcepts/model/event/SampleEvent.java | 6 +++--- .../ConceptServiceEventInterceptorTest.java | 4 ++-- .../model/event/SampleEventTest.java | 18 +++++++++++++++++- .../contract/mapper/AllSamplesMapperTest.java | 12 +++++++++--- .../web/contract/mapper/LabTestMapperTest.java | 2 +- .../web/contract/mapper/PanelMapperTest.java | 2 +- .../web/contract/mapper/SampleMapperTest.java | 4 ++-- 10 files changed, 43 insertions(+), 19 deletions(-) diff --git a/reference-data/api/src/main/java/org/bahmni/module/referencedata/labconcepts/contract/Sample.java b/reference-data/api/src/main/java/org/bahmni/module/referencedata/labconcepts/contract/Sample.java index f2b5c8728b..84aeda70ed 100644 --- a/reference-data/api/src/main/java/org/bahmni/module/referencedata/labconcepts/contract/Sample.java +++ b/reference-data/api/src/main/java/org/bahmni/module/referencedata/labconcepts/contract/Sample.java @@ -1,10 +1,11 @@ package org.bahmni.module.referencedata.labconcepts.contract; +import java.util.Arrays; import java.util.List; public class Sample extends Resource { private String shortName; - public static final String SAMPLE_CONCEPT_CLASS = "Sample"; + public static final List SAMPLE_CONCEPT_CLASSES = Arrays.asList("Sample", "Specimen"); private Double sortOrder; private List tests; private List panels; @@ -40,4 +41,4 @@ public Double getSortOrder() { public void setSortOrder(Double sortOrder) { this.sortOrder = sortOrder; } -} \ No newline at end of file +} diff --git a/reference-data/api/src/main/java/org/bahmni/module/referencedata/labconcepts/mapper/AllSamplesMapper.java b/reference-data/api/src/main/java/org/bahmni/module/referencedata/labconcepts/mapper/AllSamplesMapper.java index d033492f03..29ff54aec6 100644 --- a/reference-data/api/src/main/java/org/bahmni/module/referencedata/labconcepts/mapper/AllSamplesMapper.java +++ b/reference-data/api/src/main/java/org/bahmni/module/referencedata/labconcepts/mapper/AllSamplesMapper.java @@ -3,7 +3,7 @@ import org.bahmni.module.referencedata.labconcepts.contract.AllSamples; import org.openmrs.Concept; -import static org.bahmni.module.referencedata.labconcepts.contract.Sample.SAMPLE_CONCEPT_CLASS; +import static org.bahmni.module.referencedata.labconcepts.contract.Sample.SAMPLE_CONCEPT_CLASSES; public class AllSamplesMapper extends ResourceMapper { @@ -18,7 +18,7 @@ public AllSamples map(Concept allSamplesConcept) { allSamples.setDescription(ConceptExtension.getDescription(allSamplesConcept)); for (Concept setMember : allSamplesConcept.getSetMembers()) { - if (ConceptExtension.isOfConceptClass(setMember, SAMPLE_CONCEPT_CLASS)) { + if (ConceptExtension.isOfAnyConceptClass(setMember, SAMPLE_CONCEPT_CLASSES)) { SampleMapper sampleMapper = new SampleMapper(); allSamples.addSample(sampleMapper.map(setMember)); } diff --git a/reference-data/omod/src/main/java/org/bahmni/module/referencedata/labconcepts/model/event/SaleableTypeEvent.java b/reference-data/omod/src/main/java/org/bahmni/module/referencedata/labconcepts/model/event/SaleableTypeEvent.java index 6f884a6cd7..f71ea0a580 100644 --- a/reference-data/omod/src/main/java/org/bahmni/module/referencedata/labconcepts/model/event/SaleableTypeEvent.java +++ b/reference-data/omod/src/main/java/org/bahmni/module/referencedata/labconcepts/model/event/SaleableTypeEvent.java @@ -17,7 +17,7 @@ import static org.bahmni.module.referencedata.labconcepts.contract.LabTest.LAB_TEST_CONCEPT_CLASSES; import static org.bahmni.module.referencedata.labconcepts.contract.Panel.LAB_SET_CONCEPT_CLASS; import static org.bahmni.module.referencedata.labconcepts.contract.RadiologyTest.RADIOLOGY_TEST_CONCEPT_CLASSES; -import static org.bahmni.module.referencedata.labconcepts.contract.Sample.SAMPLE_CONCEPT_CLASS; +import static org.bahmni.module.referencedata.labconcepts.contract.Sample.SAMPLE_CONCEPT_CLASSES; public class SaleableTypeEvent implements ConceptServiceOperationEvent { @@ -29,9 +29,10 @@ public class SaleableTypeEvent implements ConceptServiceOperationEvent { private List supportedOperations = Arrays.asList("saveConcept", "updateConcept", "retireConcept", "purgeConcept"); private List unhandledClasses = new ArrayList(){{ - addAll(Arrays.asList(LAB_SET_CONCEPT_CLASS, SAMPLE_CONCEPT_CLASS, DEPARTMENT_CONCEPT_CLASS)); + addAll(Arrays.asList(LAB_SET_CONCEPT_CLASS, DEPARTMENT_CONCEPT_CLASS)); addAll(LAB_TEST_CONCEPT_CLASSES); addAll(RADIOLOGY_TEST_CONCEPT_CLASSES); + addAll(SAMPLE_CONCEPT_CLASSES); }}; private List unhandledConcepsByName = Arrays.asList(ALL_SAMPLES, ALL_TESTS_AND_PANELS); diff --git a/reference-data/omod/src/main/java/org/bahmni/module/referencedata/labconcepts/model/event/SampleEvent.java b/reference-data/omod/src/main/java/org/bahmni/module/referencedata/labconcepts/model/event/SampleEvent.java index 1191423631..fdc69f74c8 100644 --- a/reference-data/omod/src/main/java/org/bahmni/module/referencedata/labconcepts/model/event/SampleEvent.java +++ b/reference-data/omod/src/main/java/org/bahmni/module/referencedata/labconcepts/model/event/SampleEvent.java @@ -2,8 +2,8 @@ import org.openmrs.Concept; -import static org.bahmni.module.referencedata.labconcepts.contract.Sample.SAMPLE_CONCEPT_CLASS; -import static org.bahmni.module.referencedata.labconcepts.mapper.ConceptExtension.isOfConceptClass; +import static org.bahmni.module.referencedata.labconcepts.contract.Sample.SAMPLE_CONCEPT_CLASSES; +import static org.bahmni.module.referencedata.labconcepts.mapper.ConceptExtension.isOfAnyConceptClass; public class SampleEvent extends ConceptOperationEvent { @@ -14,7 +14,7 @@ public SampleEvent(String url, String category, String title) { @Override public boolean isResourceConcept(Concept concept) { - return isOfConceptClass(concept, SAMPLE_CONCEPT_CLASS); + return isOfAnyConceptClass(concept, SAMPLE_CONCEPT_CLASSES); } diff --git a/reference-data/omod/src/test/java/org/bahmni/module/referencedata/labconcepts/advice/ConceptServiceEventInterceptorTest.java b/reference-data/omod/src/test/java/org/bahmni/module/referencedata/labconcepts/advice/ConceptServiceEventInterceptorTest.java index 346d7cb4e7..033defa11e 100644 --- a/reference-data/omod/src/test/java/org/bahmni/module/referencedata/labconcepts/advice/ConceptServiceEventInterceptorTest.java +++ b/reference-data/omod/src/test/java/org/bahmni/module/referencedata/labconcepts/advice/ConceptServiceEventInterceptorTest.java @@ -55,7 +55,7 @@ public class ConceptServiceEventInterceptorTest { public void setup() { MockitoAnnotations.initMocks(this); - concept = new ConceptBuilder().withClass(Sample.SAMPLE_CONCEPT_CLASS).withUUID(SampleEventTest.SAMPLE_CONCEPT_UUID).build(); + concept = new ConceptBuilder().withClass(Sample.SAMPLE_CONCEPT_CLASSES.get(0)).withUUID(SampleEventTest.SAMPLE_CONCEPT_UUID).build(); Concept parentConcept = new ConceptBuilder().withName(AllSamples.ALL_SAMPLES).withSetMember(concept).build(); @@ -143,4 +143,4 @@ public void shouldSaveEventInTheSameTransactionAsTheTrigger() throws Throwable { assertEquals(AFTransactionWork.PropagationDefinition.PROPAGATION_REQUIRED, captor.getValue().getTxPropagationDefinition()); } -} \ No newline at end of file +} diff --git a/reference-data/omod/src/test/java/org/bahmni/module/referencedata/labconcepts/model/event/SampleEventTest.java b/reference-data/omod/src/test/java/org/bahmni/module/referencedata/labconcepts/model/event/SampleEventTest.java index 43e60125ad..ec2b778f71 100644 --- a/reference-data/omod/src/test/java/org/bahmni/module/referencedata/labconcepts/model/event/SampleEventTest.java +++ b/reference-data/omod/src/test/java/org/bahmni/module/referencedata/labconcepts/model/event/SampleEventTest.java @@ -34,8 +34,12 @@ public class SampleEventTest { public static final String SAMPLE_CONCEPT_UUID = "aebc57b7-0683-464e-ac48-48b8838abdfc"; + public static final String SPECIMEN_CONCEPT_UUID = "aebc57b7-0683-464e-ac48-48b8838abdff"; + private Concept concept; + private Concept specimenConcept; + @Mock private ConceptService conceptService; private Concept parentConcept; @@ -46,6 +50,8 @@ public void setup() { concept = new ConceptBuilder().withClass("Sample").withUUID(SAMPLE_CONCEPT_UUID).build(); + specimenConcept = new ConceptBuilder().withClass("Specimen").withUUID(SPECIMEN_CONCEPT_UUID).build(); + parentConcept = new ConceptBuilder().withName(AllSamples.ALL_SAMPLES).withSetMember(concept).build(); List conceptSets = getConceptSets(parentConcept, concept); @@ -69,6 +75,16 @@ public void createEventForSampleEvent() throws Exception { assertEquals(event.getCategory(), "lab"); } + @Test + public void createSampleEventForSpecimenConcept() throws Exception { + Event event = new Operation(ConceptService.class.getMethod("saveConcept", Concept.class)).apply(new Object[]{specimenConcept}).get(0); + Event anotherEvent = new Operation(ConceptService.class.getMethod("saveConcept", Concept.class)).apply(new Object[]{specimenConcept}).get(0); + assertNotNull(event); + assertFalse(event.getUuid().equals(anotherEvent.getUuid())); + assertEquals(event.getTitle(), "sample"); + assertEquals(event.getCategory(), "lab"); + } + @Test public void shouldNotCreateEventForSampleEventIfThereIsDifferentConceptClass() throws Exception { concept = new ConceptBuilder().withClass("procedure").withClassUUID("some").withUUID(SAMPLE_CONCEPT_UUID).build(); @@ -106,4 +122,4 @@ public void createEventForSampleWithParentConceptMissing() throws Exception { assertEquals(event.getCategory(), ConceptServiceEventFactory.LAB); } -} \ No newline at end of file +} diff --git a/reference-data/omod/src/test/java/org/bahmni/module/referencedata/web/contract/mapper/AllSamplesMapperTest.java b/reference-data/omod/src/test/java/org/bahmni/module/referencedata/web/contract/mapper/AllSamplesMapperTest.java index 93b070b8bb..053e3e5ff7 100644 --- a/reference-data/omod/src/test/java/org/bahmni/module/referencedata/web/contract/mapper/AllSamplesMapperTest.java +++ b/reference-data/omod/src/test/java/org/bahmni/module/referencedata/web/contract/mapper/AllSamplesMapperTest.java @@ -36,6 +36,7 @@ public class AllSamplesMapperTest { private AllSamplesMapper allSamplesMapper; private SampleMapper sampleMapper; private Concept sampleConcept; + private Concept specimenConcept; private Date dateCreated; private Date dateChanged; private Concept labSampleConceptSet; @@ -59,12 +60,17 @@ public void setUp() throws Exception { Concept testConcept = new ConceptBuilder().withUUID("Test UUID").withDateCreated(dateCreated).withClass(LabTest.LAB_TEST_CONCEPT_CLASSES.get(0)).withDescription("SomeDescription") .withDateChanged(dateChanged).withShortName("ShortName").withName("Test concept").withDataType(ConceptDatatype.NUMERIC).build(); - sampleConcept = new ConceptBuilder().withUUID("Sample UUID").withDateCreated(dateCreated).withClass(Sample.SAMPLE_CONCEPT_CLASS). + sampleConcept = new ConceptBuilder().withUUID("Sample UUID").withDateCreated(dateCreated).withClass(Sample.SAMPLE_CONCEPT_CLASSES.get(0)). withDateChanged(dateChanged).withSetMember(testConcept).withShortName("ShortName").withName("SampleName").build(); + specimenConcept = new ConceptBuilder().withUUID("Specimen UUID").withDateCreated(dateCreated).withClass(Sample.SAMPLE_CONCEPT_CLASSES.get(1)). + withDateChanged(dateChanged).withSetMember(testConcept).withShortName("SpecimenShortName").withName("SpecimenName").build(); + labSampleConceptSet = new ConceptBuilder().withUUID("Lab Samples UUID").withDateCreated(dateCreated).withDateChanged(dateChanged) .withName(AllSamples.ALL_SAMPLES).withClassUUID(ConceptClass.LABSET_UUID).withShortName("Lab samples short name").withDescription("Lab samples Description") - .withSetMember(sampleConcept).build(); + .withSetMember(sampleConcept) + .withSetMember(specimenConcept) + .build(); when(Context.getConceptService()).thenReturn(conceptService); } @@ -80,7 +86,7 @@ public void mapAllSampleFieldsFromConcept() throws Exception { assertEquals(dateChanged, labSamplesData.getLastUpdated()); assertEquals("Lab samples Description", labSamplesData.getDescription()); List samples = labSamplesData.getSamples(); - assertEquals(1, samples.size()); + assertEquals(2, samples.size()); assertEquals(sampleData.getId(), samples.get(0).getId()); } diff --git a/reference-data/omod/src/test/java/org/bahmni/module/referencedata/web/contract/mapper/LabTestMapperTest.java b/reference-data/omod/src/test/java/org/bahmni/module/referencedata/web/contract/mapper/LabTestMapperTest.java index 135e1b1805..fcf243d440 100644 --- a/reference-data/omod/src/test/java/org/bahmni/module/referencedata/web/contract/mapper/LabTestMapperTest.java +++ b/reference-data/omod/src/test/java/org/bahmni/module/referencedata/web/contract/mapper/LabTestMapperTest.java @@ -69,7 +69,7 @@ public void setUp() throws Exception { .withDateChanged(dateChanged).withShortName("ShortName").withName("Test Name Here").withDataType(ConceptDatatype.NUMERIC).build(); Concept testAndPanelsConcept = new ConceptBuilder().withUUID("Test and Panels UUID").withDateCreated(dateCreated).withClassUUID(ConceptClass.CONVSET_UUID) .withDateChanged(dateChanged).withShortName("ShortName").withName(AllTestsAndPanels.ALL_TESTS_AND_PANELS).withSetMember(testConcept).build(); - Concept sampleConcept = new ConceptBuilder().withUUID("Sample UUID").withDateCreated(dateCreated).withClass(Sample.SAMPLE_CONCEPT_CLASS). + Concept sampleConcept = new ConceptBuilder().withUUID("Sample UUID").withDateCreated(dateCreated).withClass(Sample.SAMPLE_CONCEPT_CLASSES.get(0)). withDateChanged(dateChanged).withSetMember(testConcept).withShortName("ShortName").withName("SampleName").build(); Concept laboratoryConcept = new ConceptBuilder().withUUID("Laboratory UUID") .withName(AllSamples.ALL_SAMPLES).withClassUUID(ConceptClass.LABSET_UUID) diff --git a/reference-data/omod/src/test/java/org/bahmni/module/referencedata/web/contract/mapper/PanelMapperTest.java b/reference-data/omod/src/test/java/org/bahmni/module/referencedata/web/contract/mapper/PanelMapperTest.java index 37a9fc3aca..843d8ef327 100644 --- a/reference-data/omod/src/test/java/org/bahmni/module/referencedata/web/contract/mapper/PanelMapperTest.java +++ b/reference-data/omod/src/test/java/org/bahmni/module/referencedata/web/contract/mapper/PanelMapperTest.java @@ -69,7 +69,7 @@ public void setUp() throws Exception { .withSetMember(testConcept).withDateChanged(dateChanged).withShortName("ShortName").withName("Panel Name Here").withDataType(ConceptDatatype.NUMERIC).build(); Concept testAndPanelsConcept = new ConceptBuilder().withUUID("Test and Panels UUID").withDateCreated(dateCreated).withClassUUID(ConceptClass.CONVSET_UUID) .withDateChanged(dateChanged).withShortName("ShortName").withName(AllTestsAndPanels.ALL_TESTS_AND_PANELS).withSetMember(panelConcept).build(); - Concept sampleConcept = new ConceptBuilder().withUUID("Sample UUID").withDateCreated(dateCreated).withClass(Sample.SAMPLE_CONCEPT_CLASS). + Concept sampleConcept = new ConceptBuilder().withUUID("Sample UUID").withDateCreated(dateCreated).withClass(Sample.SAMPLE_CONCEPT_CLASSES.get(0)). withDateChanged(dateChanged).withSetMember(panelConcept).withShortName("ShortName").withName("SampleName").build(); Concept departmentConcept = new ConceptBuilder().withUUID("Department UUID").withDateCreated(dateCreated). withDateChanged(dateChanged).withClass("Department").withClassUUID(ConceptClass.CONVSET_UUID).withSetMember(panelConcept).withDescription("Some Description").withName("Department Name").build(); diff --git a/reference-data/omod/src/test/java/org/bahmni/module/referencedata/web/contract/mapper/SampleMapperTest.java b/reference-data/omod/src/test/java/org/bahmni/module/referencedata/web/contract/mapper/SampleMapperTest.java index 429c5bbd7e..c26faf015e 100644 --- a/reference-data/omod/src/test/java/org/bahmni/module/referencedata/web/contract/mapper/SampleMapperTest.java +++ b/reference-data/omod/src/test/java/org/bahmni/module/referencedata/web/contract/mapper/SampleMapperTest.java @@ -55,7 +55,7 @@ public void setUp() { when(Context.getLocale()).thenReturn(defaultLocale); sampleConcept = new ConceptBuilder().forSample().withShortName("ShortName").build(); allSamplesConcept = new ConceptBuilder().withUUID("Laboratory UUID") - .withName(AllSamples.ALL_SAMPLES).withClass(Sample.SAMPLE_CONCEPT_CLASS) + .withName(AllSamples.ALL_SAMPLES).withClass(Sample.SAMPLE_CONCEPT_CLASSES.get(0)) .withSetMember(sampleConcept).build(); ConceptSet conceptSet = createConceptSet(allSamplesConcept, sampleConcept); sortOrder = Double.valueOf(22); @@ -120,4 +120,4 @@ public void mapPanelsFromConceptSetMembers(){ assertEquals(1, sample.getPanels().size()); assertEquals("PanelName", sample.getPanels().get(0).getName()); } -} \ No newline at end of file +}