Get fluentpath entirely working in JPA
This commit is contained in:
parent
804149205a
commit
dd95a52240
|
@ -60,6 +60,7 @@ import org.hl7.fhir.dstu3.model.IdType;
|
|||
import org.hl7.fhir.dstu3.model.StringType;
|
||||
import org.hl7.fhir.instance.model.api.IAnyResource;
|
||||
import org.hl7.fhir.instance.model.api.IBase;
|
||||
import org.hl7.fhir.instance.model.api.IBaseBundle;
|
||||
import org.hl7.fhir.instance.model.api.IBaseCoding;
|
||||
import org.hl7.fhir.instance.model.api.IBaseOperationOutcome;
|
||||
import org.hl7.fhir.instance.model.api.IBaseReference;
|
||||
|
@ -243,6 +244,14 @@ public abstract class BaseHapiFhirDao<T extends IBaseResource> implements IDao {
|
|||
protected Set<ResourceLink> extractResourceLinks(ResourceTable theEntity, IBaseResource theResource) {
|
||||
Set<ResourceLink> retVal = new HashSet<ResourceLink>();
|
||||
|
||||
/*
|
||||
* For now we don't try to load any of the links in a bundle if it's the
|
||||
* actual bundle we're storing..
|
||||
*/
|
||||
if (theResource instanceof IBaseBundle) {
|
||||
return retVal;
|
||||
}
|
||||
|
||||
RuntimeResourceDefinition def = getContext().getResourceDefinition(theResource);
|
||||
for (RuntimeSearchParam nextSpDef : def.getSearchParams()) {
|
||||
|
||||
|
@ -261,105 +270,27 @@ public abstract class BaseHapiFhirDao<T extends IBaseResource> implements IDao {
|
|||
}
|
||||
|
||||
List<PathAndRef> refs = mySearchParamExtractor.extractResourceLinks(theResource, nextSpDef);
|
||||
List<Class<? extends IBaseResource>> allowedTypesInField = null;
|
||||
for (PathAndRef nextPathAndRef : refs) {
|
||||
Object nextObject = nextPathAndRef.getRef();
|
||||
|
||||
ResourceLink nextEntity;
|
||||
IIdType nextId;
|
||||
if (nextObject instanceof IBaseReference) {
|
||||
IBaseReference nextValue = (IBaseReference) nextObject;
|
||||
if (nextValue.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
if (nextValue.getReferenceElement().isEmpty() || nextValue.getReferenceElement().getValue().startsWith("#")) {
|
||||
nextId = nextValue.getReferenceElement();
|
||||
if (nextId.isEmpty() || nextId.getValue().startsWith("#")) {
|
||||
// This is a blank or contained resource reference
|
||||
continue;
|
||||
}
|
||||
|
||||
String typeString = nextValue.getReferenceElement().getResourceType();
|
||||
if (isBlank(typeString)) {
|
||||
throw new InvalidRequestException(
|
||||
"Invalid resource reference found at path[" + nextPathsUnsplit + "] - Does not contain resource type - " + nextValue.getReferenceElement().getValue());
|
||||
}
|
||||
RuntimeResourceDefinition resourceDefinition;
|
||||
try {
|
||||
resourceDefinition = getContext().getResourceDefinition(typeString);
|
||||
} catch (DataFormatException e) {
|
||||
throw new InvalidRequestException("Invalid resource reference found at path[" + nextPathsUnsplit + "] - Resource type is unknown or not supported on this server - "
|
||||
+ nextValue.getReferenceElement().getValue());
|
||||
}
|
||||
|
||||
Class<? extends IBaseResource> type = resourceDefinition.getImplementingClass();
|
||||
String id = nextValue.getReferenceElement().getIdPart();
|
||||
if (StringUtils.isBlank(id)) {
|
||||
throw new InvalidRequestException(
|
||||
"Invalid resource reference found at path[" + nextPathsUnsplit + "] - Does not contain resource ID - " + nextValue.getReferenceElement().getValue());
|
||||
}
|
||||
|
||||
IFhirResourceDao<?> dao = getDao(type);
|
||||
if (dao == null) {
|
||||
StringBuilder b = new StringBuilder();
|
||||
b.append("This server (version ");
|
||||
b.append(myContext.getVersion().getVersion());
|
||||
b.append(") is not able to handle resources of type[");
|
||||
b.append(nextValue.getReferenceElement().getResourceType());
|
||||
b.append("] - Valid resource types for this server: ");
|
||||
b.append(myResourceTypeToDao.keySet().toString());
|
||||
|
||||
throw new InvalidRequestException(b.toString());
|
||||
}
|
||||
Long valueOf;
|
||||
try {
|
||||
valueOf = translateForcedIdToPid(typeString, id);
|
||||
} catch (ResourceNotFoundException e) {
|
||||
String resName = getContext().getResourceDefinition(type).getName();
|
||||
throw new InvalidRequestException("Resource " + resName + "/" + id + " not found, specified in path: " + nextPathsUnsplit);
|
||||
}
|
||||
ResourceTable target = myEntityManager.find(ResourceTable.class, valueOf);
|
||||
RuntimeResourceDefinition targetResourceDef = getContext().getResourceDefinition(type);
|
||||
if (target == null) {
|
||||
String resName = targetResourceDef.getName();
|
||||
throw new InvalidRequestException("Resource " + resName + "/" + id + " not found, specified in path: " + nextPathsUnsplit);
|
||||
}
|
||||
|
||||
if (!typeString.equals(target.getResourceType())) {
|
||||
throw new UnprocessableEntityException("Resource contains reference to " + nextValue.getReferenceElement().getValue() + " but resource with ID "
|
||||
+ nextValue.getReferenceElement().getIdPart() + " is actually of type " + target.getResourceType());
|
||||
}
|
||||
|
||||
if (nextSpDef.getTargets() != null && !nextSpDef.getTargets().contains(typeString)) {
|
||||
} else if (nextObject instanceof IBaseResource) {
|
||||
nextId = ((IBaseResource) nextObject).getIdElement();
|
||||
if (nextId == null || nextId.hasIdPart() == false) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// /*
|
||||
// * Is the target type an allowable type of resource for the path where it is referenced?
|
||||
// */
|
||||
//
|
||||
// if (allowedTypesInField == null) {
|
||||
// BaseRuntimeChildDefinition childDef = getContext().newTerser().getDefinition(theResource.getClass(), nextPathAndRef.getPath());
|
||||
// if (childDef instanceof RuntimeChildResourceDefinition) {
|
||||
// RuntimeChildResourceDefinition resRefDef = (RuntimeChildResourceDefinition) childDef;
|
||||
// allowedTypesInField = resRefDef.getResourceTypes();
|
||||
// } else {
|
||||
// allowedTypesInField = new ArrayList<Class<? extends IBaseResource>>();
|
||||
// allowedTypesInField.add(IBaseResource.class);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// boolean acceptableLink = false;
|
||||
// for (Class<? extends IBaseResource> next : allowedTypesInField) {
|
||||
// if (next.isAssignableFrom(targetResourceDef.getImplementingClass())) {
|
||||
// acceptableLink = true;
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// if (!acceptableLink) {
|
||||
// throw new UnprocessableEntityException(
|
||||
// "Invalid reference found at path '" + nextPathAndRef.getPath() + "'. Resource type '" + targetResourceDef.getName() + "' is not valid for this path");
|
||||
// }
|
||||
|
||||
nextEntity = new ResourceLink(nextPathAndRef.getPath(), theEntity, target);
|
||||
} else {
|
||||
if (!multiType) {
|
||||
if (nextSpDef.getName().equals("sourceuri")) {
|
||||
|
@ -370,6 +301,89 @@ public abstract class BaseHapiFhirDao<T extends IBaseResource> implements IDao {
|
|||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
String typeString = nextId.getResourceType();
|
||||
if (isBlank(typeString)) {
|
||||
throw new InvalidRequestException("Invalid resource reference found at path[" + nextPathsUnsplit + "] - Does not contain resource type - " + nextId.getValue());
|
||||
}
|
||||
RuntimeResourceDefinition resourceDefinition;
|
||||
try {
|
||||
resourceDefinition = getContext().getResourceDefinition(typeString);
|
||||
} catch (DataFormatException e) {
|
||||
throw new InvalidRequestException(
|
||||
"Invalid resource reference found at path[" + nextPathsUnsplit + "] - Resource type is unknown or not supported on this server - " + nextId.getValue());
|
||||
}
|
||||
|
||||
Class<? extends IBaseResource> type = resourceDefinition.getImplementingClass();
|
||||
String id = nextId.getIdPart();
|
||||
if (StringUtils.isBlank(id)) {
|
||||
throw new InvalidRequestException("Invalid resource reference found at path[" + nextPathsUnsplit + "] - Does not contain resource ID - " + nextId.getValue());
|
||||
}
|
||||
|
||||
IFhirResourceDao<?> dao = getDao(type);
|
||||
if (dao == null) {
|
||||
StringBuilder b = new StringBuilder();
|
||||
b.append("This server (version ");
|
||||
b.append(myContext.getVersion().getVersion());
|
||||
b.append(") is not able to handle resources of type[");
|
||||
b.append(nextId.getResourceType());
|
||||
b.append("] - Valid resource types for this server: ");
|
||||
b.append(myResourceTypeToDao.keySet().toString());
|
||||
|
||||
throw new InvalidRequestException(b.toString());
|
||||
}
|
||||
Long valueOf;
|
||||
try {
|
||||
valueOf = translateForcedIdToPid(typeString, id);
|
||||
} catch (ResourceNotFoundException e) {
|
||||
String resName = getContext().getResourceDefinition(type).getName();
|
||||
throw new InvalidRequestException("Resource " + resName + "/" + id + " not found, specified in path: " + nextPathsUnsplit);
|
||||
}
|
||||
ResourceTable target = myEntityManager.find(ResourceTable.class, valueOf);
|
||||
RuntimeResourceDefinition targetResourceDef = getContext().getResourceDefinition(type);
|
||||
if (target == null) {
|
||||
String resName = targetResourceDef.getName();
|
||||
throw new InvalidRequestException("Resource " + resName + "/" + id + " not found, specified in path: " + nextPathsUnsplit);
|
||||
}
|
||||
|
||||
if (!typeString.equals(target.getResourceType())) {
|
||||
throw new UnprocessableEntityException(
|
||||
"Resource contains reference to " + nextId.getValue() + " but resource with ID " + nextId.getIdPart() + " is actually of type " + target.getResourceType());
|
||||
}
|
||||
|
||||
if (nextSpDef.getTargets() != null && !nextSpDef.getTargets().contains(typeString)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// /*
|
||||
// * Is the target type an allowable type of resource for the path where it is referenced?
|
||||
// */
|
||||
//
|
||||
// if (allowedTypesInField == null) {
|
||||
// BaseRuntimeChildDefinition childDef = getContext().newTerser().getDefinition(theResource.getClass(), nextPathAndRef.getPath());
|
||||
// if (childDef instanceof RuntimeChildResourceDefinition) {
|
||||
// RuntimeChildResourceDefinition resRefDef = (RuntimeChildResourceDefinition) childDef;
|
||||
// allowedTypesInField = resRefDef.getResourceTypes();
|
||||
// } else {
|
||||
// allowedTypesInField = new ArrayList<Class<? extends IBaseResource>>();
|
||||
// allowedTypesInField.add(IBaseResource.class);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// boolean acceptableLink = false;
|
||||
// for (Class<? extends IBaseResource> next : allowedTypesInField) {
|
||||
// if (next.isAssignableFrom(targetResourceDef.getImplementingClass())) {
|
||||
// acceptableLink = true;
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// if (!acceptableLink) {
|
||||
// throw new UnprocessableEntityException(
|
||||
// "Invalid reference found at path '" + nextPathAndRef.getPath() + "'. Resource type '" + targetResourceDef.getName() + "' is not valid for this path");
|
||||
// }
|
||||
|
||||
nextEntity = new ResourceLink(nextPathAndRef.getPath(), theEntity, target);
|
||||
if (nextEntity != null) {
|
||||
retVal.add(nextEntity);
|
||||
}
|
||||
|
@ -1472,7 +1486,7 @@ public abstract class BaseHapiFhirDao<T extends IBaseResource> implements IDao {
|
|||
return;
|
||||
}
|
||||
|
||||
BaseRuntimeElementCompositeDefinition<?> cdef = (BaseRuntimeElementCompositeDefinition<?>)def;
|
||||
BaseRuntimeElementCompositeDefinition<?> cdef = (BaseRuntimeElementCompositeDefinition<?>) def;
|
||||
for (BaseRuntimeChildDefinition nextChildDef : cdef.getChildren()) {
|
||||
|
||||
List<IBase> values = nextChildDef.getAccessor().getValues(theElement);
|
||||
|
@ -1487,7 +1501,7 @@ public abstract class BaseHapiFhirDao<T extends IBaseResource> implements IDao {
|
|||
}
|
||||
|
||||
if (nextChildDef instanceof RuntimeChildResourceDefinition) {
|
||||
RuntimeChildResourceDefinition nextChildDefRes = (RuntimeChildResourceDefinition)nextChildDef;
|
||||
RuntimeChildResourceDefinition nextChildDefRes = (RuntimeChildResourceDefinition) nextChildDef;
|
||||
Set<String> validTypes = new HashSet<String>();
|
||||
boolean allowAny = false;
|
||||
for (Class<? extends IBaseResource> nextValidType : nextChildDefRes.getResourceTypes()) {
|
||||
|
@ -1503,11 +1517,11 @@ public abstract class BaseHapiFhirDao<T extends IBaseResource> implements IDao {
|
|||
}
|
||||
|
||||
for (IBase nextChild : values) {
|
||||
IBaseReference nextRef = (IBaseReference)nextChild;
|
||||
IBaseReference nextRef = (IBaseReference) nextChild;
|
||||
if (!isBlank(nextRef.getReferenceElement().getResourceType())) {
|
||||
if (!validTypes.contains(nextRef.getReferenceElement().getResourceType())) {
|
||||
throw new UnprocessableEntityException(
|
||||
"Invalid reference found at path '" + newPath + "'. Resource type '" + nextRef.getReferenceElement().getResourceType() + "' is not valid for this path");
|
||||
throw new UnprocessableEntityException(
|
||||
"Invalid reference found at path '" + newPath + "'. Resource type '" + nextRef.getReferenceElement().getResourceType() + "' is not valid for this path");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -666,7 +666,10 @@ public class SearchParamExtractorDstu3 extends BaseSearchParamExtractor implemen
|
|||
|
||||
List<Object> values = new ArrayList<Object>();
|
||||
try {
|
||||
values.addAll(fp.evaluate((Base) theResource, thePaths));
|
||||
String[] nextPathsSplit = SPLIT.split(thePaths);
|
||||
for (String nextPath : nextPathsSplit) {
|
||||
values.addAll(fp.evaluate((Base) theResource, nextPath));
|
||||
}
|
||||
} catch (FHIRException e) {
|
||||
throw new InternalErrorException(e);
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@ import org.hl7.fhir.dstu3.hapi.validation.DefaultProfileValidationSupport;
|
|||
import org.hl7.fhir.dstu3.hapi.validation.IValidationSupport;
|
||||
import org.hl7.fhir.dstu3.model.Observation;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import ca.uhn.fhir.context.FhirContext;
|
||||
|
@ -24,9 +25,12 @@ public class SearchParamExtractorDstu3Test {
|
|||
@AfterClass
|
||||
public static void afterClassClearContext() {
|
||||
TestUtil.clearAllStaticFieldsForUnitTest();
|
||||
ourValidationSupport = new DefaultProfileValidationSupport();
|
||||
}
|
||||
|
||||
@BeforeClass
|
||||
public static void beforeClass() {
|
||||
ourValidationSupport = new DefaultProfileValidationSupport();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParamWithOrInPath() {
|
||||
|
|
|
@ -146,6 +146,7 @@ public class ResourceProviderDstu3Test extends BaseResourceProviderDstu3Test {
|
|||
return retVal;
|
||||
}
|
||||
|
||||
// Y
|
||||
@Test
|
||||
public void testBundleCreate() throws Exception {
|
||||
IGenericClient client = ourClient;
|
||||
|
@ -2515,14 +2516,14 @@ public class ResourceProviderDstu3Test extends BaseResourceProviderDstu3Test {
|
|||
ourLog.info(resp);
|
||||
assertEquals(412, response.getStatusLine().getStatusCode());
|
||||
assertThat(resp, not(containsString("Resource has no id")));
|
||||
assertThat(resp, stringContainsInOrder(">ERROR<", "/f:Patient/f:contact", "<pre>SHALL at least contain a contact's details or a reference to an organization</pre>", "<issue><severity value=\"error\"/>", "<code value=\"processing\"/>",
|
||||
"<diagnostics value=\"SHALL at least contain a contact's details or a reference to an organization\"/>", "<location value=\"/f:Patient/f:contact\"/>"));
|
||||
assertThat(resp, stringContainsInOrder(">ERROR<", "[Patient.contact]", "<pre>SHALL at least contain a contact's details or a reference to an organization", "<issue><severity value=\"error\"/>"));
|
||||
} finally {
|
||||
IOUtils.closeQuietly(response.getEntity().getContent());
|
||||
response.close();
|
||||
}
|
||||
}
|
||||
|
||||
// Y
|
||||
@Test
|
||||
public void testValidateResourceHuge() throws IOException {
|
||||
|
||||
|
@ -2555,6 +2556,7 @@ public class ResourceProviderDstu3Test extends BaseResourceProviderDstu3Test {
|
|||
public void testValidateResourceWithId() throws IOException {
|
||||
|
||||
Patient patient = new Patient();
|
||||
patient.setId("123");
|
||||
patient.addName().addGiven("James");
|
||||
patient.setBirthDateElement(new DateType("2011-02-02"));
|
||||
|
||||
|
@ -2578,6 +2580,7 @@ public class ResourceProviderDstu3Test extends BaseResourceProviderDstu3Test {
|
|||
}
|
||||
}
|
||||
|
||||
// Y
|
||||
@Test
|
||||
public void testValidateResourceWithNoIdParameters() throws IOException {
|
||||
|
||||
|
|
|
@ -10,13 +10,11 @@
|
|||
]
|
||||
},
|
||||
"type": "document",
|
||||
"base": "http://fhir.healthintersections.com.au/open",
|
||||
"entry": [
|
||||
{
|
||||
"base": "urn:uuid:",
|
||||
"fullUrl": "urn:uuid:180f219f-97a8-486d-99d9-ed631fe4fc57",
|
||||
"resource": {
|
||||
"resourceType": "Composition",
|
||||
"id": "180f219f-97a8-486d-99d9-ed631fe4fc57",
|
||||
"meta": {
|
||||
"lastUpdated": "2013-05-28T22:12:21Z"
|
||||
},
|
||||
|
@ -197,10 +195,9 @@
|
|||
}
|
||||
},
|
||||
{
|
||||
"base": "urn:uuid:",
|
||||
"fullUrl": "urn:uuid:d0dd51d3-3ab2-4c84-b697-a630c3e40e7a",
|
||||
"resource": {
|
||||
"resourceType": "List",
|
||||
"id": "d0dd51d3-3ab2-4c84-b697-a630c3e40e7a",
|
||||
"meta": {
|
||||
"lastUpdated": "2013-05-05T16:13:03Z"
|
||||
},
|
||||
|
@ -233,10 +230,9 @@
|
|||
}
|
||||
},
|
||||
{
|
||||
"base": "urn:uuid:",
|
||||
"fullUrl": "urn:uuid:541a72a8-df75-4484-ac89-ac4923f03b81",
|
||||
"resource": {
|
||||
"resourceType": "Observation",
|
||||
"id": "541a72a8-df75-4484-ac89-ac4923f03b81",
|
||||
"meta": {
|
||||
"lastUpdated": "2013-05-05T16:13:03Z"
|
||||
},
|
||||
|
@ -259,10 +255,9 @@
|
|||
}
|
||||
},
|
||||
{
|
||||
"base": "urn:uuid:",
|
||||
"fullUrl": "urn:uuid:673f8db5-0ffd-4395-9657-6da00420bbc1",
|
||||
"resource": {
|
||||
"resourceType": "List",
|
||||
"id": "673f8db5-0ffd-4395-9657-6da00420bbc1",
|
||||
"meta": {
|
||||
"lastUpdated": "2013-05-05T16:13:03Z"
|
||||
},
|
||||
|
@ -322,10 +317,9 @@
|
|||
}
|
||||
},
|
||||
{
|
||||
"base": "urn:uuid:",
|
||||
"fullUrl": "urn:uuid:124a6916-5d84-4b8c-b250-10cefb8e6e86",
|
||||
"resource": {
|
||||
"resourceType": "MedicationOrder",
|
||||
"id": "124a6916-5d84-4b8c-b250-10cefb8e6e86",
|
||||
"meta": {
|
||||
"lastUpdated": "2013-05-05T16:13:03Z"
|
||||
},
|
||||
|
@ -395,10 +389,9 @@
|
|||
}
|
||||
},
|
||||
{
|
||||
"base": "urn:uuid:",
|
||||
"fullUrl": "urn:uuid:68f86194-e6e1-4f65-b64a-5314256f8d7b",
|
||||
"resource": {
|
||||
"resourceType": "List",
|
||||
"id": "68f86194-e6e1-4f65-b64a-5314256f8d7b",
|
||||
"meta": {
|
||||
"lastUpdated": "2013-05-05T16:13:03Z"
|
||||
},
|
||||
|
@ -431,10 +424,9 @@
|
|||
}
|
||||
},
|
||||
{
|
||||
"base": "urn:uuid:",
|
||||
"base": "urn:uuid:47600e0f-b6b5-4308-84b5-5dec157f7637",
|
||||
"resource": {
|
||||
"resourceType": "AllergyIntolerance",
|
||||
"id": "47600e0f-b6b5-4308-84b5-5dec157f7637",
|
||||
"meta": {
|
||||
"lastUpdated": "2013-05-05T16:13:03Z"
|
||||
},
|
||||
|
|
|
@ -12,6 +12,7 @@ import org.apache.commons.lang3.Validate;
|
|||
import org.hl7.fhir.dstu3.model.OperationOutcome.IssueSeverity;
|
||||
import org.hl7.fhir.dstu3.model.StructureDefinition;
|
||||
import org.hl7.fhir.dstu3.validation.IResourceValidator.BestPracticeWarningLevel;
|
||||
import org.hl7.fhir.dstu3.validation.IResourceValidator.IdStatus;
|
||||
import org.hl7.fhir.dstu3.validation.InstanceValidator;
|
||||
import org.hl7.fhir.dstu3.validation.ValidationMessage;
|
||||
import org.w3c.dom.Document;
|
||||
|
@ -32,7 +33,6 @@ import ca.uhn.fhir.validation.IValidatorModule;
|
|||
|
||||
public class FhirInstanceValidator extends BaseValidatorBridge implements IValidatorModule {
|
||||
|
||||
private static FhirContext ourHl7OrgCtx;
|
||||
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(FhirInstanceValidator.class);
|
||||
private BestPracticeWarningLevel myBestPracticeWarningLevel;
|
||||
private DocumentBuilderFactory myDocBuilderFactory;
|
||||
|
@ -139,6 +139,7 @@ public class FhirInstanceValidator extends BaseValidatorBridge implements IValid
|
|||
|
||||
v.setBestPracticeWarningLevel(myBestPracticeWarningLevel);
|
||||
v.setAnyExtensionsAllowed(true);
|
||||
v.setResourceIdRule(IdStatus.OPTIONAL);
|
||||
|
||||
List<ValidationMessage> messages = new ArrayList<ValidationMessage>();
|
||||
|
||||
|
|
|
@ -9,6 +9,7 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.commons.lang3.Validate;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.hl7.fhir.dstu3.formats.IParser;
|
||||
import org.hl7.fhir.dstu3.formats.ParserType;
|
||||
|
@ -43,6 +44,8 @@ public final class HapiWorkerContext implements IWorkerContext, ValueSetExpander
|
|||
private IValidationSupport myValidationSupport;
|
||||
|
||||
public HapiWorkerContext(FhirContext theCtx, IValidationSupport theValidationSupport) {
|
||||
Validate.notNull(theCtx, "theCtx must not be null");
|
||||
Validate.notNull(theValidationSupport, "theValidationSupport must not be null");
|
||||
myCtx = theCtx;
|
||||
myValidationSupport = theValidationSupport;
|
||||
}
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package org.hl7.fhir.dstu3.metamodel;
|
||||
|
||||
import static org.apache.commons.lang3.StringUtils.isNotBlank;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
@ -321,5 +323,18 @@ public class Element extends Base {
|
|||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
if (isNotBlank(value)) {
|
||||
return false;
|
||||
}
|
||||
for (Element next : getChildren()) {
|
||||
if (!next.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -103,7 +103,7 @@ private Map<String, Object> userData;
|
|||
public boolean hasType(String... name) {
|
||||
String t = fhirType();
|
||||
for (String n : name)
|
||||
if (n.equals(t))
|
||||
if (n.equalsIgnoreCase(t))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -1247,12 +1247,27 @@ public class InstanceValidator extends BaseValidator implements IResourceValidat
|
|||
|
||||
private boolean isParametersEntry(String path) {
|
||||
String[] parts = path.split("\\.");
|
||||
return parts.length > 2 && parts[parts.length - 1].equals("resource") && (parts[parts.length - 2].startsWith("parameter[") || parts[parts.length - 2].startsWith("part["));
|
||||
return parts.length > 2 && parts[parts.length - 1].equals("resource") && (pathEntryHasName(parts[parts.length - 2], "parameter") || pathEntryHasName(parts[parts.length - 2], "part"));
|
||||
}
|
||||
|
||||
private boolean isBundleEntry(String path) {
|
||||
String[] parts = path.split("\\.");
|
||||
return parts.length > 2 && parts[parts.length - 1].equals("resource") && parts[parts.length - 2].startsWith("entry[");
|
||||
return parts.length > 2 && parts[parts.length - 1].equals("resource") && pathEntryHasName(parts[parts.length - 2], "entry");
|
||||
}
|
||||
|
||||
|
||||
private static boolean pathEntryHasName(String thePathEntry, String theName) {
|
||||
if (thePathEntry.equals(theName)) {
|
||||
return true;
|
||||
}
|
||||
if (thePathEntry.length() >= theName.length() + 3) {
|
||||
if (thePathEntry.startsWith(theName)) {
|
||||
if (thePathEntry.charAt(theName.length()) == '[') {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean isPrimitiveType(String type) {
|
||||
|
|
|
@ -75,6 +75,7 @@ public class XhtmlNode implements IBaseXhtml {
|
|||
}
|
||||
|
||||
public void setName(String name) {
|
||||
assert name.contains(":") == false : "Name should not contain any : but was " + name;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
|
|
|
@ -42,8 +42,6 @@ import java.util.Set;
|
|||
|
||||
import org.hl7.fhir.exceptions.FHIRException;
|
||||
import org.hl7.fhir.exceptions.FHIRFormatError;
|
||||
import org.hl7.fhir.utilities.xhtml.XhtmlParser.NSMap;
|
||||
import org.hl7.fhir.utilities.xhtml.XhtmlParser.QName;
|
||||
import org.w3c.dom.Attr;
|
||||
import org.w3c.dom.Element;
|
||||
import org.w3c.dom.Node;
|
||||
|
@ -107,6 +105,7 @@ public class XhtmlParser {
|
|||
public String getNs() {
|
||||
return ns;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private Set<String> elements = new HashSet<String>();
|
||||
|
@ -515,7 +514,7 @@ private boolean elementIsOk(String name) throws FHIRFormatError {
|
|||
else
|
||||
{
|
||||
if (mustBeWellFormed)
|
||||
throw new FHIRFormatError("Malformed XHTML: Found \"</"+n+">\" expecting \"</"+node.getName()+">\""+descLoc());
|
||||
throw new FHIRFormatError("Malformed XHTML: Found \"</"+n.getName()+">\" expecting \"</"+node.getName()+">\""+descLoc());
|
||||
for (int i = parents.size() - 1; i >= 0; i--)
|
||||
{
|
||||
if (parents.get(i).getName().equals(n))
|
||||
|
@ -1106,6 +1105,12 @@ private boolean elementIsOk(String name) throws FHIRFormatError {
|
|||
String n = readName().toLowerCase();
|
||||
readToTagEnd();
|
||||
XhtmlNode result = new XhtmlNode(NodeType.Element);
|
||||
|
||||
int colonIndex = n.indexOf(':');
|
||||
if (colonIndex != -1) {
|
||||
n = n.substring(colonIndex + 1);
|
||||
}
|
||||
|
||||
result.setName(n);
|
||||
unwindPoint = null;
|
||||
List<XhtmlNode> p = new ArrayList<XhtmlNode>();
|
||||
|
|
|
@ -9,7 +9,9 @@ import org.hl7.fhir.dstu3.hapi.validation.DefaultProfileValidationSupport;
|
|||
import org.hl7.fhir.dstu3.hapi.validation.HapiWorkerContext;
|
||||
import org.hl7.fhir.dstu3.model.Base;
|
||||
import org.hl7.fhir.dstu3.model.BooleanType;
|
||||
import org.hl7.fhir.dstu3.model.Observation;
|
||||
import org.hl7.fhir.dstu3.model.Patient;
|
||||
import org.hl7.fhir.dstu3.model.StringType;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
@ -23,6 +25,16 @@ public class FhirPathEngineTest {
|
|||
private static FHIRPathEngine ourEngine;
|
||||
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(FhirPathEngineTest.class);
|
||||
|
||||
@Test
|
||||
public void testAs() throws Exception {
|
||||
Observation obs = new Observation();
|
||||
obs.setValue(new StringType("FOO"));
|
||||
|
||||
List<Base> value = ourEngine.evaluate(obs, "Observation.value.as(String)");
|
||||
assertEquals(1, value.size());
|
||||
assertEquals("FOO", ((StringType)value.get(0)).getValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExistsWithNoValue() throws FHIRException {
|
||||
Patient patient = new Patient();
|
||||
|
|
|
@ -0,0 +1,39 @@
|
|||
package org.hl7.fhir.utilities.xhtml;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class XhtmlNodeTest {
|
||||
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(XhtmlNodeTest.class);
|
||||
@Test
|
||||
public void testParseXhtmlUnqualified() {
|
||||
|
||||
XhtmlNode node = new XhtmlNode();
|
||||
node.setValueAsString("<div xmlns=\"http://www.w3.org/1999/xhtml\">" +
|
||||
"<img src=\"http://pbs.twimg.com/profile_images/544507893991485440/r_vo3uj2_bigger.png\" alt=\"Twitter Avatar\"/>" +
|
||||
"@fhirabend" +
|
||||
"</div>");
|
||||
|
||||
String output = node.getValueAsString();
|
||||
ourLog.info(output);
|
||||
|
||||
assertEquals("<div><img src=\"http://pbs.twimg.com/profile_images/544507893991485440/r_vo3uj2_bigger.png\" alt=\"Twitter Avatar\"/>@fhirabend</div>", output);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseXhtmlQualified() {
|
||||
|
||||
XhtmlNode node = new XhtmlNode();
|
||||
node.setValueAsString("<xhtml:div xmlns:xhtml=\"http://www.w3.org/1999/xhtml\">" +
|
||||
"<xhtml:img src=\"http://pbs.twimg.com/profile_images/544507893991485440/r_vo3uj2_bigger.png\" alt=\"Twitter Avatar\"/>" +
|
||||
"@fhirabend" +
|
||||
"</xhtml:div>");
|
||||
|
||||
String output = node.getValueAsString();
|
||||
ourLog.info(output);
|
||||
|
||||
assertEquals("<div><img src=\"http://pbs.twimg.com/profile_images/544507893991485440/r_vo3uj2_bigger.png\" alt=\"Twitter Avatar\"/>@fhirabend</div>", output);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue