001/*-
002 * #%L
003 * Smile CDR - CDR
004 * %%
005 * Copyright (C) 2016 - 2024 Smile CDR, Inc.
006 * %%
007 * All rights reserved.
008 * #L%
009 */
010package ca.cdr.api.fhirgw.json;
011
012import ca.cdr.api.model.json.IModelJson;
013import com.fasterxml.jackson.annotation.JsonProperty;
014import io.swagger.v3.oas.annotations.media.Schema;
015
016import java.util.ArrayList;
017import java.util.Collection;
018import java.util.List;
019
020@Schema(
021                name = "GatewayOperation",
022                description = "Defines FHIR Operation that can be called through the Smile CDR Gateway")
023public class GatewayOperationJson implements IModelJson {
024        @JsonProperty("name")
025        @Schema(description = "The name of the FHIR operation")
026        private String myName;
027
028        @JsonProperty("system")
029        @Schema(description = "This operation can be called at the system level")
030        private boolean mySystem;
031
032        @JsonProperty("type")
033        @Schema(description = "This operation can be called on a FHIR resource type")
034        private boolean myType;
035
036        @JsonProperty("instance")
037        @Schema(description = "This operation can be called on a FHIR resource instance")
038        private boolean myInstance;
039
040        public String getName() {
041                return myName;
042        }
043
044        public GatewayOperationJson setName(String theName) {
045                myName = theName;
046                return this;
047        }
048
049        public boolean isSystem() {
050                return mySystem;
051        }
052
053        public GatewayOperationJson setSystem(boolean theSystem) {
054                mySystem = theSystem;
055                return this;
056        }
057
058        public boolean isType() {
059                return myType;
060        }
061
062        public GatewayOperationJson setType(boolean theType) {
063                myType = theType;
064                return this;
065        }
066
067        public boolean isInstance() {
068                return myInstance;
069        }
070
071        public GatewayOperationJson setInstance(boolean theInstance) {
072                myInstance = theInstance;
073                return this;
074        }
075
076        public List<String> getDescriptions(Collection<String> theResourceNames) {
077                List<String> retval = new ArrayList<>();
078                if (isSystem()) {
079                        retval.add("/" + myName);
080                }
081                for (String resourceName : theResourceNames) {
082                        if (isType()) {
083                                retval.add("/" + resourceName + "/" + myName);
084                        }
085                        if (isInstance()) {
086                                retval.add("/" + resourceName + "/[id]/" + myName);
087                        }
088                }
089                return retval;
090        }
091}