Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BAH-3892 | Support atomfeed test events for concepts with class Test #263

Merged
merged 3 commits into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,18 @@
import org.openmrs.ConceptAnswer;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;

public class LabTest extends Resource {
private String description;
private String resultType;
private String testUnitOfMeasure;
private Double sortOrder;
public static final String LAB_TEST_CONCEPT_CLASS = "LabTest";

public static final List<String> LAB_TEST_CONCEPT_CLASSES = Arrays.asList("LabTest","Test");

private Collection<CodedTestAnswer> codedTestAnswer;


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ public static boolean isOfConceptClass(Concept concept, String conceptClassName)
return concept.getConceptClass() != null && concept.getConceptClass().getName() != null && concept.getConceptClass().getName().equals(conceptClassName);
}

public static boolean isOfAnyConceptClass(Concept concept, List<String> conceptClassNames) {
return concept.getConceptClass() != null && concept.getConceptClass().getName() != null && conceptClassNames.contains(concept.getConceptClass().getName());
mohan-13 marked this conversation as resolved.
Show resolved Hide resolved
}

public static boolean isOfConceptClassByUUID(Concept concept, String conceptClassUUID) {
return concept.getConceptClass() != null && concept.getConceptClass().getUuid().equals(conceptClassUUID);
}
Expand All @@ -122,4 +126,15 @@ public static List<ResourceReference> getResourceReferencesOfConceptClass(List<C
return resourceReferences;
}

