001package org.hl7.fhir.convertors.conv43_50.resources43_50;
002
003import org.hl7.fhir.convertors.context.ConversionContext43_50;
004import org.hl7.fhir.convertors.conv43_50.datatypes43_50.general43_50.CodeableConcept43_50;
005import org.hl7.fhir.convertors.conv43_50.datatypes43_50.general43_50.Identifier43_50;
006import org.hl7.fhir.convertors.conv43_50.datatypes43_50.metadata43_50.ContactDetail43_50;
007import org.hl7.fhir.convertors.conv43_50.datatypes43_50.metadata43_50.UsageContext43_50;
008import org.hl7.fhir.convertors.conv43_50.datatypes43_50.primitive43_50.Boolean43_50;
009import org.hl7.fhir.convertors.conv43_50.datatypes43_50.primitive43_50.Canonical43_50;
010import org.hl7.fhir.convertors.conv43_50.datatypes43_50.primitive43_50.DateTime43_50;
011import org.hl7.fhir.convertors.conv43_50.datatypes43_50.primitive43_50.Id43_50;
012import org.hl7.fhir.convertors.conv43_50.datatypes43_50.primitive43_50.MarkDown43_50;
013import org.hl7.fhir.convertors.conv43_50.datatypes43_50.primitive43_50.String43_50;
014import org.hl7.fhir.convertors.conv43_50.datatypes43_50.primitive43_50.Uri43_50;
015import org.hl7.fhir.convertors.conv43_50.datatypes43_50.primitive43_50.Url43_50;
016import org.hl7.fhir.convertors.conv43_50.datatypes43_50.special43_50.Reference43_50;
017import org.hl7.fhir.exceptions.FHIRException;
018import org.hl7.fhir.r4b.model.Extension;
019import org.hl7.fhir.r5.model.CanonicalType;
020import org.hl7.fhir.r5.model.CodeableConcept;
021import org.hl7.fhir.r5.model.ContactDetail;
022import org.hl7.fhir.r5.model.Enumeration;
023import org.hl7.fhir.r5.model.Enumerations.PublicationStatus;
024import org.hl7.fhir.r5.model.Reference;
025import org.hl7.fhir.r5.model.Requirements.ConformanceExpectation;
026import org.hl7.fhir.r5.model.Requirements.RequirementsStatementComponent;
027import org.hl7.fhir.r5.model.UrlType;
028import org.hl7.fhir.r5.model.UsageContext;
029
030/*
031  Copyright (c) 2011+, HL7, Inc.
032  All rights reserved.
033  
034  Redistribution and use in source and binary forms, with or without modification, 
035  are permitted provided that the following conditions are met:
036  
037   * Redistributions of source code must retain the above copyright notice, this 
038     list of conditions and the following disclaimer.
039   * Redistributions in binary form must reproduce the above copyright notice, 
040     this list of conditions and the following disclaimer in the documentation 
041     and/or other materials provided with the distribution.
042   * Neither the name of HL7 nor the names of its contributors may be used to 
043     endorse or promote products derived from this software without specific 
044     prior written permission.
045  
046  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 
047  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 
048  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 
049  IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 
050  INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 
051  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 
052  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 
053  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
054  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
055  POSSIBILITY OF SUCH DAMAGE.
056  
057*/
058// Generated on Sun, Feb 24, 2019 11:37+1100 for FHIR v4.0.0
059public class Requirements43_50 {
060
061  public static final String URL_EXTENSION_URL = "http://hl7.org/fhir/5.0/StructureDefinition/extension-Requirements.url";
062  public static final String VERSION_EXTENSION_URL = "http://hl7.org/fhir/5.0/StructureDefinition/extension-Requirements.version";
063  public static final String NAME_EXTENSION_URL = "http://hl7.org/fhir/5.0/StructureDefinition/extension-Requirements.name";
064  public static final String TITLE_EXTENSION_URL = "http://hl7.org/fhir/5.0/StructureDefinition/extension-Requirements.title";
065  public static final String STATUS_EXTENSION_URL = "http://hl7.org/fhir/5.0/StructureDefinition/extension-Requirements.status";
066  public static final String EXPERIMENTAL_EXTENSION_URL = "http://hl7.org/fhir/5.0/StructureDefinition/extension-Requirements.experimental";
067  public static final String DATE_EXTENSION_URL = "http://hl7.org/fhir/5.0/StructureDefinition/extension-Requirements.date";
068  public static final String PUBLISHER_EXTENSION_URL = "http://hl7.org/fhir/5.0/StructureDefinition/extension-Requirements.publisher";
069  public static final String CONTACT_EXTENSION_URL = "http://hl7.org/fhir/5.0/StructureDefinition/extension-Requirements.contact";
070  public static final String DESCRIPTION_EXTENSION_URL = "http://hl7.org/fhir/5.0/StructureDefinition/extension-Requirements.description";
071  public static final String USE_CONTEXT_EXTENSION_URL = "http://hl7.org/fhir/5.0/StructureDefinition/extension-Requirements.useContext";
072  public static final String JURISDICTION_EXTENSION_URL = "http://hl7.org/fhir/5.0/StructureDefinition/extension-Requirements.jurisdiction";
073  public static final String PURPOSE_EXTENSION_URL = "http://hl7.org/fhir/5.0/StructureDefinition/extension-Requirements.purpose";
074  public static final String COPYRIGHT_EXTENSION_URL = "http://hl7.org/fhir/5.0/StructureDefinition/extension-Requirements.copyright";
075  public static final String COPYRIGHT_LABEL_EXTENSION_URL = "http://hl7.org/fhir/5.0/StructureDefinition/extension-Requirements.copyrightLabel";
076  public static final String DERIVED_FROM_EXTENSION_URL = "http://hl7.org/fhir/5.0/StructureDefinition/extension-Requirements.derivedFrom";
077  public static final String ACTOR_EXTENSION_URL = "http://hl7.org/fhir/5.0/StructureDefinition/extension-Requirements.actor";
078  public static final String REQUIREMENTS_STATEMENT_EXTENSION_URL = "http://hl7.org/fhir/5.0/StructureDefinition/extension-Requirements.statement";
079
080  private static final String[] IGNORED_EXTENSION_URLS = new String[]{
081    URL_EXTENSION_URL,
082    VERSION_EXTENSION_URL,
083    NAME_EXTENSION_URL,
084    TITLE_EXTENSION_URL,
085    STATUS_EXTENSION_URL,
086    STATUS_EXTENSION_URL,
087    EXPERIMENTAL_EXTENSION_URL,
088    DATE_EXTENSION_URL,
089    PUBLISHER_EXTENSION_URL,
090    CONTACT_EXTENSION_URL,
091    DESCRIPTION_EXTENSION_URL,
092    USE_CONTEXT_EXTENSION_URL,
093    JURISDICTION_EXTENSION_URL,
094    PURPOSE_EXTENSION_URL,
095    COPYRIGHT_EXTENSION_URL,
096    COPYRIGHT_LABEL_EXTENSION_URL,
097    DERIVED_FROM_EXTENSION_URL,
098    ACTOR_EXTENSION_URL,
099    REQUIREMENTS_STATEMENT_EXTENSION_URL
100  };
101  public static org.hl7.fhir.r5.model.Requirements convertRequirements(org.hl7.fhir.r4b.model.Basic src) throws FHIRException {
102    if (src == null)
103      return null;
104    if (!src.getCode().hasCoding("http://hl7.org/fhir/fhir-types", "Requirements")) {
105      throw new FHIRException("Error in logic: this basic resource is not an Requirements");
106    }
107    org.hl7.fhir.r5.model.Requirements tgt = new org.hl7.fhir.r5.model.Requirements();
108    ConversionContext43_50.INSTANCE.getVersionConvertor_43_50().copyDomainResource(src, tgt, IGNORED_EXTENSION_URLS);
109    
110    for (org.hl7.fhir.r4b.model.Identifier t : src.getIdentifier())
111      tgt.addIdentifier(Identifier43_50.convertIdentifier(t));
112
113    if (src.hasExtension(URL_EXTENSION_URL)) {
114      tgt.setUrlElement(Uri43_50.convertUri((org.hl7.fhir.r4b.model.UriType) src.getExtensionByUrl(URL_EXTENSION_URL).getValue()));
115    }
116    if (src.hasExtension(VERSION_EXTENSION_URL)) {
117      tgt.setVersionElement(String43_50.convertString((org.hl7.fhir.r4b.model.StringType) src.getExtensionByUrl(VERSION_EXTENSION_URL).getValue()));
118    }
119    if (src.hasExtension(NAME_EXTENSION_URL)) {
120      tgt.setNameElement(String43_50.convertString((org.hl7.fhir.r4b.model.StringType) src.getExtensionByUrl(NAME_EXTENSION_URL).getValue()));
121    }
122    if (src.hasExtension(TITLE_EXTENSION_URL)) {
123      tgt.setTitleElement(String43_50.convertString((org.hl7.fhir.r4b.model.StringType) src.getExtensionByUrl(TITLE_EXTENSION_URL).getValue()));
124    }
125    if (src.hasExtension(STATUS_EXTENSION_URL)) {
126      tgt.setStatus(PublicationStatus.fromCode(src.getExtensionByUrl(STATUS_EXTENSION_URL).getValue().primitiveValue()));
127    }
128    if (src.hasExtension(EXPERIMENTAL_EXTENSION_URL)) {
129      tgt.setExperimentalElement(Boolean43_50.convertBoolean((org.hl7.fhir.r4b.model.BooleanType) src.getExtensionByUrl(EXPERIMENTAL_EXTENSION_URL).getValue()));
130    }
131    if (src.hasExtension(DATE_EXTENSION_URL)) {
132      tgt.setDateElement(DateTime43_50.convertDateTime((org.hl7.fhir.r4b.model.DateTimeType) src.getExtensionByUrl(DATE_EXTENSION_URL).getValue()));
133    }
134    if (src.hasExtension(PUBLISHER_EXTENSION_URL)) {
135      tgt.setPublisherElement(String43_50.convertString((org.hl7.fhir.r4b.model.StringType) src.getExtensionByUrl(PUBLISHER_EXTENSION_URL).getValue()));
136    }
137    for (org.hl7.fhir.r4b.model.Extension ext : src.getExtensionsByUrl(CONTACT_EXTENSION_URL)) {
138      tgt.addContact(ContactDetail43_50.convertContactDetail((org.hl7.fhir.r4b.model.ContactDetail) ext.getValue()));
139    }
140    if (src.hasExtension(DESCRIPTION_EXTENSION_URL)) {
141      tgt.setPublisherElement(MarkDown43_50.convertMarkdown((org.hl7.fhir.r4b.model.MarkdownType) src.getExtensionByUrl(DESCRIPTION_EXTENSION_URL).getValue()));
142    }
143    for (org.hl7.fhir.r4b.model.Extension ext : src.getExtensionsByUrl(USE_CONTEXT_EXTENSION_URL)) {
144      tgt.addUseContext(UsageContext43_50.convertUsageContext((org.hl7.fhir.r4b.model.UsageContext) ext.getValue()));
145    }
146    for (org.hl7.fhir.r4b.model.Extension ext : src.getExtensionsByUrl(JURISDICTION_EXTENSION_URL)) {
147      tgt.addJurisdiction(CodeableConcept43_50.convertCodeableConcept((org.hl7.fhir.r4b.model.CodeableConcept) ext.getValue()));
148    }
149    if (src.hasExtension(PURPOSE_EXTENSION_URL)) {
150      tgt.setPurposeElement(MarkDown43_50.convertMarkdown((org.hl7.fhir.r4b.model.MarkdownType) src.getExtensionByUrl(PURPOSE_EXTENSION_URL).getValue()));
151    }
152    if (src.hasExtension(COPYRIGHT_EXTENSION_URL)) {
153      tgt.setCopyrightElement(MarkDown43_50.convertMarkdown((org.hl7.fhir.r4b.model.MarkdownType) src.getExtensionByUrl(COPYRIGHT_EXTENSION_URL).getValue()));
154    }
155    if (src.hasExtension(COPYRIGHT_LABEL_EXTENSION_URL)) {
156      tgt.setCopyrightLabelElement(String43_50.convertString((org.hl7.fhir.r4b.model.StringType) src.getExtensionByUrl(COPYRIGHT_LABEL_EXTENSION_URL).getValue()));
157    }
158    for (org.hl7.fhir.r4b.model.Extension ext : src.getExtensionsByUrl(DERIVED_FROM_EXTENSION_URL)) {
159      tgt.getDerivedFrom().add(Canonical43_50.convertCanonical((org.hl7.fhir.r4b.model.CanonicalType) ext.getValue()));
160    }
161    for (org.hl7.fhir.r4b.model.Extension ext : src.getExtensionsByUrl(ACTOR_EXTENSION_URL)) {
162      tgt.getActor().add(Canonical43_50.convertCanonical((org.hl7.fhir.r4b.model.CanonicalType) ext.getValue()));
163    }
164    for (org.hl7.fhir.r4b.model.Extension ext : src.getExtensionsByUrl(REQUIREMENTS_STATEMENT_EXTENSION_URL)) {
165      convertRequirementsStatement(ext, tgt.addStatement());
166    }
167    return tgt;
168  }
169
170
171  public static org.hl7.fhir.r4b.model.Basic convertRequirements(org.hl7.fhir.r5.model.Requirements src) throws FHIRException {
172    if (src == null)
173      return null;
174    org.hl7.fhir.r4b.model.Basic tgt = new org.hl7.fhir.r4b.model.Basic();
175    ConversionContext43_50.INSTANCE.getVersionConvertor_43_50().copyDomainResource(src, tgt);
176    tgt.getCode().getCodingFirstRep().setSystem("http://hl7.org/fhir/fhir-types").setCode("Requirements"); // note use of R5 type system
177    
178    for (org.hl7.fhir.r5.model.Identifier t : src.getIdentifier())
179      tgt.addIdentifier(Identifier43_50.convertIdentifier(t));
180    if (src.hasUrl()) {
181      tgt.addExtension(URL_EXTENSION_URL, Uri43_50.convertUri(src.getUrlElement()));
182    }
183    if (src.hasVersion()) {
184      tgt.addExtension(VERSION_EXTENSION_URL, String43_50.convertString(src.getVersionElement()));
185    }
186    if (src.hasName()) {
187      tgt.addExtension(NAME_EXTENSION_URL, String43_50.convertString(src.getNameElement()));
188    }
189    if (src.hasTitle()) {
190      tgt.addExtension(TITLE_EXTENSION_URL, String43_50.convertString(src.getTitleElement()));
191    }
192    if (src.hasStatus()) {
193      tgt.addExtension(STATUS_EXTENSION_URL, new org.hl7.fhir.r4b.model.CodeType(src.getStatus().toCode()));
194    }
195    if (src.hasExperimental()) {
196      tgt.addExtension(EXPERIMENTAL_EXTENSION_URL, Boolean43_50.convertBoolean(src.getExperimentalElement()));
197    }
198    if (src.hasDate()) {
199      tgt.addExtension(DATE_EXTENSION_URL, DateTime43_50.convertDateTime(src.getDateElement()));
200    }
201    if (src.hasPublisher()) {
202      tgt.addExtension(PUBLISHER_EXTENSION_URL, String43_50.convertString(src.getPublisherElement()));
203    }
204    for (ContactDetail cd : src.getContact()) {
205      tgt.addExtension(CONTACT_EXTENSION_URL, ContactDetail43_50.convertContactDetail(cd));
206    }
207    if (src.hasDescription()) {
208      tgt.addExtension(DESCRIPTION_EXTENSION_URL, MarkDown43_50.convertMarkdown(src.getDescriptionElement()));
209    }
210    for (UsageContext cd : src.getUseContext()) {
211      tgt.addExtension(USE_CONTEXT_EXTENSION_URL, UsageContext43_50.convertUsageContext(cd));
212    }
213    for (CodeableConcept cd : src.getJurisdiction()) {
214      tgt.addExtension(JURISDICTION_EXTENSION_URL, CodeableConcept43_50.convertCodeableConcept(cd));
215    }
216    if (src.hasPurpose()) {
217      tgt.addExtension(PURPOSE_EXTENSION_URL, MarkDown43_50.convertMarkdown(src.getPurposeElement()));
218    }
219    if (src.hasCopyright()) {
220      tgt.addExtension(COPYRIGHT_EXTENSION_URL, MarkDown43_50.convertMarkdown(src.getCopyrightElement()));
221    }
222    if (src.hasCopyrightLabel()) {
223      tgt.addExtension(COPYRIGHT_LABEL_EXTENSION_URL, String43_50.convertString(src.getCopyrightLabelElement()));
224    }
225    for (CanonicalType ref : src.getDerivedFrom()) {
226      tgt.addExtension(DERIVED_FROM_EXTENSION_URL, Canonical43_50.convertCanonical(ref));
227    }
228    for (CanonicalType ref : src.getActor()) {
229      tgt.addExtension(ACTOR_EXTENSION_URL, Canonical43_50.convertCanonical(ref));
230    }
231    for (RequirementsStatementComponent ref : src.getStatement()) {
232      org.hl7.fhir.r4b.model.Extension tgte = new org.hl7.fhir.r4b.model.Extension(REQUIREMENTS_STATEMENT_EXTENSION_URL);
233      tgt.addExtension(tgte);
234      convertRequirementsStatement(ref, tgte);
235    }
236
237    return tgt;
238  }
239
240  private static void convertRequirementsStatement(RequirementsStatementComponent src, Extension tgt) {
241    ConversionContext43_50.INSTANCE.getVersionConvertor_43_50().copyElement(src, tgt);
242    if (src.hasKey()) {
243      tgt.addExtension("http://hl7.org/fhir/5.0/StructureDefinition/extension-Requirements.statement.key", Id43_50.convertId(src.getKeyElement()));
244    }
245    if (src.hasLabel()) {
246      tgt.addExtension("http://hl7.org/fhir/5.0/StructureDefinition/extension-Requirements.statement.label", String43_50.convertString(src.getLabelElement()));
247    }
248    for (Enumeration<ConformanceExpectation> t : src.getConformance()) {
249      tgt.addExtension("http://hl7.org/fhir/5.0/StructureDefinition/extension-Requirements.statement.conformance", new org.hl7.fhir.r4b.model.CodeType(t.getCode()));
250    }
251    if (src.hasRequirement()) {
252      tgt.addExtension("http://hl7.org/fhir/5.0/StructureDefinition/extension-Requirements.statement.requirement", MarkDown43_50.convertMarkdown(src.getRequirementElement()));
253    }
254    if (src.hasDerivedFrom()) {
255      tgt.addExtension("http://hl7.org/fhir/5.0/StructureDefinition/extension-Requirements.statement.derivedFrom", String43_50.convertString(src.getDerivedFromElement()));
256    }
257    for (UrlType ref : src.getSatisfiedBy()) {
258      tgt.addExtension("http://hl7.org/fhir/5.0/StructureDefinition/extension-Requirements.statement.satisfiedBy", Url43_50.convertUrl(ref));
259    }
260    for (UrlType ref : src.getReference()) {
261      tgt.addExtension("http://hl7.org/fhir/5.0/StructureDefinition/extension-Requirements.statement.reference", Url43_50.convertUrl(ref));
262    }
263    for (Reference ref : src.getSource()) {
264      tgt.addExtension("http://hl7.org/fhir/5.0/StructureDefinition/extension-Requirements.statement.source", Reference43_50.convertReference(ref));
265    }
266  }
267
268
269  private static void convertRequirementsStatement(Extension src, RequirementsStatementComponent tgt) {
270    ConversionContext43_50.INSTANCE.getVersionConvertor_43_50().copyElement(src, tgt, 
271        "http://hl7.org/fhir/5.0/StructureDefinition/extension-Requirements.statement.key",
272        "http://hl7.org/fhir/5.0/StructureDefinition/extension-Requirements.statement.label",
273        "http://hl7.org/fhir/5.0/StructureDefinition/extension-Requirements.statement.conformance",
274        "http://hl7.org/fhir/5.0/StructureDefinition/extension-Requirements.statement.requirement",
275        "http://hl7.org/fhir/5.0/StructureDefinition/extension-Requirements.statement.derivedFrom",
276        "http://hl7.org/fhir/5.0/StructureDefinition/extension-Requirements.statement.satisfiedBy",
277        "http://hl7.org/fhir/5.0/StructureDefinition/extension-Requirements.statement.reference",
278        "http://hl7.org/fhir/5.0/StructureDefinition/extension-Requirements.statement.source"
279        );
280    if (src.hasExtension("http://hl7.org/fhir/5.0/StructureDefinition/extension-Requirements.statement.key")) {
281      tgt.setKeyElement(Id43_50.convertId((org.hl7.fhir.r4b.model.IdType) src.getExtensionByUrl("http://hl7.org/fhir/5.0/StructureDefinition/extension-Requirements.statement.key").getValue()));
282    }
283    if (src.hasExtension("http://hl7.org/fhir/5.0/StructureDefinition/extension-Requirements.statement.label")) {
284      tgt.setLabelElement(String43_50.convertString((org.hl7.fhir.r4b.model.StringType) src.getExtensionByUrl("http://hl7.org/fhir/5.0/StructureDefinition/extension-Requirements.statement.label").getValue()));
285    }
286    for (org.hl7.fhir.r4b.model.Extension ext : src.getExtensionsByUrl("http://hl7.org/fhir/5.0/StructureDefinition/extension-Requirements.statement.conformance")) {
287      tgt.addConformance(ConformanceExpectation.fromCode(ext.getValue().primitiveValue()));
288    }
289    if (src.hasExtension("http://hl7.org/fhir/5.0/StructureDefinition/extension-Requirements.statement.requirement")) {
290      tgt.setRequirementElement(MarkDown43_50.convertMarkdown((org.hl7.fhir.r4b.model.MarkdownType) src.getExtensionByUrl("http://hl7.org/fhir/5.0/StructureDefinition/extension-Requirements.statement.requirement").getValue()));
291    }
292    if (src.hasExtension("http://hl7.org/fhir/5.0/StructureDefinition/extension-Requirements.statement.derivedFrom")) {
293      tgt.setDerivedFromElement(String43_50.convertString((org.hl7.fhir.r4b.model.StringType) src.getExtensionByUrl("http://hl7.org/fhir/5.0/StructureDefinition/extension-Requirements.statement.derivedFrom").getValue()));
294    }
295    for (org.hl7.fhir.r4b.model.Extension ext : src.getExtensionsByUrl("http://hl7.org/fhir/5.0/StructureDefinition/extension-Requirements.statement.satisfiedBy")) {
296      tgt.getSatisfiedBy().add(Url43_50.convertUrl((org.hl7.fhir.r4b.model.UrlType) ext.getValue()));
297    }
298    for (org.hl7.fhir.r4b.model.Extension ext : src.getExtensionsByUrl("http://hl7.org/fhir/5.0/StructureDefinition/extension-Requirements.statement.reference")) {
299      tgt.getReference().add(Url43_50.convertUrl((org.hl7.fhir.r4b.model.UrlType) ext.getValue()));
300    }
301    for (org.hl7.fhir.r4b.model.Extension ext : src.getExtensionsByUrl("http://hl7.org/fhir/5.0/StructureDefinition/extension-Requirements.statement.source")) {
302      tgt.getSource().add(Reference43_50.convertReference((org.hl7.fhir.r4b.model.Reference) ext.getValue()));
303    }
304  }
305}