001package org.hl7.fhir.convertors.conv40_50.resources40_50;
002
003import org.hl7.fhir.convertors.context.ConversionContext40_50;
004import org.hl7.fhir.convertors.conv40_50.datatypes40_50.general40_50.CodeableConcept40_50;
005import org.hl7.fhir.convertors.conv40_50.datatypes40_50.general40_50.Identifier40_50;
006import org.hl7.fhir.convertors.conv40_50.datatypes40_50.metadata40_50.ContactDetail40_50;
007import org.hl7.fhir.convertors.conv40_50.datatypes40_50.metadata40_50.UsageContext40_50;
008import org.hl7.fhir.convertors.conv40_50.datatypes40_50.primitive40_50.Boolean40_50;
009import org.hl7.fhir.convertors.conv40_50.datatypes40_50.primitive40_50.Canonical40_50;
010import org.hl7.fhir.convertors.conv40_50.datatypes40_50.primitive40_50.DateTime40_50;
011import org.hl7.fhir.convertors.conv40_50.datatypes40_50.primitive40_50.Id40_50;
012import org.hl7.fhir.convertors.conv40_50.datatypes40_50.primitive40_50.MarkDown40_50;
013import org.hl7.fhir.convertors.conv40_50.datatypes40_50.primitive40_50.String40_50;
014import org.hl7.fhir.convertors.conv40_50.datatypes40_50.primitive40_50.Uri40_50;
015import org.hl7.fhir.convertors.conv40_50.datatypes40_50.primitive40_50.Url40_50;
016import org.hl7.fhir.convertors.conv40_50.datatypes40_50.special40_50.Reference40_50;
017import org.hl7.fhir.exceptions.FHIRException;
018import org.hl7.fhir.r4.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 Requirements40_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 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    EXPERIMENTAL_EXTENSION_URL,
087    DATE_EXTENSION_URL,
088    PUBLISHER_EXTENSION_URL,
089    CONTACT_EXTENSION_URL,
090    DESCRIPTION_EXTENSION_URL,
091    USE_CONTEXT_EXTENSION_URL,
092    JURISDICTION_EXTENSION_URL,
093    PURPOSE_EXTENSION_URL,
094    COPYRIGHT_EXTENSION_URL,
095    COPYRIGHT_LABEL_EXTENSION_URL,
096    DERIVED_FROM_EXTENSION_URL,
097    ACTOR_EXTENSION_URL,
098    STATEMENT_EXTENSION_URL
099  };
100
101  public static org.hl7.fhir.r5.model.Requirements convertRequirements(org.hl7.fhir.r4.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
109    ConversionContext40_50.INSTANCE.getVersionConvertor_40_50().copyDomainResource(src, tgt, IGNORED_EXTENSION_URLS);
110    
111    for (org.hl7.fhir.r4.model.Identifier t : src.getIdentifier())
112      tgt.addIdentifier(Identifier40_50.convertIdentifier(t));
113
114    if (src.hasExtension(URL_EXTENSION_URL)) {
115      tgt.setUrlElement(Uri40_50.convertUri((org.hl7.fhir.r4.model.UriType) src.getExtensionByUrl(URL_EXTENSION_URL).getValue()));
116    }
117    if (src.hasExtension(VERSION_EXTENSION_URL)) {
118      tgt.setVersionElement(String40_50.convertString((org.hl7.fhir.r4.model.StringType) src.getExtensionByUrl(VERSION_EXTENSION_URL).getValue()));
119    }
120    if (src.hasExtension(NAME_EXTENSION_URL)) {
121      tgt.setNameElement(String40_50.convertString((org.hl7.fhir.r4.model.StringType) src.getExtensionByUrl(NAME_EXTENSION_URL).getValue()));
122    }
123    if (src.hasExtension(TITLE_EXTENSION_URL)) {
124      tgt.setTitleElement(String40_50.convertString((org.hl7.fhir.r4.model.StringType) src.getExtensionByUrl(TITLE_EXTENSION_URL).getValue()));
125    }
126    if (src.hasExtension(STATUS_EXTENSION_URL)) {
127      tgt.setStatus(PublicationStatus.fromCode(src.getExtensionByUrl(STATUS_EXTENSION_URL).getValue().primitiveValue()));
128    }
129    if (src.hasExtension(EXPERIMENTAL_EXTENSION_URL)) {
130      tgt.setExperimentalElement(Boolean40_50.convertBoolean((org.hl7.fhir.r4.model.BooleanType) src.getExtensionByUrl(EXPERIMENTAL_EXTENSION_URL).getValue()));
131    }
132    if (src.hasExtension(DATE_EXTENSION_URL)) {
133      tgt.setDateElement(DateTime40_50.convertDateTime((org.hl7.fhir.r4.model.DateTimeType) src.getExtensionByUrl(DATE_EXTENSION_URL).getValue()));
134    }
135    if (src.hasExtension(PUBLISHER_EXTENSION_URL)) {
136      tgt.setPublisherElement(String40_50.convertString((org.hl7.fhir.r4.model.StringType) src.getExtensionByUrl(PUBLISHER_EXTENSION_URL).getValue()));
137    }
138    for (org.hl7.fhir.r4.model.Extension ext : src.getExtensionsByUrl(CONTACT_EXTENSION_URL)) {
139      tgt.addContact(ContactDetail40_50.convertContactDetail((org.hl7.fhir.r4.model.ContactDetail) ext.getValue()));
140    }
141    if (src.hasExtension(DESCRIPTION_EXTENSION_URL)) {
142      tgt.setPublisherElement(MarkDown40_50.convertMarkdown((org.hl7.fhir.r4.model.MarkdownType) src.getExtensionByUrl(DESCRIPTION_EXTENSION_URL).getValue()));
143    }
144    for (org.hl7.fhir.r4.model.Extension ext : src.getExtensionsByUrl(USE_CONTEXT_EXTENSION_URL)) {
145      tgt.addUseContext(UsageContext40_50.convertUsageContext((org.hl7.fhir.r4.model.UsageContext) ext.getValue()));
146    }
147    for (org.hl7.fhir.r4.model.Extension ext : src.getExtensionsByUrl(JURISDICTION_EXTENSION_URL)) {
148      tgt.addJurisdiction(CodeableConcept40_50.convertCodeableConcept((org.hl7.fhir.r4.model.CodeableConcept) ext.getValue()));
149    }
150    if (src.hasExtension(PURPOSE_EXTENSION_URL)) {
151      tgt.setPurposeElement(MarkDown40_50.convertMarkdown((org.hl7.fhir.r4.model.MarkdownType) src.getExtensionByUrl(PURPOSE_EXTENSION_URL).getValue()));
152    }
153    if (src.hasExtension(COPYRIGHT_EXTENSION_URL)) {
154      tgt.setCopyrightElement(MarkDown40_50.convertMarkdown((org.hl7.fhir.r4.model.MarkdownType) src.getExtensionByUrl(COPYRIGHT_EXTENSION_URL).getValue()));
155    }
156    if (src.hasExtension(COPYRIGHT_LABEL_EXTENSION_URL)) {
157      tgt.setCopyrightLabelElement(String40_50.convertString((org.hl7.fhir.r4.model.StringType) src.getExtensionByUrl(COPYRIGHT_LABEL_EXTENSION_URL).getValue()));
158    }
159    for (org.hl7.fhir.r4.model.Extension ext : src.getExtensionsByUrl(DERIVED_FROM_EXTENSION_URL)) {
160      tgt.getDerivedFrom().add(Canonical40_50.convertCanonical((org.hl7.fhir.r4.model.CanonicalType) ext.getValue()));
161    }
162    for (org.hl7.fhir.r4.model.Extension ext : src.getExtensionsByUrl(ACTOR_EXTENSION_URL)) {
163      tgt.getActor().add(Canonical40_50.convertCanonical((org.hl7.fhir.r4.model.CanonicalType) ext.getValue()));
164    }
165    for (org.hl7.fhir.r4.model.Extension ext : src.getExtensionsByUrl(STATEMENT_EXTENSION_URL)) {
166      convertRequirementsStatement(ext, tgt.addStatement());
167    }
168    return tgt;
169  }
170
171
172  public static org.hl7.fhir.r4.model.Basic convertRequirements(org.hl7.fhir.r5.model.Requirements src) throws FHIRException {
173    if (src == null)
174      return null;
175    org.hl7.fhir.r4.model.Basic tgt = new org.hl7.fhir.r4.model.Basic();
176    ConversionContext40_50.INSTANCE.getVersionConvertor_40_50().copyDomainResource(src, tgt);
177    tgt.getCode().getCodingFirstRep().setSystem("http://hl7.org/fhir/fhir-types").setCode("Requirements"); // note use of R5 type system
178    
179    for (org.hl7.fhir.r5.model.Identifier t : src.getIdentifier())
180      tgt.addIdentifier(Identifier40_50.convertIdentifier(t));
181    if (src.hasUrl()) {
182      tgt.addExtension(URL_EXTENSION_URL, Uri40_50.convertUri(src.getUrlElement()));
183    }
184    if (src.hasVersion()) {
185      tgt.addExtension(VERSION_EXTENSION_URL, String40_50.convertString(src.getVersionElement()));
186    }
187    if (src.hasName()) {
188      tgt.addExtension(NAME_EXTENSION_URL, String40_50.convertString(src.getNameElement()));
189    }
190    if (src.hasTitle()) {
191      tgt.addExtension(TITLE_EXTENSION_URL, String40_50.convertString(src.getTitleElement()));
192    }
193    if (src.hasStatus()) {
194      tgt.addExtension(STATUS_EXTENSION_URL, new org.hl7.fhir.r4.model.CodeType(src.getStatus().toCode()));
195    }
196    if (src.hasExperimental()) {
197      tgt.addExtension(EXPERIMENTAL_EXTENSION_URL, Boolean40_50.convertBoolean(src.getExperimentalElement()));
198    }
199    if (src.hasDate()) {
200      tgt.addExtension(DATE_EXTENSION_URL, DateTime40_50.convertDateTime(src.getDateElement()));
201    }
202    if (src.hasPublisher()) {
203      tgt.addExtension(PUBLISHER_EXTENSION_URL, String40_50.convertString(src.getPublisherElement()));
204    }
205    for (ContactDetail cd : src.getContact()) {
206      tgt.addExtension(CONTACT_EXTENSION_URL, ContactDetail40_50.convertContactDetail(cd));
207    }
208    if (src.hasDescription()) {
209      tgt.addExtension(DESCRIPTION_EXTENSION_URL, MarkDown40_50.convertMarkdown(src.getDescriptionElement()));
210    }
211    for (UsageContext cd : src.getUseContext()) {
212      tgt.addExtension(USE_CONTEXT_EXTENSION_URL, UsageContext40_50.convertUsageContext(cd));
213    }
214    for (CodeableConcept cd : src.getJurisdiction()) {
215      tgt.addExtension(JURISDICTION_EXTENSION_URL, CodeableConcept40_50.convertCodeableConcept(cd));
216    }
217    if (src.hasPurpose()) {
218      tgt.addExtension(PURPOSE_EXTENSION_URL, MarkDown40_50.convertMarkdown(src.getPurposeElement()));
219    }
220    if (src.hasCopyright()) {
221      tgt.addExtension(COPYRIGHT_EXTENSION_URL, MarkDown40_50.convertMarkdown(src.getCopyrightElement()));
222    }
223    if (src.hasCopyrightLabel()) {
224      tgt.addExtension(COPYRIGHT_LABEL_EXTENSION_URL, String40_50.convertString(src.getCopyrightLabelElement()));
225    }
226    for (CanonicalType ref : src.getDerivedFrom()) {
227      tgt.addExtension(DERIVED_FROM_EXTENSION_URL, Canonical40_50.convertCanonical(ref));
228    }
229    for (CanonicalType ref : src.getActor()) {
230      tgt.addExtension(ACTOR_EXTENSION_URL, Canonical40_50.convertCanonical(ref));
231    }
232    for (RequirementsStatementComponent ref : src.getStatement()) {
233      org.hl7.fhir.r4.model.Extension tgte = new org.hl7.fhir.r4.model.Extension(STATEMENT_EXTENSION_URL);
234      tgt.addExtension(tgte);
235      convertRequirementsStatement(ref, tgte);
236    }
237
238    return tgt;
239  }
240
241  private static void convertRequirementsStatement(RequirementsStatementComponent src, Extension tgt) {
242    ConversionContext40_50.INSTANCE.getVersionConvertor_40_50().copyElement(src, tgt);
243    if (src.hasKey()) {
244      tgt.addExtension("http://hl7.org/fhir/5.0/StructureDefinition/extension-Requirements.statement.key", Id40_50.convertId(src.getKeyElement()));
245    }
246    if (src.hasLabel()) {
247      tgt.addExtension("http://hl7.org/fhir/5.0/StructureDefinition/extension-Requirements.statement.label", String40_50.convertString(src.getLabelElement()));
248    }
249    for (Enumeration<ConformanceExpectation> t : src.getConformance()) {
250      tgt.addExtension("http://hl7.org/fhir/5.0/StructureDefinition/extension-Requirements.statement.conformance", new org.hl7.fhir.r4.model.CodeType(t.getCode()));
251    }
252    if (src.hasRequirement()) {
253      tgt.addExtension("http://hl7.org/fhir/5.0/StructureDefinition/extension-Requirements.statement.requirement", MarkDown40_50.convertMarkdown(src.getRequirementElement()));
254    }
255    if (src.hasDerivedFrom()) {
256      tgt.addExtension("http://hl7.org/fhir/5.0/StructureDefinition/extension-Requirements.statement.derivedFrom", String40_50.convertString(src.getDerivedFromElement()));
257    }
258    for (UrlType ref : src.getSatisfiedBy()) {
259      tgt.addExtension("http://hl7.org/fhir/5.0/StructureDefinition/extension-Requirements.statement.satisfiedBy", Url40_50.convertUrl(ref));
260    }
261    for (UrlType ref : src.getReference()) {
262      tgt.addExtension("http://hl7.org/fhir/5.0/StructureDefinition/extension-Requirements.statement.reference", Url40_50.convertUrl(ref));
263    }
264    for (Reference ref : src.getSource()) {
265      tgt.addExtension("http://hl7.org/fhir/5.0/StructureDefinition/extension-Requirements.statement.source", Reference40_50.convertReference(ref));
266    }
267  }
268
269
270  private static void convertRequirementsStatement(Extension src, RequirementsStatementComponent tgt) {
271    ConversionContext40_50.INSTANCE.getVersionConvertor_40_50().copyElement(src, tgt, 
272        "http://hl7.org/fhir/5.0/StructureDefinition/extension-Requirements.statement.key",
273        "http://hl7.org/fhir/5.0/StructureDefinition/extension-Requirements.statement.label",
274        "http://hl7.org/fhir/5.0/StructureDefinition/extension-Requirements.statement.conformance",
275        "http://hl7.org/fhir/5.0/StructureDefinition/extension-Requirements.statement.requirement",
276        "http://hl7.org/fhir/5.0/StructureDefinition/extension-Requirements.statement.derivedFrom",
277        "http://hl7.org/fhir/5.0/StructureDefinition/extension-Requirements.statement.satisfiedBy",
278        "http://hl7.org/fhir/5.0/StructureDefinition/extension-Requirements.statement.reference",
279        "http://hl7.org/fhir/5.0/StructureDefinition/extension-Requirements.statement.source"
280        );
281    if (src.hasExtension("http://hl7.org/fhir/5.0/StructureDefinition/extension-Requirements.statement.key")) {
282      tgt.setKeyElement(Id40_50.convertId((org.hl7.fhir.r4.model.IdType) src.getExtensionByUrl("http://hl7.org/fhir/5.0/StructureDefinition/extension-Requirements.statement.key").getValue()));
283    }
284    if (src.hasExtension("http://hl7.org/fhir/5.0/StructureDefinition/extension-Requirements.statement.label")) {
285      tgt.setLabelElement(String40_50.convertString((org.hl7.fhir.r4.model.StringType) src.getExtensionByUrl("http://hl7.org/fhir/5.0/StructureDefinition/extension-Requirements.statement.label").getValue()));
286    }
287    for (org.hl7.fhir.r4.model.Extension ext : src.getExtensionsByUrl("http://hl7.org/fhir/5.0/StructureDefinition/extension-Requirements.statement.conformance")) {
288      tgt.addConformance(ConformanceExpectation.fromCode(ext.getValue().primitiveValue()));
289    }
290    if (src.hasExtension("http://hl7.org/fhir/5.0/StructureDefinition/extension-Requirements.statement.requirement")) {
291      tgt.setRequirementElement(MarkDown40_50.convertMarkdown((org.hl7.fhir.r4.model.MarkdownType) src.getExtensionByUrl("http://hl7.org/fhir/5.0/StructureDefinition/extension-Requirements.statement.requirement").getValue()));
292    }
293    if (src.hasExtension("http://hl7.org/fhir/5.0/StructureDefinition/extension-Requirements.statement.derivedFrom")) {
294      tgt.setDerivedFromElement(String40_50.convertString((org.hl7.fhir.r4.model.StringType) src.getExtensionByUrl("http://hl7.org/fhir/5.0/StructureDefinition/extension-Requirements.statement.derivedFrom").getValue()));
295    }
296    for (org.hl7.fhir.r4.model.Extension ext : src.getExtensionsByUrl("http://hl7.org/fhir/5.0/StructureDefinition/extension-Requirements.statement.satisfiedBy")) {
297      tgt.getSatisfiedBy().add(Url40_50.convertUrl((org.hl7.fhir.r4.model.UrlType) ext.getValue()));
298    }
299    for (org.hl7.fhir.r4.model.Extension ext : src.getExtensionsByUrl("http://hl7.org/fhir/5.0/StructureDefinition/extension-Requirements.statement.reference")) {
300      tgt.getReference().add(Url40_50.convertUrl((org.hl7.fhir.r4.model.UrlType) ext.getValue()));
301    }
302    for (org.hl7.fhir.r4.model.Extension ext : src.getExtensionsByUrl("http://hl7.org/fhir/5.0/StructureDefinition/extension-Requirements.statement.source")) {
303      tgt.getSource().add(Reference40_50.convertReference((org.hl7.fhir.r4.model.Reference) ext.getValue()));
304    }
305  }
306}