Merge remote-tracking branch 'origin/master' into hl7org_structs

Conflicts:
	hapi-fhir-structures-hl7org-dev/.gitignore
This commit is contained in:
James Agnew 2014-12-16 11:32:58 -05:00
commit 35b5f90318
271 changed files with 2192925 additions and 93374 deletions

View File

@ -101,9 +101,7 @@ public class GenericClient extends BaseClient implements IGenericClient {
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(GenericClient.class);
private FhirContext myContext;
private HttpRequestBase myLastRequest;
private boolean myLogRequestAndResponse;
/**

View File

@ -215,14 +215,14 @@ abstract class BaseHttpClientInvocationWithContents extends BaseHttpClientInvoca
contents = parser.encodeResourceToString(myResource);
contentType = encoding.getResourceContentType();
}
entity = new StringEntity(contents, ContentType.create(contentType, "UTF-8"));
entity = new StringEntity(contents, ContentType.create(contentType, Constants.CHARSET_UTF_8));
}
HttpRequestBase retVal = createRequest(url, entity);
super.addHeadersToRequest(retVal);
if (contentType != null) {
retVal.addHeader(Constants.HEADER_CONTENT_TYPE, contentType);
retVal.addHeader(Constants.HEADER_CONTENT_TYPE, contentType + Constants.HEADER_SUFFIX_CT_UTF_8);
}
return retVal;

View File

@ -44,6 +44,7 @@ public class Constants {
public static final Map<String, EncodingEnum> FORMAT_VAL_TO_ENCODING;
public static final Set<String> FORMAT_VAL_XML;
public static final String FORMAT_XML = "xml";
public static final String HEADER_SUFFIX_CT_UTF_8 = "; charset=UTF-8";
public static final String HEADER_ACCEPT = "Accept";
public static final String HEADER_ACCEPT_ENCODING = "Accept-Encoding";
public static final String HEADER_AUTHORIZATION = "Authorization";

View File

@ -957,7 +957,15 @@ public abstract class BaseFhirDao implements IDao {
protected List<IResource> loadResourcesById(Set<IdDt> theIncludePids) {
Set<Long> pids = new HashSet<Long>();
for (IdDt next : theIncludePids) {
if (next.isIdPartValidLong()) {
pids.add(next.getIdPartAsLong());
} else {
try {
pids.add(translateForcedIdToPid(next));
} catch (ResourceNotFoundException e) {
ourLog.warn("Failed to translate forced ID [{}] to PID", next.getValue());
}
}
}
CriteriaBuilder builder = myEntityManager.getCriteriaBuilder();

View File

@ -3,6 +3,7 @@ package ca.uhn.fhir.jpa.dao;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
@ -1139,6 +1140,65 @@ public class FhirResourceDaoTest {
}
/**
* Test for issue #60
*/
@Test
public void testStoreUtf8Characters() throws Exception {
String name = "測試醫院";
Organization org = new Organization();
org.setName(new String(name.getBytes(), "UTF-8"));
org.addIdentifier("urn:system", "testStoreUtf8Characters_01");
IdDt orgId = ourOrganizationDao.create(org).getId();
Organization returned = ourOrganizationDao.read(orgId);
String val = ourFhirCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(returned);
ourLog.info(val);
assertThat(val, containsString("<name value=\"測試醫院\"/>"));
}
/**
* Test for #62
*/
@Test
public void testSearchWithIncludesThatHaveTextId() {
{
Organization org = new Organization();
org.setId("testSearchWithIncludesThatHaveTextId_id1");
org.getName().setValue("testSearchWithIncludesThatHaveTextId_O1");
IdDt orgId = ourOrganizationDao.create(org).getId();
assertThat(orgId.getValue(), endsWith("Organization/testSearchWithIncludesThatHaveTextId_id1/_history/1"));
Patient patient = new Patient();
patient.addIdentifier("urn:system", "001");
patient.addName().addFamily("Tester_testSearchWithIncludesThatHaveTextId_P1").addGiven("Joe");
patient.getManagingOrganization().setReference(orgId);
ourPatientDao.create(patient);
}
{
Patient patient = new Patient();
patient.addIdentifier("urn:system", "002");
patient.addName().addFamily("Tester_testSearchWithIncludesThatHaveTextId_P2").addGiven("John");
ourPatientDao.create(patient);
}
SearchParameterMap params = new SearchParameterMap();
params.add(Patient.SP_FAMILY, new StringDt("Tester_testSearchWithIncludesThatHaveTextId_P1"));
params.addInclude(Patient.INCLUDE_MANAGINGORGANIZATION);
IBundleProvider search = ourPatientDao.search(params);
List<IResource> patients = toList(search);
assertEquals(2, patients.size());
assertEquals(Patient.class, patients.get(0).getClass());
assertEquals(Organization.class, patients.get(1).getClass());
params = new SearchParameterMap();
params.add(Patient.SP_FAMILY, new StringDt("Tester_testSearchWithIncludesThatHaveTextId_P1"));
patients = toList(ourPatientDao.search(params));
assertEquals(1, patients.size());
}
@Test
public void testSearchWithNoResults() {
IBundleProvider value = ourDeviceDao.search(new SearchParameterMap());

View File

@ -60,15 +60,43 @@ public class CompleteResourceProviderTest {
private static ClassPathXmlApplicationContext ourAppCtx;
private static IGenericClient ourClient;
private static FhirContext ourCtx;
private static FhirContext ourFhirCtx;
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(CompleteResourceProviderTest.class);
private static IFhirResourceDao<Observation> ourObservationDao;
private static IFhirResourceDao<Patient> ourPatientDao;
private static IFhirResourceDao<Questionnaire> ourQuestionnaireDao;
private static Server ourServer;
private static IFhirResourceDao<Organization> ourOrganizationDao;
// private static JpaConformanceProvider ourConfProvider;
/**
* Test for issue #60
*/
@Test
public void testStoreUtf8Characters() throws Exception {
String name = "測試醫院";
Organization org = new Organization();
org.setName(name);
org.addIdentifier("urn:system", "testStoreUtf8Characters_01");
IdDt orgId = ourClient.create().resource(org).prettyPrint().encodedXml().execute().getId();
// Read back directly from the DAO
{
Organization returned = ourOrganizationDao.read(orgId);
String val = ourFhirCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(returned);
ourLog.info(val);
assertThat(val, containsString("<name value=\"測試醫院\"/>"));
}
// Read back through the HTTP API
{
Organization returned = ourClient.read(Organization.class, orgId);
String val = ourFhirCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(returned);
ourLog.info(val);
assertThat(val, containsString("<name value=\"測試醫院\"/>"));
}
}
/**
* See issue #52
*/
@ -143,7 +171,6 @@ public class CompleteResourceProviderTest {
}
private void delete(String theResourceType, String theParamName, String theParamValue) {
Bundle resources = ourClient.search().forResource(theResourceType).where(new StringClientParam(theParamName).matches().value(theParamValue)).execute();
for (IResource next : resources.toListOfResources()) {
@ -445,9 +472,9 @@ public class CompleteResourceProviderTest {
EncounterResourceProvider encounterRp = new EncounterResourceProvider();
encounterRp.setDao(encounterDao);
IFhirResourceDao<Organization> organizationDao = (IFhirResourceDao<Organization>) ourAppCtx.getBean("myOrganizationDao", IFhirResourceDao.class);
ourOrganizationDao = (IFhirResourceDao<Organization>) ourAppCtx.getBean("myOrganizationDao", IFhirResourceDao.class);
OrganizationResourceProvider organizationRp = new OrganizationResourceProvider();
organizationRp.setDao(organizationDao);
organizationRp.setDao(ourOrganizationDao);
IFhirResourceDao<ImagingStudy> imagingStudyDao = (IFhirResourceDao<ImagingStudy>) ourAppCtx.getBean("myImagingStudyDao", IFhirResourceDao.class);
ImagingStudyResourceProvider imagingStudyRp = new ImagingStudyResourceProvider();
@ -465,7 +492,7 @@ public class CompleteResourceProviderTest {
DocumentReferenceResourceProvider documentReferenceRp = new DocumentReferenceResourceProvider();
documentReferenceRp.setDao(documentReferenceDao);
restServer.setResourceProviders(diagnosticOrderRp, documentManifestRp, documentReferenceRp, encounterRp, locationRp, patientRp, questionnaireRp, observationRp, organizationRp, imagingStudyRp);
restServer.setResourceProviders(diagnosticOrderRp, documentManifestRp, documentReferenceRp, encounterRp, locationRp, patientRp, questionnaireRp, organizationRp, imagingStudyRp);
restServer.getFhirContext().setNarrativeGenerator(new DefaultThymeleafNarrativeGenerator());
IFhirSystemDao systemDao = (IFhirSystemDao) ourAppCtx.getBean("mySystemDao", IFhirSystemDao.class);
@ -490,10 +517,10 @@ public class CompleteResourceProviderTest {
ourServer.start();
}
ourCtx = restServer.getFhirContext();
ourFhirCtx = restServer.getFhirContext();
// ourCtx.getRestfulClientFactory().setProxy("localhost", 8888);
ourClient = ourCtx.newRestfulGenericClient(serverBase);
ourClient = ourFhirCtx.newRestfulGenericClient(serverBase);
// ourClient = ourCtx.newRestfulGenericClient("http://fhir.healthintersections.com.au/open");
// ourClient = ourCtx.newRestfulGenericClient("https://fhir.orionhealth.com/blaze/fhir");
// ourClient = ourCtx.newRestfulGenericClient("http://spark.furore.com/fhir");

View File

@ -242,6 +242,7 @@
<baseResourceName>documentmanifest</baseResourceName>
<baseResourceName>documentreference</baseResourceName>
<baseResourceName>encounter</baseResourceName>
<baseResourceName>episodeofcare</baseResourceName>
<baseResourceName>familyhistory</baseResourceName>
<baseResourceName>geneexpression</baseResourceName>
<baseResourceName>geneticanalysis</baseResourceName>
@ -287,6 +288,7 @@
<baseResourceName>relatedperson</baseResourceName>
<baseResourceName>remittance</baseResourceName>
<baseResourceName>riskassessment</baseResourceName>
<baseResourceName>schedule</baseResourceName>
<baseResourceName>securityclaim</baseResourceName>
<baseResourceName>securityevent</baseResourceName>
<baseResourceName>securitygroup</baseResourceName>

View File

@ -21,13 +21,6 @@ public class ResourceWithExtensionsA extends BaseResource {
* so check the unit tests immediately after any changes
*/
@Child(name = "bar1", type = Bar1.class, order = 2, min = 1, max = Child.MAX_UNLIMITED)
@Extension(url = "http://bar/#b1", definedLocally=true, isModifier=false)
private List<Bar1> myBar1;
@Child(name = "bar2", type = Bar1.class, order = 3, min = 1, max = Child.MAX_UNLIMITED)
@Extension(url = "http://bar/#b2", definedLocally=true, isModifier=false)
private Bar1 myBar2;
@Child(name = "foo1", type = StringDt.class, order = 0, min = 0, max = Child.MAX_UNLIMITED)
@Extension(url = "http://foo/#f1", definedLocally=true, isModifier=false)
@ -37,6 +30,14 @@ public class ResourceWithExtensionsA extends BaseResource {
@Extension(url = "http://foo/#f2", definedLocally=true, isModifier=true)
private StringDt myFoo2;
@Child(name = "bar1", type = Bar1.class, order = 2, min = 1, max = Child.MAX_UNLIMITED)
@Extension(url = "http://bar/#b1", definedLocally=true, isModifier=false)
private List<Bar1> myBar1;
@Child(name = "bar2", type = Bar1.class, order = 3, min = 1, max = Child.MAX_UNLIMITED)
@Extension(url = "http://bar/#b2", definedLocally=true, isModifier=false)
private Bar1 myBar2;
@Child(name="baz", type = CodeableConceptDt.class, order = 4)
@Extension(url= "http://baz/#baz", definedLocally=true, isModifier=false)
@Description(shortDefinition = "Contains a codeable concept")

View File

@ -58,7 +58,7 @@ public class RuntimeResourceDefinitionTest {
Profile profile = (Profile) def.toProfile();
ourLog.info(ctx.newXmlParser().encodeResourceToString(profile));
ourLog.info(ctx.newXmlParser().setPrettyPrint(true).encodeResourceToString(profile));
List<StructureElement> element = profile.getStructure().get(0).getElement();
assertEquals(1, element.get(0).getDefinition().getType().size());

View File

@ -70,6 +70,11 @@ public class GenericClientTest {
myHttpResponse = mock(HttpResponse.class, new ReturnsDeepStubs());
}
private String extractBody(ArgumentCaptor<HttpUriRequest> capt, int count) throws IOException {
String body = IOUtils.toString(((HttpEntityEnclosingRequestBase) capt.getAllValues().get(count)).getEntity().getContent(), "UTF-8");
return body;
}
private String getPatientFeedWithOneResult() {
//@formatter:off
String msg = "<feed xmlns=\"http://www.w3.org/2005/Atom\">\n" +
@ -114,45 +119,51 @@ public class GenericClientTest {
return msg;
}
@Test
public void testSearchByCompartment() throws Exception {
String msg = getPatientFeedWithOneResult();
@Test
public void testCreateWithStringAutoDetectsEncoding() throws Exception {
Patient p1 = new Patient();
p1.addIdentifier("foo:bar", "12345");
p1.addName().addFamily("Smith").addGiven("John");
ArgumentCaptor<HttpUriRequest> capt = ArgumentCaptor.forClass(HttpUriRequest.class);
when(myHttpResponse.getStatusLine()).thenReturn(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), 200, "OK"));
when(myHttpResponse.getEntity().getContentType()).thenReturn(new BasicHeader("content-type", Constants.CT_FHIR_XML + "; charset=UTF-8"));
when(myHttpResponse.getEntity().getContent()).thenReturn(new ReaderInputStream(new StringReader(msg), Charset.forName("UTF-8")));
when(myHttpClient.execute(capt.capture())).thenReturn(myHttpResponse);
when(myHttpResponse.getStatusLine()).thenReturn(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), 201, "OK"));
when(myHttpResponse.getAllHeaders()).thenReturn(new Header[] { new BasicHeader(Constants.HEADER_LOCATION, "/Patient/44/_history/22") });
when(myHttpResponse.getEntity().getContentType()).thenReturn(new BasicHeader("content-type", Constants.CT_FHIR_XML + "; charset=UTF-8"));
when(myHttpResponse.getEntity().getContent()).thenReturn(new ReaderInputStream(new StringReader(""), Charset.forName("UTF-8")));
IGenericClient client = myCtx.newRestfulGenericClient("http://foo");
//@formatter:off
Bundle response = client
.search()
.forResource(Patient.class)
.withIdAndCompartment("123", "fooCompartment")
.where(Patient.BIRTHDATE.afterOrEquals().day("2011-01-02"))
.execute();
//@formatter:on
IGenericClient client = myCtx.newRestfulGenericClient("http://example.com/fhir");
assertEquals("http://foo/Patient/123/fooCompartment?birthdate=%3E%3D2011-01-02", capt.getValue().getURI().toString());
assertEquals("PRP1660", response.getResources(Patient.class).get(0).getIdentifier().get(0).getValue().getValue());
int count = 0;
client.create().resource(myCtx.newXmlParser().encodeResourceToString(p1)).execute();
assertEquals(1, capt.getAllValues().get(count).getHeaders(Constants.HEADER_CONTENT_TYPE).length);
assertEquals(EncodingEnum.XML.getResourceContentType(), capt.getAllValues().get(count).getFirstHeader(Constants.HEADER_CONTENT_TYPE).getValue());
assertThat(extractBody(capt, count), containsString("value=\"John\""));
count++;
try {
//@formatter:off
client
.search()
.forResource(Patient.class)
.withIdAndCompartment("", "fooCompartment")
.where(Patient.BIRTHDATE.afterOrEquals().day("2011-01-02"))
.execute();
//@formatter:on
fail();
} catch (InvalidRequestException e) {
assertThat(e.toString(), containsString("null or empty for compartment"));
}
client.create().resource(myCtx.newJsonParser().encodeResourceToString(p1)).execute();
assertEquals(1, capt.getAllValues().get(count).getHeaders(Constants.HEADER_CONTENT_TYPE).length);
assertEquals(EncodingEnum.JSON.getResourceContentType(), capt.getAllValues().get(count).getFirstHeader(Constants.HEADER_CONTENT_TYPE).getValue());
assertThat(extractBody(capt, count), containsString("[\"John\"]"));
count++;
/*
* e.g. Now try with reversed encoding (provide a string that's in JSON and ask the client to use XML)
*/
client.create().resource(myCtx.newXmlParser().encodeResourceToString(p1)).encodedJson().execute();
assertEquals(1, capt.getAllValues().get(count).getHeaders(Constants.HEADER_CONTENT_TYPE).length);
assertEquals(EncodingEnum.JSON.getResourceContentType(), capt.getAllValues().get(count).getFirstHeader(Constants.HEADER_CONTENT_TYPE).getValue());
assertThat(extractBody(capt, count), containsString("[\"John\"]"));
count++;
client.create().resource(myCtx.newJsonParser().encodeResourceToString(p1)).encodedXml().execute();
assertEquals(1, capt.getAllValues().get(count).getHeaders(Constants.HEADER_CONTENT_TYPE).length);
assertEquals(EncodingEnum.XML.getResourceContentType(), capt.getAllValues().get(count).getFirstHeader(Constants.HEADER_CONTENT_TYPE).getValue());
assertThat(extractBody(capt, count), containsString("value=\"John\""));
count++;
}
@ -210,104 +221,6 @@ public class GenericClientTest {
count++;
}
@Test
public void testCreateWithStringAutoDetectsEncoding() throws Exception {
Patient p1 = new Patient();
p1.addIdentifier("foo:bar", "12345");
p1.addName().addFamily("Smith").addGiven("John");
ArgumentCaptor<HttpUriRequest> capt = ArgumentCaptor.forClass(HttpUriRequest.class);
when(myHttpClient.execute(capt.capture())).thenReturn(myHttpResponse);
when(myHttpResponse.getStatusLine()).thenReturn(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), 201, "OK"));
when(myHttpResponse.getAllHeaders()).thenReturn(new Header[] { new BasicHeader(Constants.HEADER_LOCATION, "/Patient/44/_history/22") });
when(myHttpResponse.getEntity().getContentType()).thenReturn(new BasicHeader("content-type", Constants.CT_FHIR_XML + "; charset=UTF-8"));
when(myHttpResponse.getEntity().getContent()).thenReturn(new ReaderInputStream(new StringReader(""), Charset.forName("UTF-8")));
IGenericClient client = myCtx.newRestfulGenericClient("http://example.com/fhir");
int count = 0;
client.create().resource(myCtx.newXmlParser().encodeResourceToString(p1)).execute();
assertEquals(1, capt.getAllValues().get(count).getHeaders(Constants.HEADER_CONTENT_TYPE).length);
assertEquals(EncodingEnum.XML.getResourceContentType(), capt.getAllValues().get(count).getFirstHeader(Constants.HEADER_CONTENT_TYPE).getValue());
assertThat(extractBody(capt, count), containsString("value=\"John\""));
count++;
client.create().resource(myCtx.newJsonParser().encodeResourceToString(p1)).execute();
assertEquals(1, capt.getAllValues().get(count).getHeaders(Constants.HEADER_CONTENT_TYPE).length);
assertEquals(EncodingEnum.JSON.getResourceContentType(), capt.getAllValues().get(count).getFirstHeader(Constants.HEADER_CONTENT_TYPE).getValue());
assertThat(extractBody(capt, count), containsString("[\"John\"]"));
count++;
/*
* e.g. Now try with reversed encoding (provide a string that's in JSON and ask the client to use XML)
*/
client.create().resource(myCtx.newXmlParser().encodeResourceToString(p1)).encodedJson().execute();
assertEquals(1, capt.getAllValues().get(count).getHeaders(Constants.HEADER_CONTENT_TYPE).length);
assertEquals(EncodingEnum.JSON.getResourceContentType(), capt.getAllValues().get(count).getFirstHeader(Constants.HEADER_CONTENT_TYPE).getValue());
assertThat(extractBody(capt, count), containsString("[\"John\"]"));
count++;
client.create().resource(myCtx.newJsonParser().encodeResourceToString(p1)).encodedXml().execute();
assertEquals(1, capt.getAllValues().get(count).getHeaders(Constants.HEADER_CONTENT_TYPE).length);
assertEquals(EncodingEnum.XML.getResourceContentType(), capt.getAllValues().get(count).getFirstHeader(Constants.HEADER_CONTENT_TYPE).getValue());
assertThat(extractBody(capt, count), containsString("value=\"John\""));
count++;
}
private String extractBody(ArgumentCaptor<HttpUriRequest> capt, int count) throws IOException {
String body = IOUtils.toString(((HttpEntityEnclosingRequestBase) capt.getAllValues().get(count)).getEntity().getContent());
return body;
}
@Test
public void testUpdateWithStringAutoDetectsEncoding() throws Exception {
Patient p1 = new Patient();
p1.addIdentifier("foo:bar", "12345");
p1.addName().addFamily("Smith").addGiven("John");
ArgumentCaptor<HttpUriRequest> capt = ArgumentCaptor.forClass(HttpUriRequest.class);
when(myHttpClient.execute(capt.capture())).thenReturn(myHttpResponse);
when(myHttpResponse.getStatusLine()).thenReturn(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), 201, "OK"));
when(myHttpResponse.getAllHeaders()).thenReturn(new Header[] { new BasicHeader(Constants.HEADER_LOCATION, "/Patient/44/_history/22") });
when(myHttpResponse.getEntity().getContentType()).thenReturn(new BasicHeader("content-type", Constants.CT_FHIR_XML + "; charset=UTF-8"));
when(myHttpResponse.getEntity().getContent()).thenReturn(new ReaderInputStream(new StringReader(""), Charset.forName("UTF-8")));
IGenericClient client = myCtx.newRestfulGenericClient("http://example.com/fhir");
int count = 0;
client.update().resource(myCtx.newXmlParser().encodeResourceToString(p1)).withId("1").execute();
assertEquals(1, capt.getAllValues().get(count).getHeaders(Constants.HEADER_CONTENT_TYPE).length);
assertEquals(EncodingEnum.XML.getResourceContentType(), capt.getAllValues().get(count).getFirstHeader(Constants.HEADER_CONTENT_TYPE).getValue());
assertThat(extractBody(capt, count), containsString("value=\"John\""));
count++;
client.update().resource(myCtx.newJsonParser().encodeResourceToString(p1)).withId("1").execute();
assertEquals(1, capt.getAllValues().get(count).getHeaders(Constants.HEADER_CONTENT_TYPE).length);
assertEquals(EncodingEnum.JSON.getResourceContentType(), capt.getAllValues().get(count).getFirstHeader(Constants.HEADER_CONTENT_TYPE).getValue());
assertThat(extractBody(capt, count), containsString("[\"John\"]"));
count++;
/*
* e.g. Now try with reversed encoding (provide a string that's in JSON and ask the client to use XML)
*/
client.update().resource(myCtx.newXmlParser().encodeResourceToString(p1)).withId("1").encodedJson().execute();
assertEquals(1, capt.getAllValues().get(count).getHeaders(Constants.HEADER_CONTENT_TYPE).length);
assertEquals(EncodingEnum.JSON.getResourceContentType(), capt.getAllValues().get(count).getFirstHeader(Constants.HEADER_CONTENT_TYPE).getValue());
assertThat(extractBody(capt, count), containsString("[\"John\"]"));
count++;
client.update().resource(myCtx.newJsonParser().encodeResourceToString(p1)).withId("1").encodedXml().execute();
assertEquals(1, capt.getAllValues().get(count).getHeaders(Constants.HEADER_CONTENT_TYPE).length);
assertEquals(EncodingEnum.XML.getResourceContentType(), capt.getAllValues().get(count).getFirstHeader(Constants.HEADER_CONTENT_TYPE).getValue());
assertThat(extractBody(capt, count), containsString("value=\"John\""));
count++;
}
@Test
public void testCreateWithTagNonFluent() throws Exception {
@ -338,6 +251,34 @@ public class GenericClientTest {
assertEquals("urn:happytag; label=\"This is a happy resource\"; scheme=\"http://hl7.org/fhir/tag\"", catH.getValue());
}
/**
* Test for issue #60
*/
@Test
public void testCreateWithUtf8Characters() throws Exception {
String name = "測試醫院";
Organization org = new Organization();
org.setName(name);
org.addIdentifier("urn:system", "testCreateWithUtf8Characters_01");
ArgumentCaptor<HttpUriRequest> capt = ArgumentCaptor.forClass(HttpUriRequest.class);
when(myHttpClient.execute(capt.capture())).thenReturn(myHttpResponse);
when(myHttpResponse.getStatusLine()).thenReturn(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), 201, "OK"));
when(myHttpResponse.getAllHeaders()).thenReturn(new Header[] { new BasicHeader(Constants.HEADER_LOCATION, "/Patient/44/_history/22") });
when(myHttpResponse.getEntity().getContentType()).thenReturn(new BasicHeader("content-type", Constants.CT_FHIR_XML + "; charset=UTF-8"));
when(myHttpResponse.getEntity().getContent()).thenReturn(new ReaderInputStream(new StringReader(""), Charset.forName("UTF-8")));
IGenericClient client = myCtx.newRestfulGenericClient("http://example.com/fhir");
int count = 0;
client.create().resource(org).prettyPrint().encodedXml().execute();
assertEquals(1, capt.getAllValues().get(count).getHeaders(Constants.HEADER_CONTENT_TYPE).length);
assertEquals(EncodingEnum.XML.getResourceContentType() + Constants.HEADER_SUFFIX_CT_UTF_8, capt.getAllValues().get(count).getFirstHeader(Constants.HEADER_CONTENT_TYPE).getValue());
assertThat(extractBody(capt, count), containsString("<name value=\"測試醫院\"/>"));
count++;
}
@Test
public void testDelete() throws Exception {
OperationOutcome oo = new OperationOutcome();
@ -472,36 +413,6 @@ public class GenericClientTest {
}
@Test
public void testVReadWithAbsoluteUrl() throws Exception {
String msg = getResourceResult();
ArgumentCaptor<HttpUriRequest> capt = ArgumentCaptor.forClass(HttpUriRequest.class);
when(myHttpClient.execute(capt.capture())).thenReturn(myHttpResponse);
when(myHttpResponse.getStatusLine()).thenReturn(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), 200, "OK"));
when(myHttpResponse.getEntity().getContentType()).thenReturn(new BasicHeader("content-type", Constants.CT_FHIR_XML + "; charset=UTF-8"));
when(myHttpResponse.getEntity().getContent()).thenReturn(new ReaderInputStream(new StringReader(msg), Charset.forName("UTF-8")));
Header[] headers = new Header[] { new BasicHeader(Constants.HEADER_LAST_MODIFIED, "Wed, 15 Nov 1995 04:58:08 GMT"),
new BasicHeader(Constants.HEADER_CONTENT_LOCATION, "http://foo.com/Patient/123/_history/2333"),
new BasicHeader(Constants.HEADER_CATEGORY, "http://foo/tagdefinition.html; scheme=\"http://hl7.org/fhir/tag\"; label=\"Some tag\"") };
when(myHttpResponse.getAllHeaders()).thenReturn(headers);
IGenericClient client = myCtx.newRestfulGenericClient("http://example.com/fhir");
Patient response = client.vread(Patient.class, new IdDt("http://somebase.com/path/to/base/Patient/1234/_history/2222"));
assertThat(response.getNameFirstRep().getFamilyAsSingleString(), StringContains.containsString("Cardinal"));
assertEquals("http://somebase.com/path/to/base/Patient/1234/_history/2222", capt.getAllValues().get(0).getURI().toString());
try {
client.vread(Patient.class, new IdDt("http://somebase.com/path/to/base/Patient/1234"));
fail();
} catch (IllegalArgumentException e) {
assertThat(e.getMessage(), containsString("No version specified in URL"));
}
}
@SuppressWarnings("unused")
@Test
public void testSearchAllResources() throws Exception {
@ -527,6 +438,80 @@ public class GenericClientTest {
}
@SuppressWarnings("unused")
@Test
public void testSearchAutomaticallyUsesPost() throws Exception {
String msg = getPatientFeedWithOneResult();
ArgumentCaptor<HttpUriRequest> capt = ArgumentCaptor.forClass(HttpUriRequest.class);
when(myHttpClient.execute(capt.capture())).thenReturn(myHttpResponse);
when(myHttpResponse.getStatusLine()).thenReturn(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), 200, "OK"));
when(myHttpResponse.getEntity().getContentType()).thenReturn(new BasicHeader("content-type", Constants.CT_FHIR_XML + "; charset=UTF-8"));
when(myHttpResponse.getEntity().getContent()).thenReturn(new ReaderInputStream(new StringReader(msg), Charset.forName("UTF-8")));
IGenericClient client = myCtx.newRestfulGenericClient("http://example.com/fhir");
String longValue = StringUtils.leftPad("", 20000, 'B');
//@formatter:off
Bundle response = client.search()
.forResource("Patient")
.where(Patient.NAME.matches().value(longValue))
.execute();
//@formatter:on
assertEquals("http://example.com/fhir/Patient/_search", capt.getValue().getURI().toString());
HttpEntityEnclosingRequestBase enc = (HttpEntityEnclosingRequestBase) capt.getValue();
UrlEncodedFormEntity ent = (UrlEncodedFormEntity) enc.getEntity();
String string = IOUtils.toString(ent.getContent());
ourLog.info(string);
assertEquals("name=" + longValue, string);
}
@Test
public void testSearchByCompartment() throws Exception {
String msg = getPatientFeedWithOneResult();
ArgumentCaptor<HttpUriRequest> capt = ArgumentCaptor.forClass(HttpUriRequest.class);
when(myHttpResponse.getStatusLine()).thenReturn(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), 200, "OK"));
when(myHttpResponse.getEntity().getContentType()).thenReturn(new BasicHeader("content-type", Constants.CT_FHIR_XML + "; charset=UTF-8"));
when(myHttpResponse.getEntity().getContent()).thenReturn(new ReaderInputStream(new StringReader(msg), Charset.forName("UTF-8")));
when(myHttpClient.execute(capt.capture())).thenReturn(myHttpResponse);
IGenericClient client = myCtx.newRestfulGenericClient("http://foo");
//@formatter:off
Bundle response = client
.search()
.forResource(Patient.class)
.withIdAndCompartment("123", "fooCompartment")
.where(Patient.BIRTHDATE.afterOrEquals().day("2011-01-02"))
.execute();
//@formatter:on
assertEquals("http://foo/Patient/123/fooCompartment?birthdate=%3E%3D2011-01-02", capt.getValue().getURI().toString());
assertEquals("PRP1660", response.getResources(Patient.class).get(0).getIdentifier().get(0).getValue().getValue());
try {
//@formatter:off
client
.search()
.forResource(Patient.class)
.withIdAndCompartment("", "fooCompartment")
.where(Patient.BIRTHDATE.afterOrEquals().day("2011-01-02"))
.execute();
//@formatter:on
fail();
} catch (InvalidRequestException e) {
assertThat(e.toString(), containsString("null or empty for compartment"));
}
}
@SuppressWarnings("unused")
@Test
public void testSearchByComposite() throws Exception {
@ -555,32 +540,6 @@ public class GenericClientTest {
}
@SuppressWarnings("unused")
@Test
public void testSearchWithClientEncodingAndPrettyPrintConfig() throws Exception {
String msg = getPatientFeedWithOneResult();
ArgumentCaptor<HttpUriRequest> capt = ArgumentCaptor.forClass(HttpUriRequest.class);
when(myHttpClient.execute(capt.capture())).thenReturn(myHttpResponse);
when(myHttpResponse.getStatusLine()).thenReturn(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), 200, "OK"));
when(myHttpResponse.getEntity().getContentType()).thenReturn(new BasicHeader("content-type", Constants.CT_FHIR_XML + "; charset=UTF-8"));
when(myHttpResponse.getEntity().getContent()).thenReturn(new ReaderInputStream(new StringReader(msg), Charset.forName("UTF-8")));
GenericClient client = (GenericClient) myCtx.newRestfulGenericClient("http://example.com/fhir");
client.setPrettyPrint(true);
client.setEncoding(EncodingEnum.JSON);
//@formatter:off
Bundle response = client.search()
.forResource(Patient.class)
.execute();
//@formatter:on
assertEquals("http://example.com/fhir/Patient?_format=json&_pretty=true", capt.getValue().getURI().toString());
}
@SuppressWarnings("unused")
@Test
public void testSearchByDate() throws Exception {
@ -614,55 +573,6 @@ public class GenericClientTest {
}
@Test
public void testSearchWithAbsoluteUrl() throws Exception {
String msg = getPatientFeedWithOneResult();
ArgumentCaptor<HttpUriRequest> capt = ArgumentCaptor.forClass(HttpUriRequest.class);
when(myHttpClient.execute(capt.capture())).thenReturn(myHttpResponse);
when(myHttpResponse.getStatusLine()).thenReturn(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), 200, "OK"));
when(myHttpResponse.getEntity().getContentType()).thenReturn(new BasicHeader("content-type", Constants.CT_FHIR_XML + "; charset=UTF-8"));
when(myHttpResponse.getEntity().getContent()).thenReturn(new ReaderInputStream(new StringReader(msg), Charset.forName("UTF-8")));
IGenericClient client = myCtx.newRestfulGenericClient("http://example.com/fhir");
Bundle response = client
.search(new UriDt(
"http://example.com/fhir/Patient?birthdate=%3C%3D2012-01-22&birthdate=%3E2011-01-01&_include=Patient.managingOrganization&_sort%3Aasc=birthdate&_sort%3Adesc=name&_count=123&_format=json"));
assertEquals(
"http://example.com/fhir/Patient?birthdate=%3C%3D2012-01-22&birthdate=%3E2011-01-01&_include=Patient.managingOrganization&_sort%3Aasc=birthdate&_sort%3Adesc=name&_count=123&_format=json",
capt.getValue().getURI().toString());
assertEquals(1, response.size());
}
@Test
public void testSearchWithAbsoluteUrlAndType() throws Exception {
String msg = getPatientFeedWithOneResult();
ArgumentCaptor<HttpUriRequest> capt = ArgumentCaptor.forClass(HttpUriRequest.class);
when(myHttpClient.execute(capt.capture())).thenReturn(myHttpResponse);
when(myHttpResponse.getStatusLine()).thenReturn(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), 200, "OK"));
when(myHttpResponse.getEntity().getContentType()).thenReturn(new BasicHeader("content-type", Constants.CT_FHIR_XML + "; charset=UTF-8"));
when(myHttpResponse.getEntity().getContent()).thenReturn(new ReaderInputStream(new StringReader(msg), Charset.forName("UTF-8")));
IGenericClient client = myCtx.newRestfulGenericClient("http://example.com/fhir");
Bundle response = client
.search(Patient.class,
new UriDt(
"http://example.com/fhir/Patient?birthdate=%3C%3D2012-01-22&birthdate=%3E2011-01-01&_include=Patient.managingOrganization&_sort%3Aasc=birthdate&_sort%3Adesc=name&_count=123&_format=json"));
assertEquals(
"http://example.com/fhir/Patient?birthdate=%3C%3D2012-01-22&birthdate=%3E2011-01-01&_include=Patient.managingOrganization&_sort%3Aasc=birthdate&_sort%3Adesc=name&_count=123&_format=json",
capt.getValue().getURI().toString());
assertEquals(1, response.size());
}
@SuppressWarnings("unused")
@Test
public void testSearchByNumberExact() throws Exception {
@ -868,6 +778,31 @@ public class GenericClientTest {
}
@SuppressWarnings("unused")
@Test
public void testSearchUsingGetSearch() throws Exception {
String msg = getPatientFeedWithOneResult();
ArgumentCaptor<HttpUriRequest> capt = ArgumentCaptor.forClass(HttpUriRequest.class);
when(myHttpClient.execute(capt.capture())).thenReturn(myHttpResponse);
when(myHttpResponse.getStatusLine()).thenReturn(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), 200, "OK"));
when(myHttpResponse.getEntity().getContentType()).thenReturn(new BasicHeader("content-type", Constants.CT_FHIR_XML + "; charset=UTF-8"));
when(myHttpResponse.getEntity().getContent()).thenReturn(new ReaderInputStream(new StringReader(msg), Charset.forName("UTF-8")));
IGenericClient client = myCtx.newRestfulGenericClient("http://example.com/fhir");
//@formatter:off
Bundle response = client.search()
.forResource("Patient")
.where(Patient.NAME.matches().value("james"))
.usingStyle(SearchStyleEnum.GET_WITH_SEARCH)
.execute();
//@formatter:on
assertEquals("http://example.com/fhir/Patient/_search?name=james", capt.getValue().getURI().toString());
}
@SuppressWarnings("unused")
@Test
public void testSearchUsingPost() throws Exception {
@ -899,9 +834,8 @@ public class GenericClientTest {
assertEquals("name=james", string);
}
@SuppressWarnings("unused")
@Test
public void testSearchAutomaticallyUsesPost() throws Exception {
public void testSearchWithAbsoluteUrl() throws Exception {
String msg = getPatientFeedWithOneResult();
@ -913,27 +847,45 @@ public class GenericClientTest {
IGenericClient client = myCtx.newRestfulGenericClient("http://example.com/fhir");
String longValue = StringUtils.leftPad("", 20000, 'B');
Bundle response = client
.search(new UriDt(
"http://example.com/fhir/Patient?birthdate=%3C%3D2012-01-22&birthdate=%3E2011-01-01&_include=Patient.managingOrganization&_sort%3Aasc=birthdate&_sort%3Adesc=name&_count=123&_format=json"));
//@formatter:off
Bundle response = client.search()
.forResource("Patient")
.where(Patient.NAME.matches().value(longValue))
.execute();
//@formatter:on
assertEquals(
"http://example.com/fhir/Patient?birthdate=%3C%3D2012-01-22&birthdate=%3E2011-01-01&_include=Patient.managingOrganization&_sort%3Aasc=birthdate&_sort%3Adesc=name&_count=123&_format=json",
capt.getValue().getURI().toString());
assertEquals("http://example.com/fhir/Patient/_search", capt.getValue().getURI().toString());
assertEquals(1, response.size());
}
HttpEntityEnclosingRequestBase enc = (HttpEntityEnclosingRequestBase) capt.getValue();
UrlEncodedFormEntity ent = (UrlEncodedFormEntity) enc.getEntity();
String string = IOUtils.toString(ent.getContent());
ourLog.info(string);
assertEquals("name=" + longValue, string);
@Test
public void testSearchWithAbsoluteUrlAndType() throws Exception {
String msg = getPatientFeedWithOneResult();
ArgumentCaptor<HttpUriRequest> capt = ArgumentCaptor.forClass(HttpUriRequest.class);
when(myHttpClient.execute(capt.capture())).thenReturn(myHttpResponse);
when(myHttpResponse.getStatusLine()).thenReturn(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), 200, "OK"));
when(myHttpResponse.getEntity().getContentType()).thenReturn(new BasicHeader("content-type", Constants.CT_FHIR_XML + "; charset=UTF-8"));
when(myHttpResponse.getEntity().getContent()).thenReturn(new ReaderInputStream(new StringReader(msg), Charset.forName("UTF-8")));
IGenericClient client = myCtx.newRestfulGenericClient("http://example.com/fhir");
Bundle response = client
.search(Patient.class,
new UriDt(
"http://example.com/fhir/Patient?birthdate=%3C%3D2012-01-22&birthdate=%3E2011-01-01&_include=Patient.managingOrganization&_sort%3Aasc=birthdate&_sort%3Adesc=name&_count=123&_format=json"));
assertEquals(
"http://example.com/fhir/Patient?birthdate=%3C%3D2012-01-22&birthdate=%3E2011-01-01&_include=Patient.managingOrganization&_sort%3Aasc=birthdate&_sort%3Adesc=name&_count=123&_format=json",
capt.getValue().getURI().toString());
assertEquals(1, response.size());
}
@SuppressWarnings("unused")
@Test
public void testSearchUsingGetSearch() throws Exception {
public void testSearchWithClientEncodingAndPrettyPrintConfig() throws Exception {
String msg = getPatientFeedWithOneResult();
@ -943,17 +895,18 @@ public class GenericClientTest {
when(myHttpResponse.getEntity().getContentType()).thenReturn(new BasicHeader("content-type", Constants.CT_FHIR_XML + "; charset=UTF-8"));
when(myHttpResponse.getEntity().getContent()).thenReturn(new ReaderInputStream(new StringReader(msg), Charset.forName("UTF-8")));
IGenericClient client = myCtx.newRestfulGenericClient("http://example.com/fhir");
GenericClient client = (GenericClient) myCtx.newRestfulGenericClient("http://example.com/fhir");
client.setPrettyPrint(true);
client.setEncoding(EncodingEnum.JSON);
//@formatter:off
Bundle response = client.search()
.forResource("Patient")
.where(Patient.NAME.matches().value("james"))
.usingStyle(SearchStyleEnum.GET_WITH_SEARCH)
.forResource(Patient.class)
.execute();
//@formatter:on
assertEquals("http://example.com/fhir/Patient/_search?name=james", capt.getValue().getURI().toString());
assertEquals("http://example.com/fhir/Patient?_format=json&_pretty=true", capt.getValue().getURI().toString());
}
@SuppressWarnings("unused")
@ -1126,6 +1079,82 @@ public class GenericClientTest {
}
@Test
public void testUpdateWithStringAutoDetectsEncoding() throws Exception {
Patient p1 = new Patient();
p1.addIdentifier("foo:bar", "12345");
p1.addName().addFamily("Smith").addGiven("John");
ArgumentCaptor<HttpUriRequest> capt = ArgumentCaptor.forClass(HttpUriRequest.class);
when(myHttpClient.execute(capt.capture())).thenReturn(myHttpResponse);
when(myHttpResponse.getStatusLine()).thenReturn(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), 201, "OK"));
when(myHttpResponse.getAllHeaders()).thenReturn(new Header[] { new BasicHeader(Constants.HEADER_LOCATION, "/Patient/44/_history/22") });
when(myHttpResponse.getEntity().getContentType()).thenReturn(new BasicHeader("content-type", Constants.CT_FHIR_XML + "; charset=UTF-8"));
when(myHttpResponse.getEntity().getContent()).thenReturn(new ReaderInputStream(new StringReader(""), Charset.forName("UTF-8")));
IGenericClient client = myCtx.newRestfulGenericClient("http://example.com/fhir");
int count = 0;
client.update().resource(myCtx.newXmlParser().encodeResourceToString(p1)).withId("1").execute();
assertEquals(1, capt.getAllValues().get(count).getHeaders(Constants.HEADER_CONTENT_TYPE).length);
assertEquals(EncodingEnum.XML.getResourceContentType(), capt.getAllValues().get(count).getFirstHeader(Constants.HEADER_CONTENT_TYPE).getValue());
assertThat(extractBody(capt, count), containsString("value=\"John\""));
count++;
client.update().resource(myCtx.newJsonParser().encodeResourceToString(p1)).withId("1").execute();
assertEquals(1, capt.getAllValues().get(count).getHeaders(Constants.HEADER_CONTENT_TYPE).length);
assertEquals(EncodingEnum.JSON.getResourceContentType(), capt.getAllValues().get(count).getFirstHeader(Constants.HEADER_CONTENT_TYPE).getValue());
assertThat(extractBody(capt, count), containsString("[\"John\"]"));
count++;
/*
* e.g. Now try with reversed encoding (provide a string that's in JSON and ask the client to use XML)
*/
client.update().resource(myCtx.newXmlParser().encodeResourceToString(p1)).withId("1").encodedJson().execute();
assertEquals(1, capt.getAllValues().get(count).getHeaders(Constants.HEADER_CONTENT_TYPE).length);
assertEquals(EncodingEnum.JSON.getResourceContentType(), capt.getAllValues().get(count).getFirstHeader(Constants.HEADER_CONTENT_TYPE).getValue());
assertThat(extractBody(capt, count), containsString("[\"John\"]"));
count++;
client.update().resource(myCtx.newJsonParser().encodeResourceToString(p1)).withId("1").encodedXml().execute();
assertEquals(1, capt.getAllValues().get(count).getHeaders(Constants.HEADER_CONTENT_TYPE).length);
assertEquals(EncodingEnum.XML.getResourceContentType(), capt.getAllValues().get(count).getFirstHeader(Constants.HEADER_CONTENT_TYPE).getValue());
assertThat(extractBody(capt, count), containsString("value=\"John\""));
count++;
}
@Test
public void testVReadWithAbsoluteUrl() throws Exception {
String msg = getResourceResult();
ArgumentCaptor<HttpUriRequest> capt = ArgumentCaptor.forClass(HttpUriRequest.class);
when(myHttpClient.execute(capt.capture())).thenReturn(myHttpResponse);
when(myHttpResponse.getStatusLine()).thenReturn(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), 200, "OK"));
when(myHttpResponse.getEntity().getContentType()).thenReturn(new BasicHeader("content-type", Constants.CT_FHIR_XML + "; charset=UTF-8"));
when(myHttpResponse.getEntity().getContent()).thenReturn(new ReaderInputStream(new StringReader(msg), Charset.forName("UTF-8")));
Header[] headers = new Header[] { new BasicHeader(Constants.HEADER_LAST_MODIFIED, "Wed, 15 Nov 1995 04:58:08 GMT"),
new BasicHeader(Constants.HEADER_CONTENT_LOCATION, "http://foo.com/Patient/123/_history/2333"),
new BasicHeader(Constants.HEADER_CATEGORY, "http://foo/tagdefinition.html; scheme=\"http://hl7.org/fhir/tag\"; label=\"Some tag\"") };
when(myHttpResponse.getAllHeaders()).thenReturn(headers);
IGenericClient client = myCtx.newRestfulGenericClient("http://example.com/fhir");
Patient response = client.vread(Patient.class, new IdDt("http://somebase.com/path/to/base/Patient/1234/_history/2222"));
assertThat(response.getNameFirstRep().getFamilyAsSingleString(), StringContains.containsString("Cardinal"));
assertEquals("http://somebase.com/path/to/base/Patient/1234/_history/2222", capt.getAllValues().get(0).getURI().toString());
try {
client.vread(Patient.class, new IdDt("http://somebase.com/path/to/base/Patient/1234"));
fail();
} catch (IllegalArgumentException e) {
assertThat(e.getMessage(), containsString("No version specified in URL"));
}
}
@BeforeClass
public static void beforeClass() {
myCtx = new FhirContext();

View File

@ -1,2 +1 @@
/bin/
/target/

View File

@ -33,5 +33,6 @@
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry combineaccessrules="false" kind="src" path="/hapi-fhir-structures-dev"/>
<classpathentry kind="output" path="target/classes"/>
</classpath>

View File

@ -0,0 +1,25 @@
package ca.uhn.fhir.model.dstu.composite;
/*
* #%L
* HAPI FHIR Structures - DEV (FHIR Latest)
* %%
* Copyright (C) 2014 University Health Network
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* #L%
*/
public class CountDt extends QuantityDt {
}

View File

@ -0,0 +1,25 @@
package ca.uhn.fhir.model.dstu.composite;
/*
* #%L
* HAPI FHIR Structures - DEV (FHIR Latest)
* %%
* Copyright (C) 2014 University Health Network
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* #L%
*/
public class DistanceDt extends QuantityDt {
}

View File

@ -0,0 +1,25 @@
package ca.uhn.fhir.model.dstu.composite;
/*
* #%L
* HAPI FHIR Structures - DEV (FHIR Latest)
* %%
* Copyright (C) 2014 University Health Network
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* #L%
*/
public class MoneyDt extends QuantityDt {
}

View File

@ -221,8 +221,10 @@ public class TinderStructuresMojo extends AbstractMojo {
String dtOutputDir = "target/generated-sources/tinder/ca/uhn/fhir/model/dev/composite";
ResourceGeneratorUsingSpreadsheet rp = new ResourceGeneratorUsingSpreadsheet("dev", ".");
rp.setBaseResourceNames(Arrays.asList("conformance", "referralrequest", "patient","practitioner","encounter",
"organization","location","relatedperson","appointment","slot","order","availability","device", "valueset"));
rp.setBaseResourceNames(Arrays.asList("contract", "valueset", "organization", "location"
// , "observation", "conformance", "referralrequest", "patient","practitioner","encounter",
// "organization","location","relatedperson","appointment","slot","order","availability","device", "valueset"
));
rp.parse();
rp.bindValueSets(vsp);
rp.markResourcesForImports();

View File

@ -52,6 +52,8 @@ public abstract class BaseElement {
// if (theElem.getDeclaringClassNameComplete()==null) {
theElem.setDeclaringClassNameComplete(getDeclaringClassNameCompleteForChildren());
// }
// clearTypes();
}
public String getBinding() {

View File

@ -3,19 +3,20 @@ package ca.uhn.fhir.tinder.model;
import java.util.ArrayList;
import java.util.List;
import ca.uhn.fhir.tinder.model.SearchParameter.Include;
import edu.emory.mathcs.backport.java.util.Collections;
public abstract class BaseRootType extends BaseElement {
private String myId;
private String myProfile;
private List<SearchParameter> mySearchParameters;
private List<Include> myIncludes = new ArrayList<SearchParameter.Include>();
public String getId() {
return myId;
}
public String getProfile() {
return myProfile;
}
@ -59,9 +60,22 @@ public abstract class BaseRootType extends BaseElement {
}
return retVal;
}
public void addSearchParameter(SearchParameter theParam) {
getSearchParameters();
mySearchParameters.add(theParam);
List<Include> includes = theParam.getPaths();
for (Include include : includes) {
if (myIncludes.contains(include)==false) {
myIncludes.add(include);
}
}
}
public List<SearchParameter.Include> getIncludes() {
Collections.sort(myIncludes);
return myIncludes;
}
}

View File

@ -1,6 +1,8 @@
package ca.uhn.fhir.tinder.model;
import java.lang.reflect.GenericArrayType;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
@ -176,7 +178,12 @@ public abstract class Child extends BaseElement {
}
ParameterizedType type = (ParameterizedType) clazz.getGenericSuperclass();
Class<?> rawType = (Class<?>) type.getActualTypeArguments()[0];
Type type2 = type.getActualTypeArguments()[0];
if (type2 instanceof GenericArrayType) {
String arrayType = ((GenericArrayType) type2).getGenericComponentType().toString();
return arrayType + "[]";
}
Class<?> rawType = (Class<?>) type2;
return rawType.getSimpleName();
}

View File

@ -4,6 +4,10 @@ import java.util.List;
public class ResourceBlock extends Child {
public ResourceBlock() {
super();
}
private String myForcedClassName;
@Override

View File

@ -21,6 +21,20 @@ public class SearchParameter {
}
public List<String> getCompositeOf() {
if (myCompositeOf == null) {
myCompositeOf = new ArrayList<String>();
}
return myCompositeOf;
}
public List<String> getCompositeTypes() {
if (myCompositeTypes == null) {
myCompositeTypes = new ArrayList<String>();
}
return myCompositeTypes;
}
public String getConstantName() {
return "SP_" + myName.toUpperCase().replace("_[X]", "_X").replace("-[X]", "_X").replace('-', '_').replace("!", "");
}
@ -72,6 +86,14 @@ public class SearchParameter {
return WordUtils.capitalize(myType);
}
public void setCompositeOf(List<String> theCompositeOf) {
myCompositeOf = theCompositeOf;
}
public void setCompositeTypes(List<String> theCompositeTypes) {
myCompositeTypes = theCompositeTypes;
}
public void setDescription(String theDescription) {
myDescription = theDescription;
}
@ -96,13 +118,38 @@ public class SearchParameter {
myType = theType;
}
public static class Include {
public static class Include implements Comparable<Include>{
private String myPath;
public Include(String thePath) {
myPath = thePath;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((myPath == null) ? 0 : myPath.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Include other = (Include) obj;
if (myPath == null) {
if (other.myPath != null)
return false;
} else if (!myPath.equals(other.myPath))
return false;
return true;
}
public String getIncludeName() {
String retVal = myPath;
retVal = retVal.substring(retVal.indexOf('.') + 1);
@ -116,28 +163,11 @@ public class SearchParameter {
return myPath;
}
}
public void setCompositeOf(List<String> theCompositeOf) {
myCompositeOf = theCompositeOf;
}
public List<String> getCompositeOf() {
if (myCompositeOf == null) {
myCompositeOf = new ArrayList<String>();
}
return myCompositeOf;
}
public void setCompositeTypes(List<String> theCompositeTypes) {
myCompositeTypes = theCompositeTypes;
}
public List<String> getCompositeTypes() {
if (myCompositeTypes == null) {
myCompositeTypes = new ArrayList<String>();
}
return myCompositeTypes;
@Override
public int compareTo(Include theO) {
return myPath.compareTo(theO.myPath);
}
}
}

View File

@ -209,6 +209,9 @@ public abstract class BaseStructureParser {
if ("Binary".equals(theNextType)) {
return Binary.class.getCanonicalName();
}
// if ("BoundCodeableConceptDt".equals(theNextType)) {
// return "ca.uhn.fhir.model." + myVersion + ".composite.BoundCodeableConceptDt";
// }
// QuantityCompararatorEnum
// QuantityComparatorEnum
@ -423,6 +426,7 @@ public abstract class BaseStructureParser {
ctx.put("searchParams", (theResource.getSearchParameters()));
ctx.put("searchParamsReference", (theResource.getSearchParametersResource()));
ctx.put("searchParamsWithoutComposite", (theResource.getSearchParametersWithoutComposite()));
ctx.put("includes", (theResource.getIncludes()));
VelocityEngine v = new VelocityEngine();
v.setProperty("resource.loader", "cp");

View File

@ -50,16 +50,28 @@ public abstract class BaseStructureSpreadsheetParser extends BaseStructureParser
int index = 0;
for (InputStream nextInputStream : getInputStreams()) {
ourLog.info("Reading spreadsheet file {}", getInputStreamNames().get(index));
String spreadsheetName = getInputStreamNames().get(index);
ourLog.info("Reading spreadsheet file {}", spreadsheetName);
Document file;
try {
file = XMLUtils.parse(nextInputStream, false);
} catch (Exception e) {
throw new Exception("Failed during reading: " + getInputStreamNames().get(index), e);
throw new Exception("Failed during reading: " + spreadsheetName, e);
}
Element dataElementsSheet = null;
for (int i = 0; i < file.getElementsByTagName("Worksheet").getLength() && dataElementsSheet == null; i++) {
dataElementsSheet = (Element) file.getElementsByTagName("Worksheet").item(i);
if (!"Data Elements".equals(dataElementsSheet.getAttributeNS("urn:schemas-microsoft-com:office:spreadsheet", "Name"))) {
dataElementsSheet = null;
}
}
if (dataElementsSheet == null) {
throw new Exception("Failed to find worksheet with name 'Data Elements' in spreadsheet: " + spreadsheetName);
}
Element dataElementsSheet = (Element) file.getElementsByTagName("Worksheet").item(0);
NodeList tableList = dataElementsSheet.getElementsByTagName("Table");
Element table = (Element) tableList.item(0);
@ -99,6 +111,16 @@ public abstract class BaseStructureSpreadsheetParser extends BaseStructureParser
String type = cellValue(nextRow, myColType);
if (i < rows.getLength() - 1) {
Element followingRow = (Element) rows.item(i + 1);
if (followingRow != null) {
String followingName = cellValue(followingRow, 0);
if (followingName != null && followingName.startsWith(name + ".")) {
type = "";
}
}
}
Child elem;
if (StringUtils.isBlank(type) || type.startsWith("=")) {
elem = new ResourceBlock();
@ -128,6 +150,7 @@ public abstract class BaseStructureSpreadsheetParser extends BaseStructureParser
}
pathToResourceTypes.put(name, elem.getType());
}
for (SearchParameter nextParam : resource.getSearchParameters()) {
@ -150,7 +173,6 @@ public abstract class BaseStructureSpreadsheetParser extends BaseStructureParser
index++;
}
ourLog.info("Parsed {} spreadsheet structures", getResources().size());
}
@ -247,6 +269,15 @@ public abstract class BaseStructureSpreadsheetParser extends BaseStructureParser
}
}
/*
* Paths have changed in DSTU2
*/
for (SearchParameter nextParam : theResource.getSearchParameters()) {
if (nextPart.equals("value[x]") && nextParam.getName().startsWith("value-")) {
part.add(nextParam);
}
}
if (part.isEmpty()) {
throw new MojoExecutionException("Composite param " + nextCompositeParam.getName() + " has path that doesn't seem to correspond to any other params: " + nextPart);
}
@ -270,7 +301,6 @@ public abstract class BaseStructureSpreadsheetParser extends BaseStructureParser
}
}
}
}
}

