001package ca.uhn.fhir.model.dstu2.resource; 002 003/* 004 * #%L 005 * HAPI FHIR Structures - DSTU2 (FHIR v1.0.0) 006 * %% 007 * Copyright (C) 2014 - 2016 University Health Network 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.apache.commons.lang3.Validate; 024import org.apache.commons.lang3.builder.ToStringBuilder; 025import org.apache.commons.lang3.builder.ToStringStyle; 026import org.hl7.fhir.instance.model.api.IIdType; 027 028import ca.uhn.fhir.model.api.BaseElement; 029import ca.uhn.fhir.model.api.IResource; 030import ca.uhn.fhir.model.api.annotation.Child; 031import ca.uhn.fhir.model.api.annotation.SearchParamDefinition; 032import ca.uhn.fhir.model.base.resource.ResourceMetadataMap; 033import ca.uhn.fhir.model.dstu2.composite.ContainedDt; 034import ca.uhn.fhir.model.dstu2.composite.NarrativeDt; 035import ca.uhn.fhir.model.primitive.CodeDt; 036import ca.uhn.fhir.model.primitive.IdDt; 037import ca.uhn.fhir.rest.gclient.StringClientParam; 038import ca.uhn.fhir.util.ElementUtil; 039 040public abstract class BaseResource extends BaseElement implements IResource { 041 042 /** 043 * Search parameter constant for <b>_language</b> 044 */ 045 @SearchParamDefinition(name="_language", path="", description="The language of the resource", type="string" ) 046 public static final String SP_RES_LANGUAGE = "_language"; 047 048 049 /** 050 * Search parameter constant for <b>_id</b> 051 */ 052 @SearchParamDefinition(name="_id", path="", description="The ID of the resource", type="string" ) 053 public static final String SP_RES_ID = "_id"; 054 055 /** 056 * <b>Fluent Client</b> search parameter constant for <b>_id</b> 057 * <p> 058 * Description: <b>the _id of a resource</b><br> 059 * Type: <b>string</b><br> 060 * Path: <b>Resource._id</b><br> 061 * </p> 062 */ 063 public static final StringClientParam RES_ID = new StringClientParam(BaseResource.SP_RES_ID); 064 065 066 @Child(name = "contained", order = 2, min = 0, max = 1) 067 private ContainedDt myContained; 068 069 private IdDt myId; 070 071 @Child(name = "language", order = 0, min = 0, max = Child.MAX_UNLIMITED) 072 private CodeDt myLanguage; 073 074 private ResourceMetadataMap myResourceMetadata; 075 076 @Child(name = "text", order = 1, min = 0, max = 1) 077 private NarrativeDt myText; 078 079 @Override 080 public ContainedDt getContained() { 081 if (myContained == null) { 082 myContained = new ContainedDt(); 083 } 084 return myContained; 085 } 086 087 public IdDt getId() { 088 if (myId == null) { 089 myId = new IdDt(); 090 } 091 return myId; 092 } 093 094 @Override 095 public IIdType getIdElement() { 096 return getId(); 097 } 098 099 @Override 100 public CodeDt getLanguage() { 101 if (myLanguage == null) { 102 myLanguage = new CodeDt(); 103 } 104 return myLanguage; 105 } 106 107 @Override 108 public ResourceMetadataMap getResourceMetadata() { 109 if (myResourceMetadata == null) { 110 myResourceMetadata = new ResourceMetadataMap(); 111 } 112 return myResourceMetadata; 113 } 114 115 @Override 116 public NarrativeDt getText() { 117 if (myText == null) { 118 myText = new NarrativeDt(); 119 } 120 return myText; 121 } 122 123 public void setContained(ContainedDt theContained) { 124 myContained = theContained; 125 } 126 127 public void setId(IdDt theId) { 128 myId = theId; 129 } 130 131 public BaseResource setId(IIdType theId) { 132 if (theId instanceof IdDt) { 133 myId = (IdDt) theId; 134 } else if (theId != null) { 135 myId = new IdDt(theId.getValue()); 136 } 137 return this; 138 } 139 140 public BaseResource setId(String theId) { 141 if (theId == null) { 142 myId = null; 143 } else { 144 myId = new IdDt(theId); 145 } 146 return this; 147 } 148 149 @Override 150 public void setLanguage(CodeDt theLanguage) { 151 myLanguage = theLanguage; 152 } 153 154 @Override 155 public void setResourceMetadata(ResourceMetadataMap theMap) { 156 Validate.notNull(theMap, "The Map must not be null"); 157 myResourceMetadata = theMap; 158 } 159 160 public void setText(NarrativeDt theText) { 161 myText = theText; 162 } 163 164 @Override 165 public String toString() { 166 ToStringBuilder b = new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE); 167 b.append("id", getId().toUnqualified()); 168 return b.toString(); 169 } 170 171 /** 172 * Intended to be called by extending classes {@link #isEmpty()} implementations, returns <code>true</code> if all 173 * content in this superclass instance is empty per the semantics of {@link #isEmpty()}. 174 */ 175 @Override 176 protected boolean isBaseEmpty() { 177 return super.isBaseEmpty() && ElementUtil.isEmpty(myLanguage, myText, myId); 178 } 179 180}