001package ca.uhn.fhir.jpa.dao.r4;
002
003/*
004 * #%L
005 * HAPI FHIR JPA Server
006 * %%
007 * Copyright (C) 2014 - 2021 Smile CDR, Inc.
008 * %%
009 * Licensed under the Apache License, Version 2.0 (the "License");
010 * you may not use this file except in compliance with the License.
011 * You may obtain a copy of the License at
012 *
013 *      http://www.apache.org/licenses/LICENSE-2.0
014 *
015 * Unless required by applicable law or agreed to in writing, software
016 * distributed under the License is distributed on an "AS IS" BASIS,
017 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
018 * See the License for the specific language governing permissions and
019 * limitations under the License.
020 * #L%
021 */
022
023import ca.uhn.fhir.jpa.dao.BaseHapiFhirResourceDao;
024import org.hl7.fhir.r4.model.QuestionnaireResponse;
025
026public class FhirResourceDaoQuestionnaireResponseR4 extends BaseHapiFhirResourceDao<QuestionnaireResponse> {
027
028        
029//      @Override
030//      protected void validateResourceForStorage(QuestionnaireResponse theResource, ResourceTable theEntityToSave, RequestDetails theRequestDetails) {
031//              super.validateResourceForStorage(theResource, theEntityToSave, theRequestDetails);
032//              if (!myValidateResponses) {
033//                      return;
034//              }
035//              
036//              if (theResource == null || theResource.getQuestionnaire() == null || theResource.getQuestionnaire().getReference() == null || theResource.getQuestionnaire().getReference().isEmpty()) {
037//                      return;
038//              }
039//
040//              FhirValidator val = getContext().newValidator();
041//              val.setValidateAgainstStandardSchema(false);
042//              val.setValidateAgainstStandardSchematron(false);
043//
044//              val.registerValidatorModule(myQuestionnaireResponseValidatorR4);
045//
046//              ValidationResult result = val.validateWithResult(getContext().newJsonParser().parseResource(getContext().newJsonParser().encodeResourceToString(theResource)));
047//              if (!result.isSuccessful()) {
048//                      IBaseOperationOutcome oo = getContext().newJsonParser().parseResource(OperationOutcome.class, getContext().newJsonParser().encodeResourceToString(result.toOperationOutcome()));
049//                      throw new UnprocessableEntityException(getContext(), oo);
050//              }
051//      }
052//
053//      public class JpaResourceLoader implements IResourceLoader {
054//
055//              private RequestDetails myRequestDetails;
056//
057//              public JpaResourceLoader(RequestDetails theRequestDetails) {
058//                      super();
059//                      myRequestDetails = theRequestDetails;
060//              }
061//
062//              @Override
063//              public <T extends IBaseResource> T load(Class<T> theType, IIdType theId) throws ResourceNotFoundException {
064//
065//                      /*
066//                       * The QuestionnaireResponse validator uses RI structures, so for now we need to convert between that and HAPI
067//                       * structures. This is a bit hackish, but hopefully it will go away at some point.
068//                       */
069//                      if ("ValueSet".equals(theType.getSimpleName())) {
070//                              IFhirResourceDao<ValueSet> dao = getDao(ValueSet.class);
071//                              ValueSet in = dao.read(theId, myRequestDetails);
072//                              return (T) in;
073//                      } else if ("Questionnaire".equals(theType.getSimpleName())) {
074//                              IFhirResourceDao<Questionnaire> dao = getDao(Questionnaire.class);
075//                              Questionnaire vs = dao.read(theId, myRequestDetails);
076//                              return (T) vs;
077//                      } else {
078//                              // Should not happen, validator will only ask for these two
079//                              throw new IllegalStateException("Unexpected request to load resource of type " + theType);
080//                      }
081//
082//              }
083//
084//      }
085
086}