001package org.hl7.fhir.r4.model; 002 003import java.util.ArrayList; 004import java.util.List; 005 006/** 007 * A child element or property defined by the FHIR specification 008 * This class is defined as a helper class when iterating the 009 * children of an element in a generic fashion 010 * 011 * At present, iteration is only based on the specification, but 012 * this may be changed to allow profile based expression at a 013 * later date 014 * 015 * note: there's no point in creating one of these classes outside this package 016 */ 017public class Property { 018 019 /** 020 * The name of the property as found in the FHIR specification 021 */ 022 private String name; 023 024 /** 025 * The type of the property as specified in the FHIR specification (e.g. type|type|Reference(Name|Name) 026 */ 027 private String typeCode; 028 029 /** 030 * The formal definition of the element given in the FHIR specification 031 */ 032 private String definition; 033 034 /** 035 * The minimum allowed cardinality - 0 or 1 when based on the specification 036 */ 037 private int minCardinality; 038 039 /** 040 * The maximum allowed cardinality - 1 or MAX_INT when based on the specification 041 */ 042 private int maxCardinality; 043 044 /** 045 * The actual elements that exist on this instance 046 */ 047 private List<Base> values = new ArrayList<Base>(); 048 049 /** 050 * For run time, if/once a property is hooked up to it's definition 051 */ 052 private StructureDefinition structure; 053 054 /** 055 * Internal constructor 056 */ 057 public Property(String name, String typeCode, String definition, int minCardinality, int maxCardinality, Base value) { 058 super(); 059 this.name = name; 060 this.typeCode = typeCode; 061 this.definition = definition; 062 this.minCardinality = minCardinality; 063 this.maxCardinality = maxCardinality; 064 if (value != null) 065 this.values.add(value); 066 } 067 068 /** 069 * Internal constructor 070 */ 071 public Property(String name, String typeCode, String definition, int minCardinality, int maxCardinality, List<? extends Base> values) { 072 super(); 073 this.name = name; 074 this.typeCode = typeCode; 075 this.definition = definition; 076 this.minCardinality = minCardinality; 077 this.maxCardinality = maxCardinality; 078 if (values != null) 079 this.values.addAll(values); 080 } 081 082 /** 083 * @return The name of this property in the FHIR Specification 084 */ 085 public String getName() { 086 return name; 087 } 088 089 /** 090 * @return The stated type in the FHIR specification 091 */ 092 public String getTypeCode() { 093 return typeCode; 094 } 095 096 /** 097 * @return The definition of this element in the FHIR spec 098 */ 099 public String getDefinition() { 100 return definition; 101 } 102 103 /** 104 * @return the minimum cardinality for this element 105 */ 106 public int getMinCardinality() { 107 return minCardinality; 108 } 109 110 /** 111 * @return the maximum cardinality for this element 112 */ 113 public int getMaxCardinality() { 114 return maxCardinality; 115 } 116 117 /** 118 * @return the actual values - will only be 1 unless maximum cardinality == MAX_INT 119 */ 120 public List<Base> getValues() { 121 return values; 122 } 123 124 public boolean hasValues() { 125 for (Base e : getValues()) 126 if (e != null) 127 return true; 128 return false; 129 } 130 131 public StructureDefinition getStructure() { 132 return structure; 133 } 134 135 public void setStructure(StructureDefinition structure) { 136 this.structure = structure; 137 } 138 139 public boolean isList() { 140 return maxCardinality > 1; 141 } 142 143 144 public String toString() { 145 return name; 146 } 147 148}