Adding tests that don't yet work

This commit is contained in:
James Agnew 2014-12-04 11:21:08 -05:00
parent a346219930
commit 81d842548c
10 changed files with 3310 additions and 1 deletions

View File

@ -1,6 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="hapi-fhir-structures-dstu/target/generated-sources/tinder"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
<classpathentry kind="output" path="bin"/>
</classpath>

View File

@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/classes" path="src/main/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>

View File

@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>hapi-fhir-structures-hl7org-dev</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
</natures>
</projectDescription>

View File

@ -0,0 +1,198 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-deployable-pom</artifactId>
<version>0.8-SNAPSHOT</version>
<relativePath>../hapi-deployable-pom/pom.xml</relativePath>
</parent>
<artifactId>hapi-fhir-structures-hl7org-dev</artifactId>
<packaging>jar</packaging>
<name>HAPI FHIR Structures - HL7.org DEV (FHIR Latest)</name>
<dependencies>
<dependency>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-fhir-base</artifactId>
<version>0.8-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>${servlet_api_version}</version>
<scope>provided</scope>
</dependency>
<!-- Testing -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit_version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>xmlunit</groupId>
<artifactId>xmlunit</artifactId>
<version>1.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-servlets</artifactId>
<version>${jetty_version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-servlet</artifactId>
<version>${jetty_version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-server</artifactId>
<version>${jetty_version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-servlet</artifactId>
<version>${jetty_version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-util</artifactId>
<version>${jetty_version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-webapp</artifactId>
<version>${jetty_version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-http</artifactId>
<version>${jetty_version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>${logback_version}</version>
<optional>true</optional>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.ebaysf.web</groupId>
<artifactId>cors-filter</artifactId>
<version>${ebay_cors_filter_version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.thymeleaf</groupId>
<artifactId>thymeleaf</artifactId>
<version>${thymeleaf-version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.phloc</groupId>
<artifactId>phloc-schematron</artifactId>
<version>${phloc_schematron_version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.phloc</groupId>
<artifactId>phloc-commons</artifactId>
<version>${phloc_commons_version}</version>
<scope>test</scope>
</dependency>
<!-- UNIT TEST DEPENDENCIES -->
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>1.9.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>net.sf.json-lib</groupId>
<artifactId>json-lib</artifactId>
<version>2.4</version>
<classifier>jdk15</classifier>
<scope>test</scope>
<exclusions>
<exclusion>
<artifactId>commons-logging</artifactId>
<groupId>commons-logging</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>net.sf.json-lib</groupId>
<artifactId>json-lib</artifactId>
<version>2.4</version>
<classifier>jdk15-sources</classifier>
<scope>test</scope>
</dependency>
<dependency>
<groupId>directory-naming</groupId>
<artifactId>naming-java</artifactId>
<version>0.8</version>
<scope>test</scope>
<exclusions>
<exclusion>
<artifactId>commons-logging</artifactId>
<groupId>commons-logging</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-all</artifactId>
<version>${hamcrest_version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>${guava_version}</version>
<scope>test</scope>
</dependency>
<!--
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-web</artifactId>
<version>${spring_security_version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-config</artifactId>
<version>${spring_security_version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-jwt</artifactId>
<version>1.0.2.RELEASE</version>
<scope>test</scope>
</dependency>
-->
</dependencies>
<build>
<plugins>
</plugins>
</build>
</project>

View File

@ -0,0 +1,246 @@
package ca.uhn.fhir.parser;
import static org.junit.Assert.*;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.model.api.Bundle;
import ca.uhn.fhir.model.api.IResource;
import ca.uhn.fhir.model.dstu.composite.CodeableConceptDt;
import ca.uhn.fhir.model.dstu.composite.CodingDt;
import ca.uhn.fhir.model.dstu.composite.HumanNameDt;
import ca.uhn.fhir.model.dstu.composite.ResourceReferenceDt;
import ca.uhn.fhir.model.dstu.resource.Composition;
import ca.uhn.fhir.model.dstu.resource.Composition.Section;
import ca.uhn.fhir.model.dstu.resource.Condition;
import ca.uhn.fhir.model.dstu.resource.DiagnosticReport;
import ca.uhn.fhir.model.dstu.resource.Observation;
import ca.uhn.fhir.model.dstu.resource.Patient;
import ca.uhn.fhir.model.dstu.resource.Practitioner;
import ca.uhn.fhir.model.dstu.valueset.AdministrativeGenderCodesEnum;
import ca.uhn.fhir.model.dstu.valueset.ConditionStatusEnum;
import ca.uhn.fhir.model.dstu.valueset.NameUseEnum;
import ca.uhn.fhir.model.dstu.valueset.PractitionerRoleEnum;
import ca.uhn.fhir.model.primitive.IdDt;
import ca.uhn.fhir.rest.server.RestfulServer;
/**
* Initially contributed by Alexander Kley for bug #29
*/
public class ContainedResourceEncodingTest {
private static Logger logger = LoggerFactory.getLogger(ContainedResourceEncodingTest.class);
private FhirContext ctx;
private Composition comp;
private Practitioner author;
private Patient patient;
private final String patFamName1 = "FirstFamilyName";
private final String patGivName1 = "FirstGivenName";
@Before
public void initTest() {
logger.info("[initTest]");
initPatient();
initAuthor();
initComposition();
this.ctx = new FhirContext();
}
private void initComposition() {
// new ConditionList
final Condition c = new Condition();
c.setId(UUID.randomUUID().toString());
c.setNotes("This is a note");
c.setSubject(new ResourceReferenceDt(this.patient));
c.setCode(new CodeableConceptDt("mySystem", "theCode"));
c.setStatus(ConditionStatusEnum.CONFIRMED);
// new General Note Section
final Section generalNoteSection = new Section();
generalNoteSection.setElementSpecificId("Note");
generalNoteSection.setTitle("Note");
generalNoteSection.setContent(new ResourceReferenceDt(c));
// new SectionList
final List<Section> sectionList = new ArrayList<Section>();
sectionList.add(generalNoteSection);
// fill composition
this.comp = new Composition();
this.comp.addAuthor().setResource(this.author);
this.comp.setSubject(new ResourceReferenceDt(this.patient));
this.comp.setSection(sectionList);
}
private void initPatient() {
this.patient = new Patient();
this.patient.setId(new IdDt(UUID.randomUUID().toString()));
this.patient.addIdentifier().setSystem("http://example.com/fictitious-mrns").setValue("MRN001");
this.patient.setGender(AdministrativeGenderCodesEnum.M);
this.patient.addName().setUse(NameUseEnum.OFFICIAL).addFamily(this.patFamName1).addGiven(this.patGivName1);
}
private void initAuthor() {
this.author = new Practitioner();
this.author.setId(new IdDt(UUID.randomUUID().toString()));
this.author.addIdentifier().setSystem("DoctorID").setValue("4711");
this.author.addRole(PractitionerRoleEnum.DOCTOR);
this.author.setName(new HumanNameDt().addFamily("Mueller").addGiven("Klaus").addPrefix("Prof. Dr."));
}
@Test
public void testPatient() {
logger.debug("[xmlEncoding] encode resource to xml.");
/**
* This works fine, although patient instance is modifing from encoder
*/
final String expectedPatientXml = this.ctx.newXmlParser().setPrettyPrint(true).encodeResourceToString(this.patient);
logger.debug("[xmlEncoding] first encoding: {}", expectedPatientXml);
final String actualPatientXml = this.ctx.newXmlParser().setPrettyPrint(true).encodeResourceToString(this.patient);
// second encoding - xml is corrupt - i.e.: patient content 4 times! should be the same as after first encoding!
logger.debug("[xmlEncoding] second encoding: {}", actualPatientXml);
Assert.assertEquals(expectedPatientXml.length(), actualPatientXml.length());
Assert.assertArrayEquals(expectedPatientXml.getBytes(), actualPatientXml.getBytes());
}
@Test
public void testComposition() {
IParser parser = this.ctx.newXmlParser().setPrettyPrint(true);
assertEquals(0, this.comp.getContained().getContainedResources().size());
/**
* This doesn't works, secund encoding creates corrupt xml
*/
final String expectedCompXml = parser.encodeResourceToString(this.comp);
logger.debug("[xmlEncoding] first encoding: {}", expectedCompXml);
assertEquals(0, this.comp.getContained().getContainedResources().size());
final String actualCompXml = parser.encodeResourceToString(this.comp);
assertEquals(0, this.comp.getContained().getContainedResources().size());
// second encoding - xml could not be parsed back to compositon - i.e.: patient content 4 times! should be the same
// as after first encoding!
logger.debug("[xmlEncoding] second encoding: {}", actualCompXml);
final String thirdCompXml = parser.encodeResourceToString(this.comp);
assertEquals(0, this.comp.getContained().getContainedResources().size());
// third encoding - xml could not be parsed back to compositon i.e.: patient content 4 times! should be the same as
// afterfirst encoding!
logger.debug("[xmlEncoding] third encoding: {}", thirdCompXml);
Assert.assertEquals(expectedCompXml.length(), actualCompXml.length());
Assert.assertArrayEquals(expectedCompXml.getBytes(), actualCompXml.getBytes());
}
@Test
public void testBundleWithContained() {
DiagnosticReport dr = new DiagnosticReport();
dr.setId(new IdDt("DiagnosticReport","123"));
Observation observation = new Observation();
CodeableConceptDt obsName = new CodeableConceptDt();
obsName.setText("name");
observation.setName(obsName);
ResourceReferenceDt result = dr.addResult();
result.setResource(observation);
ArrayList<ResourceReferenceDt> performers = new ArrayList<ResourceReferenceDt>();
ResourceReferenceDt performer = new ResourceReferenceDt();
Practitioner p = new Practitioner();
p.setId(new IdDt(UUID.randomUUID().toString()));
p.addIdentifier().setSystem("DoctorID").setValue("4711");
p.addRole(PractitionerRoleEnum.DOCTOR);
p.setName(new HumanNameDt().addFamily("Mueller").addGiven("Klaus").addPrefix("Prof. Dr."));
performer.setResource(p);
performers.add(performer);
observation.setPerformer(performers);
List<IResource> list = new ArrayList<IResource>();
list.add(dr);
Bundle bundle = RestfulServer.createBundleFromResourceList(new FhirContext(), null, list, null, null, 0);
IParser parser = this.ctx.newXmlParser().setPrettyPrint(true);
String xml = parser.encodeBundleToString(bundle);
Assert.assertTrue(xml.contains("Mueller"));
}
@Test
public void testBundleWithContainedWithNoIdDt() {
DiagnosticReport dr = new DiagnosticReport();
dr.setId(new IdDt("DiagnosticReport","123"));
Observation observation = new Observation();
CodeableConceptDt obsName = new CodeableConceptDt();
obsName.setText("name");
observation.setName(obsName);
ResourceReferenceDt result = dr.addResult();
result.setResource(observation);
ArrayList<ResourceReferenceDt> performers = new ArrayList<ResourceReferenceDt>();
ResourceReferenceDt performer = new ResourceReferenceDt();
Practitioner p = new Practitioner();
// no idDt on practitioner p
p.addIdentifier().setSystem("DoctorID").setValue("4711");
p.addRole(PractitionerRoleEnum.DOCTOR);
p.setName(new HumanNameDt().addFamily("Mueller").addGiven("Klaus").addPrefix("Prof. Dr."));
performer.setResource(p);
performers.add(performer);
observation.setPerformer(performers);
List<IResource> list = new ArrayList<IResource>();
list.add(dr);
Bundle bundle = RestfulServer.createBundleFromResourceList(new FhirContext(), null, list, null, null, 0);
IParser parser = this.ctx.newXmlParser().setPrettyPrint(true);
String xml = parser.encodeBundleToString(bundle);
Assert.assertTrue(xml.contains("Mueller"));
}
}

View File

@ -0,0 +1,109 @@
package ca.uhn.fhir.parser;
import java.util.Collections;
import java.util.List;
import ca.uhn.fhir.model.api.BaseIdentifiableElement;
import ca.uhn.fhir.model.api.IElement;
import ca.uhn.fhir.model.api.IResourceBlock;
import ca.uhn.fhir.model.api.annotation.Block;
import ca.uhn.fhir.model.api.annotation.Child;
import ca.uhn.fhir.model.api.annotation.Extension;
import ca.uhn.fhir.model.api.annotation.ResourceDef;
import ca.uhn.fhir.model.dstu.composite.AttachmentDt;
import ca.uhn.fhir.model.dstu.resource.Patient;
import ca.uhn.fhir.model.primitive.DateDt;
import ca.uhn.fhir.model.primitive.StringDt;
import ca.uhn.fhir.util.ElementUtil;
@ResourceDef(name="Patient")
public class MyObservationWithExtensions extends Patient {
@Extension(url = "urn:patientext:att", definedLocally = false, isModifier = false)
@Child(name = "extAtt", order = 0)
private AttachmentDt myExtAtt;
@Extension(url = "urn:patientext:moreext", definedLocally = false, isModifier = false)
@Child(name = "moreExt", order = 1)
private MoreExt myMoreExt;
@Extension(url = "urn:modext", definedLocally = false, isModifier = true)
@Child(name = "modExt", order = 2)
private DateDt myModExt;
public AttachmentDt getExtAtt() {
return myExtAtt;
}
public MoreExt getMoreExt() {
return myMoreExt;
}
public void setMoreExt(MoreExt theMoreExt) {
myMoreExt = theMoreExt;
}
public DateDt getModExt() {
return myModExt;
}
public void setModExt(DateDt theModExt) {
myModExt = theModExt;
}
public void setExtAtt(AttachmentDt theExtAtt) {
myExtAtt = theExtAtt;
}
@Override
public boolean isEmpty() {
return super.isEmpty() && ElementUtil.isEmpty(myExtAtt, myModExt, myMoreExt);
}
/**
* Block class for child element: <b>Observation.referenceRange</b> (Provides guide for interpretation)
*
* <p>
* <b>Definition:</b> Guidance on how to interpret the value by comparison to a normal or recommended range
* </p>
*/
@Block(name = "Observation.someExtensions")
public static class MoreExt extends BaseIdentifiableElement implements IResourceBlock {
@Extension(url = "urn:patientext:moreext:1", definedLocally = false, isModifier = false)
@Child(name = "str1", order = 0)
private StringDt myStr1;
@Extension(url = "urn:patientext:moreext:2", definedLocally = false, isModifier = false)
@Child(name = "str2", order = 1)
private StringDt myStr2;
public StringDt getStr1() {
return myStr1;
}
public void setStr1(StringDt theStr1) {
myStr1 = theStr1;
}
public StringDt getStr2() {
return myStr2;
}
public void setStr2(StringDt theStr2) {
myStr2 = theStr2;
}
@Override
public <T extends IElement> List<T> getAllPopulatedChildElementsOfType(Class<T> theType) {
return Collections.emptyList();
}
@Override
public boolean isEmpty() {
return ElementUtil.isEmpty(myStr1, myStr2);
}
}
}

View File

@ -0,0 +1,9 @@
package ca.uhn.fhir.parser;
import ca.uhn.fhir.model.api.annotation.ResourceDef;
import ca.uhn.fhir.model.dstu.resource.Organization;
@ResourceDef()
public class MyOrganization extends Organization {
}

View File

@ -0,0 +1,62 @@
package ca.uhn.fhir.parser;
import java.util.ArrayList;
import java.util.List;
import ca.uhn.fhir.model.api.annotation.Child;
import ca.uhn.fhir.model.api.annotation.Description;
import ca.uhn.fhir.model.api.annotation.Extension;
import ca.uhn.fhir.model.api.annotation.ResourceDef;
import ca.uhn.fhir.model.dstu.composite.ResourceReferenceDt;
import ca.uhn.fhir.model.dstu.resource.Patient;
import ca.uhn.fhir.model.primitive.DateTimeDt;
import ca.uhn.fhir.model.primitive.StringDt;
@ResourceDef()
public class MyPatient extends Patient {
@Child(name="petName")
@Extension(url="http://example.com/dontuse#petname", definedLocally=false, isModifier=false)
@Description(shortDefinition="The name of the patient's favourite pet")
private StringDt myPetName;
@Child(name="importantDates", max=Child.MAX_UNLIMITED)
@Extension(url="http://example.com/dontuse#importantDates", definedLocally=false, isModifier=true)
@Description(shortDefinition="Some dates of note for the patient")
private List<DateTimeDt> myImportantDates;
@Child(name="managingOrganization", order=Child.REPLACE_PARENT, min=0, max=1, type={
MyOrganization.class })
@Description(
shortDefinition="Organization that is the custodian of the patient record",
formalDefinition="Organization that is the custodian of the patient record"
)
private ResourceReferenceDt myManagingOrganization;
@Override
public boolean isEmpty() {
return super.isEmpty() && myPetName.isEmpty();
}
public List<DateTimeDt> getImportantDates() {
if (myImportantDates==null) {
myImportantDates = new ArrayList<DateTimeDt>();
}
return myImportantDates;
}
public StringDt getPetName() {
return myPetName;
}
public void setImportantDates(List<DateTimeDt> theImportantDates) {
myImportantDates = theImportantDates;
}
public void setPetName(StringDt thePetName) {
myPetName = thePetName;
}
}