View File

@ -97,9 +97,10 @@ public class DatatypeGeneratorUsingSpreadsheet extends BaseStructureSpreadsheetP
}
if (!myVersion.equals("dstu")) {
retVal.add(("/dt/" + myVersion + "/reference.xml"));
retVal.add(("/dt/" + myVersion + "/attachment.xml"));
retVal.add(("/dt/" + myVersion + "/contactpoint.xml"));
retVal.add(("/dt/" + myVersion + "/elementdefinition.xml"));
retVal.add(("/dt/" + myVersion + "/reference.xml"));
retVal.add(("/dt/" + myVersion + "/timing.xml"));
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -7,10 +7,10 @@
xmlns:html="http://www.w3.org/TR/REC-html40">
<DocumentProperties xmlns="urn:schemas-microsoft-com:office:office">
<Author>Grahame</Author>
<LastAuthor>Grahame</LastAuthor>
<LastAuthor>Lloyd</LastAuthor>
<Created>2012-03-21T19:16:26Z</Created>
<LastSaved>2014-10-14T21:58:56Z</LastSaved>
<Version>12.00</Version>
<LastSaved>2014-11-12T03:16:15Z</LastSaved>
<Version>14.00</Version>
</DocumentProperties>
<OfficeDocumentSettings xmlns="urn:schemas-microsoft-com:office:office">
<AllowPNG/>
@ -20,7 +20,8 @@
<WindowWidth>15270</WindowWidth>
<WindowTopX>630</WindowTopX>
<WindowTopY>780</WindowTopY>
<ActiveSheet>1</ActiveSheet>
<DoNotCalculateBeforeSave/>
<RefModeR1C1/>
<ProtectStructure>False</ProtectStructure>
<ProtectWindows>False</ProtectWindows>
</ExcelWorkbook>
@ -137,7 +138,7 @@
html:Color="#000000">A date, date-time or partial date (e.g. just year or year + month). If hours and minutes are specified, a time zone SHALL be populated. The format is a union of the schema types gYear, gYearMonth, date and dateTime. Seconds may be provided but may also be ignored. </Font><B><Font
html:Color="#000000">Dates SHALL be valid dates.</Font></B></ss:Data></Cell>
<Cell ss:Index="4"><Data ss:Type="String">xs:gYear, xs:gYearMonth, xs:date, xs:dateTime</Data></Cell>
<Cell><Data ss:Type="String" x:Ticked="1">-?[0-9]{4}(-(0[1-9]|1[0-2])(-(0[0-9]|[1-2][0-9]|3[0-1])(T([01][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9](\.[0-9]+)?(Z|(\+|-)((0[0-9]|1[0-3]):[0-5][0-9]|14:00))?)?)?)?</Data></Cell>
<Cell><Data ss:Type="String" x:Ticked="1">-?[0-9]{4}(-(0[1-9]|1[0-2])(-(0[0-9]|[1-2][0-9]|3[0-1])(T([01][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9](\.[0-9]+)?(Z|(\+|-)((0[0-9]|1[0-3]):[0-5][0-9]|14:00)))?)?)?</Data></Cell>
<Cell ss:Index="7"><Data ss:Type="String">TS</Data></Cell>
<Cell><Data ss:Type="String">DTM</Data></Cell>
</Row>
@ -158,11 +159,12 @@
<PageMargins x:Bottom="0.75" x:Left="0.7" x:Right="0.7" x:Top="0.75"/>
</PageSetup>
<Unsynced/>
<Selected/>
<Panes>
<Pane>
<Number>3</Number>
<ActiveRow>8</ActiveRow>
<ActiveCol>7</ActiveCol>
<ActiveRow>9</ActiveRow>
<ActiveCol>4</ActiveCol>
</Pane>
</Panes>
<ProtectObjects>False</ProtectObjects>
@ -176,7 +178,6 @@
<NamedRange ss:Name="dateTime" ss:RefersTo="=Imports!R10C1"/>
<NamedRange ss:Name="id" ss:RefersTo="='String Patterns'!R5C1"/>
<NamedRange ss:Name="oid" ss:RefersTo="='String Patterns'!R3C1"/>
<NamedRange ss:Name="sid" ss:RefersTo="='String Patterns'!#REF!"/>
<NamedRange ss:Name="uuid" ss:RefersTo="='String Patterns'!R4C1"/>
</Names>
<Table ss:ExpandedColumnCount="7" ss:ExpandedRowCount="5" x:FullColumns="1"
@ -218,13 +219,13 @@
<Cell><Data ss:Type="String">xs:anyURI+</Data></Cell>
<Cell><Data ss:Type="String">urn:uuid:[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}</Data></Cell>
</Row>
<Row ss:Height="105">
<Row ss:AutoFitHeight="0" ss:Height="105">
<Cell><Data ss:Type="String">id</Data><NamedCell ss:Name="id"/></Cell>
<Cell><Data ss:Type="String">Any combination of lowercase letters, numerals, &quot;-&quot; and &quot;.&quot;, with a length limit of 36 characters. (This might be an integer, an unprefixed OID, UUID or any other identifier pattern that meets these constraints.) Systems SHALL send ids as lower-case but SHOULD interpret them case-insensitively.</Data></Cell>
<Cell><Data ss:Type="String">RFC 4122</Data></Cell>
<Cell><Data ss:Type="String">string</Data></Cell>
<Cell><Data ss:Type="String">xs:string+</Data></Cell>
<Cell><Data ss:Type="String">[a-z0-9\-\.]{1,36}</Data></Cell>
<Cell><Data ss:Type="String">[A-Za-z0-9\-\.]{1,64}</Data></Cell>
</Row>
</Table>
<WorksheetOptions xmlns="urn:schemas-microsoft-com:office:excel">
@ -240,12 +241,11 @@
<HorizontalResolution>600</HorizontalResolution>
<VerticalResolution>600</VerticalResolution>
</Print>
<Selected/>
<Panes>
<Pane>
<Number>3</Number>
<ActiveRow>6</ActiveRow>
<ActiveCol>1</ActiveCol>
<ActiveRow>4</ActiveRow>
<ActiveCol>4</ActiveCol>
</Pane>
</Panes>
<ProtectObjects>False</ProtectObjects>

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

Some files were not shown because too many files have changed in this diff Show More