001package org.hl7.fhir.r5.conformance;
002
003import org.hl7.fhir.r5.model.CanonicalType;
004import org.hl7.fhir.r5.model.ElementDefinition;
005import org.hl7.fhir.r5.model.ElementDefinition.TypeRefComponent;
006import org.hl7.fhir.r5.model.Resource;
007import org.hl7.fhir.r5.model.StructureDefinition;
008import org.hl7.fhir.utilities.VersionUtilities;
009
010/**
011 * This doesn't do anythign at this time
012 * 
013 * @author graha
014 *
015 */
016public class StructureDefinitionHacker {
017
018  private String version;
019
020  public StructureDefinitionHacker(String version) {
021    super();
022    this.version = version;
023  }
024
025  public Resource fixSD(StructureDefinition sd) {
026    if (VersionUtilities.isR4Ver(version) && "http://hl7.org/fhir/StructureDefinition/example-composition".equals(sd.getUrl())) {
027      for (ElementDefinition ed : sd.getSnapshot().getElement()) {
028        fixDocSecURL(ed);
029      } 
030      for (ElementDefinition ed : sd.getDifferential().getElement()) {
031        fixDocSecURL(ed);
032        if ("ClinicalImpression.problem".equals(ed.getPath())) {
033          // work around a bidi problem
034          ed.setComment("e.g. The patient is a pregnant, has congestive heart failure, has an Adenocarcinoma, and is allergic to penicillin.");
035        }
036      }
037    }
038    if (VersionUtilities.isR4Ver(version) && "http://hl7.org/fhir/StructureDefinition/ClinicalImpression".equals(sd.getUrl())) {
039      for (ElementDefinition ed : sd.getSnapshot().getElement()) {
040        if ("ClinicalImpression.problem".equals(ed.getPath())) {
041          // work around a bidi problem
042          ed.setComment("e.g. The patient is a pregnant, has congestive heart failure, has an Adenocarcinoma, and is allergic to penicillin.");
043        }
044      } 
045      for (ElementDefinition ed : sd.getDifferential().getElement()) {
046        if ("ClinicalImpression.problem".equals(ed.getPath())) {
047          // work around a bidi problem
048          ed.setComment("e.g. The patient is a pregnant, has congestive heart failure, has an Adenocarcinoma, and is allergic to penicillin.");
049        }
050      }
051    }
052    return sd;
053  }
054
055  private void fixDocSecURL(ElementDefinition ed) {
056    for (TypeRefComponent tr : ed.getType()) {
057      for (CanonicalType c : tr.getProfile()) {
058        if ("http://hl7.org/fhir/StructureDefinition/document-section-library".equals(c.getValue())) {
059          c.setValue("http://hl7.org/fhir/StructureDefinition/example-section-library");
060        }
061      }
062    }
063  }
064
065
066}