diff --git a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/model/dstu2/ModelDstu2Test.java b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/model/dstu2/ModelDstu2Test.java index a59ef63e308..f51c1611695 100644 --- a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/model/dstu2/ModelDstu2Test.java +++ b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/model/dstu2/ModelDstu2Test.java @@ -8,12 +8,28 @@ import java.util.List; import org.junit.Test; import ca.uhn.fhir.context.FhirContext; +import ca.uhn.fhir.model.dstu2.composite.BoundCodeableConceptDt; +import ca.uhn.fhir.model.dstu2.composite.CodeableConceptDt; import ca.uhn.fhir.model.dstu2.resource.Patient; +import ca.uhn.fhir.model.dstu2.resource.Practitioner; +import ca.uhn.fhir.model.dstu2.resource.Practitioner.PractitionerRole; +import ca.uhn.fhir.model.dstu2.valueset.PractitionerRoleEnum; public class ModelDstu2Test { private static FhirContext ourCtx = FhirContext.forDstu2(); + /** + * See #320 + */ + @Test + public void testDontUseBoundCodeForExampleBinding() { + Practitioner p = new Practitioner(); + PractitionerRole role = p.addPractitionerRole(); + CodeableConceptDt roleField = role.getRole(); + assertEquals(CodeableConceptDt.class, roleField.getClass()); + } + /** * See #304 */ diff --git a/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/model/ModelDstu3Test.java b/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/model/ModelDstu3Test.java index 7c2e9444527..cfad91dc433 100644 --- a/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/model/ModelDstu3Test.java +++ b/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/model/ModelDstu3Test.java @@ -5,7 +5,11 @@ import static org.junit.Assert.assertEquals; import java.util.Arrays; import java.util.List; +import org.hl7.fhir.dstu3.model.CodeableConcept; import org.hl7.fhir.dstu3.model.Patient; +import org.hl7.fhir.dstu3.model.Practitioner; +import org.hl7.fhir.dstu3.model.Practitioner.PractitionerPractitionerRoleComponent; +import org.hl7.fhir.dstu3.model.valuesets.PractitionerRole; import org.junit.Test; import ca.uhn.fhir.context.FhirContext; @@ -13,7 +17,18 @@ import ca.uhn.fhir.context.FhirContext; public class ModelDstu3Test { private static FhirContext ourCtx = FhirContext.forDstu3(); - + + /** + * See #320 + */ + @Test + public void testDontUseBoundCodeForExampleBinding() { + Practitioner p = new Practitioner(); + PractitionerPractitionerRoleComponent role = p.addPractitionerRole(); + CodeableConcept roleField = role.getRole(); + assertEquals(CodeableConcept.class, roleField.getClass()); + } + /** * See #304 */ @@ -22,10 +37,10 @@ public class ModelDstu3Test { public void testPopulateWrongGenericType() { Patient p = new Patient(); List names = Arrays.asList("name"); - + List existingNames = p.getName(); existingNames.addAll(names); - + try { ourCtx.newXmlParser().encodeResourceToString(p); } catch (ClassCastException e) { @@ -33,5 +48,4 @@ public class ModelDstu3Test { } } - } diff --git a/hapi-tinder-plugin/src/main/java/ca/uhn/fhir/tinder/TinderStructuresMojo.java b/hapi-tinder-plugin/src/main/java/ca/uhn/fhir/tinder/TinderStructuresMojo.java index 890d35745ce..b2a96b1ab11 100644 --- a/hapi-tinder-plugin/src/main/java/ca/uhn/fhir/tinder/TinderStructuresMojo.java +++ b/hapi-tinder-plugin/src/main/java/ca/uhn/fhir/tinder/TinderStructuresMojo.java @@ -228,7 +228,7 @@ public class TinderStructuresMojo extends AbstractMojo { String dtOutputDir = "target/generated-sources/tinder/ca/uhn/fhir/model/dev/composite"; ResourceGeneratorUsingSpreadsheet rp = new ResourceGeneratorUsingSpreadsheet("dstu2", "."); - rp.setBaseResourceNames(Arrays.asList( "patient", "auditevent" , "observation" + rp.setBaseResourceNames(Arrays.asList( "practitioner"//, "auditevent" , "observation" // //, "contract" // "valueset", "organization", "location" // , "observation", "conformance" diff --git a/hapi-tinder-plugin/src/main/java/ca/uhn/fhir/tinder/parser/BaseStructureSpreadsheetParser.java b/hapi-tinder-plugin/src/main/java/ca/uhn/fhir/tinder/parser/BaseStructureSpreadsheetParser.java index 14ef3483899..8d9444a61ea 100644 --- a/hapi-tinder-plugin/src/main/java/ca/uhn/fhir/tinder/parser/BaseStructureSpreadsheetParser.java +++ b/hapi-tinder-plugin/src/main/java/ca/uhn/fhir/tinder/parser/BaseStructureSpreadsheetParser.java @@ -1,6 +1,7 @@ package ca.uhn.fhir.tinder.parser; import static org.apache.commons.lang3.StringUtils.isBlank; +import static org.apache.commons.lang3.StringUtils.isNotBlank; import java.io.InputStream; import java.util.ArrayList; @@ -48,6 +49,7 @@ public abstract class BaseStructureSpreadsheetParser extends BaseStructureParser private int myColShortName=-1; private int myColType=-1; private int myColV2Mapping=-1; + private HashMap myBindingStrengths; public void parse() throws Exception { int index = 0; @@ -75,6 +77,15 @@ public abstract class BaseStructureSpreadsheetParser extends BaseStructureParser throw new Exception("Failed to find worksheet with name 'Data Elements' in spreadsheet: " + spreadsheetName); } + myBindingStrengths = new HashMap(); + for (int i = 0; i < file.getElementsByTagName("Worksheet").getLength(); i++) { + Element bindingsSheet = (Element) file.getElementsByTagName("Worksheet").item(i); + if ("Bindings".equals(bindingsSheet.getAttributeNS("urn:schemas-microsoft-com:office:spreadsheet", "Name"))) { + processBindingsSheet(bindingsSheet, myBindingStrengths); + } + } + + NodeList tableList = dataElementsSheet.getElementsByTagName("Table"); Element table = (Element) tableList.item(0); @@ -183,6 +194,38 @@ public abstract class BaseStructureSpreadsheetParser extends BaseStructureParser } + private void processBindingsSheet(Element theBindingsSheet, Map theBindingStrengths) { + NodeList tableList = theBindingsSheet.getElementsByTagName("Table"); + Element table = (Element) tableList.item(0); + NodeList rows = table.getElementsByTagName("Row"); + Element defRow = (Element) rows.item(0); + + int colName = 0; + int colStrength = 0; + for (int j = 0; j < 20; j++) { + String nextName = cellValue(defRow, j); + if (nextName == null) { + continue; + } + nextName = nextName.toLowerCase().trim().replace(".", ""); + if ("name".equals(nextName)) { + colName = j; + } else if ("conformance".equals(nextName)) { + colStrength = j; + } + } + + for (int j = 1; j < rows.getLength(); j++) { + Element nextRow = (Element) rows.item(j); + + String name = cellValue(nextRow, colName); + String strength = cellValue(nextRow, colStrength); + if (isNotBlank(name) && isNotBlank(strength)) { + theBindingStrengths.put(name, strength); + } + } + } + protected abstract BaseRootType createRootType(); private void parseParameters(Document theFile, BaseRootType theResource) throws MojoExecutionException { @@ -400,6 +443,10 @@ public abstract class BaseStructureSpreadsheetParser extends BaseStructureParser theTarget.setSummary(cellValue(theRowXml,myColSummary)); theTarget.setModifier(cellValue(theRowXml,myColModifier)); + // Per #320 + if ("example".equals(myBindingStrengths.get(theTarget.getBinding()))) { + theTarget.setBinding(null); + } } /** diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 5b57905ce44..4b2adbcd8c6 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -332,6 +332,12 @@ resource contained a null extension. Thanks to steve1medix for reporting! + + In generated model classes (DSTU1/2) don't + use BoundCodeDt and BoundCodeableConceptDt for + coded fields which use example bindings. Thanks + to GitHub user Ricq for reporting! +