
001/*- 002 * #%L 003 * HAPI FHIR JPA Server 004 * %% 005 * Copyright (C) 2014 - 2025 Smile CDR, Inc. 006 * %% 007 * Licensed under the Apache License, Version 2.0 (the "License"); 008 * you may not use this file except in compliance with the License. 009 * You may obtain a copy of the License at 010 * 011 * http://www.apache.org/licenses/LICENSE-2.0 012 * 013 * Unless required by applicable law or agreed to in writing, software 014 * distributed under the License is distributed on an "AS IS" BASIS, 015 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 016 * See the License for the specific language governing permissions and 017 * limitations under the License. 018 * #L% 019 */ 020package ca.uhn.fhir.jpa.provider; 021 022import ca.uhn.fhir.jpa.api.dao.IFhirResourceDaoConceptMap; 023import ca.uhn.fhir.jpa.model.util.JpaConstants; 024import ca.uhn.fhir.rest.annotation.Operation; 025import ca.uhn.fhir.rest.annotation.OperationParam; 026import ca.uhn.fhir.rest.api.server.RequestDetails; 027import ca.uhn.fhir.util.DatatypeUtil; 028import jakarta.annotation.Nonnull; 029import org.apache.commons.lang3.Validate; 030import org.hl7.fhir.instance.model.api.IBaseOperationOutcome; 031import org.hl7.fhir.instance.model.api.IPrimitiveType; 032 033/** 034 * This resource provider implements the <code>ConceptMap/$hapi.fhir.add-mapping</code> 035 * and <code>ConceptMap/$hapi.fhir.remove-mapping</code> operations. 036 */ 037@SuppressWarnings("ClassCanBeRecord") 038public class ConceptMapAddAndRemoveMappingProvider { 039 040 private final IFhirResourceDaoConceptMap<?> myConceptMapDao; 041 042 /** 043 * Constructor 044 */ 045 public ConceptMapAddAndRemoveMappingProvider(@Nonnull IFhirResourceDaoConceptMap<?> theConceptMapDao) { 046 Validate.notNull(theConceptMapDao, "theConceptMapDao must not be null"); 047 myConceptMapDao = theConceptMapDao; 048 } 049 050 /** 051 * Operation: <code>ConceptMap/$hapi.fhir.add-mapping</code> 052 */ 053 @Operation(typeName = "ConceptMap", name = JpaConstants.OPERATION_CONCEPTMAP_ADD_MAPPING) 054 public IBaseOperationOutcome addMapping( 055 @OperationParam(name = JpaConstants.OPERATION_CONCEPTMAP_ADD_MAPPING_CONCEPTMAP_URL, typeName = "uri") 056 IPrimitiveType<String> theUrl, 057 @OperationParam(name = JpaConstants.OPERATION_CONCEPTMAP_ADD_MAPPING_SOURCE_SYSTEM, typeName = "uri") 058 IPrimitiveType<String> theSourceSystem, 059 @OperationParam(name = JpaConstants.OPERATION_CONCEPTMAP_ADD_MAPPING_SOURCE_VERSION, typeName = "code") 060 IPrimitiveType<String> theSourceVersion, 061 @OperationParam(name = JpaConstants.OPERATION_CONCEPTMAP_ADD_MAPPING_SOURCE_CODE, typeName = "code") 062 IPrimitiveType<String> theSourceCode, 063 @OperationParam(name = JpaConstants.OPERATION_CONCEPTMAP_ADD_MAPPING_SOURCE_DISPLAY, typeName = "string") 064 IPrimitiveType<String> theSourceDisplay, 065 @OperationParam(name = JpaConstants.OPERATION_CONCEPTMAP_ADD_MAPPING_TARGET_SYSTEM, typeName = "uri") 066 IPrimitiveType<String> theTargetSystem, 067 @OperationParam(name = JpaConstants.OPERATION_CONCEPTMAP_ADD_MAPPING_TARGET_VERSION, typeName = "code") 068 IPrimitiveType<String> theTargetVersion, 069 @OperationParam(name = JpaConstants.OPERATION_CONCEPTMAP_ADD_MAPPING_TARGET_CODE, typeName = "code") 070 IPrimitiveType<String> theTargetCode, 071 @OperationParam(name = JpaConstants.OPERATION_CONCEPTMAP_ADD_MAPPING_TARGET_DISPLAY, typeName = "string") 072 IPrimitiveType<String> theTargetDisplay, 073 @OperationParam(name = JpaConstants.OPERATION_CONCEPTMAP_ADD_MAPPING_EQUIVALENCE, typeName = "code") 074 IPrimitiveType<String> theEquivalence, 075 RequestDetails theRequestDetails) { 076 077 IFhirResourceDaoConceptMap.AddMappingRequest request = new IFhirResourceDaoConceptMap.AddMappingRequest(); 078 request.setConceptMapUri(DatatypeUtil.toStringValue(theUrl)); 079 request.setSourceSystem(DatatypeUtil.toStringValue(theSourceSystem)); 080 request.setSourceSystemVersion(DatatypeUtil.toStringValue(theSourceVersion)); 081 request.setSourceCode(DatatypeUtil.toStringValue(theSourceCode)); 082 request.setSourceDisplay(DatatypeUtil.toStringValue(theSourceDisplay)); 083 request.setTargetSystem(DatatypeUtil.toStringValue(theTargetSystem)); 084 request.setTargetSystemVersion(DatatypeUtil.toStringValue(theTargetVersion)); 085 request.setTargetCode(DatatypeUtil.toStringValue(theTargetCode)); 086 request.setTargetDisplay(DatatypeUtil.toStringValue(theTargetDisplay)); 087 request.setEquivalence(DatatypeUtil.toStringValue(theEquivalence)); 088 089 return myConceptMapDao.addMapping(request, theRequestDetails); 090 } 091 092 /** 093 * Operation: <code>ConceptMap/$hapi.fhir.remove-mapping</code> 094 */ 095 @Operation(typeName = "ConceptMap", name = JpaConstants.OPERATION_CONCEPTMAP_REMOVE_MAPPING) 096 public IBaseOperationOutcome removeMapping( 097 @OperationParam(name = JpaConstants.OPERATION_CONCEPTMAP_ADD_MAPPING_CONCEPTMAP_URL, typeName = "uri") 098 IPrimitiveType<String> theUrl, 099 @OperationParam(name = JpaConstants.OPERATION_CONCEPTMAP_ADD_MAPPING_SOURCE_SYSTEM, typeName = "uri") 100 IPrimitiveType<String> theSourceSystem, 101 @OperationParam(name = JpaConstants.OPERATION_CONCEPTMAP_ADD_MAPPING_SOURCE_VERSION, typeName = "code") 102 IPrimitiveType<String> theSourceVersion, 103 @OperationParam(name = JpaConstants.OPERATION_CONCEPTMAP_ADD_MAPPING_SOURCE_CODE, typeName = "code") 104 IPrimitiveType<String> theSourceCode, 105 @OperationParam(name = JpaConstants.OPERATION_CONCEPTMAP_ADD_MAPPING_TARGET_SYSTEM, typeName = "uri") 106 IPrimitiveType<String> theTargetSystem, 107 @OperationParam(name = JpaConstants.OPERATION_CONCEPTMAP_ADD_MAPPING_TARGET_VERSION, typeName = "code") 108 IPrimitiveType<String> theTargetVersion, 109 @OperationParam(name = JpaConstants.OPERATION_CONCEPTMAP_ADD_MAPPING_TARGET_CODE, typeName = "code") 110 IPrimitiveType<String> theTargetCode, 111 RequestDetails theRequestDetails) { 112 113 IFhirResourceDaoConceptMap.RemoveMappingRequest request = new IFhirResourceDaoConceptMap.RemoveMappingRequest(); 114 request.setConceptMapUri(DatatypeUtil.toStringValue(theUrl)); 115 request.setSourceSystem(DatatypeUtil.toStringValue(theSourceSystem)); 116 request.setSourceSystemVersion(DatatypeUtil.toStringValue(theSourceVersion)); 117 request.setSourceCode(DatatypeUtil.toStringValue(theSourceCode)); 118 request.setTargetSystem(DatatypeUtil.toStringValue(theTargetSystem)); 119 request.setTargetSystemVersion(DatatypeUtil.toStringValue(theTargetVersion)); 120 request.setTargetCode(DatatypeUtil.toStringValue(theTargetCode)); 121 122 return myConceptMapDao.removeMapping(request, theRequestDetails); 123 } 124}