001package ca.uhn.fhir.jpa.provider.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.context.support.IValidationSupport;
025import ca.uhn.fhir.jpa.api.dao.IFhirResourceDaoCodeSystem;
026import ca.uhn.fhir.jpa.model.util.JpaConstants;
027import ca.uhn.fhir.rest.annotation.Operation;
028import ca.uhn.fhir.rest.annotation.OperationParam;
029import ca.uhn.fhir.rest.api.server.RequestDetails;
030import ca.uhn.fhir.rest.server.exceptions.InternalErrorException;
031import org.hl7.fhir.dstu3.model.BooleanType;
032import org.hl7.fhir.dstu3.model.CodeSystem;
033import org.hl7.fhir.dstu3.model.CodeType;
034import org.hl7.fhir.dstu3.model.CodeableConcept;
035import org.hl7.fhir.dstu3.model.Coding;
036import org.hl7.fhir.dstu3.model.Parameters;
037import org.hl7.fhir.dstu3.model.StringType;
038import org.hl7.fhir.dstu3.model.UriType;
039import org.hl7.fhir.exceptions.FHIRException;
040
041import javax.servlet.http.HttpServletRequest;
042import java.util.List;
043
044public class BaseJpaResourceProviderCodeSystemDstu3 extends JpaResourceProviderDstu3<CodeSystem> {
045
046        @Operation(name = JpaConstants.OPERATION_LOOKUP, idempotent = true, returnParameters = {
047                @OperationParam(name = "name", type = StringType.class, min = 1),
048                @OperationParam(name = "version", type = StringType.class, min = 0),
049                @OperationParam(name = "display", type = StringType.class, min = 1),
050                @OperationParam(name = "abstract", type = BooleanType.class, min = 1),
051        })
052        public Parameters lookup(
053                HttpServletRequest theServletRequest,
054                @OperationParam(name = "code", min = 0, max = 1) CodeType theCode,
055                @OperationParam(name = "system", min = 0, max = 1) UriType theSystem,
056                @OperationParam(name = "coding", min = 0, max = 1) Coding theCoding,
057                @OperationParam(name = "version", min=0, max=1) StringType theVersion,
058                @OperationParam(name = "displayLanguage", min=0, max=1) CodeType theDisplayLanguage,
059                @OperationParam(name = "property", min = 0, max = OperationParam.MAX_UNLIMITED) List<CodeType> theProperties,
060                RequestDetails theRequestDetails
061        ) {
062
063                startRequest(theServletRequest);
064                try {
065                        IFhirResourceDaoCodeSystem<CodeSystem, Coding, CodeableConcept> dao = (IFhirResourceDaoCodeSystem<CodeSystem, Coding, CodeableConcept>) getDao();
066                        IValidationSupport.LookupCodeResult result;
067                        if (theVersion != null) {
068                                result = dao.lookupCode(theCode, new UriType(theSystem.getValue() + "|" + theVersion), theCoding, theDisplayLanguage, theRequestDetails);
069                        } else {
070                                result = dao.lookupCode(theCode, theSystem, theCoding, theDisplayLanguage, theRequestDetails);
071                        }
072                        result.throwNotFoundIfAppropriate();
073                        return (Parameters) result.toParameters(theRequestDetails.getFhirContext(), theProperties);
074                } catch (FHIRException e) {
075                        throw new InternalErrorException(Msg.code(1153) + e);
076                } finally {
077                        endRequest(theServletRequest);
078                }
079        }
080
081
082        /**
083         * $subsumes operation
084         */
085        @Operation(name = JpaConstants.OPERATION_SUBSUMES, idempotent = true, returnParameters = {
086                @OperationParam(name = "outcome", type = CodeType.class, min = 1),
087        })
088        public Parameters subsumes(
089                HttpServletRequest theServletRequest,
090                @OperationParam(name = "codeA", min = 0, max = 1) CodeType theCodeA,
091                @OperationParam(name = "codeB", min = 0, max = 1) CodeType theCodeB,
092                @OperationParam(name = "system", min = 0, max = 1) UriType theSystem,
093                @OperationParam(name = "codingA", min = 0, max = 1) Coding theCodingA,
094                @OperationParam(name = "codingB", min = 0, max = 1) Coding theCodingB,
095                @OperationParam(name = "version", min = 0, max = 1) StringType theVersion,
096                RequestDetails theRequestDetails
097        ) {
098
099                startRequest(theServletRequest);
100                try {
101                        IFhirResourceDaoCodeSystem<CodeSystem, Coding, CodeableConcept> dao = (IFhirResourceDaoCodeSystem<CodeSystem, Coding, CodeableConcept>) getDao();
102                        IFhirResourceDaoCodeSystem.SubsumesResult result;
103                        if (theVersion != null) {
104                                theSystem = new UriType(theSystem.asStringValue() + "|" + theVersion.toString());
105                        }
106                        result = dao.subsumes(theCodeA, theCodeB, theSystem, theCodingA, theCodingB, theRequestDetails);
107                        return (Parameters) result.toParameters(theRequestDetails.getFhirContext());
108                } finally {
109                        endRequest(theServletRequest);
110                }
111        }
112
113}