validation fixes for bundle resolution
This commit is contained in:
parent
bf9ead2c9e
commit
0cea5c2bcc
|
@ -226,7 +226,8 @@ public class FHIRPathEngine {
|
|||
|
||||
/**
|
||||
* Implementation of resolve() function. Passed a string, return matching resource, if one is known - else null
|
||||
* @param url
|
||||
* @appContext - passed in by the host to the FHIRPathEngine
|
||||
* @param url the reference (Reference.reference or the value of the canonical
|
||||
* @return
|
||||
* @throws FHIRException
|
||||
*/
|
||||
|
|
|
@ -180,6 +180,7 @@ public class InstanceValidator extends BaseValidator implements IResourceValidat
|
|||
public ValidatorHostContext forContained(Element element) {
|
||||
ValidatorHostContext res = new ValidatorHostContext(appContext);
|
||||
res.resource = element;
|
||||
res.container = resource;
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
@ -230,15 +231,47 @@ public class InstanceValidator extends BaseValidator implements IResourceValidat
|
|||
@Override
|
||||
public Base resolveReference(Object appContext, String url) throws FHIRException {
|
||||
ValidatorHostContext c = (ValidatorHostContext) appContext;
|
||||
if (c.container != null)
|
||||
throw new Error("Not done yet - resolve "+url+" locally (1)");
|
||||
else if (externalHostServices == null)
|
||||
|
||||
if (c.appContext instanceof Element) {
|
||||
Element bnd = (Element) c.appContext;
|
||||
Base res = resolveInBundle(url, bnd);
|
||||
if (res != null)
|
||||
return res;
|
||||
}
|
||||
Base res = resolveInBundle(url, c.resource);
|
||||
if (res != null)
|
||||
return res;
|
||||
res = resolveInBundle(url, c.container);
|
||||
if (res != null)
|
||||
return res;
|
||||
|
||||
if (externalHostServices == null)
|
||||
throw new Error("Not done yet - resolve "+url+" locally (2)");
|
||||
else
|
||||
return externalHostServices.resolveReference(c.appContext, url);
|
||||
|
||||
}
|
||||
|
||||
public Base resolveInBundle(String url, Element bnd) {
|
||||
if (bnd == null)
|
||||
return null;
|
||||
if (bnd.fhirType().equals("Bundle")) {
|
||||
for (Element be : bnd.getChildrenByName("entry")) {
|
||||
Element res = be.getNamedChild("resource");
|
||||
if (res != null) {
|
||||
String fullUrl = be.getChildValue("fullUrl");
|
||||
String rt = res.fhirType();
|
||||
String id = res.getChildValue("id");
|
||||
if (url.equals(fullUrl))
|
||||
return res;
|
||||
if (url.equals(rt+"/"+id))
|
||||
return res;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean conformsToProfile(Object appContext, Base item, String url) throws FHIRException {
|
||||
IResourceValidator val = new InstanceValidator(context, this);
|
||||
|
@ -252,10 +285,6 @@ public class InstanceValidator extends BaseValidator implements IResourceValidat
|
|||
boolean ok = true;
|
||||
for (ValidationMessage v : valerrors)
|
||||
ok = ok && !v.getLevel().isError();
|
||||
if(item instanceof Element) {
|
||||
Element e = (Element) item;
|
||||
System.out.println("Conforms to: resource "+(e.getIdBase() != null ? item.getIdBase() : e.getChildValue("id"))+", url = "+url+", outcome = "+Boolean.toString(ok));
|
||||
}
|
||||
return ok;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue