diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/method/OperationParameter.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/method/OperationParameter.java index bd3f388c393..65a565fa914 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/method/OperationParameter.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/method/OperationParameter.java @@ -23,6 +23,7 @@ package ca.uhn.fhir.rest.method; import java.lang.reflect.Method; import java.lang.reflect.Modifier; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collection; import java.util.List; import java.util.Map; @@ -82,8 +83,6 @@ public class OperationParameter implements IParameter { myContext = theCtx; } - - protected FhirContext getContext() { return myContext; } @@ -109,22 +108,22 @@ public class OperationParameter implements IParameter { public void initializeTypes(Method theMethod, Class> theOuterCollectionType, Class> theInnerCollectionType, Class theParameterType) { if (getContext().getVersion().getVersion().isRi()) { if (IDatatype.class.isAssignableFrom(theParameterType)) { - throw new ConfigurationException("Incorrect use of type " + theParameterType.getSimpleName() + " as parameter type for method when context is for version " + getContext().getVersion().getVersion().name() + " in method: " + theMethod.toString()); + throw new ConfigurationException("Incorrect use of type " + theParameterType.getSimpleName() + " as parameter type for method when context is for version " + + getContext().getVersion().getVersion().name() + " in method: " + theMethod.toString()); } } - + myParameterType = theParameterType; if (theInnerCollectionType != null) { myInnerCollectionType = CollectionBinder.getInstantiableCollectionType(theInnerCollectionType, myName); } else { myMax = 1; } - + myAllowGet = IPrimitiveType.class.isAssignableFrom(myParameterType) || String.class.equals(myParameterType); - + /* - * The parameter can be of type string for validation methods - This is a bit - * weird. See ValidateDstu2Test. We should probably clean this up.. + * The parameter can be of type string for validation methods - This is a bit weird. See ValidateDstu2Test. We should probably clean this up.. */ if (!myParameterType.equals(IBase.class) && !myParameterType.equals(String.class)) { if (IBaseResource.class.isAssignableFrom(myParameterType) && myParameterType.isInterface()) { @@ -150,7 +149,8 @@ public class OperationParameter implements IParameter { } @Override - public void translateClientArgumentIntoQueryArgument(FhirContext theContext, Object theSourceClientArgument, Map> theTargetQueryArguments, IBaseResource theTargetResource) throws InternalErrorException { + public void translateClientArgumentIntoQueryArgument(FhirContext theContext, Object theSourceClientArgument, Map> theTargetQueryArguments, IBaseResource theTargetResource) + throws InternalErrorException { assert theTargetResource != null; Object sourceClientArgument = theSourceClientArgument; if (sourceClientArgument == null) { @@ -173,7 +173,7 @@ public class OperationParameter implements IParameter { String[] paramValues = theRequest.getParameters().get(myName); if (paramValues != null && paramValues.length > 0) { if (myAllowGet) { - + if (DateRangeParam.class.isAssignableFrom(myParameterType)) { List parameters = new ArrayList(); parameters.add(QualifiedParamList.singleton(paramValues[0])); @@ -184,11 +184,11 @@ public class OperationParameter implements IParameter { dateRangeParam.setValuesAsQueryTokens(parameters); matchingParamValues.add(dateRangeParam); } else if (String.class.isAssignableFrom(myParameterType)) { - + for (String next : paramValues) { matchingParamValues.add(next); } - + } else { for (String nextValue : paramValues) { FhirContext ctx = theRequest.getServer().getFhirContext(); @@ -212,42 +212,51 @@ public class OperationParameter implements IParameter { return null; } - Class wantedResourceType = theMethodBinding.getContext().getResourceDefinition("Parameters").getImplementingClass(); + // Class wantedResourceType = theMethodBinding.getContext().getResourceDefinition("Parameters").getImplementingClass(); + Class wantedResourceType = null; IBaseResource requestContents = ResourceParameter.loadResourceFromRequest(theRequest, theMethodBinding, wantedResourceType); RuntimeResourceDefinition def = ctx.getResourceDefinition(requestContents); + if (def.getName().equals("Parameters")) { - BaseRuntimeChildDefinition paramChild = def.getChildByName("parameter"); - BaseRuntimeElementCompositeDefinition paramChildElem = (BaseRuntimeElementCompositeDefinition) paramChild.getChildByName("parameter"); + BaseRuntimeChildDefinition paramChild = def.getChildByName("parameter"); + BaseRuntimeElementCompositeDefinition paramChildElem = (BaseRuntimeElementCompositeDefinition) paramChild.getChildByName("parameter"); - RuntimeChildPrimitiveDatatypeDefinition nameChild = (RuntimeChildPrimitiveDatatypeDefinition) paramChildElem.getChildByName("name"); - BaseRuntimeChildDefinition valueChild = paramChildElem.getChildByName("value[x]"); - BaseRuntimeChildDefinition resourceChild = paramChildElem.getChildByName("resource"); + RuntimeChildPrimitiveDatatypeDefinition nameChild = (RuntimeChildPrimitiveDatatypeDefinition) paramChildElem.getChildByName("name"); + BaseRuntimeChildDefinition valueChild = paramChildElem.getChildByName("value[x]"); + BaseRuntimeChildDefinition resourceChild = paramChildElem.getChildByName("resource"); - IAccessor paramChildAccessor = paramChild.getAccessor(); - List values = paramChildAccessor.getValues(requestContents); - for (IBase nextParameter : values) { - List nextNames = nameChild.getAccessor().getValues(nextParameter); - if (nextNames != null && nextNames.size() > 0) { - IPrimitiveType nextName = (IPrimitiveType) nextNames.get(0); - if (myName.equals(nextName.getValueAsString())) { + IAccessor paramChildAccessor = paramChild.getAccessor(); + List values = paramChildAccessor.getValues(requestContents); + for (IBase nextParameter : values) { + List nextNames = nameChild.getAccessor().getValues(nextParameter); + if (nextNames != null && nextNames.size() > 0) { + IPrimitiveType nextName = (IPrimitiveType) nextNames.get(0); + if (myName.equals(nextName.getValueAsString())) { - if (myParameterType.isAssignableFrom(nextParameter.getClass())) { - matchingParamValues.add(nextParameter); - } else { - List paramValues = valueChild.getAccessor().getValues(nextParameter); - List paramResources = resourceChild.getAccessor().getValues(nextParameter); - if (paramValues != null && paramValues.size() > 0) { - tryToAddValues(paramValues, matchingParamValues); - } else if (paramResources != null && paramResources.size() > 0) { - tryToAddValues(paramResources, matchingParamValues); + if (myParameterType.isAssignableFrom(nextParameter.getClass())) { + matchingParamValues.add(nextParameter); + } else { + List paramValues = valueChild.getAccessor().getValues(nextParameter); + List paramResources = resourceChild.getAccessor().getValues(nextParameter); + if (paramValues != null && paramValues.size() > 0) { + tryToAddValues(paramValues, matchingParamValues); + } else if (paramResources != null && paramResources.size() > 0) { + tryToAddValues(paramResources, matchingParamValues); + } } - } + } } } - } + } else { + + if (myParameterType.isAssignableFrom(requestContents.getClass())) { + tryToAddValues(Arrays.asList((IBase) requestContents), matchingParamValues); + } + + } } if (matchingParamValues.isEmpty()) { diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/validation/ValidationResult.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/validation/ValidationResult.java index 7b781f8cd13..7503218c34c 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/validation/ValidationResult.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/validation/ValidationResult.java @@ -111,6 +111,11 @@ public class ValidationResult { OperationOutcomeUtil.addIssue(myCtx, oo, severity, next.getMessage(), location, ExceptionHandlingInterceptor.PROCESSING); } + if (myMessages.isEmpty()) { + String message = myCtx.getLocalizer().getMessage(ValidationResult.class, "noIssuesDetected"); + OperationOutcomeUtil.addIssue(myCtx, oo, "information", message, null, "informational"); + } + return oo; } diff --git a/hapi-fhir-base/src/main/resources/ca/uhn/fhir/i18n/hapi-messages.properties b/hapi-fhir-base/src/main/resources/ca/uhn/fhir/i18n/hapi-messages.properties index d48a019215b..356d9211828 100644 --- a/hapi-fhir-base/src/main/resources/ca/uhn/fhir/i18n/hapi-messages.properties +++ b/hapi-fhir-base/src/main/resources/ca/uhn/fhir/i18n/hapi-messages.properties @@ -38,6 +38,7 @@ ca.uhn.fhir.rest.server.RestfulServer.rootRequest=This is the base URL of FHIR s ca.uhn.fhir.validation.ValidationContext.unableToDetermineEncoding=Unable to determine encoding (e.g. XML / JSON) on validation input. Is this a valid FHIR resource body? ca.uhn.fhir.validation.FhirValidator.noPhlocWarningOnStartup=Phloc-schematron library not found on classpath, will not attempt to perform schematron validation ca.uhn.fhir.validation.FhirValidator.noPhlocError=Phloc-schematron library not found on classpath, can not enable perform schematron validation +ca.uhn.fhir.validation.ValidationResult.noIssuesDetected=No issues detected during validation # JPA Messages diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/provider/BaseJpaResourceProviderQuestionnaireResponseDstu21.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/provider/BaseJpaResourceProviderQuestionnaireResponseDstu21.java index f1c75648dec..dc1a25bb7f3 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/provider/BaseJpaResourceProviderQuestionnaireResponseDstu21.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/provider/BaseJpaResourceProviderQuestionnaireResponseDstu21.java @@ -1,5 +1,7 @@ package ca.uhn.fhir.jpa.provider; +import org.hl7.fhir.dstu21.model.QuestionnaireResponse; + /* * #%L * HAPI FHIR JPA Server @@ -20,9 +22,7 @@ package ca.uhn.fhir.jpa.provider; * #L% */ -import ca.uhn.fhir.model.dstu2.resource.QuestionnaireResponse; - -public class BaseJpaResourceProviderQuestionnaireResponseDstu21 extends JpaResourceProviderDstu2 { +public class BaseJpaResourceProviderQuestionnaireResponseDstu21 extends JpaResourceProviderDstu21 { // nothing yet diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/config/Tmp.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/config/Tmp.java new file mode 100644 index 00000000000..04bd323c8c3 --- /dev/null +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/config/Tmp.java @@ -0,0 +1,56 @@ +package ca.uhn.fhir.jpa.config; + +import ca.uhn.fhir.context.FhirContext; +import ca.uhn.fhir.model.dstu2.resource.Bundle; +import ca.uhn.fhir.model.dstu2.resource.Organization; +import ca.uhn.fhir.model.dstu2.resource.Patient; +import ca.uhn.fhir.model.dstu2.valueset.BundleTypeEnum; +import ca.uhn.fhir.model.dstu2.valueset.HTTPVerbEnum; +import ca.uhn.fhir.model.primitive.IdDt; +import ca.uhn.fhir.rest.client.IGenericClient; +import ca.uhn.fhir.rest.client.ServerValidationModeEnum; + +public class Tmp { + + public static void main(String[] args) { + + FhirContext ctx = FhirContext.forDstu2(); + ctx.getRestfulClientFactory().setSocketTimeout(200000); + ctx.getRestfulClientFactory().setServerValidationMode(ServerValidationModeEnum.NEVER); + IGenericClient client = ctx.newRestfulGenericClient("http://localhost:8080/hapi-fhir-jpaserver-example/baseDstu2"); + + Bundle b = new Bundle(); + b.setType(BundleTypeEnum.TRANSACTION); + int resCount = 20; + for (int i = 0; i < (resCount / 2); i++) { + Organization org = new Organization(); + org.setId(IdDt.newRandomUuid()); + org.setName("Random Org " + i); + org.addAddress().addLine("Random Org Line 1"); + org.addIdentifier().setSystem("urn:foo").setValue("some_system" + i); + b.addEntry().setResource(org).getRequest().setMethod(HTTPVerbEnum.POST).setUrl("Organization"); + + Patient patient = new Patient(); + patient.setId(IdDt.newRandomUuid()); + patient.addName().addFamily("Family" + i).addGiven("Gigven " + i); + patient.addAddress().addLine("Random Patient Line 1"); + patient.addIdentifier().setSystem("urn:bar").setValue("some_system" + i); + b.addEntry().setResource(patient).getRequest().setMethod(HTTPVerbEnum.POST).setUrl("Patient"); + } + + int total = 0; + long start = System.currentTimeMillis(); + for (int i = 0; i < 300; i++) { + client.transaction().withBundle(b).execute(); + ourLog.info("" + i); + total += resCount; + } + + long delay = System.currentTimeMillis() - start; + ourLog.info("Wrote {} resources at {}ms / res", total, delay / total); + + //sync 13:57:14.683 [main] INFO ca.uhn.fhir.jpa.config.Tmp - Wrote 6000 resources at 7ms / res + } +private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(Tmp.class); + +} diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/dstu21/ResourceProviderDstu21Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/dstu21/ResourceProviderDstu21Test.java index 3ee3702ea37..b3c70456a64 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/dstu21/ResourceProviderDstu21Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/dstu21/ResourceProviderDstu21Test.java @@ -57,6 +57,7 @@ import org.hl7.fhir.dstu21.model.Encounter; import org.hl7.fhir.dstu21.model.Encounter.EncounterClass; import org.hl7.fhir.dstu21.model.Encounter.EncounterLocationComponent; import org.hl7.fhir.dstu21.model.Encounter.EncounterState; +import org.hl7.fhir.dstu21.model.Enumerations.AdministrativeGender; import org.hl7.fhir.dstu21.model.IdType; import org.hl7.fhir.dstu21.model.ImagingStudy; import org.hl7.fhir.dstu21.model.InstantType; @@ -111,10 +112,10 @@ public class ResourceProviderDstu21Test extends BaseResourceProviderDstu21Test { @Override public void before() throws Exception { super.before(); - + myDaoConfig.setAllowMultipleDelete(true); } - + private void checkParamMissing(String paramName) throws IOException, ClientProtocolException { HttpGet get = new HttpGet(ourServerBase + "/Observation?" + paramName + ":missing=false"); CloseableHttpResponse resp = ourHttpClient.execute(get); @@ -135,7 +136,7 @@ public class ResourceProviderDstu21Test extends BaseResourceProviderDstu21Test { Device dev1 = new Device(); dev1.setManufacturer("Some Manufacturer"); IIdType devId1 = myDeviceDao.create(dev1).getId().toUnqualifiedVersionless(); - + Device dev2 = new Device(); dev2.setManufacturer("Some Manufacturer 2"); myDeviceDao.create(dev2).getId().toUnqualifiedVersionless(); @@ -159,12 +160,12 @@ public class ResourceProviderDstu21Test extends BaseResourceProviderDstu21Test { obs3.getCode().addCoding().setCode("CODE3"); obs3.setValue(new StringType("obsvalue3")); IIdType obsId3 = myObservationDao.create(obs3).getId().toUnqualifiedVersionless(); - + List actual; StringAndListParam param; - - ourLog.info("Pt1:{} Pt2:{} Obs1:{} Obs2:{} Obs3:{}", new Object[] {ptId1.getIdPart(), ptId2.getIdPart(), obsId1.getIdPart(), obsId2.getIdPart(), obsId3.getIdPart()}); - + + ourLog.info("Pt1:{} Pt2:{} Obs1:{} Obs2:{} Obs3:{}", new Object[] { ptId1.getIdPart(), ptId2.getIdPart(), obsId1.getIdPart(), obsId2.getIdPart(), obsId3.getIdPart() }); + param = new StringAndListParam(); param.addAnd(new StringOrListParam().addOr(new StringParam("obsvalue1"))); @@ -176,13 +177,12 @@ public class ResourceProviderDstu21Test extends BaseResourceProviderDstu21Test { .withParameter(Parameters.class, Constants.PARAM_CONTENT, new StringType("obsvalue1")) .execute(); //@formatter:on - - actual = toUnqualifiedVersionlessIds((Bundle)response.getParameter().get(0).getResource()); + + actual = toUnqualifiedVersionlessIds((Bundle) response.getParameter().get(0).getResource()); assertThat(actual, containsInAnyOrder(ptId1, obsId1, devId1)); } - - + @Test public void testBundleCreate() throws Exception { IGenericClient client = ourClient; @@ -211,7 +211,6 @@ public class ResourceProviderDstu21Test extends BaseResourceProviderDstu21Test { } } - // private void delete(String theResourceType, String theParamName, String theParamValue) { // Bundle resources; // do { @@ -244,7 +243,7 @@ public class ResourceProviderDstu21Test extends BaseResourceProviderDstu21Test { subs.getChannel().setType(SubscriptionChannelType.WEBSOCKET); subs.setCriteria("Observation?"); IIdType id = ourClient.create().resource(subs).execute().getId().toUnqualifiedVersionless(); - + //@formatter:off Bundle resp = ourClient .search() @@ -297,24 +296,11 @@ public class ResourceProviderDstu21Test extends BaseResourceProviderDstu21Test { ourClient.transaction().withResources(resources).prettyPrint().encodedXml().execute(); //@formatter:on - Bundle found = ourClient - .search() - .forResource(Organization.class) - .where(Organization.NAME.matches() - .value("rpdstu2_testCountParam_01")) - .count(10) - .returnBundle(Bundle.class) - .execute(); + Bundle found = ourClient.search().forResource(Organization.class).where(Organization.NAME.matches().value("rpdstu2_testCountParam_01")).count(10).returnBundle(Bundle.class).execute(); assertEquals(100, found.getTotal()); assertEquals(10, found.getEntry().size()); - found = ourClient - .search() - .forResource(Organization.class) - .where(Organization.NAME.matches().value("rpdstu2_testCountParam_01")) - .count(999) - .returnBundle(Bundle.class) - .execute(); + found = ourClient.search().forResource(Organization.class).where(Organization.NAME.matches().value("rpdstu2_testCountParam_01")).count(999).returnBundle(Bundle.class).execute(); //@formatter:on assertEquals(100, found.getTotal()); assertEquals(50, found.getEntry().size()); @@ -353,7 +339,7 @@ public class ResourceProviderDstu21Test extends BaseResourceProviderDstu21Test { assertThat(e.getMessage(), containsString("Question with linkId[link0]")); } } - + @Test public void testUpdateResourceConditionalComplex() throws IOException { Patient pt = new Patient(); @@ -374,12 +360,12 @@ public class ResourceProviderDstu21Test extends BaseResourceProviderDstu21Test { } finally { response.close(); } - + pt.addName().addFamily("FOO"); resource = myFhirCtx.newXmlParser().encodeResourceToString(pt); HttpPut put = new HttpPut(ourServerBase + "/Patient?identifier=" + ("http://general-hospital.co.uk/Identifiers|09832345234543876876".replace("|", UrlUtil.escape("|")))); put.setEntity(new StringEntity(resource, ContentType.create(Constants.CT_FHIR_XML, "UTF-8"))); - + IdType id2; response = ourHttpClient.execute(put); try { @@ -390,7 +376,7 @@ public class ResourceProviderDstu21Test extends BaseResourceProviderDstu21Test { } finally { response.close(); } - + assertEquals(id.getIdPart(), id2.getIdPart()); assertEquals("1", id.getVersionIdPart()); assertEquals("2", id2.getVersionIdPart()); @@ -416,7 +402,7 @@ public class ResourceProviderDstu21Test extends BaseResourceProviderDstu21Test { } finally { response.close(); } - + IdType id2; response = ourHttpClient.execute(post); try { @@ -427,7 +413,7 @@ public class ResourceProviderDstu21Test extends BaseResourceProviderDstu21Test { } finally { response.close(); } - + // //@formatter:off // IIdType id3 = ourClient // .update() @@ -435,10 +421,10 @@ public class ResourceProviderDstu21Test extends BaseResourceProviderDstu21Test { // .conditionalByUrl("Patient?identifier=http://general-hospital.co.uk/Identifiers|09832345234543876876") // .execute().getId(); // //@formatter:on - + assertEquals(id.getValue(), id2.getValue()); } - + @Test public void testCreateResourceConditional() throws IOException { String methodName = "testCreateResourceConditional"; @@ -581,12 +567,12 @@ public class ResourceProviderDstu21Test extends BaseResourceProviderDstu21Test { String methodName = "testDeleteConditionalMultiple"; myDaoConfig.setAllowMultipleDelete(false); - + Patient p = new Patient(); p.addIdentifier().setSystem("urn:system").setValue(methodName); p.addName().addFamily("FAM1"); IIdType id1 = myPatientDao.create(p).getId().toUnqualifiedVersionless(); - + p = new Patient(); p.addIdentifier().setSystem("urn:system").setValue(methodName); p.addName().addFamily("FAM2"); @@ -602,15 +588,16 @@ public class ResourceProviderDstu21Test extends BaseResourceProviderDstu21Test { //@formatter:on fail(); } catch (PreconditionFailedException e) { - assertEquals("HTTP 412 Precondition Failed: Failed to DELETE resource with match URL \"Patient?identifier=testDeleteConditionalMultiple\" because this search matched 2 resources", e.getMessage()); + assertEquals("HTTP 412 Precondition Failed: Failed to DELETE resource with match URL \"Patient?identifier=testDeleteConditionalMultiple\" because this search matched 2 resources", + e.getMessage()); } - + // Not deleted yet.. ourClient.read().resource("Patient").withId(id1).execute(); ourClient.read().resource("Patient").withId(id2).execute(); myDaoConfig.setAllowMultipleDelete(true); - + //@formatter:off ourClient .delete() @@ -686,7 +673,7 @@ public class ResourceProviderDstu21Test extends BaseResourceProviderDstu21Test { } } - + /** * Based on email from Rene Spronk */ @@ -713,8 +700,7 @@ public class ResourceProviderDstu21Test extends BaseResourceProviderDstu21Test { } /* - * Try it with a raw socket call. The Apache client won't let us use the unescaped "|" in the URL but we want to - * make sure that works too.. + * Try it with a raw socket call. The Apache client won't let us use the unescaped "|" in the URL but we want to make sure that works too.. */ Socket sock = new Socket(); sock.setSoTimeout(3000); @@ -842,7 +828,7 @@ public class ResourceProviderDstu21Test extends BaseResourceProviderDstu21Test { IIdType devId = ourClient.create().resource(dev).execute().getId().toUnqualifiedVersionless(); Location locParent = new Location(); - locParent.setName(methodName+"Parent"); + locParent.setName(methodName + "Parent"); IIdType locPId = ourClient.create().resource(locParent).execute().getId().toUnqualifiedVersionless(); Location locChild = new Location(); @@ -854,7 +840,7 @@ public class ResourceProviderDstu21Test extends BaseResourceProviderDstu21Test { encU.getPatient().setReferenceElement(patientId); encU.addLocation().getLocation().setReferenceElement(locCId); IIdType encUId = ourClient.create().resource(encU).execute().getId().toUnqualifiedVersionless(); - + Encounter enc = new Encounter(); enc.getPatient().setReferenceElement(patientId); enc.addLocation().getLocation().setReferenceElement(locCId); @@ -867,7 +853,7 @@ public class ResourceProviderDstu21Test extends BaseResourceProviderDstu21Test { IIdType obsId = ourClient.create().resource(obs).execute().getId().toUnqualifiedVersionless(); ourLog.info("IDs: EncU:" + encUId.getIdPart() + " Enc:" + encId.getIdPart() + " " + patientId.toUnqualifiedVersionless()); - + Parameters output = ourClient.operation().onInstance(encId).named("everything").withNoParameters(Parameters.class).execute(); Bundle b = (Bundle) output.getParameter().get(0).getResource(); List ids = toUnqualifiedVersionlessIds(b); @@ -906,7 +892,7 @@ public class ResourceProviderDstu21Test extends BaseResourceProviderDstu21Test { IIdType devId = ourClient.create().resource(dev).execute().getId().toUnqualifiedVersionless(); Location locParent = new Location(); - locParent.setName(methodName+"Parent"); + locParent.setName(methodName + "Parent"); IIdType locPId = ourClient.create().resource(locParent).execute().getId().toUnqualifiedVersionless(); Location locChild = new Location(); @@ -917,7 +903,7 @@ public class ResourceProviderDstu21Test extends BaseResourceProviderDstu21Test { Encounter encU = new Encounter(); encU.addIdentifier().setValue(methodName); IIdType encUId = ourClient.create().resource(encU).execute().getId().toUnqualifiedVersionless(); - + Encounter enc = new Encounter(); enc.getPatient().setReferenceElement(patientId); enc.addLocation().getLocation().setReferenceElement(locCId); @@ -995,18 +981,18 @@ public class ResourceProviderDstu21Test extends BaseResourceProviderDstu21Test { assertThat(ids.size(), greaterThan(10)); } } - + /** * Test for #226 */ @Test public void testEverythingPatientIncludesBackReferences() throws Exception { String methodName = "testEverythingIncludesBackReferences"; - + Medication med = new Medication(); med.getCode().setText(methodName); IIdType medId = myMedicationDao.create(med).getId().toUnqualifiedVersionless(); - + Patient pat = new Patient(); pat.addAddress().addLine(methodName); IIdType patId = myPatientDao.create(pat).getId().toUnqualifiedVersionless(); @@ -1015,7 +1001,7 @@ public class ResourceProviderDstu21Test extends BaseResourceProviderDstu21Test { mo.getPatient().setReferenceElement(patId); mo.setMedication(new Reference(medId)); IIdType moId = myMedicationOrderDao.create(mo).getId().toUnqualifiedVersionless(); - + Parameters output = ourClient.operation().onInstance(patId).named("everything").withNoParameters(Parameters.class).execute(); Bundle b = (Bundle) output.getParameter().get(0).getResource(); List ids = toUnqualifiedVersionlessIds(b); @@ -1058,8 +1044,6 @@ public class ResourceProviderDstu21Test extends BaseResourceProviderDstu21Test { } - - @Test public void testEverythingPatientOperation() throws Exception { String methodName = "testEverythingOperation"; @@ -1104,27 +1088,27 @@ public class ResourceProviderDstu21Test extends BaseResourceProviderDstu21Test { ourLog.info(ids.toString()); } - + @Test public void testEverythingPatientType() throws Exception { String methodName = "testEverythingPatientType"; - + Organization o1 = new Organization(); - o1.setName(methodName+"1"); + o1.setName(methodName + "1"); IIdType o1Id = ourClient.create().resource(o1).execute().getId().toUnqualifiedVersionless(); Organization o2 = new Organization(); - o2.setName(methodName+"2"); + o2.setName(methodName + "2"); IIdType o2Id = ourClient.create().resource(o2).execute().getId().toUnqualifiedVersionless(); - + Patient p1 = new Patient(); - p1.addName().addFamily(methodName+"1"); + p1.addName().addFamily(methodName + "1"); p1.getManagingOrganization().setReferenceElement(o1Id); IIdType p1Id = ourClient.create().resource(p1).execute().getId().toUnqualifiedVersionless(); Patient p2 = new Patient(); - p2.addName().addFamily(methodName+"2"); + p2.addName().addFamily(methodName + "2"); p2.getManagingOrganization().setReferenceElement(o2Id); IIdType p2Id = ourClient.create().resource(p2).execute().getId().toUnqualifiedVersionless(); - + Condition c1 = new Condition(); c1.getPatient().setReferenceElement(p1Id); IIdType c1Id = ourClient.create().resource(c1).execute().getId().toUnqualifiedVersionless(); @@ -1133,7 +1117,7 @@ public class ResourceProviderDstu21Test extends BaseResourceProviderDstu21Test { IIdType c2Id = ourClient.create().resource(c2).execute().getId().toUnqualifiedVersionless(); Condition c3 = new Condition(); - c3.addIdentifier().setValue(methodName+"3"); + c3.addIdentifier().setValue(methodName + "3"); IIdType c3Id = ourClient.create().resource(c3).execute().getId().toUnqualifiedVersionless(); Parameters output = ourClient.operation().onType(Patient.class).named("everything").withNoParameters(Parameters.class).execute(); @@ -1152,18 +1136,18 @@ public class ResourceProviderDstu21Test extends BaseResourceProviderDstu21Test { Organization org = new Organization(); org.setName(methodName); IIdType oId = ourClient.create().resource(org).execute().getId().toUnqualifiedVersionless(); - + long time1 = System.currentTimeMillis(); Thread.sleep(10); - + Patient p = new Patient(); p.addName().addFamily(methodName); p.getManagingOrganization().setReferenceElement(oId); IIdType pId = ourClient.create().resource(p).execute().getId().toUnqualifiedVersionless(); - + long time2 = System.currentTimeMillis(); Thread.sleep(10); - + Condition c = new Condition(); c.getCode().setText(methodName); c.getPatient().setReferenceElement(pId); @@ -1171,8 +1155,8 @@ public class ResourceProviderDstu21Test extends BaseResourceProviderDstu21Test { Thread.sleep(10); long time3 = System.currentTimeMillis(); - - // %3E=> %3C=< + + // %3E=> %3C=< HttpGet get = new HttpGet(ourServerBase + "/Patient/" + pId.getIdPart() + "/$everything?_lastUpdated=%3E" + new InstantType(new Date(time1)).getValueAsString()); CloseableHttpResponse response = ourHttpClient.execute(get); @@ -1188,7 +1172,8 @@ public class ResourceProviderDstu21Test extends BaseResourceProviderDstu21Test { response.close(); } - get = new HttpGet(ourServerBase + "/Patient/" + pId.getIdPart() + "/$everything?_lastUpdated=%3E" + new InstantType(new Date(time2)).getValueAsString() + "&_lastUpdated=%3C" + new InstantType(new Date(time3)).getValueAsString()); + get = new HttpGet(ourServerBase + "/Patient/" + pId.getIdPart() + "/$everything?_lastUpdated=%3E" + new InstantType(new Date(time2)).getValueAsString() + "&_lastUpdated=%3C" + + new InstantType(new Date(time3)).getValueAsString()); response = ourHttpClient.execute(get); try { assertEquals(200, response.getStatusLine().getStatusCode()); @@ -1229,7 +1214,7 @@ public class ResourceProviderDstu21Test extends BaseResourceProviderDstu21Test { } finally { response.close(); } - + } @Test @@ -1805,11 +1790,11 @@ public class ResourceProviderDstu21Test extends BaseResourceProviderDstu21Test { org = new Organization(); org.addIdentifier().setSystem("urn:system:rpdstu2").setValue(methodName + "01"); org.setName(methodName + "name"); - IIdType orgNotMissing = (IdType) ourClient.create().resource(org).prettyPrint().encodedXml().execute().getId().toUnqualifiedVersionless(); + IIdType orgNotMissing = ourClient.create().resource(org).prettyPrint().encodedXml().execute().getId().toUnqualifiedVersionless(); org = new Organization(); org.addIdentifier().setSystem("urn:system:rpdstu2").setValue(methodName + "01"); - IIdType orgMissing = (IdType) ourClient.create().resource(org).prettyPrint().encodedXml().execute().getId().toUnqualifiedVersionless(); + IIdType orgMissing = ourClient.create().resource(org).prettyPrint().encodedXml().execute().getId().toUnqualifiedVersionless(); { //@formatter:off @@ -1817,7 +1802,7 @@ public class ResourceProviderDstu21Test extends BaseResourceProviderDstu21Test { .search() .forResource(Organization.class) .where(Organization.NAME.isMissing(false)) - .limitTo(100) + .count(100) .prettyPrint() .returnBundle(Bundle.class) .execute(); @@ -2207,14 +2192,14 @@ public class ResourceProviderDstu21Test extends BaseResourceProviderDstu21Test { .returnBundle(Bundle.class) .execute(); //@formatter:on - + assertEquals(1, actual.getEntry().size()); assertEquals(p1Id.getIdPart(), actual.getEntry().get(0).getResource().getIdElement().getIdPart()); } @Test - public void testValidateResource() throws IOException { + public void testValidateResourceWithNoIdParameters() throws IOException { Patient patient = new Patient(); patient.addName().addGiven("James"); @@ -2224,8 +2209,6 @@ public class ResourceProviderDstu21Test extends BaseResourceProviderDstu21Test { input.addParameter().setName("resource").setResource(patient); String inputStr = myFhirCtx.newXmlParser().encodeResourceToString(input); - ourLog.info(inputStr); - HttpPost post = new HttpPost(ourServerBase + "/Patient/$validate?_pretty=true"); post.setEntity(new StringEntity(inputStr, ContentType.create(Constants.CT_FHIR_XML, "UTF-8"))); @@ -2235,6 +2218,61 @@ public class ResourceProviderDstu21Test extends BaseResourceProviderDstu21Test { ourLog.info(resp); assertEquals(200, response.getStatusLine().getStatusCode()); assertThat(resp, not(containsString("Resource has no id"))); + assertThat(resp, containsString("
No issues detected during validation
")); + assertThat(resp, + stringContainsInOrder("", "", "", "", "")); + } finally { + IOUtils.closeQuietly(response.getEntity().getContent()); + response.close(); + } + } + + @Test + public void testValidateResourceWithNoIdRaw() throws IOException { + + Patient patient = new Patient(); + patient.addName().addGiven("James"); + patient.setBirthDateElement(new DateType("2011-02-02")); + + String inputStr = myFhirCtx.newXmlParser().encodeResourceToString(patient); + HttpPost post = new HttpPost(ourServerBase + "/Patient/$validate"); + post.setEntity(new StringEntity(inputStr, ContentType.create(Constants.CT_FHIR_XML, "UTF-8"))); + + CloseableHttpResponse response = ourHttpClient.execute(post); + try { + String resp = IOUtils.toString(response.getEntity().getContent()); + ourLog.info(resp); + assertEquals(200, response.getStatusLine().getStatusCode()); + assertThat(resp, not(containsString("Resource has no id"))); + assertThat(resp, containsString("
No issues detected during validation
")); + assertThat(resp, + stringContainsInOrder("", "", "", "", "")); + } finally { + IOUtils.closeQuietly(response.getEntity().getContent()); + response.close(); + } + } + + @Test + public void testValidateResourceBaseWithNoIdRaw() throws IOException { + + Patient patient = new Patient(); + patient.addName().addGiven("James"); + patient.setBirthDateElement(new DateType("2011-02-02")); + patient.addContact().setGender(AdministrativeGender.MALE); + + String inputStr = myFhirCtx.newXmlParser().encodeResourceToString(patient); + HttpPost post = new HttpPost(ourServerBase + "/Patient/$validate"); + post.setEntity(new StringEntity(inputStr, ContentType.create(Constants.CT_FHIR_XML, "UTF-8"))); + + CloseableHttpResponse response = ourHttpClient.execute(post); + try { + String resp = IOUtils.toString(response.getEntity().getContent()); + ourLog.info(resp); + assertEquals(412, response.getStatusLine().getStatusCode()); + assertThat(resp, not(containsString("Resource has no id"))); + assertThat(resp, + stringContainsInOrder(">ERROR<","/f:Patient/f:contact","
SHALL at least contain a contact's details or a reference to an organization
","","","","")); } finally { IOUtils.closeQuietly(response.getEntity().getContent()); response.close(); diff --git a/hapi-fhir-jpaserver-example/src/main/java/ca/uhn/fhir/jpa/demo/FhirServerConfigDstu21.java b/hapi-fhir-jpaserver-example/src/main/java/ca/uhn/fhir/jpa/demo/FhirServerConfigDstu21.java index 5c84e90f112..5d68f49df9e 100644 --- a/hapi-fhir-jpaserver-example/src/main/java/ca/uhn/fhir/jpa/demo/FhirServerConfigDstu21.java +++ b/hapi-fhir-jpaserver-example/src/main/java/ca/uhn/fhir/jpa/demo/FhirServerConfigDstu21.java @@ -88,6 +88,7 @@ public class FhirServerConfigDstu21 extends BaseJavaConfigDstu21 { extraProperties.put("hibernate.search.default.directory_provider", "filesystem"); extraProperties.put("hibernate.search.default.indexBase", "target/lucenefiles"); extraProperties.put("hibernate.search.lucene_version", "LUCENE_CURRENT"); +// extraProperties.put("hibernate.search.default.worker.execution", "async"); return extraProperties; } diff --git a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/model/primitive/DateDtTest.java b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/model/primitive/DateDtTest.java new file mode 100644 index 00000000000..cd86a67ad19 --- /dev/null +++ b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/model/primitive/DateDtTest.java @@ -0,0 +1,39 @@ +package ca.uhn.fhir.model.primitive; + +import java.util.Arrays; +import java.util.Calendar; +import java.util.TimeZone; +import java.util.TreeSet; + +import org.junit.Test; + +public class DateDtTest { + private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(DateDtTest.class); + + @Test + public void testPrecision() { + +// ourLog.info(""+ new TreeSet(Arrays.asList(TimeZone.getAvailableIDs()))); + + final Calendar cal = Calendar.getInstance(); + cal.setTimeZone(TimeZone.getTimeZone("GMT")); + cal.set(1990, Calendar.JANUARY, 1, 0, 0, 0); + ourLog.info("Time: {}", cal); // 631152000775 + + DateDt dateDt = new DateDt(cal.getTime()); + long time = dateDt.getValue().getTime(); + ourLog.info("Time: {}", time); // 631152000775 + ourLog.info("Time: {}", dateDt.getValue()); // 631152000775 + + dateDt.setTimeZone(TimeZone.getTimeZone("Europe/Berlin")); + time = dateDt.getValue().getTime(); + ourLog.info("Time: {}", time); // 631152000775 + ourLog.info("Time: {}", dateDt.getValue()); // 631152000775 + + String valueAsString = dateDt.getValueAsString(); + ourLog.info(valueAsString); + // is 631152000030 + + } + +} diff --git a/pom.xml b/pom.xml index a1180ffc885..8c427294891 100644 --- a/pom.xml +++ b/pom.xml @@ -248,7 +248,6 @@ 5.0.6.Final 5.2.2.Final 2.5.3 - 2.18.1 1.8 3.4 2.4 @@ -731,7 +730,7 @@ org.apache.maven.plugins maven-failsafe-plugin - 2.19 + 2.19.1 org.apache.maven.plugins @@ -741,7 +740,7 @@ org.apache.maven.plugins maven-surefire-plugin - 2.19 + 2.19.1 true random @@ -1314,7 +1313,7 @@ org.apache.maven.plugins maven-surefire-report-plugin - 2.19 + 2.19.1 diff --git a/src/site/xdoc/doc_cli.xml b/src/site/xdoc/doc_cli.xml index 28ad6a8ed44..0c815c46286 100644 --- a/src/site/xdoc/doc_cli.xml +++ b/src/site/xdoc/doc_cli.xml @@ -13,7 +13,7 @@ hapi-fhir-cli is the HAPI FHIR Command Line tool. It features a number of HAPI's built-in features as easy to use command line options.

- +

You can get the tool by downloading it from our @@ -35,7 +35,12 @@

- The tool should work correctly on any system that has Java 6 (or newer) installed. If + Note on Java version support: The HAPI library is designed to + work in Java 6+, but the Command Line Tool required a minimum of Java 8. This + is because the Jetty Web Server that is used within the tool has this requirement. +

+

+ The tool should work correctly on any system that has Java 8 (or newer) installed. If it is not working correctly, first try the following command to test if Java is installed:
$ java -version