Fix #320 - Don't generate binding enums for example binding fields on

resources
This commit is contained in:
James Agnew 2016-03-25 20:15:01 +01:00
parent cf22277d6e
commit 20081a419d
5 changed files with 88 additions and 5 deletions

View File

@ -8,12 +8,28 @@ import java.util.List;
import org.junit.Test; import org.junit.Test;
import ca.uhn.fhir.context.FhirContext; 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.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 { public class ModelDstu2Test {
private static FhirContext ourCtx = FhirContext.forDstu2(); 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 * See #304
*/ */

View File

@ -5,7 +5,11 @@ import static org.junit.Assert.assertEquals;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import org.hl7.fhir.dstu3.model.CodeableConcept;
import org.hl7.fhir.dstu3.model.Patient; 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 org.junit.Test;
import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.context.FhirContext;
@ -13,7 +17,18 @@ import ca.uhn.fhir.context.FhirContext;
public class ModelDstu3Test { public class ModelDstu3Test {
private static FhirContext ourCtx = FhirContext.forDstu3(); 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 * See #304
*/ */
@ -22,10 +37,10 @@ public class ModelDstu3Test {
public void testPopulateWrongGenericType() { public void testPopulateWrongGenericType() {
Patient p = new Patient(); Patient p = new Patient();
List names = Arrays.asList("name"); List names = Arrays.asList("name");
List existingNames = p.getName(); List existingNames = p.getName();
existingNames.addAll(names); existingNames.addAll(names);
try { try {
ourCtx.newXmlParser().encodeResourceToString(p); ourCtx.newXmlParser().encodeResourceToString(p);
} catch (ClassCastException e) { } catch (ClassCastException e) {
@ -33,5 +48,4 @@ public class ModelDstu3Test {
} }
} }
} }

View File

@ -228,7 +228,7 @@ public class TinderStructuresMojo extends AbstractMojo {
String dtOutputDir = "target/generated-sources/tinder/ca/uhn/fhir/model/dev/composite"; String dtOutputDir = "target/generated-sources/tinder/ca/uhn/fhir/model/dev/composite";
ResourceGeneratorUsingSpreadsheet rp = new ResourceGeneratorUsingSpreadsheet("dstu2", "."); ResourceGeneratorUsingSpreadsheet rp = new ResourceGeneratorUsingSpreadsheet("dstu2", ".");
rp.setBaseResourceNames(Arrays.asList( "patient", "auditevent" , "observation" rp.setBaseResourceNames(Arrays.asList( "practitioner"//, "auditevent" , "observation"
// //, "contract" // //, "contract"
// "valueset", "organization", "location" // "valueset", "organization", "location"
// , "observation", "conformance" // , "observation", "conformance"

View File

@ -1,6 +1,7 @@
package ca.uhn.fhir.tinder.parser; package ca.uhn.fhir.tinder.parser;
import static org.apache.commons.lang3.StringUtils.isBlank; import static org.apache.commons.lang3.StringUtils.isBlank;
import static org.apache.commons.lang3.StringUtils.isNotBlank;
import java.io.InputStream; import java.io.InputStream;
import java.util.ArrayList; import java.util.ArrayList;
@ -48,6 +49,7 @@ public abstract class BaseStructureSpreadsheetParser extends BaseStructureParser
private int myColShortName=-1; private int myColShortName=-1;
private int myColType=-1; private int myColType=-1;
private int myColV2Mapping=-1; private int myColV2Mapping=-1;
private HashMap<String, String> myBindingStrengths;
public void parse() throws Exception { public void parse() throws Exception {
int index = 0; 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); throw new Exception("Failed to find worksheet with name 'Data Elements' in spreadsheet: " + spreadsheetName);
} }
myBindingStrengths = new HashMap<String, String>();
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"); NodeList tableList = dataElementsSheet.getElementsByTagName("Table");
Element table = (Element) tableList.item(0); Element table = (Element) tableList.item(0);
@ -183,6 +194,38 @@ public abstract class BaseStructureSpreadsheetParser extends BaseStructureParser
} }
private void processBindingsSheet(Element theBindingsSheet, Map<String, String> 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(); protected abstract BaseRootType createRootType();
private void parseParameters(Document theFile, BaseRootType theResource) throws MojoExecutionException { 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.setSummary(cellValue(theRowXml,myColSummary));
theTarget.setModifier(cellValue(theRowXml,myColModifier)); theTarget.setModifier(cellValue(theRowXml,myColModifier));
// Per #320
if ("example".equals(myBindingStrengths.get(theTarget.getBinding()))) {
theTarget.setBinding(null);
}
} }
/** /**

View File

@ -332,6 +332,12 @@
resource contained a null extension. Thanks to resource contained a null extension. Thanks to
steve1medix for reporting! steve1medix for reporting!
</action> </action>
<action type="fix" issue="320">
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!
</action>
</release> </release>
<release version="1.4" date="2016-02-04"> <release version="1.4" date="2016-02-04">
<action type="add"> <action type="add">