001package ca.uhn.fhir.jpa.subscription.model;
002
003/*-
004 * #%L
005 * HAPI FHIR Subscription Server
006 * %%
007 * Copyright (C) 2014 - 2021 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 org.hl7.fhir.dstu2.model.Subscription;
024import org.hl7.fhir.exceptions.FHIRException;
025
026import javax.annotation.Nonnull;
027import javax.annotation.Nullable;
028
029import static org.apache.commons.lang3.StringUtils.isBlank;
030
031public enum CanonicalSubscriptionChannelType {
032        /**
033         * 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.
034         */
035        RESTHOOK,
036        /**
037         * 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.
038         */
039        WEBSOCKET,
040        /**
041         * The channel is executed by sending an email to the email addressed in the URI (which must be a mailto:).
042         */
043        EMAIL,
044        /**
045         * The channel is executed by sending an SMS message to the phone number identified in the URL (tel:).
046         */
047        SMS,
048        /**
049         * The channel is executed by sending a message (e.g. a Bundle with a MessageHeader resource etc.) to the application identified in the URI.
050         */
051        MESSAGE,
052        /**
053         * added to help the parsers with the generic types
054         */
055        NULL;
056
057        public String toCode() {
058                switch (this) {
059                        case RESTHOOK:
060                                return "rest-hook";
061                        case WEBSOCKET:
062                                return "websocket";
063                        case EMAIL:
064                                return "email";
065                        case SMS:
066                                return "sms";
067                        case MESSAGE:
068                                return "message";
069                        case NULL:
070                        default:
071                                return "?";
072                }
073        }
074
075        public String getSystem() {
076                switch (this) {
077                        case RESTHOOK:
078                        case WEBSOCKET:
079                        case EMAIL:
080                        case SMS:
081                        case MESSAGE:
082                                return "http://terminology.hl7.org/CodeSystem/subscription-channel-type";
083                        case NULL:
084                        default:
085                                return "?";
086                }
087        }
088
089        public String getDefinition() {
090                switch (this) {
091                        case RESTHOOK:
092                                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.";
093                        case WEBSOCKET:
094                                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.";
095                        case EMAIL:
096                                return "The channel is executed by sending an email to the email addressed in the URI (which must be a mailto:).";
097                        case SMS:
098                                return "The channel is executed by sending an SMS message to the phone number identified in the URL (tel:).";
099                        case MESSAGE:
100                                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.";
101                        case NULL:
102                        default:
103                                return "?";
104                }
105        }
106
107        public String getDisplay() {
108                switch (this) {
109                        case RESTHOOK:
110                                return "Rest Hook";
111                        case WEBSOCKET:
112                                return "Websocket";
113                        case EMAIL:
114                                return "Email";
115                        case SMS:
116                                return "SMS";
117                        case MESSAGE:
118                                return "Message";
119                        case NULL:
120                        default:
121                                return "?";
122                }
123        }
124
125        public Subscription.SubscriptionChannelType toCanonical() {
126                return Subscription.SubscriptionChannelType.fromCode(toCode());
127        }
128
129        public static CanonicalSubscriptionChannelType fromCode(@Nullable String theSystem, @Nonnull String codeString) throws FHIRException {
130                if (isBlank(codeString)) {
131                        return null;
132                } else if ("rest-hook".equals(codeString)) {
133                        if (theSystem == null || theSystem.equals("http://terminology.hl7.org/CodeSystem/subscription-channel-type")) {
134                                return RESTHOOK;
135                        }
136                } else if ("websocket".equals(codeString)) {
137                        if (theSystem == null || theSystem.equals("http://terminology.hl7.org/CodeSystem/subscription-channel-type")) {
138                                return WEBSOCKET;
139                        }
140                } else if ("email".equals(codeString)) {
141                        if (theSystem == null || theSystem.equals("http://terminology.hl7.org/CodeSystem/subscription-channel-type")) {
142                                return EMAIL;
143                        }
144                } else if ("sms".equals(codeString)) {
145                        if (theSystem == null || theSystem.equals("http://terminology.hl7.org/CodeSystem/subscription-channel-type")) {
146                                return SMS;
147                        }
148                } else if ("message".equals(codeString)) {
149                        if (theSystem == null || theSystem.equals("http://terminology.hl7.org/CodeSystem/subscription-channel-type")) {
150                                return MESSAGE;
151                        }
152                }
153
154                throw new FHIRException("Unknown SubscriptionChannelType code '" + codeString + "'");
155        }
156}