001package org.hl7.fhir.r4.model.api;
002
003
004
005/*
006 * #%L
007 * HAPI FHIR - Core Library
008 * %%
009 * Copyright (C) 2014 - 2015 University Health Network
010 * %%
011 * Licensed under the Apache License, Version 2.0 (the "License");
012 * you may not use this file except in compliance with the License.
013 * You may obtain a copy of the License at
014 * 
015 *      http://www.apache.org/licenses/LICENSE-2.0
016 * 
017 * Unless required by applicable law or agreed to in writing, software
018 * distributed under the License is distributed on an "AS IS" BASIS,
019 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
020 * See the License for the specific language governing permissions and
021 * limitations under the License.
022 * #L%
023 */
024
025/**
026 * Base interface for ID datatype. 
027 * 
028 * <p>
029 * <b>Concrete Implementations:</b> This interface is often returned and/or accepted by methods in HAPI's API
030 * where either {@link ca.uhn.fhir.model.primitive.IdDt} (the HAPI structure ID type) or 
031 * <code>org.hl7.fhir.instance.model.IdType</code> (the RI structure ID type) will be used, depending on 
032 * which version of the strctures your application is using.   
033 * </p>
034 */
035public interface IIdType {
036
037        void applyTo(IBaseResource theResource);
038
039        /**
040         * Returns the server base URL if this ID contains one. For example, the base URL is
041         * the 'http://example.com/fhir' in the following ID: <code>http://example.com/fhir/Patient/123/_history/55</code>
042         */
043        String getBaseUrl();
044
045        /**
046         * Returns only the logical ID part of this ID. For example, given the ID
047         * "http://example,.com/fhir/Patient/123/_history/456", this method would
048         * return "123".
049         */
050        String getIdPart();
051
052        /**
053         * Returns the ID part of this ID (e.g. in the ID http://example.com/Patient/123/_history/456 this would be the
054         * part "123") parsed as a {@link Long}.
055         * 
056         * @throws NumberFormatException If the value can't be parsed as a long
057         */
058        Long getIdPartAsLong();
059
060        String getResourceType();
061
062        /**
063         * Returns the value of this ID. Note that this value may be a fully qualified URL, a relative/partial URL, or a simple ID. Use {@link #getIdPart()} to get just the ID portion.
064         * 
065         * @see #getIdPart()
066         */
067        String getValue();
068
069        String getVersionIdPart();
070
071        /**
072         * Returns the version ID part of this ID (e.g. in the ID http://example.com/Patient/123/_history/456 this would be the
073         * part "456") parsed as a {@link Long}.
074         * 
075         * @throws NumberFormatException If the value can't be parsed as a long
076         */
077        Long getVersionIdPartAsLong();
078
079        boolean hasBaseUrl();
080
081        /**
082         * Returns <code>true</code> if this ID contains an actual ID part. For example, the ID part is
083         * the '123' in the following ID: <code>http://example.com/fhir/Patient/123/_history/55</code>
084         */
085        boolean hasIdPart();
086
087        boolean hasResourceType();
088
089        boolean hasVersionIdPart();
090
091        /**
092         * Returns <code>true</code> if this ID contains an absolute URL (in other words, a URL starting with "http://" or "https://"
093         */
094        boolean isAbsolute();
095
096        boolean isEmpty();
097
098        /**
099         * Returns <code>true</code> if the {@link #getIdPart() ID part of this object} is valid according to the FHIR rules for valid IDs. 
100         * <p>
101         * The FHIR specification states:
102         * <code>Any combination of upper or lower case ASCII letters ('A'..'Z', and 'a'..'z', numerals ('0'..'9'), '-' and '.', with a length limit of 64 characters. (This might be an integer, an un-prefixed OID, UUID or any other identifier pattern that meets these constraints.) regex: [A-Za-z0-9\-\.]{1,64}</code>
103         * </p>
104         */
105        boolean isIdPartValid();
106
107        /**
108         * Returns <code>true</code> if the {@link #getIdPart() ID part of this object} contains
109         * only numbers 
110         */
111        boolean isIdPartValidLong();
112
113        /**
114         * Returns <code>true</code> if the ID is a local reference (in other words, it begins with the '#' character)
115         */
116        boolean isLocal();
117
118        /**
119         * Returns <code>true</code> if the {@link #getVersionIdPart() version ID part of this object} contains
120         * only numbers 
121         */
122        boolean isVersionIdPartValidLong();
123
124        IIdType setValue(String theString);
125
126        IIdType toUnqualified();
127
128        IIdType toUnqualifiedVersionless();
129
130        IIdType toVersionless();
131
132        IIdType withResourceType(String theResName);
133        
134        IIdType withServerBase(String theServerBase, String theResourceName);
135
136        IIdType withVersion(String theVersion);
137
138}