View Javadoc
1   package ca.uhn.fhir.jpa.subscription;
2   
3   /*-
4    * #%L
5    * HAPI FHIR JPA Server
6    * %%
7    * Copyright (C) 2014 - 2018 University Health Network
8    * %%
9    * Licensed under the Apache License, Version 2.0 (the "License");
10   * you may not use this file except in compliance with the License.
11   * You may obtain a copy of the License at
12   * 
13   *      http://www.apache.org/licenses/LICENSE-2.0
14   * 
15   * Unless required by applicable law or agreed to in writing, software
16   * distributed under the License is distributed on an "AS IS" BASIS,
17   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18   * See the License for the specific language governing permissions and
19   * limitations under the License.
20   * #L%
21   */
22  
23  import ca.uhn.fhir.context.FhirContext;
24  import com.fasterxml.jackson.annotation.JsonAutoDetect;
25  import com.fasterxml.jackson.annotation.JsonIgnore;
26  import com.fasterxml.jackson.annotation.JsonInclude;
27  import com.fasterxml.jackson.annotation.JsonProperty;
28  import org.hl7.fhir.instance.model.api.IBaseResource;
29  import org.hl7.fhir.instance.model.api.IIdType;
30  
31  @JsonInclude(JsonInclude.Include.NON_NULL)
32  @JsonAutoDetect(creatorVisibility = JsonAutoDetect.Visibility.NONE, fieldVisibility = JsonAutoDetect.Visibility.NONE, getterVisibility = JsonAutoDetect.Visibility.NONE, isGetterVisibility = JsonAutoDetect.Visibility.NONE, setterVisibility = JsonAutoDetect.Visibility.NONE)
33  public class ResourceModifiedMessage {
34  
35  	private static final long serialVersionUID = 1L;
36  
37  	@JsonProperty("resourceId")
38  	private String myId;
39  	@JsonProperty("operationType")
40  	private OperationTypeEnum myOperationType;
41  	/**
42  	 * This will only be set if the resource is being triggered for a specific
43  	 * subscription
44  	 */
45  	@JsonProperty(value = "subscriptionId", required = false)
46  	private String mySubscriptionId;
47  	@JsonProperty("newPayload")
48  	private String myNewPayloadEncoded;
49  	@JsonIgnore
50  	private transient IBaseResource myNewPayload;
51  
52  	public String getSubscriptionId() {
53  		return mySubscriptionId;
54  	}
55  
56  	public void setSubscriptionId(String theSubscriptionId) {
57  		mySubscriptionId = theSubscriptionId;
58  	}
59  
60  	public IIdType getId(FhirContext theCtx) {
61  		IIdType retVal = null;
62  		if (myId != null) {
63  			retVal = theCtx.getVersion().newIdType().setValue(myId);
64  		}
65  		return retVal;
66  	}
67  
68  	public IBaseResource getNewPayload(FhirContext theCtx) {
69  		if (myNewPayload == null && myNewPayloadEncoded != null) {
70  			myNewPayload = theCtx.newJsonParser().parseResource(myNewPayloadEncoded);
71  		}
72  		return myNewPayload;
73  	}
74  
75  	public OperationTypeEnum getOperationType() {
76  		return myOperationType;
77  	}
78  
79  	public void setOperationType(OperationTypeEnum theOperationType) {
80  		myOperationType = theOperationType;
81  	}
82  
83  	public void setId(IIdType theId) {
84  		myId = null;
85  		if (theId != null) {
86  			myId = theId.getValue();
87  		}
88  	}
89  
90  	public void setNewPayload(FhirContext theCtx, IBaseResource theNewPayload) {
91  		myNewPayload = theNewPayload;
92  		myNewPayloadEncoded = theCtx.newJsonParser().encodeResourceToString(theNewPayload);
93  	}
94  
95  
96  	public enum OperationTypeEnum {
97  		CREATE,
98  		UPDATE,
99  		DELETE,
100 		MANUALLY_TRIGGERED;
101 
102 	}
103 
104 }