001package org.hl7.fhir.r5.profilemodel.gen;
002
003import java.util.ArrayList;
004import java.util.List;
005
006import org.hl7.fhir.r5.context.IWorkerContext;
007import org.hl7.fhir.r5.model.CodeType;
008import org.hl7.fhir.r5.model.CodeableConcept;
009import org.hl7.fhir.r5.model.Coding;
010import org.hl7.fhir.r5.model.Enumerations.ObservationStatus;
011import org.hl7.fhir.r5.model.Observation;
012import org.hl7.fhir.r5.model.StringType;
013import org.hl7.fhir.r5.profilemodel.PEBuilder;
014import org.hl7.fhir.r5.profilemodel.PEBuilder.PEElementPropertiesPolicy;
015import org.hl7.fhir.r5.profilemodel.PEInstance;
016
017/**
018 * This class is a manually written example of the code that a POJO code
019 * generator for Profiles would produce 
020 * 
021 * Should you generate code? If you can bind at compile time, then you should. 
022 * If you can't - and most systems can't, given the nature of profiles, then 
023 * you should use PEInstance directly
024 * 
025 * @author grahamegrieve
026 *
027 */
028public class ProfileExample extends PEGeneratedBase {
029
030  public enum LOINCCodesForCholesterolInSerumPlasma {
031    L14647_2, L2093_3, L35200_5, L9342_7;
032    
033    public String getCode() {
034      switch (this) {
035      case L14647_2: return "14647-2";
036      case L2093_3: return "2093-3";
037      case L35200_5: return "35200-5";
038      case L9342_7: return "9342-7";
039      }
040      return null;
041    }
042    
043    public String getDisplay() {
044      switch (this) {
045      case L14647_2: return "Cholesterol [Moles/Volume]";
046      case L2093_3: return "Cholesterol [Mass/Volume]";
047      case L35200_5: return "Cholesterol [Mass Or Moles/Volume]";
048      case L9342_7: return "Cholesterol [Percentile]";
049      }
050      return null;
051    }
052    
053    public static LOINCCodesForCholesterolInSerumPlasma fromCode(String code) {
054      if (code != null) {
055        switch (code) {
056        case "14647-2": return L14647_2;
057        case "2093-3": return L2093_3;
058        case "35200-5": return L35200_5;
059        case "9342-7": return L9342_7;
060        }
061      }
062      return null;
063    }
064  }
065
066  
067  public static class ProfileExampleComplexSlice3 extends PEGeneratedBase {
068    private ProfileExampleComplexSlice3(PEInstance instance) {
069      super();
070      this.instance = instance;
071    }
072
073    public List<Coding> getSlice3a() {
074      List<Coding> res = new ArrayList<>();
075      for (PEInstance pe : instance.children("slice3a")) {
076        res.add((Coding) pe.asDataType());
077      }
078      return res;
079    }
080    
081    public boolean hasSlice3a() {
082      return instance.children("slice3a").size() > 0;    
083    }
084    
085    public ProfileExampleComplexSlice3 clearSlice3a() {
086      removeChildren("slice3a");
087      return this;
088    }
089    
090
091    public List<StringType> getSlice3b() {
092      List<StringType> res = new ArrayList<>();
093      for (PEInstance pe : instance.children("slice3b")) {
094        res.add((StringType) pe.asDataType());
095      }
096      return res;
097    }
098    
099    public boolean hasSlice3b() {
100      return instance.children("slice3b").size() > 0;    
101    }
102    
103    public ProfileExampleComplexSlice3 clearSlice3b() {
104      removeChildren("slice3b");
105      return this;
106    }
107  }
108  
109  public static class ProfileExampleComplex extends PEGeneratedBase {
110    private ProfileExampleComplex(PEInstance instance) {
111      super();
112      this.instance = instance;
113    }
114    
115    public List<Coding> getSlice1() {
116      List<Coding> res = new ArrayList<>();
117      for (PEInstance pe : instance.children("slice1")) {
118        res.add((Coding) pe.asDataType());
119      }
120      return res;
121    }
122    
123    public boolean hasSlice1() {
124      return instance.children("slice1").size() > 0;    
125    }
126    
127    public ProfileExampleComplex clearSlice1() {
128      removeChildren("slice1");
129      return this;
130    }
131    
132    public List<StringType> getSlice2() {
133      List<StringType> res = new ArrayList<>();
134      for (PEInstance pe : instance.children("slice2")) {
135        res.add((StringType) pe.asDataType());
136      }
137      return res;
138    }
139    
140    public boolean hasSlice2() {
141      return instance.children("slice2").size() > 0;    
142    }
143    
144    public ProfileExampleComplex clearSlice2() {
145      removeChildren("slice1");
146      return this;
147    }
148    
149    public ProfileExampleComplexSlice3 getSlice3() {
150      PEInstance pe = instance.forceChild("slice3");
151      return new ProfileExampleComplexSlice3(pe);
152    }
153    
154    public boolean hasComplex() {
155      return instance.child("slice3") != null;
156    }
157    
158    public ProfileExampleComplex clearComplex() {
159      removeChild("slice3");
160      return this;
161    }
162    
163  }
164  
165  public ProfileExample(IWorkerContext context, Observation observation) {
166    super();
167    PEBuilder builder = new PEBuilder(context, PEElementPropertiesPolicy.EXTENSION_ID, true);
168    instance = builder.buildPEInstance("http://hl7.org/fhir/test/StructureDefinition/pe-profile1", "0.1", observation);
169  }
170  
171  /** 
172   * this is public for testing purposes, but you generally shouldn't use it. If you do, make 
173   * sure the parameters are (PEElementPropertiesPolicy.EXTENSION_ID, true) when building the PEBuilder
174   * 
175   * @param instance
176   */
177  public ProfileExample(PEInstance instance) {
178    super();
179    this.instance = instance;
180  }
181  
182  /** 
183   * @return fixed value "final"
184   */
185  public ObservationStatus getStatus() {
186    return ObservationStatus.FINAL;
187  }
188
189  public CodeableConcept getCode() {
190    return instance.forceChild("code").asCodeableConcept();
191  }
192  
193  /**
194   * Extension http://hl7.org/fhir/test/StructureDefinition/pe-extension-simple, type code
195   * @return
196   */
197  public LOINCCodesForCholesterolInSerumPlasma getSimple() {
198    return LOINCCodesForCholesterolInSerumPlasma.fromCode(((CodeType) instance.forceChild("simple").asDataType()).primitiveValue());
199  }
200  
201  public boolean hasSimple() {
202    return instance.child("simple") != null;    
203  }
204  
205  public ProfileExample clearSimple() {
206    removeChild("simple");
207    return this;
208  }
209
210  public ProfileExampleComplex getComplex() {
211    PEInstance pe = instance.child("complex");
212    return new ProfileExampleComplex(pe);
213  }
214  
215  public boolean hasComplex() {
216    return instance.child("complex") != null;
217  }
218  
219  public ProfileExample clearComplex() {
220    removeChild("complex");
221    return this;
222  }
223  
224  /*
225   * this doesn't exist, because of the way infrastructure works.
226   * You get the value and set the properties
227   */
228//  public void setSimple() {
229//    return (CodeType) instance.forceChild("simple").asDataType();
230//  }
231  
232}