001/*-
002 * #%L
003 * HAPI FHIR Storage api
004 * %%
005 * Copyright (C) 2014 - 2025 Smile CDR, Inc.
006 * %%
007 * Licensed under the Apache License, Version 2.0 (the "License");
008 * you may not use this file except in compliance with the License.
009 * You may obtain a copy of the License at
010 *
011 *      http://www.apache.org/licenses/LICENSE-2.0
012 *
013 * Unless required by applicable law or agreed to in writing, software
014 * distributed under the License is distributed on an "AS IS" BASIS,
015 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
016 * See the License for the specific language governing permissions and
017 * limitations under the License.
018 * #L%
019 */
020package ca.uhn.fhir.jpa.bulk.export.model;
021
022import ca.uhn.fhir.model.api.IModelJson;
023import ca.uhn.fhir.rest.server.util.JsonDateDeserializer;
024import ca.uhn.fhir.rest.server.util.JsonDateSerializer;
025import com.fasterxml.jackson.annotation.JsonAutoDetect;
026import com.fasterxml.jackson.annotation.JsonInclude;
027import com.fasterxml.jackson.annotation.JsonProperty;
028import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
029import com.fasterxml.jackson.databind.annotation.JsonSerialize;
030import org.apache.commons.lang3.builder.EqualsBuilder;
031import org.apache.commons.lang3.builder.HashCodeBuilder;
032
033import java.util.ArrayList;
034import java.util.Date;
035import java.util.List;
036
037@JsonInclude(JsonInclude.Include.NON_DEFAULT)
038@JsonAutoDetect(
039                creatorVisibility = JsonAutoDetect.Visibility.NONE,
040                fieldVisibility = JsonAutoDetect.Visibility.NONE,
041                getterVisibility = JsonAutoDetect.Visibility.NONE,
042                isGetterVisibility = JsonAutoDetect.Visibility.NONE,
043                setterVisibility = JsonAutoDetect.Visibility.NONE)
044public class BulkExportResponseJson {
045
046        @JsonProperty("transactionTime")
047        @JsonSerialize(using = JsonDateSerializer.class)
048        @JsonDeserialize(using = JsonDateDeserializer.class)
049        private Date myTransactionTime;
050
051        @JsonProperty("request")
052        private String myRequest;
053
054        @JsonProperty("requiresAccessToken")
055        private Boolean myRequiresAccessToken;
056
057        @JsonInclude
058        @JsonProperty("output")
059        private final List<Output> myOutput = new ArrayList<>();
060
061        /*
062         * Note that we override the include here as ONC regulations require that we actually serialize the empty error array.
063         */
064        @JsonInclude
065        @JsonProperty("error")
066        private final List<Output> myError = new ArrayList<>();
067
068        @JsonProperty("message")
069        private String myMsg;
070
071        public Date getTransactionTime() {
072                return myTransactionTime;
073        }
074
075        public BulkExportResponseJson setTransactionTime(Date theTransactionTime) {
076                myTransactionTime = theTransactionTime;
077                return this;
078        }
079
080        public String getRequest() {
081                return myRequest;
082        }
083
084        public BulkExportResponseJson setRequest(String theRequest) {
085                myRequest = theRequest;
086                return this;
087        }
088
089        public Boolean getRequiresAccessToken() {
090                return myRequiresAccessToken;
091        }
092
093        public BulkExportResponseJson setRequiresAccessToken(Boolean theRequiresAccessToken) {
094                myRequiresAccessToken = theRequiresAccessToken;
095                return this;
096        }
097
098        public List<Output> getOutput() {
099                return myOutput;
100        }
101
102        public List<Output> getError() {
103                return myError;
104        }
105
106        public Output addOutput() {
107                Output retVal = new Output();
108                getOutput().add(retVal);
109                return retVal;
110        }
111
112        public String getMsg() {
113                return myMsg;
114        }
115
116        public void setMsg(String theMsg) {
117                myMsg = theMsg;
118        }
119
120        public static class Output implements IModelJson {
121
122                @JsonProperty("type")
123                private String myType;
124
125                @JsonProperty("url")
126                private String myUrl;
127
128                public String getType() {
129                        return myType;
130                }
131
132                public Output setType(String theType) {
133                        myType = theType;
134                        return this;
135                }
136
137                public String getUrl() {
138                        return myUrl;
139                }
140
141                public Output setUrl(String theUrl) {
142                        myUrl = theUrl;
143                        return this;
144                }
145
146                @Override
147                public boolean equals(Object theO) {
148                        if (this == theO) return true;
149
150                        if (!(theO instanceof Output)) return false;
151
152                        Output output = (Output) theO;
153
154                        return new EqualsBuilder()
155                                        .append(myType, output.myType)
156                                        .append(myUrl, output.myUrl)
157                                        .isEquals();
158                }
159
160                @Override
161                public int hashCode() {
162                        return new HashCodeBuilder(17, 37).append(myType).append(myUrl).toHashCode();
163                }
164        }
165}