001package ca.uhn.fhir.jpa.subscription.model;
002
003/*-
004 * #%L
005 * HAPI FHIR Storage api
006 * %%
007 * Copyright (C) 2014 - 2022 Smile CDR, Inc.
008 * %%
009 * Licensed under the Apache License, Version 2.0 (the "License");
010 * you may not use this file except in compliance with the License.
011 * You may obtain a copy of the License at
012 *
013 *      http://www.apache.org/licenses/LICENSE-2.0
014 *
015 * Unless required by applicable law or agreed to in writing, software
016 * distributed under the License is distributed on an "AS IS" BASIS,
017 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
018 * See the License for the specific language governing permissions and
019 * limitations under the License.
020 * #L%
021 */
022
023import ca.uhn.fhir.i18n.Msg;
024import org.hl7.fhir.dstu2.model.Subscription;
025import org.hl7.fhir.exceptions.FHIRException;
026
027import javax.annotation.Nonnull;
028import javax.annotation.Nullable;
029
030import static org.apache.commons.lang3.StringUtils.isBlank;
031
032public enum CanonicalSubscriptionChannelType {
033        /**
034         * The channel is executed by making a post to the URI. If a payload is included, the URL is interpreted as the service base, and an update (PUT) is made.
035         */
036        RESTHOOK,
037        /**
038         * The channel is executed by sending a packet across a web socket connection maintained by the client. The URL identifies the websocket, and the client binds to this URL.
039         */
040        WEBSOCKET,
041        /**
042         * The channel is executed by sending an email to the email addressed in the URI (which must be a mailto:).
043         */
044        EMAIL,
045        /**
046         * The channel is executed by sending an SMS message to the phone number identified in the URL (tel:).
047         */
048        SMS,
049        /**
050         * The channel is executed by sending a message (e.g. a Bundle with a MessageHeader resource etc.) to the application identified in the URI.
051         */
052        MESSAGE,
053        /**
054         * added to help the parsers with the generic types
055         */
056        NULL;
057
058        public static CanonicalSubscriptionChannelType fromCode(@Nullable String theSystem, @Nonnull String codeString) throws FHIRException {
059                if (isBlank(codeString)) {
060                        return null;
061                } else if ("rest-hook".equals(codeString)) {
062                        if (theSystem == null || theSystem.equals("http://terminology.hl7.org/CodeSystem/subscription-channel-type")) {
063                                return RESTHOOK;
064                        }
065                } else if ("websocket".equals(codeString)) {
066                        if (theSystem == null || theSystem.equals("http://terminology.hl7.org/CodeSystem/subscription-channel-type")) {
067                                return WEBSOCKET;
068                        }
069                } else if ("email".equals(codeString)) {
070                        if (theSystem == null || theSystem.equals("http://terminology.hl7.org/CodeSystem/subscription-channel-type")) {
071                                return EMAIL;
072                        }
073                } else if ("sms".equals(codeString)) {
074                        if (theSystem == null || theSystem.equals("http://terminology.hl7.org/CodeSystem/subscription-channel-type")) {
075                                return SMS;
076                        }
077                } else if ("message".equals(codeString)) {
078                        if (theSystem == null || theSystem.equals("http://terminology.hl7.org/CodeSystem/subscription-channel-type")) {
079                                return MESSAGE;
080                        }
081                }
082
083                throw new FHIRException(Msg.code(569) + "Unknown SubscriptionChannelType code '" + codeString + "'");
084        }
085
086        public String toCode() {
087                switch (this) {
088                        case RESTHOOK:
089                                return "rest-hook";
090                        case WEBSOCKET:
091                                return "websocket";
092                        case EMAIL:
093                                return "email";
094                        case SMS:
095                                return "sms";
096                        case MESSAGE:
097                                return "message";
098                        case NULL:
099                        default:
100                                return "?";
101                }
102        }
103
104        public String getSystem() {
105                switch (this) {
106                        case RESTHOOK:
107                        case WEBSOCKET:
108                        case EMAIL:
109                        case SMS:
110                        case MESSAGE:
111                                return "http://terminology.hl7.org/CodeSystem/subscription-channel-type";
112                        case NULL:
113                        default:
114                                return "?";
115                }
116        }
117
118        public String getDefinition() {
119                switch (this) {
120                        case RESTHOOK:
121                                return "The channel is executed by making a post to the URI. If a payload is included, the URL is interpreted as the service base, and an update (PUT) is made.";
122                        case WEBSOCKET:
123                                return "The channel is executed by sending a packet across a web socket connection maintained by the client. The URL identifies the websocket, and the client binds to this URL.";
124                        case EMAIL:
125                                return "The channel is executed by sending an email to the email addressed in the URI (which must be a mailto:).";
126                        case SMS:
127                                return "The channel is executed by sending an SMS message to the phone number identified in the URL (tel:).";
128                        case MESSAGE:
129                                return "The channel is executed by sending a message (e.g. a Bundle with a MessageHeader resource etc.) to the application identified in the URI.";
130                        case NULL:
131                        default:
132                                return "?";
133                }
134        }
135
136        public String getDisplay() {
137                switch (this) {
138                        case RESTHOOK:
139                                return "Rest Hook";
140                        case WEBSOCKET:
141                                return "Websocket";
142                        case EMAIL:
143                                return "Email";
144                        case SMS:
145                                return "SMS";
146                        case MESSAGE:
147                                return "Message";
148                        case NULL:
149                        default:
150                                return "?";
151                }
152        }
153
154        public Subscription.SubscriptionChannelType toCanonical() {
155                return Subscription.SubscriptionChannelType.fromCode(toCode());
156        }
157}