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()); }
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()); }