diff --git a/ui/react-components/api/smsService.js b/ui/react-components/api/smsService.js deleted file mode 100644 index 4ba2b96d9..000000000 --- a/ui/react-components/api/smsService.js +++ /dev/null @@ -1,21 +0,0 @@ -import axios from 'axios'; -import {getFromGlobalProperty} from "../api/configApi"; -import {isEmpty} from 'lodash'; - -export const sendSMS = async (phoneNumber, message) => { - try { - if (phoneNumber && !(isEmpty(message))) { - var data = { - "phoneNumber": phoneNumber, - "message": message - }; - const smsEndpoint = await getFromGlobalProperty("sms.endpoint"); - if (smsEndpoint != undefined && smsEndpoint != '') { - const response = await axios.post(smsEndpoint, data); - return response; - } - } - } catch (error) { - return error.response; - } -}; diff --git a/ui/react-components/components/AddAppointment/AddAppointment.jsx b/ui/react-components/components/AddAppointment/AddAppointment.jsx index 45455719c..c56f6c362 100644 --- a/ui/react-components/components/AddAppointment/AddAppointment.jsx +++ b/ui/react-components/components/AddAppointment/AddAppointment.jsx @@ -26,7 +26,6 @@ import { } from "../../services/AppointmentsService/AppointmentsService"; import Label from '../Label/Label.jsx'; import {getDateTime, isStartTimeBeforeEndTime} from '../../utils/DateUtil.js' -import {getAppointmentBookingMessage, getRecurringAppointmentBookingMessage, getPhoneNumber} from '../../utils/AppointmentSMS.js' import TimeSelector from "../TimeSelector/TimeSelector.jsx"; import AppointmentNotes from "../AppointmentNotes/AppointmentNotes.jsx"; import AppointmentPlan from "../AppointmentPlan/AppointmentPlan.jsx"; @@ -65,11 +64,10 @@ import Conflicts from "../Conflicts/Conflicts.jsx"; import updateAppointmentStatusAndProviderResponse from "../../appointment-request/AppointmentRequest"; import * as patientApi from "../../api/patientApi"; import {mapOpenMRSPatient} from "../../mapper/patientMapper"; -import {sendSMS} from "../../api/smsService"; const AddAppointment = props => { - const {appConfig, intl, appointmentParams, currentProvider, urlParams, isAppointmentSMSEnabled } = props; + const {appConfig, intl, appointmentParams, currentProvider, urlParams } = props; const {setViewDate} = React.useContext(AppContext); const errorTranslations = getErrorTranslations(intl); @@ -279,10 +277,6 @@ const AddAppointment = props => { setShowEmailWarning((isVirtual(response.data) && !checkPatientEmailAvailability(response.data))); setShowEmailNotSentWarning((isVirtual(response.data) && !checkNotificationStatus(response.data))); setViewDateAndShowSuccessPopup(response.data.startDateTime); - if (isAppointmentSMSEnabled) { - sendSMS(await getPhoneNumber(response.data.patient.uuid, appConfig.smsAttribute), - getAppointmentBookingMessage(response.data, appConfig, intl)); - } } else if (response.data && response.data.error) { setConflicts(undefined); setServiceErrorMessageFromResponse(response.data); @@ -344,10 +338,6 @@ const AddAppointment = props => { setServiceErrorMessage(''); const immediateAppointment = response.data[0]; setViewDateAndShowSuccessPopup(immediateAppointment.appointmentDefaultResponse.startDateTime); - if (isAppointmentSMSEnabled) { - sendSMS(await getPhoneNumber(immediateAppointment.appointmentDefaultResponse.patient.uuid, appConfig.smsAttribute), - getRecurringAppointmentBookingMessage(immediateAppointment, appConfig, intl)); - } } else if (status === 204) { setServiceErrorMessage(errorTranslations.noContentErrorMessage); resetServiceErrorMessage(); @@ -666,8 +656,7 @@ AddAppointment.propTypes = { appConfig: PropTypes.object, appointmentParams: PropTypes.object, currentProvider: PropTypes.object, - urlParams: PropTypes.object, - isAppointmentSMSEnabled: PropTypes.bool + urlParams: PropTypes.object }; export const isVirtual = (appt) => { diff --git a/ui/react-components/components/EditAppointment/EditAppointment.jsx b/ui/react-components/components/EditAppointment/EditAppointment.jsx index 24dbb7137..f4bd9434b 100644 --- a/ui/react-components/components/EditAppointment/EditAppointment.jsx +++ b/ui/react-components/components/EditAppointment/EditAppointment.jsx @@ -70,7 +70,6 @@ import { updateRecurring } from "../../services/AppointmentsService/AppointmentsService"; import {getDateTime, isStartTimeBeforeEndTime} from "../../utils/DateUtil"; -import {getAppointmentBookingMessage, getRecurringAppointmentBookingMessage, getPhoneNumber} from '../../utils/AppointmentSMS.js' import UpdateSuccessModal from "../SuccessModal/UpdateSuccessModal.jsx"; import UpdateConfirmationModal from "../UpdateConfirmationModal/UpdateConfirmationModal.jsx"; import {getComponentsDisableStatus} from "./ComponentsDisableStatus"; @@ -78,11 +77,10 @@ import ErrorMessage from "../ErrorMessage/ErrorMessage.jsx"; import {getErrorTranslations} from "../../utils/ErrorTranslationsUtil"; import {AppContext} from "../AppContext/AppContext"; import updateAppointmentStatusAndProviderResponse from "../../appointment-request/AppointmentRequest"; -import {sendSMS} from "../../api/smsService"; const EditAppointment = props => { - const {appConfig, appointmentUuid, isRecurring, intl, currentProvider, isAppointmentSMSEnabled} = props; + const {appConfig, appointmentUuid, isRecurring, intl, currentProvider} = props; const {setViewDate} = React.useContext(AppContext); @@ -296,10 +294,6 @@ const EditAppointment = props => { setConflicts(undefined); setShowUpdateConfirmPopup(false); setViewDateAndShowSuccessPopup(appointmentDetails.appointmentDate); - if (isAppointmentSMSEnabled) { - sendSMS(await getPhoneNumber(response.data.patient.uuid, appConfig.smsAttribute), - getAppointmentBookingMessage(response.data, appConfig, intl)); - } } else if (response.data && response.data.error) { setConflicts(undefined); setServiceErrorMessageFromResponse(response.data); @@ -319,10 +313,6 @@ const EditAppointment = props => { setConflicts(undefined); setShowUpdateConfirmPopup(false); setViewDateAndShowSuccessPopup(appointmentDetails.appointmentDate); - if (isAppointmentSMSEnabled) { - sendSMS(await getPhoneNumber(response.data[0].appointmentDefaultResponse.patient.uuid, appConfig.smsAttribute), - getRecurringAppointmentBookingMessage(response.data[0], appConfig, intl)); - } } else if (response.data && response.data.error) { setConflicts(undefined); setServiceErrorMessageFromResponse(response.data); @@ -690,8 +680,7 @@ EditAppointment.propTypes = { appConfig: PropTypes.object, appointmentUuid: PropTypes.string.isRequired, isRecurring: PropTypes.string.isRequired, - currentProvider: PropTypes.object, - isAppointmentSMSEnabled: PropTypes.bool + currentProvider: PropTypes.object }; export default injectIntl(EditAppointment); diff --git a/ui/react-components/constants.js b/ui/react-components/constants.js index a3b3af033..44cb35bd9 100644 --- a/ui/react-components/constants.js +++ b/ui/react-components/constants.js @@ -61,4 +61,3 @@ export const appointmentEndTimeProps = endTime => { }; export const helpDeskNumber = "clinic.helpDeskNumber"; -export const appointmentSMSToggle = "sms.enableAppointmentBookingSMSAlert"; diff --git a/ui/react-components/containers/AppointmentContainer.jsx b/ui/react-components/containers/AppointmentContainer.jsx index 1b00e01b4..efc4256e3 100644 --- a/ui/react-components/containers/AppointmentContainer.jsx +++ b/ui/react-components/containers/AppointmentContainer.jsx @@ -9,7 +9,6 @@ import {getAppConfig, getMessages} from "../components/AppContext/AppService"; import EditAppointment from "../components/EditAppointment/EditAppointment.jsx"; import moment from "moment"; import {getFromGlobalProperty} from "../api/configApi"; -import { appointmentSMSToggle, helpDeskNumber } from "../constants"; // TODO : need to add connection to redux @@ -20,29 +19,24 @@ class AppointmentContainer extends Component { this.state = { locale: getLocale() === 'pt_BR' ? 'pt-BR': getLocale(), messages: translations[props.locale], - appConfig: null, - isAppointmentSMSEnabled: false + appConfig: null }; (async () => { this.setState({messages: await getMessages(getLocale())}); this.setState({appConfig: await getAppConfig()}); - this.setState({isAppointmentSMSEnabled: await getFromGlobalProperty(appointmentSMSToggle)}); - if (this.state.isAppointmentSMSEnabled) { - localStorage.setItem(helpDeskNumber, await getFromGlobalProperty(helpDeskNumber)); - } })(); moment.locale(getLocale() === 'pt_BR' ? 'pt-BR': getLocale()); } render() { - const {locale, messages, appConfig, isAppointmentSMSEnabled} = this.state; + const {locale, messages, appConfig} = this.state; const {appointmentUuid,isRecurring, setViewDate, onBack, appointmentParams, currentProvider, urlParams} = this.props; return ( {appointmentUuid - ? - : } + ? + : } ); } diff --git a/ui/react-components/utils/AppointmentSMS.js b/ui/react-components/utils/AppointmentSMS.js deleted file mode 100644 index 62f75cc38..000000000 --- a/ui/react-components/utils/AppointmentSMS.js +++ /dev/null @@ -1,57 +0,0 @@ -import _ from 'lodash' -import {isVirtual} from "../components/AddAppointment/AddAppointment.jsx"; -import {getPersonAttribute} from "../api/patientApi"; -import {currentLocation} from "./CookieUtil"; -import {getHelpDeskNumber} from "./LocalStorageUtil"; - -const getMessage = (data, message, recurring = null) => { - message = message.replace("#clinicName", currentLocation().name); - message = message.replace("#patientId", data.patient.identifier); - message = message.replace("#patientName", data.patient.name); - message = message.replaceAll("#dateTime", new Date(data.startDateTime).toLocaleString()); - message = message.replace("#helpDeskNumber", getHelpDeskNumber()); - message = message.replace("#service", data.service.name); - if (recurring) { - message = message.replace("#frequency", (recurring.period + " " + recurring.type.toLowerCase() + (recurring.daysOfWeek ? " on " + recurring.daysOfWeek.map(_.capitalize).join(", ") : ""))); - } - message = message.replace("#meetingLink", data.teleconsultationLink); - return message; -}; - -export const getAppointmentBookingMessage = (apptData, appConfig, intl) => { - var type = getAppointmentMessageType(apptData); - var messageTemplate = getMessageTranslation(appConfig, intl)[type]; - return getMessage(apptData, messageTemplate); -}; - -export const getRecurringAppointmentBookingMessage = (apptData, appConfig, intl) => { - var type = getAppointmentMessageType(apptData.appointmentDefaultResponse, apptData.recurringPattern); - var messageTemplate = getMessageTranslation(appConfig, intl)[type]; - return getMessage(apptData.appointmentDefaultResponse, messageTemplate, apptData.recurringPattern); -}; - -const getMessageTranslation = (appConfig, intl) => { - return { - teleconsultationAppointmentBookingMessage: intl.formatMessage({ - id: appConfig.teleconsultationAppointmentBookingMessage, defaultMessage: 'TELECONSULTATION_APPOINTMENT_BOOKING_MESSAGE' - }), - recurringAppointmentBookingMessage: intl.formatMessage({ - id: appConfig.recurringAppointmentBookingMessage, defaultMessage: 'RECURRING_APPOINTMENT_BOOKING_MESSAGE' - }), - appointmentBookingMessage: intl.formatMessage({ - id: appConfig.appointmentBookingMessage, defaultMessage: 'APPOINTMENT_BOOKING_MESSAGE' - }) - } -}; - -const getAppointmentMessageType = (apptData, isRecurring = null) => { - if (isVirtual(apptData)) { - return "teleconsultationAppointmentBookingMessage"; - } - return isRecurring ? "recurringAppointmentBookingMessage" : "appointmentBookingMessage"; -}; - -export const getPhoneNumber = async (patientUuid, attribute) => { - var phoneNumber = await getPersonAttribute(patientUuid, attribute) - return phoneNumber ? phoneNumber : null; -};