001/*-
002 * #%L
003 * HAPI FHIR - Master Data Management
004 * %%
005 * Copyright (C) 2014 - 2024 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.mdm.model;
021
022import ca.uhn.fhir.mdm.api.MdmLinkSourceEnum;
023import ca.uhn.fhir.mdm.api.MdmMatchResultEnum;
024
025import java.util.HashMap;
026import java.util.Map;
027
028public class MdmLinkMetrics {
029        /**
030         * The resource type to which these metrics apply.
031         */
032        private String myResourceType;
033
034        /**
035         * A mapping of MatchType -> LinkSource -> count.
036         * Eg:
037         * MATCH
038         *              AUTO    - 2
039         *              MANUAL  - 1
040         * NO_MATCH
041         *      AUTO    - 1
042         *      MANUAL  - 3
043         */
044        private Map<MdmMatchResultEnum, Map<MdmLinkSourceEnum, Long>> myMatchTypeToLinkToCountMap;
045
046        public String getResourceType() {
047                return myResourceType;
048        }
049
050        public void setResourceType(String theResourceType) {
051                myResourceType = theResourceType;
052        }
053
054        public Map<MdmMatchResultEnum, Map<MdmLinkSourceEnum, Long>> getMatchTypeToLinkToCountMap() {
055                if (myMatchTypeToLinkToCountMap == null) {
056                        myMatchTypeToLinkToCountMap = new HashMap<>();
057                }
058                return myMatchTypeToLinkToCountMap;
059        }
060
061        public void addMetric(
062                        MdmMatchResultEnum theMdmMatchResultEnum, MdmLinkSourceEnum theLinkSourceEnum, long theCount) {
063                Map<MdmMatchResultEnum, Map<MdmLinkSourceEnum, Long>> map = getMatchTypeToLinkToCountMap();
064
065                if (!map.containsKey(theMdmMatchResultEnum)) {
066                        map.put(theMdmMatchResultEnum, new HashMap<>());
067                }
068                Map<MdmLinkSourceEnum, Long> lsToCountMap = map.get(theMdmMatchResultEnum);
069                lsToCountMap.put(theLinkSourceEnum, theCount);
070        }
071}