View Javadoc
1   package ca.uhn.fhir.jpa.dao.dstu3;
2   
3   /*
4    * #%L
5    * HAPI FHIR JPA Server
6    * %%
7    * Copyright (C) 2014 - 2019 University Health Network
8    * %%
9    * Licensed under the Apache License, Version 2.0 (the "License");
10   * you may not use this file except in compliance with the License.
11   * You may obtain a copy of the License at
12   *
13   * http://www.apache.org/licenses/LICENSE-2.0
14   *
15   * Unless required by applicable law or agreed to in writing, software
16   * distributed under the License is distributed on an "AS IS" BASIS,
17   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18   * See the License for the specific language governing permissions and
19   * limitations under the License.
20   * #L%
21   */
22  
23  import ca.uhn.fhir.jpa.dao.BaseHapiFhirResourceDao;
24  import ca.uhn.fhir.rest.api.ValidationModeEnum;
25  import ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException;
26  import ca.uhn.fhir.validation.IValidationContext;
27  import ca.uhn.fhir.validation.IValidatorModule;
28  import org.hl7.fhir.dstu3.model.OperationOutcome;
29  import org.hl7.fhir.dstu3.model.OperationOutcome.OperationOutcomeIssueComponent;
30  import org.hl7.fhir.exceptions.FHIRException;
31  import org.hl7.fhir.instance.model.api.IAnyResource;
32  import org.hl7.fhir.instance.model.api.IBaseOperationOutcome;
33  import org.hl7.fhir.instance.model.api.IBaseResource;
34  import org.springframework.beans.factory.annotation.Autowired;
35  import org.springframework.beans.factory.annotation.Qualifier;
36  
37  public class FhirResourceDaoDstu3<T extends IAnyResource> extends BaseHapiFhirResourceDao<T> {
38  
39  	private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(FhirResourceDaoDstu3.class);
40  
41  	@Autowired()
42  	@Qualifier("myInstanceValidatorDstu3")
43  	private IValidatorModule myInstanceValidator;
44  
45  	@Override
46  	protected IValidatorModule getInstanceValidator() {
47  		return myInstanceValidator;
48  	}
49  
50  	@Override
51  	protected IBaseOperationOutcome createOperationOutcome(String theSeverity, String theMessage, String theCode) {
52  		OperationOutcome oo = new OperationOutcome();
53  		OperationOutcomeIssueComponent issue = oo.addIssue();
54  		issue.getSeverityElement().setValueAsString(theSeverity);
55  		issue.setDiagnostics(theMessage);
56  		try {
57  			issue.setCode(org.hl7.fhir.dstu3.model.OperationOutcome.IssueType.fromCode(theCode));
58  		} catch (FHIRException e) {
59  			ourLog.error("Unknown code: {}", theCode);
60  		}
61  		return oo;
62  	}
63  
64  
65  }