1 /* 2 * Copyright (C) 2024 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package android.health.connect; 18 19 import static com.android.healthfitness.flags.Flags.FLAG_PERSONAL_HEALTH_RECORD; 20 21 import static java.util.Objects.hash; 22 import static java.util.Objects.requireNonNull; 23 24 import android.annotation.FlaggedApi; 25 import android.annotation.NonNull; 26 import android.annotation.Nullable; 27 import android.os.Parcel; 28 import android.os.Parcelable; 29 30 /** Represents a create request for {@link HealthConnectManager#createMedicalDataSource}. */ 31 @FlaggedApi(FLAG_PERSONAL_HEALTH_RECORD) 32 public final class CreateMedicalDataSourceRequest implements Parcelable { 33 @NonNull private final String mFhirBaseUri; 34 @NonNull private final String mDisplayName; 35 36 @NonNull 37 public static final Creator<CreateMedicalDataSourceRequest> CREATOR = 38 new Creator<CreateMedicalDataSourceRequest>() { 39 @NonNull 40 @Override 41 public CreateMedicalDataSourceRequest createFromParcel(@NonNull Parcel in) { 42 return new CreateMedicalDataSourceRequest(in); 43 } 44 45 @NonNull 46 @Override 47 public CreateMedicalDataSourceRequest[] newArray(int size) { 48 return new CreateMedicalDataSourceRequest[size]; 49 } 50 }; 51 CreateMedicalDataSourceRequest( @onNull String fhirBaseUri, @NonNull String displayName)52 private CreateMedicalDataSourceRequest( 53 @NonNull String fhirBaseUri, @NonNull String displayName) { 54 requireNonNull(fhirBaseUri); 55 requireNonNull(displayName); 56 57 mFhirBaseUri = fhirBaseUri; 58 mDisplayName = displayName; 59 } 60 CreateMedicalDataSourceRequest(@onNull Parcel in)61 private CreateMedicalDataSourceRequest(@NonNull Parcel in) { 62 requireNonNull(in); 63 mFhirBaseUri = requireNonNull(in.readString()); 64 mDisplayName = requireNonNull(in.readString()); 65 } 66 67 /** Returns the fhir base uri. */ 68 @NonNull getFhirBaseUri()69 public String getFhirBaseUri() { 70 return mFhirBaseUri; 71 } 72 73 /** Returns the display name. */ 74 @NonNull getDisplayName()75 public String getDisplayName() { 76 return mDisplayName; 77 } 78 79 @Override describeContents()80 public int describeContents() { 81 return 0; 82 } 83 84 @Override writeToParcel(@onNull Parcel dest, int flags)85 public void writeToParcel(@NonNull Parcel dest, int flags) { 86 dest.writeString(mFhirBaseUri); 87 dest.writeString(mDisplayName); 88 } 89 90 /** Indicates whether some other object is "equal to" this one. */ 91 @Override equals(@ullable Object o)92 public boolean equals(@Nullable Object o) { 93 if (this == o) return true; 94 if (!(o instanceof CreateMedicalDataSourceRequest that)) return false; 95 return getFhirBaseUri().equals(that.getFhirBaseUri()) 96 && getDisplayName().equals(that.getDisplayName()); 97 } 98 99 /** Returns a hash code value for the object. */ 100 @Override hashCode()101 public int hashCode() { 102 return hash(getFhirBaseUri(), getDisplayName()); 103 } 104 105 /** Returns a string representation of this {@link CreateMedicalDataSourceRequest}. */ 106 @Override toString()107 public String toString() { 108 StringBuilder sb = new StringBuilder(); 109 sb.append(this.getClass().getSimpleName()).append("{"); 110 sb.append("fhirBaseUri=").append(getFhirBaseUri()); 111 sb.append(",displayName=").append(getDisplayName()); 112 sb.append("}"); 113 return sb.toString(); 114 } 115 116 /** Builder class for {@link CreateMedicalDataSourceRequest} */ 117 public static final class Builder { 118 @NonNull private String mFhirBaseUri; 119 @NonNull private String mDisplayName; 120 121 /** 122 * @param fhirBaseUri The FHIR base URI of the data source. For data coming from a FHIR 123 * server this should be the base URL. 124 * @param displayName The display name that describes the data source. 125 */ Builder(@onNull String fhirBaseUri, @NonNull String displayName)126 public Builder(@NonNull String fhirBaseUri, @NonNull String displayName) { 127 requireNonNull(fhirBaseUri); 128 requireNonNull(displayName); 129 130 mFhirBaseUri = fhirBaseUri; 131 mDisplayName = displayName; 132 } 133 Builder(@onNull Builder original)134 public Builder(@NonNull Builder original) { 135 requireNonNull(original); 136 mFhirBaseUri = original.mFhirBaseUri; 137 mDisplayName = original.mDisplayName; 138 } 139 Builder(@onNull CreateMedicalDataSourceRequest original)140 public Builder(@NonNull CreateMedicalDataSourceRequest original) { 141 requireNonNull(original); 142 mFhirBaseUri = original.getFhirBaseUri(); 143 mDisplayName = original.getDisplayName(); 144 } 145 146 /** 147 * Sets the fhir base URI. For data coming from a FHIR server this should be the base URL. 148 */ 149 @NonNull setFhirBaseUri(@onNull String fhirBaseUri)150 public Builder setFhirBaseUri(@NonNull String fhirBaseUri) { 151 requireNonNull(fhirBaseUri); 152 mFhirBaseUri = fhirBaseUri; 153 return this; 154 } 155 156 /** Sets the display name. */ 157 @NonNull setDisplayName(@onNull String displayName)158 public Builder setDisplayName(@NonNull String displayName) { 159 requireNonNull(displayName); 160 mDisplayName = displayName; 161 return this; 162 } 163 164 /** 165 * Returns a new instance of {@link CreateMedicalDataSourceRequest} with the specified 166 * parameters. 167 */ 168 @NonNull build()169 public CreateMedicalDataSourceRequest build() { 170 return new CreateMedicalDataSourceRequest(mFhirBaseUri, mDisplayName); 171 } 172 } 173 } 174