Narrative fixes

This commit is contained in:
jamesagnew 2014-04-01 13:28:33 -04:00
parent 5a3de7c3dd
commit 57a3a4881e
5 changed files with 50 additions and 4905 deletions

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
package ca.uhn.fhir.narrative; package ca.uhn.fhir.narrative;
import static org.apache.commons.lang3.StringUtils.*; import static org.apache.commons.lang3.StringUtils.isBlank;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
@ -32,14 +32,13 @@ import org.thymeleaf.standard.expression.StandardExpressions;
import org.thymeleaf.templateresolver.TemplateResolver; import org.thymeleaf.templateresolver.TemplateResolver;
import org.thymeleaf.util.DOMUtils; import org.thymeleaf.util.DOMUtils;
import ca.uhn.fhir.context.ConfigurationException;
import ca.uhn.fhir.model.api.IResource; import ca.uhn.fhir.model.api.IResource;
import ca.uhn.fhir.model.dstu.composite.NarrativeDt; import ca.uhn.fhir.model.dstu.composite.NarrativeDt;
import ca.uhn.fhir.model.dstu.valueset.NarrativeStatusEnum; import ca.uhn.fhir.model.dstu.valueset.NarrativeStatusEnum;
import ca.uhn.fhir.model.primitive.XhtmlDt; import ca.uhn.fhir.model.primitive.XhtmlDt;
import ca.uhn.fhir.parser.DataFormatException; import ca.uhn.fhir.parser.DataFormatException;
public class BaseThymeleafNarrativeGenerator implements INarrativeGenerator { public abstract class BaseThymeleafNarrativeGenerator implements INarrativeGenerator {
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(BaseThymeleafNarrativeGenerator.class); private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(BaseThymeleafNarrativeGenerator.class);
private boolean myCleanWhitespace = true; private boolean myCleanWhitespace = true;
@ -112,9 +111,7 @@ public class BaseThymeleafNarrativeGenerator implements INarrativeGenerator {
} }
} }
public String getPropertyFile() { protected abstract String getPropertyFile();
return null;
}
/** /**
* If set to <code>true</code> (which is the default), most whitespace will * If set to <code>true</code> (which is the default), most whitespace will
@ -233,7 +230,7 @@ public class BaseThymeleafNarrativeGenerator implements INarrativeGenerator {
if (resource == null) { if (resource == null) {
resource = DefaultThymeleafNarrativeGenerator.class.getResourceAsStream("/" + cpName); resource = DefaultThymeleafNarrativeGenerator.class.getResourceAsStream("/" + cpName);
if (resource == null) { if (resource == null) {
throw new ConfigurationException("Can not find '" + cpName + "' on classpath"); throw new IOException("Can not find '" + cpName + "' on classpath");
} }
} }
return resource; return resource;
@ -244,7 +241,7 @@ public class BaseThymeleafNarrativeGenerator implements INarrativeGenerator {
} }
return new FileInputStream(file); return new FileInputStream(file);
} else { } else {
throw new IllegalArgumentException("Invalid resource name: '" + name + "'"); throw new IOException("Invalid resource name: '" + name + "'");
} }
} }

View File

@ -2,14 +2,17 @@ package ca.uhn.fhir.narrative;
import java.io.IOException; import java.io.IOException;
import org.apache.commons.lang3.Validate;
public class CustomThymeleafNarrativeGenerator extends BaseThymeleafNarrativeGenerator { public class CustomThymeleafNarrativeGenerator extends BaseThymeleafNarrativeGenerator {
private String myPropertyFile;
/** /**
* Create a new narrative generator * Create a new narrative generator
* *
* @param thePropertyFile * @param thePropertyFile
* The name of the property file, in one of the following * The name of the property file, in one of the following formats:
* formats:
* <ul> * <ul>
* <li>file:/path/to/file/file.properties</li> * <li>file:/path/to/file/file.properties</li>
* <li>classpath:/com/package/file.properties</li> * <li>classpath:/com/package/file.properties</li>
@ -18,7 +21,29 @@ public class CustomThymeleafNarrativeGenerator extends BaseThymeleafNarrativeGen
* If the file can not be found/read * If the file can not be found/read
*/ */
public CustomThymeleafNarrativeGenerator(String thePropertyFile) throws IOException { public CustomThymeleafNarrativeGenerator(String thePropertyFile) throws IOException {
super(); setPropertyFile(thePropertyFile);
}
/**
* Set the property file to use
*
* @param thePropertyFile
* The name of the property file, in one of the following formats:
* <ul>
* <li>file:/path/to/file/file.properties</li>
* <li>classpath:/com/package/file.properties</li>
* </ul>
* @throws IOException
* If the file can not be found/read
*/
public void setPropertyFile(String thePropertyFile) {
Validate.notNull(thePropertyFile, "Property file can not be null");
myPropertyFile = thePropertyFile;
}
@Override
public String getPropertyFile() {
return myPropertyFile;
} }
} }

View File

@ -9,7 +9,7 @@ public class DefaultThymeleafNarrativeGenerator extends BaseThymeleafNarrativeGe
} }
@Override @Override
public String getPropertyFile() { protected String getPropertyFile() {
return "classpath:ca/uhn/fhir/narrative/narratives.properties"; return "classpath:ca/uhn/fhir/narrative/narratives.properties";
} }

View File

@ -0,0 +1,16 @@
package ca.uhn.fhir.narrative;
import java.io.IOException;
import org.junit.Test;
public class CustomThymeleafNarrativeGeneratorTest {
@Test
public void testGenerator() throws IOException {
CustomThymeleafNarrativeGenerator gen = new CustomThymeleafNarrativeGenerator("src/test/resources/narrative/customnarrative.properties");
}
}