use of org.hl7.gravity.refimpl.sdohexchange.dto.Validated in project org.hl7.fhir.core by hapifhir.
the class InstanceValidator method startInner.
public void startInner(ValidatorHostContext hostContext, List<ValidationMessage> errors, Element resource, Element element, StructureDefinition defn, NodeStack stack, boolean checkSpecials) {
// the first piece of business is to see if we've validated this resource against this profile before.
// if we have (*or if we still are*), then we'll just return our existing errors
ResourceValidationTracker resTracker = getResourceTracker(element);
List<ValidationMessage> cachedErrors = resTracker.getOutcomes(defn);
if (cachedErrors != null) {
for (ValidationMessage vm : cachedErrors) {
if (!errors.contains(vm)) {
errors.add(vm);
}
}
return;
}
if (rule(errors, IssueType.STRUCTURE, element.line(), element.col(), stack.getLiteralPath(), defn.hasSnapshot(), I18nConstants.VALIDATION_VAL_PROFILE_NOSNAPSHOT, defn.getUrl())) {
List<ValidationMessage> localErrors = new ArrayList<ValidationMessage>();
resTracker.startValidating(defn);
trackUsage(defn, hostContext, element);
validateElement(hostContext, localErrors, defn, defn.getSnapshot().getElement().get(0), null, null, resource, element, element.getName(), stack, false, true, null);
resTracker.storeOutcomes(defn, localErrors);
for (ValidationMessage vm : localErrors) {
if (!errors.contains(vm)) {
errors.add(vm);
}
}
}
if (checkSpecials) {
checkSpecials(hostContext, errors, element, stack, checkSpecials);
validateResourceRules(errors, element, stack);
}
}
use of org.hl7.gravity.refimpl.sdohexchange.dto.Validated in project org.hl7.fhir.core by hapifhir.
the class SHCParser method parse.
public List<NamedElement> parse(InputStream stream) throws IOException, FHIRFormatError, DefinitionException, FHIRException {
List<NamedElement> res = new ArrayList<>();
String src = TextFile.streamToString(stream).trim();
List<String> list = new ArrayList<>();
String pfx = null;
if (src.startsWith("{")) {
JsonObject json = JsonTrackingParser.parseJson(src);
if (checkProperty(json, "$", "verifiableCredential", true, "Array")) {
pfx = "verifiableCredential";
JsonArray arr = json.getAsJsonArray("verifiableCredential");
int i = 0;
for (JsonElement e : arr) {
if (!(e instanceof JsonPrimitive)) {
logError(line(e), col(e), "$.verifiableCredential[" + i + "]", IssueType.STRUCTURE, "Wrong Property verifiableCredential in JSON Payload. Expected : String but found " + JSONUtil.type(e), IssueSeverity.ERROR);
} else {
list.add(e.getAsString());
}
i++;
}
} else {
return res;
}
} else {
list.add(src);
}
int c = 0;
for (String ssrc : list) {
String prefix = pfx == null ? "" : pfx + "[" + Integer.toString(c) + "].";
c++;
JWT jwt = null;
try {
jwt = decodeJWT(ssrc);
} catch (Exception e) {
logError(1, 1, prefix + "JWT", IssueType.INVALID, "Unable to decode JWT token", IssueSeverity.ERROR);
return res;
}
map = jwt.map;
checkNamedProperties(jwt.getPayload(), prefix + "payload", "iss", "nbf", "vc");
checkProperty(jwt.getPayload(), prefix + "payload", "iss", true, "String");
logError(1, 1, prefix + "JWT", IssueType.INFORMATIONAL, "The FHIR Validator does not check the JWT signature " + "(see https://demo-portals.smarthealth.cards/VerifierPortal.html or https://github.com/smart-on-fhir/health-cards-dev-tools) (Issuer = '" + jwt.getPayload().get("iss").getAsString() + "')", IssueSeverity.INFORMATION);
checkProperty(jwt.getPayload(), prefix + "payload", "nbf", true, "Number");
JsonObject vc = jwt.getPayload().getAsJsonObject("vc");
if (vc == null) {
logError(1, 1, "JWT", IssueType.STRUCTURE, "Unable to find property 'vc' in the payload", IssueSeverity.ERROR);
return res;
}
String path = prefix + "payload.vc";
checkNamedProperties(vc, path, "type", "credentialSubject");
if (!checkProperty(vc, path, "type", true, "Array")) {
return res;
}
JsonArray type = vc.getAsJsonArray("type");
int i = 0;
for (JsonElement e : type) {
if (!(e instanceof JsonPrimitive)) {
logError(line(e), col(e), path + ".type[" + i + "]", IssueType.STRUCTURE, "Wrong Property Type in JSON Payload. Expected : String but found " + JSONUtil.type(e), IssueSeverity.ERROR);
} else {
types.add(e.getAsString());
}
i++;
}
if (!types.contains("https://smarthealth.cards#health-card")) {
logError(line(vc), col(vc), path, IssueType.STRUCTURE, "Card does not claim to be of type https://smarthealth.cards#health-card, cannot validate", IssueSeverity.ERROR);
return res;
}
if (!checkProperty(vc, path, "credentialSubject", true, "Object")) {
return res;
}
JsonObject cs = vc.getAsJsonObject("credentialSubject");
path = path + ".credentialSubject";
if (!checkProperty(cs, path, "fhirVersion", true, "String")) {
return res;
}
JsonElement fv = cs.get("fhirVersion");
if (!VersionUtilities.versionsCompatible(context.getVersion(), fv.getAsString())) {
logError(line(fv), col(fv), path + ".fhirVersion", IssueType.STRUCTURE, "Card claims to be of version " + fv.getAsString() + ", cannot be validated against version " + context.getVersion(), IssueSeverity.ERROR);
return res;
}
if (!checkProperty(cs, path, "fhirBundle", true, "Object")) {
return res;
}
// ok. all checks passed, we can now validate the bundle
Element e = jsonParser.parse(cs.getAsJsonObject("fhirBundle"), map);
if (e != null) {
res.add(new NamedElement(path, e));
}
}
return res;
}
use of org.hl7.gravity.refimpl.sdohexchange.dto.Validated in project fhir-bridge by ehrbase.
the class FhirProfileValidator method process.
@Override
public void process(Exchange exchange) {
Resource resource = exchange.getIn().getBody(Resource.class);
LOG.trace("Validating {} resource...", resource.getResourceType());
List<String> profiles = Resources.getProfileUris(resource);
if (profiles.isEmpty()) {
validateDefault(resource, exchange);
} else {
validateProfiles(resource, exchange);
}
LOG.info("{} resource validated", resource.getResourceType());
}
use of org.hl7.gravity.refimpl.sdohexchange.dto.Validated in project Gravity-SDOH-Exchange-RI by FHIR.
the class ResourceService method getTaskResources.
public TaskJsonResourcesDto getTaskResources(String id) {
// Getting task by id with Patient, requester Organization and ServiceRequest
Bundle taskBundle = cpClient.search().forResource(Task.class).where(Task.RES_ID.exactly().code(id)).include(Task.INCLUDE_FOCUS).include(Task.INCLUDE_PATIENT).include(Task.INCLUDE_REQUESTER).returnBundle(Bundle.class).execute();
Task task = FhirUtil.getFromBundle(taskBundle, Task.class).stream().findFirst().orElseThrow(() -> new ResourceNotFoundException(new IdType(Task.class.getSimpleName(), id)));
// We expect that task was validated and contains all resources
ServiceRequest serviceRequest = FhirUtil.getFirstFromBundle(taskBundle, ServiceRequest.class);
Patient patient = FhirUtil.getFirstFromBundle(taskBundle, Patient.class);
Organization requester = FhirUtil.getFirstFromBundle(taskBundle, Organization.class);
// Load all Task Procedures and ServiceRequest required resources as one transaction
Map<Class<? extends Resource>, List<Resource>> loadedResources = resourceLoader.getResources(cpClient, collectAllReferences(task, serviceRequest));
TaskJsonResourcesDto resourcesDto = new TaskJsonResourcesDto();
resourcesDto.setTask(resourceParser.parse(task));
resourcesDto.setServiceRequest(resourceParser.parse(serviceRequest));
resourcesDto.setPatient(resourceParser.parse(patient));
resourcesDto.setRequester(resourceParser.parse(requester));
resourcesDto.setConsent(resourceParser.parse(loadedResources.get(Consent.class)).stream().findFirst().orElse(null));
resourcesDto.setConditions(resourceParser.parse(loadedResources.get(Condition.class)));
resourcesDto.setGoals(resourceParser.parse(loadedResources.get(Goal.class)));
resourcesDto.setProcedures(resourceParser.parse(loadedResources.get(Procedure.class)));
return resourcesDto;
}
use of org.hl7.gravity.refimpl.sdohexchange.dto.Validated in project Gravity-SDOH-Exchange-RI by FHIR.
the class ResourceService method getTaskResources.
public TaskJsonResourcesDto getTaskResources(Integer serverId, String taskId) {
Server server = serverRepository.findById(serverId).orElseThrow(() -> new ServerNotFoundException(String.format("No server was found by id '%s'", serverId)));
IGenericClient fhirClient = fhirContext.newRestfulGenericClient(server.getFhirServerUrl());
// Doesn't support now
// fhirClient.registerInterceptor(new BearerTokenAuthInterceptor(
// authorizationClient.getTokenResponse(URI.create(server.getAuthServerUrl()), server.getClientId(),
// server.getClientSecret(), SCOPE)
// .getAccessToken()));
// Getting task by id with Patient, requester Organization and ServiceRequest
Bundle taskBundle = fhirClient.search().forResource(Task.class).where(Task.RES_ID.exactly().code(taskId)).include(Task.INCLUDE_FOCUS).include(Task.INCLUDE_PATIENT).include(Task.INCLUDE_REQUESTER).returnBundle(Bundle.class).execute();
Task task = FhirUtil.getFromBundle(taskBundle, Task.class).stream().findFirst().orElseThrow(() -> new ResourceNotFoundException(new IdType(Task.class.getSimpleName(), taskId)));
// We expect that task was validated and contains all resources
ServiceRequest serviceRequest = FhirUtil.getFirstFromBundle(taskBundle, ServiceRequest.class);
Patient patient = FhirUtil.getFirstFromBundle(taskBundle, Patient.class);
Organization requester = FhirUtil.getFirstFromBundle(taskBundle, Organization.class);
// Load all Task Procedures and ServiceRequest required resources as one transaction
Map<Class<? extends Resource>, List<Resource>> loadedResources = resourceLoader.getResources(fhirClient, collectAllReferences(task, serviceRequest));
TaskJsonResourcesDto resourcesDto = new TaskJsonResourcesDto();
resourcesDto.setTask(resourceParser.parse(task));
resourcesDto.setServiceRequest(resourceParser.parse(serviceRequest));
resourcesDto.setPatient(resourceParser.parse(patient));
resourcesDto.setRequester(resourceParser.parse(requester));
resourcesDto.setConsent(resourceParser.parse(loadedResources.get(Consent.class)).stream().findFirst().orElse(null));
resourcesDto.setConditions(resourceParser.parse(loadedResources.get(Condition.class)));
resourcesDto.setGoals(resourceParser.parse(loadedResources.get(Goal.class)));
resourcesDto.setProcedures(resourceParser.parse(loadedResources.get(Procedure.class)));
return resourcesDto;
}
Aggregations