
001package ca.uhn.fhir.jpa.dao.dstu3; 002 003/* 004 * #%L 005 * HAPI FHIR JPA Server 006 * %% 007 * Copyright (C) 2014 - 2022 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.i18n.Msg; 024import ca.uhn.fhir.jpa.dao.BaseHapiFhirResourceDao; 025import org.hl7.fhir.dstu3.model.QuestionnaireResponse; 026 027public class FhirResourceDaoQuestionnaireResponseDstu3 extends BaseHapiFhirResourceDao<QuestionnaireResponse> { 028 029 030// @Override 031// protected void validateResourceForStorage(QuestionnaireResponse theResource, ResourceTable theEntityToSave, RequestDetails theRequestDetails) { 032// super.validateResourceForStorage(theResource, theEntityToSave, theRequestDetails); 033// if (!myValidateResponses) { 034// return; 035// } 036// 037// if (theResource == null || theResource.getQuestionnaire() == null || theResource.getQuestionnaire().getReference() == null || theResource.getQuestionnaire().getReference().isEmpty()) { 038// return; 039// } 040// 041// FhirValidator val = getContext().newValidator(); 042// val.setValidateAgainstStandardSchema(false); 043// val.setValidateAgainstStandardSchematron(false); 044// 045// val.registerValidatorModule(myQuestionnaireResponseValidatorDstu3); 046// 047// ValidationResult result = val.validateWithResult(getContext().newJsonParser().parseResource(getContext().newJsonParser().encodeResourceToString(theResource))); 048// if (!result.isSuccessful()) { 049// IBaseOperationOutcome oo = getContext().newJsonParser().parseResource(OperationOutcome.class, getContext().newJsonParser().encodeResourceToString(result.toOperationOutcome())); 050// throw new UnprocessableEntityException(Msg.code(1078) + getContext(), oo); 051// } 052// } 053// 054// public class JpaResourceLoader implements IResourceLoader { 055// 056// private RequestDetails myRequestDetails; 057// 058// public JpaResourceLoader(RequestDetails theRequestDetails) { 059// super(); 060// myRequestDetails = theRequestDetails; 061// } 062// 063// @Override 064// public <T extends IBaseResource> T load(Class<T> theType, IIdType theId) throws ResourceNotFoundException { 065// 066// /* 067// * The QuestionnaireResponse validator uses RI structures, so for now we need to convert between that and HAPI 068// * structures. This is a bit hackish, but hopefully it will go away at some point. 069// */ 070// if ("ValueSet".equals(theType.getSimpleName())) { 071// IFhirResourceDao<ValueSet> dao = getDao(ValueSet.class); 072// ValueSet in = dao.read(theId, myRequestDetails); 073// return (T) in; 074// } else if ("Questionnaire".equals(theType.getSimpleName())) { 075// IFhirResourceDao<Questionnaire> dao = getDao(Questionnaire.class); 076// Questionnaire vs = dao.read(theId, myRequestDetails); 077// return (T) vs; 078// } else { 079// // Should not happen, validator will only ask for these two 080// throw new IllegalStateException(Msg.code(1079) + "Unexpected request to load resource of type " + theType); 081// } 082// 083// } 084// 085// } 086 087}