Fix #320 - Don't generate binding enums for example binding fields on
resources
This commit is contained in:
parent
cf22277d6e
commit
20081a419d
|
@ -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
|
||||
*/
|
||||
|
|
|
@ -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;
|
||||
|
@ -14,6 +18,17 @@ 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
|
||||
*/
|
||||
|
@ -33,5 +48,4 @@ public class ModelDstu3Test {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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<String, String> 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<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");
|
||||
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();
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -332,6 +332,12 @@
|
|||
resource contained a null extension. Thanks to
|
||||
steve1medix for reporting!
|
||||
</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 version="1.4" date="2016-02-04">
|
||||
<action type="add">
|
||||
|
|
Loading…
Reference in New Issue