Skip to content

Commit

Permalink
Added an event listener
Browse files Browse the repository at this point in the history
  • Loading branch information
atishbeehyv123 committed Aug 28, 2023
1 parent 48bff2d commit d0e8c7a
Show file tree
Hide file tree
Showing 14 changed files with 105 additions and 201 deletions.
5 changes: 5 additions & 0 deletions bahmnicore-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,11 @@
<version>4.5.14</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.bahmni.module</groupId>
<artifactId>bahmni-events-api</artifactId>
<version>1.0.0-SNAPSHOT</version>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
package org.bahmni.module.bahmnicore.config;


import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

import java.util.concurrent.Executor;
@Configuration
@EnableAsync
public class AsyncConfig {

@Bean(name = "bahmniCoreAsync")
public Executor threadPoolTaskExecutor() {
ThreadPoolTaskExecutor threadPoolTaskExecutor = new ThreadPoolTaskExecutor();
return threadPoolTaskExecutor;
}
}
//package org.bahmni.module.bahmnicore.config;
//
//
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.scheduling.annotation.EnableAsync;
//import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
//
//import java.util.concurrent.Executor;
//@Configuration
//@EnableAsync
//public class AsyncConfig {
//
// @Bean(name = "bahmniCoreAsync")
// public Executor threadPoolTaskExecutor() {
// ThreadPoolTaskExecutor threadPoolTaskExecutor = new ThreadPoolTaskExecutor();
// return threadPoolTaskExecutor;
// }
//}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package org.bahmni.module.bahmnicore.eventListener;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.bahmni.module.events.api.model.BahmniEventType;
import org.openmrs.Person;
import org.openmrs.api.context.Context;
import org.openmrs.api.context.UserContext;
import org.openmrs.module.webservices.rest.SimpleObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.event.EventListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;
import org.bahmni.module.events.api.model.Event;

import java.util.Locale;

@Component
public class SMSEventListenerBahmniCore {


private final Log log = LogFactory.getLog(this.getClass());


@EventListener
public void onApplicationEvent(Event event) {
System.out.println("inside event listner bahmni core");
if (event.eventType == BahmniEventType.BAHMNI_PATIENT_CREATED) {
Boolean isregistrationSmsEnabled = Boolean.valueOf(Context.getAdministrationService().getGlobalProperty("sms.enableRegistrationSMSAlert"));
if (isregistrationSmsEnabled) {
System.out.println("hi");
Object person = ((SimpleObject) event.payload).get("person");
// String phoneNumber = person.get("phoneNumebr");
// if (null == phoneNumber) {
// log.info("Since no mobile number found for the patient. SMS not sent.");
// return;
// }
// if (savePatientEvent.isRegistrationSmsEnabled()) {
// UserContext userContext = savePatientEvent.getUserContext();
// Context.openSession();
// Context.setUserContext(userContext);

// Location location = Context.getLocationService().getLocationByUuid(locationUuid);
// String message = smsService.getRegistrationMessage(new Locale("en"), person, location);
// smsService.sendSMS(phoneNumber, message);
// }
}
}
}
}

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

5 changes: 5 additions & 0 deletions bahmnicore-omod/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,11 @@
<groupId>org.bahmni.module</groupId>
<artifactId>bahmni-mapping</artifactId>
</dependency>
<dependency>
<groupId>org.bahmni.module</groupId>
<artifactId>bahmni-events-api</artifactId>
<version>1.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.openmrs.module</groupId>
<artifactId>uiframework-api</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import org.apache.commons.beanutils.ConversionException;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.bahmni.module.bahmnicore.service.RegistrationSmsService;
import org.codehaus.jackson.map.ObjectMapper;
import org.hibernate.NonUniqueObjectException;
import org.hibernate.exception.DataException;
Expand Down Expand Up @@ -55,20 +54,16 @@ public class BahmniPatientProfileResource extends DelegatingCrudResource<Patient

private EmrPatientProfileService emrPatientProfileService;
private IdentifierSourceServiceWrapper identifierSourceServiceWrapper;
private RegistrationSmsService registrationSmsService;

@Autowired
public BahmniPatientProfileResource(EmrPatientProfileService emrPatientProfileService, IdentifierSourceServiceWrapper identifierSourceServiceWrapper, RegistrationSmsService registrationSmsService) {
public BahmniPatientProfileResource(EmrPatientProfileService emrPatientProfileService, IdentifierSourceServiceWrapper identifierSourceServiceWrapper) {
this.emrPatientProfileService = emrPatientProfileService;
this.identifierSourceServiceWrapper = identifierSourceServiceWrapper;
this.registrationSmsService =registrationSmsService;
}

@RequestMapping(method = RequestMethod.POST)
@ResponseBody
public ResponseEntity<Object> create(@CookieValue(value="bahmni.user.location", required=true) String loginCookie,
@RequestHeader(value = "Jump-Accepted", required = false) boolean jumpAccepted,
@RequestBody SimpleObject propertiesToCreate) throws Exception {
public ResponseEntity<Object> create(@RequestHeader(value = "Jump-Accepted", required = false) boolean jumpAccepted,@RequestBody SimpleObject propertiesToCreate) throws Exception {
List identifiers = ((ArrayList) ((LinkedHashMap) propertiesToCreate.get("patient")).get("identifiers"));
List<Object> jumpSizes = new ArrayList<>();

Expand Down Expand Up @@ -119,12 +114,6 @@ public ResponseEntity<Object> create(@CookieValue(value="bahmni.user.location",
setConvertedProperties(delegate, propertiesToCreate, getCreatableProperties(), true);
try {
delegate = emrPatientProfileService.save(delegate);
Boolean isregistrationSmsEnabled=Boolean.valueOf(Context.getAdministrationService().getGlobalProperty("sms.enableRegistrationSMSAlert"));
if (isregistrationSmsEnabled){
JsonParser jsonParser = new JsonParser();
JsonObject jsonObject = (JsonObject) jsonParser.parse(loginCookie);
String loginlocation = jsonObject.get("uuid").getAsString();
registrationSmsService.sendRegistrationSMS(delegate,loginlocation,Context.getUserContext());}
setRelationships(delegate);
return new ResponseEntity<>(ConversionUtil.convertToRepresentation(delegate, Representation.FULL), HttpStatus.OK);
} catch (ContextAuthenticationException e) {
Expand Down
Loading

0 comments on commit d0e8c7a

Please sign in to comment.