Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
@@ -0,0 +1,53 @@
/**
* This Source Code Form is subject to the terms of the Mozilla Public License,
* v. 2.0. If a copy of the MPL was not distributed with this file, You can
* obtain one at http://mozilla.org/MPL/2.0/. OpenMRS is also distributed under
* the terms of the Healthcare Disclaimer located at http://openmrs.org/license.
*
* Copyright (C) OpenMRS Inc. OpenMRS is a registered trademark and the OpenMRS
* graphic logo is a trademark of OpenMRS Inc.
*/
package org.openmrs.module.referenceapplication.administrativenotification;

import java.util.List;
import java.util.Arrays;

import org.openmrs.api.context.Context;
import org.openmrs.module.appframework.factory.AdministrativeNotificationProducer;
import org.openmrs.module.appframework.domain.AdministrativeNotification;
import org.springframework.stereotype.Component;

@Component
public class DuplicateConceptNotification implements AdministrativeNotificationProducer{



@Override
public List<AdministrativeNotification> generateNotifications() {


if (!Context.hasPrivilege("Manage Concepts")) {
return null;
}

AdministrativeNotification notification = new AdministrativeNotification();


// checking whether concepts 1 and 2 exist in the system

if( Context.getConceptService().getConcept(1)==null || Context.getConceptService().getConcept(2)==null
) {
return null;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

condition on line 29 and line 38 can me merged into a single if statement instead of using two if statements

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mozzy11 could respond to @haripriya999 comment please


notification.setId("DuplicateConcepts.id");
notification.setIcon("icon-info-sign");
notification.setCssClass("success");
notification.setLabel("DuplicateConcepts.label");
notification.setRequiredPrivilege("Manage Concepts");



return Arrays.asList(notification);
}
}
3 changes: 3 additions & 0 deletions api/src/main/resources/messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,6 @@ referenceapplication.formentryapp.manageforms.label=Manage Forms

general.auditInfo=Audit Info

DuplicateConcepts.label= Duplicate concepts exist. Please Upgrade to the latest version of reference Metadata Module
DuplicateConcepts.id = Duplicate

Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package org.openmrs.module.referenceapplication.administrativenotification;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;

import java.util.List;

import org.junit.Before;
import org.junit.Test;
import org.openmrs.module.appframework.domain.AdministrativeNotification;
import org.openmrs.test.BaseModuleContextSensitiveTest;
import org.springframework.beans.factory.annotation.Autowired;

public class DuplicateConceptNotificationTest extends BaseModuleContextSensitiveTest {

@Autowired
DuplicateConceptNotification producer;

@Before
public void setUp() throws Exception {
initializeInMemoryDatabase();
}

@Test
public void shouldNotProduceNotificationWhenDuplicateConceptsDoesNotExist() throws Exception {
executeDataSet("NoConceptsDuplicates.xml");
authenticate();
assertNull(producer.generateNotifications());
}


@Test
public void shouldProduceNotificationWhenDuplicateConceptsExist() throws Exception {

executeDataSet("ConceptsDuplicates.xml");
authenticate();

List<AdministrativeNotification> notifications = producer.generateNotifications();
assertEquals(notifications.size(), 1);
assertEquals(notifications.get(0).getId(), "DuplicateConcepts.id");

}

;

}
12 changes: 12 additions & 0 deletions api/src/test/resources/ConceptsDuplicates.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<dataset>

<concept concept_id="1" retired="0" datatype_id="1" class_id="7" is_set="0" creator="1" date_created="2013-04-26 14:32:16.0" version="" changed_by="1" retired_by="1" uuid="161655AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"/>
<concept_numeric concept_id="1" units="" precise="0"/>
<concept_name concept_id="1" name="ANC ID" locale="en" creator="1" date_created="2013-04-26 14:32:16.0" concept_name_id="123687" voided="0" voided_by="1" uuid="123687BBBBBBBBBBBBBBBBBBBBBBBBBBBBBB" concept_name_type="SHORT" locale_preferred="false"/>

<concept concept_id="2" retired="0" datatype_id="2" class_id="7" is_set="0" creator="1" date_created="2013-04-26 14:32:16.0" version="" changed_by="1" retired_by="1" uuid="161655AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA2"/>
<concept_numeric concept_id="2" units="" precise="0"/>
<concept_name concept_id="2" name="ANC ID" locale="en" creator="1" date_created="2013-04-26 14:32:16.0" concept_name_id="123687" voided="0" voided_by="1" uuid="123687BBBBBBBBBBBBBBBBBBBBBBBBBBBBBB2" concept_name_type="SHORT" locale_preferred="false"/>

</dataset>
12 changes: 12 additions & 0 deletions api/src/test/resources/NoConceptsDuplicates.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<dataset>

<concept concept_id="3" retired="0" datatype_id="1" class_id="7" is_set="0" creator="1" date_created="2013-04-26 14:32:16.0" version="" changed_by="1" retired_by="1" uuid="161655AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"/>
<concept_numeric concept_id="3" units="" precise="0"/>
<concept_name concept_id="3" name="ANC ID" locale="en" creator="1" date_created="2013-04-26 14:32:16.0" concept_name_id="123687" voided="0" voided_by="1" uuid="123687BBBBBBBBBBBBBBBBBBBBBBBBBBBBBB" concept_name_type="SHORT" locale_preferred="false"/>

<concept concept_id="4" retired="0" datatype_id="2" class_id="7" is_set="0" creator="1" date_created="2013-04-26 14:32:16.0" version="" changed_by="1" retired_by="1" uuid="161655AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA2"/>
<concept_numeric concept_id="4" units="" precise="0"/>
<concept_name concept_id="4" name="ANC ID" locale="en" creator="1" date_created="2013-04-26 14:32:16.0" concept_name_id="123687" voided="0" voided_by="1" uuid="123687BBBBBBBBBBBBBBBBBBBBBBBBBBBBBB2" concept_name_type="SHORT" locale_preferred="false"/>

</dataset>