com.ibm.fhir.model.util.ReferenceFinder Maven / Gradle / Ivy
/*
* (C) Copyright IBM Corp. 2017,2019
*
* SPDX-License-Identifier: Apache-2.0
*/
package com.ibm.fhir.model.util;
import java.util.List;
import com.ibm.fhir.model.resource.Resource;
import com.ibm.fhir.model.type.Reference;
/**
* This class contains utility functions for finding "reference" fields within a FHIR resource.
*/
public class ReferenceFinder {
/**
* Returns a list of Reference fields that are found in the
* specified resource instance. For example, an Observation has a "subject" field of type
* Reference, so if this method is called on an Observation instance that has the "subject" field
* set, then we'll return the Reference instance that represents this "subject" field
* @param resource the FHIR resource for which we want to find all Reference fields
* @return list of Reference instances found in the specified FHIR resource
* @throws Exception
*/
public static List getReferences(Resource resource) throws Exception {
CollectingVisitor visitor = new CollectingVisitor(Reference.class);
resource.accept(visitor);
return visitor.getResult();
}
}