Skip to content

Commit

Permalink
BAH-4026 | Raise Sample event when the concept class is Specimen (#267)
Browse files Browse the repository at this point in the history
  • Loading branch information
mohan-13 authored Jul 12, 2024
1 parent 1555fbe commit 6359f3c
Show file tree
Hide file tree
Showing 10 changed files with 43 additions and 19 deletions.
Original file line number Diff line number Diff line change
@@ -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<String> SAMPLE_CONCEPT_CLASSES = Arrays.asList("Sample", "Specimen");
private Double sortOrder;
private List<ResourceReference> tests;
private List<ResourceReference> panels;
Expand Down Expand Up @@ -40,4 +41,4 @@ public Double getSortOrder() {
public void setSortOrder(Double sortOrder) {
this.sortOrder = sortOrder;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -29,9 +29,10 @@ public class SaleableTypeEvent implements ConceptServiceOperationEvent {
private List<String> supportedOperations = Arrays.asList("saveConcept", "updateConcept", "retireConcept", "purgeConcept");

private List<String> unhandledClasses = new ArrayList<String>(){{
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<String> unhandledConcepsByName = Arrays.asList(ALL_SAMPLES, ALL_TESTS_AND_PANELS);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -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);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -143,4 +143,4 @@ public void shouldSaveEventInTheSameTransactionAsTheTrigger() throws Throwable {
assertEquals(AFTransactionWork.PropagationDefinition.PROPAGATION_REQUIRED, captor.getValue().getTxPropagationDefinition());
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<ConceptSet> conceptSets = getConceptSets(parentConcept, concept);
Expand All @@ -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();
Expand Down Expand Up @@ -106,4 +122,4 @@ public void createEventForSampleWithParentConceptMissing() throws Exception {
assertEquals(event.getCategory(), ConceptServiceEventFactory.LAB);
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}
Expand All @@ -80,7 +86,7 @@ public void mapAllSampleFieldsFromConcept() throws Exception {
assertEquals(dateChanged, labSamplesData.getLastUpdated());
assertEquals("Lab samples Description", labSamplesData.getDescription());
List<Sample> samples = labSamplesData.getSamples();
assertEquals(1, samples.size());
assertEquals(2, samples.size());
assertEquals(sampleData.getId(), samples.get(0).getId());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -120,4 +120,4 @@ public void mapPanelsFromConceptSetMembers(){
assertEquals(1, sample.getPanels().size());
assertEquals("PanelName", sample.getPanels().get(0).getName());
}
}
}

0 comments on commit 6359f3c

Please sign in to comment.