001/*-
002 * #%L
003 * Smile CDR - CDR
004 * %%
005 * Copyright (C) 2016 - 2026 Smile CDR, Inc.
006 * %%
007 * All rights reserved.
008 * #L%
009 */
010package ca.cdr.api.fhirgw.model;
011
012import org.apache.commons.lang3.StringUtils;
013import org.hl7.fhir.instance.model.api.IBaseParameters;
014import org.hl7.fhir.instance.model.api.IBaseResource;
015
016import java.util.ArrayList;
017import java.util.List;
018
019/**
020 * This class represents a FHIR Gateway Operation request
021 */
022public class OperationRequest extends BaseRequest<OperationRequest> {
023        private String myResourceId;
024        private final String myOperationName;
025        private IBaseParameters myParameters;
026        /**
027         * A raw resource to forward as the operation body. Mutually exclusive with {@link #myParameters}.
028         * When set, the gateway forwards the resource directly as the POST body.
029         */
030        private IBaseResource myResource;
031
032        private boolean myIsPaged;
033
034        /**
035         * Constructor
036         * @param theOperationName
037         */
038        public OperationRequest(String theOperationName) {
039                // nothing
040                myOperationName = theOperationName;
041        }
042
043        /**
044         * Copy constructor
045         */
046        public OperationRequest(OperationRequest theRequest) {
047                super(theRequest);
048                myResourceId = theRequest.getResourceId();
049                myOperationName = theRequest.getOperationName();
050                myParameters = theRequest.getParameters();
051                myResource = theRequest.getResource();
052        }
053
054        public String getResourceId() {
055                return myResourceId;
056        }
057
058        public OperationRequest setResourceId(String theResourceId) {
059                myResourceId = theResourceId;
060                return this;
061        }
062
063        public IBaseParameters getParameters() {
064                return myParameters;
065        }
066
067        public OperationRequest setParameters(IBaseParameters theParameters) {
068                myParameters = theParameters;
069                return this;
070        }
071
072        // Generated by claude-sonnet-4-6
073        public IBaseResource getResource() {
074                return myResource;
075        }
076
077        // Generated by claude-sonnet-4-6
078        public OperationRequest setResource(IBaseResource theResource) {
079                myResource = theResource;
080                return this;
081        }
082
083        public String getOperationName() {
084                return myOperationName;
085        }
086
087        public boolean isInstanceRequest() {
088                return myResourceId != null;
089        }
090
091        public boolean isTypeRequest() {
092                return !isInstanceRequest() && getResourceType() != null;
093        }
094
095        public boolean isSystemRequest() {
096                return !isInstanceRequest() && !isTypeRequest();
097        }
098
099        public String getDescription() {
100                List<String> operations = new ArrayList<>();
101                if (isSystemRequest()) {
102                        operations.add("/" + myOperationName);
103                }
104                if (isTypeRequest()) {
105                        operations.add(getResourceType() + "/" + myOperationName);
106                }
107                if (isInstanceRequest()) {
108                        operations.add(getResourceId() + "/" + myOperationName);
109                }
110                return StringUtils.join(operations, ",");
111        }
112
113        public boolean isPaged() {
114                return myIsPaged;
115        }
116
117        public void setPaged(boolean thePaged) {
118                myIsPaged = thePaged;
119        }
120}