public static List<ResourceReference> getResourceReferencesOfConceptClasses(List<Concept> setMembers, List<String> conceptClasses) {
ResourceReferenceMapper resourceReferenceMapper = new ResourceReferenceMapper();
List<ResourceReference> resourceReferences = new ArrayList<>();
for (Concept setMember : setMembers) {
if (isOfAnyConceptClass(setMember, conceptClasses)) {
resourceReferences.add(resourceReferenceMapper.map(setMember));
}
}
return resourceReferences;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import org.bahmni.module.referencedata.labconcepts.contract.LabTest;
import org.openmrs.Concept;

import static org.bahmni.module.referencedata.labconcepts.mapper.ConceptExtension.getResourceReferencesOfConceptClass;
import static org.bahmni.module.referencedata.labconcepts.mapper.ConceptExtension.getResourceReferencesOfConceptClasses;

public class DepartmentMapper extends ResourceMapper {

Expand All @@ -17,7 +17,7 @@ public Department map(Concept departmentConcept) {
Department department = new Department();
department = mapResource(department, departmentConcept);
department.setDescription(ConceptExtension.getDescriptionOrName(departmentConcept));
department.setTests(getResourceReferencesOfConceptClass(departmentConcept.getSetMembers(), LabTest.LAB_TEST_CONCEPT_CLASS));
department.setTests(getResourceReferencesOfConceptClasses(departmentConcept.getSetMembers(), LabTest.LAB_TEST_CONCEPT_CLASSES));
return department;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public PanelMapper() {
public Panel map(Concept panelConcept) {
Panel panel = new Panel();
panel = mapResource(panel, panelConcept);
panel.setTests(ConceptExtension.getResourceReferencesOfConceptClass(panelConcept.getSetMembers(), LabTest.LAB_TEST_CONCEPT_CLASS));
panel.setTests(ConceptExtension.getResourceReferencesOfConceptClasses(panelConcept.getSetMembers(), LabTest.LAB_TEST_CONCEPT_CLASSES));
panel.setSortOrder(getSortWeight(panelConcept));
panel.setDescription(ConceptExtension.getDescriptionOrName(panelConcept));
return panel;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.openmrs.api.context.Context;

import static org.bahmni.module.referencedata.labconcepts.mapper.ConceptExtension.getResourceReferencesOfConceptClass;
import static org.bahmni.module.referencedata.labconcepts.mapper.ConceptExtension.getResourceReferencesOfConceptClasses;

public class SampleMapper extends ResourceMapper {
public SampleMapper() {
Expand All @@ -20,9 +21,9 @@ public Sample map(Concept sampleConcept) {
sample = mapResource(sample, sampleConcept);
sample.setShortName(sampleConcept.getShortestName(Context.getLocale(), false).getName());
sample.setSortOrder(getSortWeight(sampleConcept));
sample.setTests(getResourceReferencesOfConceptClass(sampleConcept.getSetMembers(), LabTest.LAB_TEST_CONCEPT_CLASS));
sample.setTests(getResourceReferencesOfConceptClasses(sampleConcept.getSetMembers(), LabTest.LAB_TEST_CONCEPT_CLASSES));
sample.setPanels(getResourceReferencesOfConceptClass(sampleConcept.getSetMembers(), Panel.LAB_SET_CONCEPT_CLASS));
return sample;
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@
import org.openmrs.Concept;
import org.openmrs.ConceptClass;

import static org.bahmni.module.referencedata.labconcepts.contract.LabTest.LAB_TEST_CONCEPT_CLASS;
import static org.bahmni.module.referencedata.labconcepts.mapper.ConceptExtension.isOfConceptClass;
import static org.bahmni.module.referencedata.labconcepts.mapper.ConceptExtension.isOfConceptClassByUUID;
import static org.bahmni.module.referencedata.labconcepts.contract.LabTest.LAB_TEST_CONCEPT_CLASSES;
import static org.bahmni.module.referencedata.labconcepts.mapper.ConceptExtension.*;

public class TestAndPanelMapper extends ResourceMapper {

Expand All @@ -31,12 +30,12 @@ public TestsAndPanels map(Concept sampleConcept) {
}

private void addConcept(TestsAndPanels testsAndPanels, Concept concept) {
if (isOfConceptClass(concept, LAB_TEST_CONCEPT_CLASS)) {
if (isOfAnyConceptClass(concept, LAB_TEST_CONCEPT_CLASSES)) {
LabTest test = labTestMapper.map(concept);
testsAndPanels.addTest(test);
} else if (isOfConceptClassByUUID(concept, ConceptClass.LABSET_UUID)) {
Panel panel = panelMapper.map(concept);
testsAndPanels.addPanel(panel);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
import java.util.List;
import java.util.UUID;

import static org.bahmni.module.referencedata.labconcepts.contract.LabTest.LAB_TEST_CONCEPT_CLASS;
import static org.bahmni.module.referencedata.labconcepts.mapper.ConceptExtension.isOfConceptClass;
import static org.bahmni.module.referencedata.labconcepts.contract.LabTest.LAB_TEST_CONCEPT_CLASSES;
import static org.bahmni.module.referencedata.labconcepts.mapper.ConceptExtension.isOfAnyConceptClass;

public class LabTestEvent extends ConceptOperationEvent {

Expand All @@ -20,25 +20,24 @@ public LabTestEvent(String url, String category, String title) {
}

public boolean isResourceConcept(Concept concept) {
return isOfConceptClass(concept, LAB_TEST_CONCEPT_CLASS) || (getParentOfTypeLabTest(concept) != null);
return isOfAnyConceptClass(concept, LAB_TEST_CONCEPT_CLASSES) || (getParentOfTypeLabTest(concept) != null);
}

private Concept getParentOfTypeLabTest(Concept concept) {
ConceptHelper conceptHelper = new ConceptHelper(Context.getConceptService());
List<Concept> parentConcepts = conceptHelper.getParentConcepts(concept);
for (Concept parentConcept : parentConcepts) {
if (isOfConceptClass(parentConcept, LAB_TEST_CONCEPT_CLASS)) {
if (isOfAnyConceptClass(parentConcept, LAB_TEST_CONCEPT_CLASSES)) {
return parentConcept;
}
;
}
return null;
}

@Override
public Event asAtomFeedEvent(Object[] arguments) throws URISyntaxException {
Concept concept = (Concept) arguments[0];
if (!isOfConceptClass(concept, LAB_TEST_CONCEPT_CLASS)) {
if (!isOfAnyConceptClass(concept, LAB_TEST_CONCEPT_CLASSES)) {
concept = getParentOfTypeLabTest(concept);
}
String url = String.format(this.url, title, concept.getUuid());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,12 @@

import java.net.URI;
import java.net.URISyntaxException;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.UUID;
import java.util.*;

import static org.bahmni.module.referencedata.labconcepts.contract.AllSamples.ALL_SAMPLES;
import static org.bahmni.module.referencedata.labconcepts.contract.AllTestsAndPanels.ALL_TESTS_AND_PANELS;
import static org.bahmni.module.referencedata.labconcepts.contract.Department.DEPARTMENT_CONCEPT_CLASS;
import static org.bahmni.module.referencedata.labconcepts.contract.LabTest.LAB_TEST_CONCEPT_CLASS;
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_CLASS;
import static org.bahmni.module.referencedata.labconcepts.contract.Sample.SAMPLE_CONCEPT_CLASS;
Expand All @@ -31,7 +28,10 @@ public class SaleableTypeEvent implements ConceptServiceOperationEvent {
private final String category;
private List<String> supportedOperations = Arrays.asList("saveConcept", "updateConcept", "retireConcept", "purgeConcept");

private List<String> unhandledClasses = Arrays.asList(LAB_TEST_CONCEPT_CLASS, LAB_SET_CONCEPT_CLASS, SAMPLE_CONCEPT_CLASS, DEPARTMENT_CONCEPT_CLASS, RADIOLOGY_TEST_CONCEPT_CLASS);
private List<String> unhandledClasses = new ArrayList<String>(){{
addAll(Arrays.asList(LAB_SET_CONCEPT_CLASS, SAMPLE_CONCEPT_CLASS, DEPARTMENT_CONCEPT_CLASS, RADIOLOGY_TEST_CONCEPT_CLASS));
addAll(LAB_TEST_CONCEPT_CLASSES);
}};
private List<String> unhandledConcepsByName = Arrays.asList(ALL_SAMPLES, ALL_TESTS_AND_PANELS);

public SaleableTypeEvent(String url, String category) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public void setUp() {
PowerMockito.mockStatic(Context.class);
when(Context.getLocale()).thenReturn(defaultLocale);
when(Context.getConceptService()).thenReturn(conceptService);
testConcept = new ConceptBuilder().withClass(LabTest.LAB_TEST_CONCEPT_CLASS).build();
testConcept = new ConceptBuilder().withClass(LabTest.LAB_TEST_CONCEPT_CLASSES.get(0)).build();
panelConcept = new ConceptBuilder().withClassUUID(ConceptClass.LABSET_UUID).build();
parentConcept = new ConceptBuilder().withName(AllTestsAndPanels.ALL_TESTS_AND_PANELS).withClass("ConvSet").withSetMember(testConcept).withSetMember(panelConcept).build();
}
Expand All @@ -60,4 +60,4 @@ public void shouldCreateOneEventForAllTestsAndPanelsAndSetMembers() throws Excep
assertEquals(ConceptServiceEventFactory.TESTS_AND_PANEL, event.getTitle());
assertEquals("lab", event.getCategory());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@
@RunWith(PowerMockRunner.class)
public class LabTestEventTest {
public static final String TEST_CONCEPT_UUID = "aebc57b7-0683-464e-ac48-48b8838abdfc";
public static final String LAB_TEST_CONCEPT_UUID = "9b11d2d1-c7ea-40f7-8616-be9bec4c6bb7";

private Concept concept;
private Concept conceptWithLabTestClass;
private Concept conceptWithTestClass;

@Mock
private ConceptService conceptService;
Expand All @@ -45,11 +47,13 @@ public class LabTestEventTest {
public void setup() {
MockitoAnnotations.initMocks(this);

concept = new ConceptBuilder().withClass(LabTest.LAB_TEST_CONCEPT_CLASS).withUUID(TEST_CONCEPT_UUID).build();
conceptWithLabTestClass = new ConceptBuilder().withClass("LabTest").withUUID(LAB_TEST_CONCEPT_UUID).build();
conceptWithTestClass = new ConceptBuilder().withClass("Test").withUUID(TEST_CONCEPT_UUID).build();

parentConcept = new ConceptBuilder().withName(AllTestsAndPanels.ALL_TESTS_AND_PANELS).withSetMember(concept).build();
parentConcept = new ConceptBuilder().withName(AllTestsAndPanels.ALL_TESTS_AND_PANELS).withSetMember(conceptWithLabTestClass).build();
parentConcept.addSetMember(conceptWithTestClass);

List<ConceptSet> conceptSets = getConceptSets(parentConcept, concept);
List<ConceptSet> conceptSets = getConceptSets(parentConcept, conceptWithLabTestClass);

when(conceptService.getSetsContainingConcept(any(Concept.class))).thenReturn(conceptSets);

Expand All @@ -61,26 +65,32 @@ public void setup() {


@Test
public void createEventForTestEvent() throws Exception {
Event event = new Operation(ConceptService.class.getMethod("saveConcept", Concept.class)).apply(new Object[]{concept}).get(0);
Event anotherEvent = new Operation(ConceptService.class.getMethod("saveConcept", Concept.class)).apply(new Object[]{concept}).get(0);
assertNotNull(event);
assertFalse(event.getUuid().equals(anotherEvent.getUuid()));
assertEquals(event.getTitle(), ConceptServiceEventFactory.TEST);
assertEquals(event.getCategory(), ConceptServiceEventFactory.LAB);
public void createEventForTestEventIfConceptClassIsLabTestOrTest() throws Exception {
Event eventForLabTestConceptClass = new Operation(ConceptService.class.getMethod("saveConcept", Concept.class)).apply(new Object[]{conceptWithLabTestClass}).get(0);
Event anotherEventForLabTestConceptClass = new Operation(ConceptService.class.getMethod("saveConcept", Concept.class)).apply(new Object[]{conceptWithLabTestClass}).get(0);
Event eventForTestConceptClass = new Operation(ConceptService.class.getMethod("saveConcept", Concept.class)).apply(new Object[]{conceptWithTestClass}).get(0);
Event anotherEventForTestConceptClass = new Operation(ConceptService.class.getMethod("saveConcept", Concept.class)).apply(new Object[]{conceptWithTestClass}).get(0);
assertNotNull(eventForLabTestConceptClass);
assertNotNull(eventForTestConceptClass);
assertFalse(eventForLabTestConceptClass.getUuid().equals(anotherEventForLabTestConceptClass.getUuid()));
assertEquals(eventForLabTestConceptClass.getTitle(), ConceptServiceEventFactory.TEST);
assertEquals(eventForLabTestConceptClass.getCategory(), ConceptServiceEventFactory.LAB);
assertFalse(eventForTestConceptClass.getUuid().equals(anotherEventForTestConceptClass.getUuid()));
assertEquals(eventForTestConceptClass.getTitle(), ConceptServiceEventFactory.TEST);
assertEquals(eventForTestConceptClass.getCategory(), ConceptServiceEventFactory.LAB);
}

@Test
public void shouldNotCreateEventForTestEventIfThereIsDifferentConceptClass() throws Exception {
concept = new ConceptBuilder().withClassUUID("some").withClass("some").withUUID(TEST_CONCEPT_UUID).build();
List<Event> events = new Operation(ConceptService.class.getMethod("saveConcept", Concept.class)).apply(new Object[]{concept});
conceptWithLabTestClass = new ConceptBuilder().withClassUUID("some").withClass("some").withUUID(TEST_CONCEPT_UUID).build();
List<Event> events = new Operation(ConceptService.class.getMethod("saveConcept", Concept.class)).apply(new Object[]{conceptWithLabTestClass});
assertTrue(events.isEmpty());
}

@Test
public void shouldCreateEventForTestEventIfParentConceptIsMissing() throws Exception {
when(conceptService.getSetsContainingConcept(any(Concept.class))).thenReturn(new ArrayList<ConceptSet>());
List<Event> events = new Operation(ConceptService.class.getMethod("saveConcept", Concept.class)).apply(new Object[]{concept});
List<Event> events = new Operation(ConceptService.class.getMethod("saveConcept", Concept.class)).apply(new Object[]{conceptWithLabTestClass});
Event event = events.get(0);
assertNotNull(event);
assertEquals(event.getTitle(), ConceptServiceEventFactory.TEST);
Expand All @@ -90,9 +100,9 @@ public void shouldCreateEventForTestEventIfParentConceptIsMissing() throws Excep

@Test
public void shouldCreateEventForTestEventIfParentConceptIsWrong() throws Exception {
parentConcept = new ConceptBuilder().withName("Some wrong name").withSetMember(concept).build();
when(conceptService.getSetsContainingConcept(any(Concept.class))).thenReturn(getConceptSets(parentConcept, concept));
List<Event> events = new Operation(ConceptService.class.getMethod("saveConcept", Concept.class)).apply(new Object[]{concept});
parentConcept = new ConceptBuilder().withName("Some wrong name").withSetMember(conceptWithLabTestClass).build();
when(conceptService.getSetsContainingConcept(any(Concept.class))).thenReturn(getConceptSets(parentConcept, conceptWithLabTestClass));
List<Event> events = new Operation(ConceptService.class.getMethod("saveConcept", Concept.class)).apply(new Object[]{conceptWithLabTestClass});
Event event = events.get(0);
assertNotNull(event);
assertEquals(event.getTitle(), ConceptServiceEventFactory.TEST);
Expand All @@ -102,12 +112,12 @@ public void shouldCreateEventForTestEventIfParentConceptIsWrong() throws Excepti

@Test
public void createEventForTestWithParentConceptMissing() throws Exception {
Concept testConcept = new ConceptBuilder().withClass(LabTest.LAB_TEST_CONCEPT_CLASS).withUUID("testUUID").withClass("LabTest").build();
Concept testConcept = new ConceptBuilder().withUUID("testUUID").withClass("LabTest").build();
List<Event> events = new Operation(ConceptService.class.getMethod("saveConcept", Concept.class)).apply(new Object[]{testConcept});
Event event = events.get(0);
assertNotNull(event);
assertEquals(event.getTitle(), ConceptServiceEventFactory.TEST);
assertEquals(event.getCategory(), ConceptServiceEventFactory.LAB);
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public void setUp() throws Exception {
Locale defaultLocale = new Locale("en", "GB");
PowerMockito.mockStatic(Context.class);
when(Context.getLocale()).thenReturn(defaultLocale);
Concept testConcept = new ConceptBuilder().withUUID("Test UUID").withDateCreated(dateCreated).withClass(LabTest.LAB_TEST_CONCEPT_CLASS).withDescription("SomeDescription")
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).
Expand Down
Loading
Loading