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.api.dao.IFhirResourceDaoConceptMap;
024import ca.uhn.fhir.jpa.api.model.TranslationRequest;
025import ca.uhn.fhir.context.support.TranslateConceptResults;
026import ca.uhn.fhir.jpa.dao.BaseHapiFhirResourceDao;
027import ca.uhn.fhir.jpa.model.cross.IBasePersistedResource;
028import ca.uhn.fhir.jpa.model.entity.ResourceTable;
029import ca.uhn.fhir.jpa.term.api.ITermConceptMappingSvc;
030import ca.uhn.fhir.rest.api.server.RequestDetails;
031import ca.uhn.fhir.rest.api.server.storage.TransactionDetails;
032import org.hl7.fhir.instance.model.api.IBaseResource;
033import org.hl7.fhir.r4.model.ConceptMap;
034import org.springframework.beans.factory.annotation.Autowired;
035
036import java.util.Date;
037
038public class FhirResourceDaoConceptMapR4 extends BaseHapiFhirResourceDao<ConceptMap> implements IFhirResourceDaoConceptMap<ConceptMap> {
039        @Autowired
040        private ITermConceptMappingSvc myTermConceptMappingSvc;
041
042        @Override
043        public TranslateConceptResults translate(TranslationRequest theTranslationRequest, RequestDetails theRequestDetails) {
044                if (theTranslationRequest.hasReverse() && theTranslationRequest.getReverseAsBoolean()) {
045                        return myTermConceptMappingSvc.translateWithReverse(theTranslationRequest);
046                }
047
048                return myTermConceptMappingSvc.translate(theTranslationRequest);
049        }
050
051        @Override
052        public ResourceTable updateEntity(RequestDetails theRequestDetails, IBaseResource theResource, IBasePersistedResource theEntity, Date theDeletedTimestampOrNull, boolean thePerformIndexing,
053                                                                                                 boolean theUpdateVersion, TransactionDetails theTransactionDetails, boolean theForceUpdate, boolean theCreateNewHistoryEntry) {
054                ResourceTable retVal = super.updateEntity(theRequestDetails, theResource, theEntity, theDeletedTimestampOrNull, thePerformIndexing, theUpdateVersion, theTransactionDetails, theForceUpdate, theCreateNewHistoryEntry);
055
056                if (!retVal.isUnchangedInCurrentOperation()) {
057                        if (retVal.getDeleted() == null) {
058                                ConceptMap conceptMap = (ConceptMap) theResource;
059                                myTermConceptMappingSvc.storeTermConceptMapAndChildren(retVal, conceptMap);
060                        } else {
061                                myTermConceptMappingSvc.deleteConceptMapAndChildren(retVal);
062                        }
063                }
064
065                return retVal;
066        }
067}