NPE proofing property handling for Code Systems

This commit is contained in:
Grahame Grieve 2023-09-04 13:38:37 +10:00
parent 5cc4e3ef03
commit 808acb9d29
1 changed files with 15 additions and 14 deletions

View File

@ -105,7 +105,7 @@ public class CodeSystemUtilities {
@Override
public int compare(ConceptDefinitionComponent o1, ConceptDefinitionComponent o2) {
return o1.getCode().compareToIgnoreCase(o2.getCode());
return o1.hasCode() ? o1.getCode().compareToIgnoreCase(o2.getCode()) : 0;
}
}
@ -252,7 +252,7 @@ public class CodeSystemUtilities {
private static String defineProperty(CodeSystem cs, String code, PropertyType pt) {
String url = "http://hl7.org/fhir/concept-properties#"+code;
for (PropertyComponent p : cs.getProperty()) {
if (p.getCode().equals(code)) {
if (p.hasCode() && p.getCode().equals(code)) {
if (!p.getUri().equals(url)) {
throw new Error("URI mismatch for code "+code+" url = "+p.getUri()+" vs "+url);
}
@ -391,7 +391,7 @@ public class CodeSystemUtilities {
public static void defineCodeSystemProperty(CodeSystem cs, String code, String description, PropertyType type) {
for (PropertyComponent p : cs.getProperty()) {
if (p.getCode().equals(code))
if (p.hasCode() && p.getCode().equals(code))
return;
}
cs.addProperty().setCode(code).setDescription(description).setType(type).setUri("http://hl7.org/fhir/concept-properties#"+code);
@ -466,7 +466,7 @@ public class CodeSystemUtilities {
public static ConceptDefinitionComponent findCode(List<ConceptDefinitionComponent> list, String code) {
for (ConceptDefinitionComponent c : list) {
if (c.getCode().equals(code))
if (c.hasCode() && c.getCode().equals(code))
return c;
ConceptDefinitionComponent s = findCode(c.getConcept(), code);
if (s != null)
@ -477,7 +477,7 @@ public class CodeSystemUtilities {
public static ConceptDefinitionComponent findCodeOrAltCode(List<ConceptDefinitionComponent> list, String code, String use) {
for (ConceptDefinitionComponent c : list) {
if (c.getCode().equals(code))
if (c.hasCode() && c.getCode().equals(code))
return c;
for (ConceptPropertyComponent p : c.getProperty()) {
if ("alternateCode".equals(p.getCode()) && (use == null || hasUse(p, use)) && p.hasValue() && p.getValue().isPrimitive() && code.equals(p.getValue().primitiveValue())) {
@ -537,29 +537,30 @@ public class CodeSystemUtilities {
public static DataType readProperty(ConceptDefinitionComponent concept, String code) {
for (ConceptPropertyComponent p : concept.getProperty())
if (p.getCode().equals(code))
if (p.hasCode() && p.getCode().equals(code))
return p.getValue();
return null;
}
public static ConceptPropertyComponent getProperty(ConceptDefinitionComponent concept, String code) {
for (ConceptPropertyComponent p : concept.getProperty())
if (p.getCode().equals(code))
if (p.hasCode() && p.getCode().equals(code))
return p;
return null;
}
public static List<ConceptPropertyComponent> getPropertyValues(ConceptDefinitionComponent concept, String code) {
List<ConceptPropertyComponent> res = new ArrayList<>();
if (code != null) {
for (ConceptPropertyComponent p : concept.getProperty()) {
if (p.getCode().equals(code)) {
if (code.equals(p.getCode())) {
res.add(p);
}
}
}
return res;
}
// see http://hl7.org/fhir/R4/codesystem.html#hierachy
// returns additional parents not in the heirarchy
public static List<String> getOtherChildren(CodeSystem cs, ConceptDefinitionComponent c) {
@ -828,7 +829,7 @@ public class CodeSystemUtilities {
private static String defineProperty(CodeSystem cs, PropertyComponent pd, PropertyType pt) {
for (PropertyComponent p : cs.getProperty()) {
if (p.getCode().equals(pd.getCode())) {
if (p.hasCode() && p.getCode().equals(pd.getCode())) {
if (!p.getUri().equals(pd.getUri())) {
throw new Error("URI mismatch for code "+pd.getCode()+" url = "+p.getUri()+" vs "+pd.getUri());
}
@ -846,7 +847,7 @@ public class CodeSystemUtilities {
private static PropertyComponent getPropertyDefinition(CodeSystem cs, ConceptPropertyComponent p) {
for (PropertyComponent t : cs.getProperty()) {
if (t.getCode().equals(p.getCode())) {
if (t.hasCode() && t.getCode().equals(p.getCode())) {
return t;
}
}
@ -881,7 +882,7 @@ public class CodeSystemUtilities {
public static boolean hasPropertyDef(CodeSystem cs, String property) {
for (PropertyComponent pd : cs.getProperty()) {
if (pd.getCode().equals(property)) {
if (pd.hasCode() && pd.getCode().equals(property)) {
return true;
}
}