package edu.gatech.i3l.fhir.jpa.dao;
//package edu.gatech.i3l.fhir.jpa.dao;
//
///*
// * #%L
// * HAPI FHIR JPA Server
// * %%
// * Copyright (C) 2014 - 2015 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%
// */
//
//import java.util.Collections;
//import java.util.List;
//import java.util.ArrayList;
//
//import org.hl7.fhir.instance.model.api.IBaseOperationOutcome;
//import org.hl7.fhir.instance.model.api.IBaseResource;
//
//import ca.uhn.fhir.context.RuntimeResourceDefinition;
//import ca.uhn.fhir.context.RuntimeSearchParam;
//import ca.uhn.fhir.model.api.IResource;
//import ca.uhn.fhir.model.api.Include;
//import ca.uhn.fhir.model.base.composite.BaseResourceReferenceDt;
//import ca.uhn.fhir.model.base.resource.BaseOperationOutcome.BaseIssue;
//import ca.uhn.fhir.model.dstu2.resource.OperationOutcome;
//import ca.uhn.fhir.model.dstu2.resource.OperationOutcome.Issue;
//import ca.uhn.fhir.model.dstu2.valueset.IssueSeverityEnum;
//import ca.uhn.fhir.model.dstu2.valueset.IssueTypeEnum;
//import ca.uhn.fhir.model.primitive.IdDt;
//import ca.uhn.fhir.parser.IParser;
//import ca.uhn.fhir.parser.IParserErrorHandler;
//import ca.uhn.fhir.rest.api.MethodOutcome;
//import ca.uhn.fhir.rest.api.ValidationModeEnum;
//import ca.uhn.fhir.rest.server.EncodingEnum;
//import ca.uhn.fhir.util.FhirTerser;
//import ca.uhn.fhir.validation.FhirValidator;
//import ca.uhn.fhir.validation.ValidationResult;
//
//public class FhirResourceDaoDstu2<T extends IResource> extends BaseHapiFhirResourceDao<T> {
//
// protected List<Object> getIncludeValues(FhirTerser theTerser, Include theInclude, IBaseResource theResource, RuntimeResourceDefinition theResourceDef) {
// List<Object> values;
// if ("*".equals(theInclude.getValue())) {
// values = new ArrayList<Object>();
// values.addAll(theTerser.getAllPopulatedChildElementsOfType(theResource, BaseResourceReferenceDt.class));
// } else if (theInclude.getValue().startsWith(theResourceDef.getName() + ":")) {
// values = new ArrayList<Object>();
// RuntimeSearchParam sp = theResourceDef.getSearchParam(theInclude.getValue().substring(theInclude.getValue().indexOf(':')+1));
// for (String nextPath : sp.getPathsSplit()) {
// values.addAll(theTerser.getValues(theResource, nextPath));
// }
// } else {
// values = Collections.emptyList();
// }
// return values;
// }
//
// @Override
// protected IBaseOperationOutcome createOperationOutcome(String theSeverity, String theMessage) {
// OperationOutcome oo = new OperationOutcome();
// oo.getIssueFirstRep().getSeverityElement().setValue(theSeverity);
// oo.getIssueFirstRep().getDetailsElement().setValue(theMessage);
// return oo;
// }
//
// @Override
// public MethodOutcome validate(T theResource, IdDt theId, String theRawResource, EncodingEnum theEncoding, ValidationModeEnum theMode, String theProfile) {
// final OperationOutcome oo = new OperationOutcome();
//
// IParser parser = theEncoding.newParser(getBaseDao().getContext());
// parser.setParserErrorHandler(new IParserErrorHandler() {
//
// @Override
// public void unknownAttribute(IParseLocation theLocation, String theAttributeName) {
// oo.addIssue().setSeverity(IssueSeverityEnum.ERROR).setCode(IssueTypeEnum.INVALID_CONTENT).setDetails("Unknown attribute found: " + theAttributeName);
// }
//
// @Override
// public void unknownElement(IParseLocation theLocation, String theElementName) {
// oo.addIssue().setSeverity(IssueSeverityEnum.ERROR).setCode(IssueTypeEnum.INVALID_CONTENT).setDetails("Unknown element found: " + theElementName);
// }
//
// //@Override
// public void unexpectedRepeatingElement(IParseLocation theLocation, String theElementName) {
// oo.addIssue().setSeverity(IssueSeverityEnum.ERROR).setCode(IssueTypeEnum.INVALID_CONTENT).setDetails("Multiple repetitions of non-repeatable element found: " + theElementName);
// }
// });
//
// FhirValidator validator = getBaseDao().getContext().newValidator();
// validator.setValidateAgainstStandardSchema(true);
// validator.setValidateAgainstStandardSchematron(true);
// ValidationResult result = validator.validateWithResult(theResource);
// OperationOutcome operationOutcome = (OperationOutcome) result.toOperationOutcome();
// for (BaseIssue next : operationOutcome.getIssue()) {
// oo.getIssue().add((Issue) next);
// }
//
// // This method returns a MethodOutcome object
// MethodOutcome retVal = new MethodOutcome();
// oo.addIssue().setSeverity(IssueSeverityEnum.INFORMATION).setDetails("Validation succeeded");
// retVal.setOperationOutcome(oo);
//
// return retVal;
// }
//
//
//}