001/*- 002 * #%L 003 * Smile CDR - CDR 004 * %% 005 * Copyright (C) 2016 - 2024 Smile CDR, Inc. 006 * %% 007 * All rights reserved. 008 * #L% 009 */ 010package ca.cdr.api.fhirgw.model; 011 012import ca.uhn.fhir.context.FhirContext; 013import ca.uhn.fhir.util.BundleUtil; 014import jakarta.annotation.Nonnull; 015import org.hl7.fhir.instance.model.api.IBaseBundle; 016 017/** 018 * This class represents the response to a FHIR Gateway Search request executed 019 * against a single target 020 */ 021public class SearchSingleTargetResponse extends BaseResponse<SearchSingleTargetResponse> { 022 023 @Nonnull 024 private IBaseBundle mySearchResults; 025 026 // indicates gateway determined that request addressed an id which was not prefixed for the targeted server 027 private boolean myWrongTarget; 028 029 /** 030 * Constructor - Create an empty object 031 */ 032 public SearchSingleTargetResponse() { 033 super(); 034 } 035 036 /** 037 * Copy constructor - Creates a shallow copy only 038 */ 039 public SearchSingleTargetResponse(SearchSingleTargetResponse theSearchResponse) { 040 super(theSearchResponse); 041 mySearchResults = theSearchResponse.getSearchResults(); 042 } 043 044 public SearchSingleTargetResponse(IBaseBundle theResult) { 045 this(theResult, false); 046 } 047 048 public SearchSingleTargetResponse(@Nonnull IBaseBundle theResult, boolean isWrongTarget) { 049 mySearchResults = theResult; 050 myWrongTarget = isWrongTarget; 051 } 052 053 @Nonnull 054 public IBaseBundle getSearchResults() { 055 return mySearchResults; 056 } 057 058 public boolean isEmpty(FhirContext theFhirContext) { 059 return BundleUtil.getSearchBundleEntryParts(theFhirContext, mySearchResults) 060 .isEmpty(); 061 } 062 063 public void setSearchResults(@Nonnull IBaseBundle theSearchResults) { 064 mySearchResults = theSearchResults; 065 } 066 067 /** 068 * Create a clone of this object using a <b>shallow copy only</b>. Values 069 * are copied by reference only, so things like Resources should only be 070 * modified if you are sure that the changes won't affect the value 071 * stored in cache. 072 */ 073 @Override 074 public SearchSingleTargetResponse clone() { 075 return new SearchSingleTargetResponse(this); 076 } 077 078 public boolean isWrongTarget() { 079 return myWrongTarget; 080 } 081}