001package org.hl7.fhir.convertors.conv10_50.datatypes10_50;
002
003import java.util.Arrays;
004
005import org.hl7.fhir.convertors.advisors.impl.BaseAdvisor_10_50;
006import org.hl7.fhir.exceptions.FHIRException;
007
008public class Element10_50 {
009
010  public final BaseAdvisor_10_50 advisor;
011
012  public Element10_50(BaseAdvisor_10_50 advisor) {
013    this.advisor = advisor;
014  }
015
016  public boolean isExemptExtension(String url, String[] extensionsToIgnore) {
017    return Arrays.asList(extensionsToIgnore).contains(url);
018  }
019
020  public void copyElement(org.hl7.fhir.dstu2.model.Element src,
021                          org.hl7.fhir.r5.model.Element tgt,
022                          String path,
023                          String... extensionUrlsToIgnore) throws FHIRException {
024    if (src.hasId()) tgt.setId(src.getId());
025    src.getExtension().stream()
026      .filter(e -> !isExemptExtension(e.getUrl(), extensionUrlsToIgnore))
027      .forEach(e -> {
028        if (advisor.useAdvisorForExtension(path, e)) {
029          org.hl7.fhir.r5.model.Extension convertedExtension = new org.hl7.fhir.r5.model.Extension();
030          advisor.handleExtension(path, e, convertedExtension);
031          tgt.addExtension(convertedExtension);
032        } else {
033          tgt.addExtension(Extension10_50.convertExtension(e));
034        }
035      });
036  }
037
038  public void copyElement(org.hl7.fhir.r5.model.Element src,
039                          org.hl7.fhir.dstu2.model.Element tgt,
040                          String path,
041                          String... extensionUrlsToIgnore) throws FHIRException {
042    if (src.hasId()) tgt.setId(src.getId());
043    src.getExtension().stream()
044      .filter(e -> !isExemptExtension(e.getUrl(), extensionUrlsToIgnore))
045      .forEach(e -> {
046        if (advisor.useAdvisorForExtension(path, e)) {
047          org.hl7.fhir.dstu2.model.Extension convertedExtension = new org.hl7.fhir.dstu2.model.Extension();
048          advisor.handleExtension(path, e, convertedExtension);
049          tgt.addExtension(convertedExtension);
050        } else {
051          tgt.addExtension(Extension10_50.convertExtension(e));
052        }
053      });
054  }
055
056  public void copyElement(org.hl7.fhir.r5.model.DomainResource src,
057                          org.hl7.fhir.dstu2.model.Element tgt,
058                          String path,
059                          String... extensionUrlsToIgnore) throws FHIRException {
060    if (src.hasId()) tgt.setId(src.getId());
061    src.getExtension().stream()
062      .filter(e -> !isExemptExtension(e.getUrl(), extensionUrlsToIgnore))
063      .forEach(e -> {
064        if (advisor.useAdvisorForExtension(path, e)) {
065          org.hl7.fhir.dstu2.model.Extension convertedExtension = new org.hl7.fhir.dstu2.model.Extension();
066          advisor.handleExtension(path, e, convertedExtension);
067          tgt.addExtension(convertedExtension);
068        } else {
069          tgt.addExtension(Extension10_50.convertExtension(e));
070        }
071      });
072  }
073}