Пример #1
0
  public MessageStatus scheduleMessage(String content, String recipient) {
    if (recipient == null || recipient.isEmpty()) {
      return MessageStatus.REJECTED;
    }

    logger.info("Constructing MessageDetails object...");

    MessageRequest messageRequest = coreManager.createMessageRequest();
    messageRequest.setTryNumber(1);
    messageRequest.setRequestId("");
    messageRequest.setDateFrom(null);
    messageRequest.setDateTo(null);
    messageRequest.setRecipientNumber(recipient);
    messageRequest.setNotificationType(null);
    messageRequest.setMessageType(MessageType.TEXT);
    messageRequest.setLanguage(null);
    messageRequest.setStatus(MStatus.QUEUED);
    messageRequest.setDateCreated(new Date());

    logger.info("MessageRequest object successfully constructed");
    logger.debug(messageRequest);

    MessageStatus status = scheduleMessage(messageRequest, content);
    return status;
  }
Пример #2
0
  public MessageStatus sendBulkCaresMessage(
      String messageId,
      String workerNumber,
      Care[] cares,
      MediaType messageType,
      Date startDate,
      Date endDate) {
    if (workerNumber == null || workerNumber.isEmpty()) {
      return MessageStatus.REJECTED;
    }

    logger.info("Constructing MessageDetails object...");

    MessageFormatter formatter = omiManager.createMessageFormatter();
    MessageRequest messageRequest = coreManager.createMessageRequest();

    String content = formatter.formatBulkCaresMessage(cares);

    messageRequest.setTryNumber(1);
    messageRequest.setRequestId(messageId);
    messageRequest.setDateFrom(startDate);
    messageRequest.setDateTo(endDate);
    messageRequest.setRecipientNumber(workerNumber);
    messageRequest.setMessageType(MessageType.valueOf(messageType.toString()));
    messageRequest.setStatus(MStatus.QUEUED);
    messageRequest.setDateCreated(new Date());

    logger.info("MessageRequest object successfully constructed");
    logger.debug(messageRequest);

    MessageStatus status = scheduleMessage(messageRequest, content);
    return status;
  }
Пример #3
0
  public MessageStatus savePatientMessageRequest(
      String messageId,
      NameValuePair[] personalInfo,
      String patientNumber,
      ContactNumberType patientNumberType,
      String langCode,
      MediaType messageType,
      Long notificationType,
      Date startDate,
      Date endDate,
      String recipientId) {
    logger.debug("Constructing MessageRequest object...");

    if (patientNumberType == ContactNumberType.PUBLIC && messageType == MediaType.TEXT) {
      return MessageStatus.REJECTED;
    }

    if ((patientNumber == null || patientNumber.isEmpty())
        && patientNumberType != ContactNumberType.PUBLIC) {
      return MessageStatus.REJECTED;
    }

    MessageRequest messageRequest = coreManager.createMessageRequest();

    NotificationTypeDAO noteTypeDao = coreManager.createNotificationTypeDAO();
    NotificationType noteType = (NotificationType) noteTypeDao.getById(notificationType);

    Language langObject = coreManager.createLanguageDAO().getByCode(langCode);

    if (personalInfo != null) {
      HashSet<NameValuePair> details = new HashSet<NameValuePair>();
      details.addAll(Arrays.asList(personalInfo));
      messageRequest.setPersInfos(details);
    }

    messageRequest.setTryNumber(1);
    messageRequest.setRequestId(messageId);
    // VOICE messages need to have a start date to accommodate replaying DELIVERED messages
    messageRequest.setDateFrom(
        startDate == null && messageType == MediaType.VOICE ? new Date() : startDate);
    messageRequest.setDateTo(endDate);
    messageRequest.setRecipientNumber(patientNumber);
    messageRequest.setPhoneNumberType(patientNumberType.toString());
    messageRequest.setRecipientId(recipientId);
    messageRequest.setNotificationType(noteType);
    messageRequest.setMessageType(MessageType.valueOf(messageType.toString()));
    messageRequest.setLanguage(langObject);
    messageRequest.setStatus(MStatus.QUEUED);
    messageRequest.setDateCreated(new Date());

    logger.debug("MessageRequest object successfully constructed");
    logger.debug(messageRequest);

    if (messageRequest.getDateFrom() == null && messageRequest.getDateTo() == null) {
      return sendMessage(messageRequest);
    }

    logger.info("Saving MessageRequest...");
    MessageRequestDAO msgReqDao = coreManager.createMessageRequestDAO();

    msgReqDao.save(messageRequest);
    return MessageStatus.valueOf(messageRequest.getStatus().toString());
  }
Пример #4
0
  public MessageStatus saveCHPSMessageRequest(
      String messageId,
      NameValuePair[] personalInfo,
      String workerNumber,
      Patient[] patientList,
      String langCode,
      MediaType messageType,
      Long notificationType,
      Date startDate,
      Date endDate) {
    logger.info("Constructing MessageDetails object...");

    if (workerNumber == null || workerNumber.isEmpty()) {
      return MessageStatus.REJECTED;
    }

    MessageRequest messageRequest = coreManager.createMessageRequest();

    NotificationTypeDAO noteTypeDao = coreManager.createNotificationTypeDAO();
    NotificationType noteType = (NotificationType) noteTypeDao.getById(notificationType);

    Language langObject = coreManager.createLanguageDAO().getByCode(langCode);

    HashSet<NameValuePair> details = new HashSet<NameValuePair>();
    if (personalInfo != null) {
      details.addAll(Arrays.asList(personalInfo));
    }
    if (patientList != null) {
      for (Patient p : patientList) {
        if (p.getPreferredName() != null) {
          details.add(new NameValuePair("PreferredName", p.getPreferredName()));
        }
        if (p.getLastName() != null) {
          details.add(new NameValuePair("LastName", p.getLastName()));
        }
        if (p.getCommunity() != null) {
          details.add(new NameValuePair("Community", p.getCommunity()));
        }
        if (p.getFirstName() != null) {
          details.add(new NameValuePair("FirstName", p.getFirstName()));
        }
        if (p.getMotechId() != null) {
          details.add(new NameValuePair("MotechId", p.getMotechId()));
        }
        if (p.getPhoneNumber() != null) {
          details.add(new NameValuePair("PhoneNumber", p.getPhoneNumber()));
        }
      }
    }
    messageRequest.setPersInfos(details);

    messageRequest.setTryNumber(1);
    messageRequest.setRequestId(messageId);
    messageRequest.setDateFrom(startDate);
    messageRequest.setDateTo(endDate);
    messageRequest.setRecipientNumber(workerNumber);
    messageRequest.setNotificationType(noteType);
    messageRequest.setMessageType(MessageType.valueOf(messageType.toString()));
    messageRequest.setLanguage(langObject);
    messageRequest.setStatus(MStatus.QUEUED);
    messageRequest.setDateCreated(new Date());

    logger.info("MessageRequest object successfully constructed");
    logger.debug(messageRequest);

    if (messageRequest.getDateFrom() == null && messageRequest.getDateTo() == null) {
      return sendMessage(messageRequest);
    }

    logger.info("Saving MessageRequest...");
    MessageRequestDAO msgReqDao = coreManager.createMessageRequestDAO();

    msgReqDao.save(messageRequest);

    return MessageStatus.valueOf(messageRequest.getStatus().toString());
  }