/* * Copyright (C) 2024 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package android.health.connect; import static com.android.healthfitness.flags.Flags.FLAG_PERSONAL_HEALTH_RECORD; import static java.util.Objects.hash; import static java.util.Objects.requireNonNull; import android.annotation.FlaggedApi; import android.annotation.NonNull; import android.annotation.Nullable; import android.health.connect.datatypes.FhirVersion; import android.net.Uri; import android.os.Parcel; import android.os.Parcelable; /** * A create request for {@link HealthConnectManager#createMedicalDataSource}. * *
Medical data is represented using the Fast Healthcare
* Interoperability Resources (FHIR) standard.
*/
@FlaggedApi(FLAG_PERSONAL_HEALTH_RECORD)
public final class CreateMedicalDataSourceRequest implements Parcelable {
// The character limit for the {@code mDisplayName}
private static final int DISPLAY_NAME_CHARACTER_LIMIT = 90;
// The character limit for the {@code mFhirBaseUri}
private static final int FHIR_BASE_URI_CHARACTER_LIMIT = 2000;
@NonNull private final Uri mFhirBaseUri;
@NonNull private final String mDisplayName;
@NonNull private final FhirVersion mFhirVersion;
private long mDataSize;
@NonNull
public static final Creator If the data is generated by an app without a FHIR base URL, this can be populated by a
* URI defined by the app (e.g. `myapp://..`) that should:
*
* The URI may not exceed 2000 characters.
*/
@NonNull
public Builder setFhirBaseUri(@NonNull Uri fhirBaseUri) {
requireNonNull(fhirBaseUri);
mFhirBaseUri = fhirBaseUri;
return this;
}
/**
* Sets the display name. For the request to succeed this must be unique per app.
*
* The display name may not exceed 90 characters.
*/
@NonNull
public Builder setDisplayName(@NonNull String displayName) {
requireNonNull(displayName);
mDisplayName = displayName;
return this;
}
/**
* Sets the FHIR version of data from this data source.
*
* This has to be a version supported by Health Connect, as documented on the {@link
* FhirVersion}.
*/
@NonNull
public Builder setFhirVersion(@NonNull FhirVersion fhirVersion) {
requireNonNull(fhirVersion);
mFhirVersion = fhirVersion;
return this;
}
/**
* Returns a new instance of {@link CreateMedicalDataSourceRequest} with the specified
* parameters.
*
* @throws IllegalArgumentException if the {@code mFhirBaseUri} or {@code mDisplayName}
* exceed the character limits or if the {@code mFhirVersion} is not supported by Health
* Connect.
*/
@NonNull
public CreateMedicalDataSourceRequest build() {
return new CreateMedicalDataSourceRequest(mFhirBaseUri, mDisplayName, mFhirVersion);
}
}
private static void validateDisplayNameCharacterLimit(String displayName) {
if (displayName.isEmpty()) {
throw new IllegalArgumentException("Display name cannot be empty.");
}
if (displayName.length() > DISPLAY_NAME_CHARACTER_LIMIT) {
throw new IllegalArgumentException(
"Display name cannot be longer than "
+ DISPLAY_NAME_CHARACTER_LIMIT
+ " characters.");
}
}
private static void validateFhirBaseUriCharacterLimit(Uri fhirBaseUri) {
String fhirBaseUriString = fhirBaseUri.toString();
if (fhirBaseUriString.isEmpty()) {
throw new IllegalArgumentException("FHIR base URI cannot be empty.");
}
if (fhirBaseUriString.length() > FHIR_BASE_URI_CHARACTER_LIMIT) {
throw new IllegalArgumentException(
"FHIR base URI cannot be longer than "
+ FHIR_BASE_URI_CHARACTER_LIMIT
+ " characters.");
}
}
private static void validateFhirVersion(FhirVersion fhirVersion) {
if (!fhirVersion.isSupportedFhirVersion()) {
throw new IllegalArgumentException("Unsupported FHIR version " + fhirVersion + ".");
}
}
}
*
*
*