001package org.hl7.fhir.convertors.conv40_50.datatypes40_50;
002
003import java.util.Arrays;
004
005import org.hl7.fhir.convertors.advisors.impl.BaseAdvisor_40_50;
006import org.hl7.fhir.convertors.conv40_50.datatypes40_50.special40_50.Extension40_50;
007import org.hl7.fhir.exceptions.FHIRException;
008
009public class Element40_50 {
010
011  public final BaseAdvisor_40_50 advisor;
012
013  public Element40_50(BaseAdvisor_40_50 advisor) {
014    this.advisor = advisor;
015  }
016
017  public static boolean isExemptExtension(String url, String[] extensionsToIgnore) {
018    return Arrays.asList(extensionsToIgnore).contains(url);
019  }
020
021  public void copyElement(org.hl7.fhir.r4.model.Element src,
022                          org.hl7.fhir.r5.model.Element tgt,
023                          String path,
024                          String... extensionsToIgnore) throws FHIRException {
025    if (src.hasId()) tgt.setId(src.getId());
026    src.getExtension().stream()
027      .filter(e -> !isExemptExtension(e.getUrl(), extensionsToIgnore))
028      .forEach(e -> {
029        if (advisor.useAdvisorForExtension(path, e)) {
030          org.hl7.fhir.r5.model.Extension convertedExtension = new org.hl7.fhir.r5.model.Extension();
031          advisor.handleExtension(path, e, convertedExtension);
032          tgt.addExtension(convertedExtension);
033        } else {
034          tgt.addExtension(Extension40_50.convertExtension(e));
035        }
036      });
037  }
038
039  public void copyElement(org.hl7.fhir.r5.model.Element src,
040                          org.hl7.fhir.r4.model.Element tgt,
041                          String path,
042                          String... extensionsToIgnore) throws FHIRException {
043    if (src.hasId()) tgt.setId(src.getId());
044    src.getExtension().stream()
045      .filter(e -> !isExemptExtension(e.getUrl(), extensionsToIgnore))
046      .forEach(e -> {
047        if (advisor.useAdvisorForExtension(path, e)) {
048          org.hl7.fhir.r4.model.Extension convertedExtension = new org.hl7.fhir.r4.model.Extension();
049          advisor.handleExtension(path, e, convertedExtension);
050          tgt.addExtension(convertedExtension);
051        } else {
052          tgt.addExtension(Extension40_50.convertExtension(e));
053        }
054      });
055  }
056}