001/*-
002 * #%L
003 * Smile CDR - CDR
004 * %%
005 * Copyright (C) 2016 - 2026 Smile CDR, Inc.
006 * %%
007 * All rights reserved.
008 * #L%
009 */
010package ca.cdr.api.util;
011
012import org.apache.commons.lang3.StringUtils;
013import org.hl7.fhir.instance.model.api.IBaseCoding;
014
015import java.util.List;
016
017/**
018 * In places, we need to create a synthetic coding. These codings behave as a tuple of (system, code, display) for
019 * the benefit of calling a library that usually operates on real FHIR data and expects its input to implement the
020 * IBaseCoding interface. However, they are never actually inserted into a real FHIR Resource or persisted to
021 * a repository. Any class that extends IBaseCoding would do, but most such classes are part of one FHIR release
022 * or another. In order to prevent an otherwise unnecessary coupling to some real version, we introduce this simple
023 * implementation that can be used in such cases.
024 */
025public class VersionIndependentCoding implements IBaseCoding {
026        private final String mySystem;
027        private final String myCode;
028        private final String myDisplay;
029
030        // user defined version
031        private String myVersion;
032        private boolean myUserSelected;
033
034        public VersionIndependentCoding() {
035                this(null, null, null);
036        }
037
038        public VersionIndependentCoding(String theSystem, String theCode, String theDisplay) {
039                mySystem = theSystem;
040                myCode = theCode;
041                myDisplay = theDisplay;
042        }
043
044        @Override
045        public String getCode() {
046                return myCode;
047        }
048
049        @Override
050        public String getDisplay() {
051                return myDisplay;
052        }
053
054        @Override
055        public String getSystem() {
056                return mySystem;
057        }
058
059        @Override
060        public String getVersion() {
061                return myVersion;
062        }
063
064        @Override
065        public boolean getUserSelected() {
066                return myUserSelected;
067        }
068
069        @Override
070        public IBaseCoding setCode(String s) {
071                throw new UnsupportedOperationException();
072        }
073
074        @Override
075        public IBaseCoding setDisplay(String s) {
076                throw new UnsupportedOperationException();
077        }
078
079        @Override
080        public IBaseCoding setSystem(String s) {
081                throw new UnsupportedOperationException();
082        }
083
084        @Override
085        public IBaseCoding setVersion(String theVersion) {
086                myVersion = theVersion;
087                return this;
088        }
089
090        @Override
091        public IBaseCoding setUserSelected(boolean theUserSelected) {
092                myUserSelected = theUserSelected;
093                return this;
094        }
095
096        @Override
097        public boolean isEmpty() {
098                return StringUtils.isAllEmpty(mySystem, myCode, myDisplay);
099        }
100
101        @Override
102        public boolean hasFormatComment() {
103                return false;
104        }
105
106        @Override
107        public List<String> getFormatCommentsPre() {
108                return null;
109        }
110
111        @Override
112        public List<String> getFormatCommentsPost() {
113                return null;
114        }
115
116        @Override
117        public Object getUserData(String s) {
118                return null;
119        }
120
121        @Override
122        public void setUserData(String s, Object o) {
123                throw new UnsupportedOperationException();
124        }
125}