private static void addAnyResourcesNotAlreadyPresentToBundle(Bundle theAggregatedBundle, Bundle thePartialBundle, Set<String> theResourcesAlreadyAdded) { for (Bundle.Entry entry : thePartialBundle.getEntry()) { if (!theResourcesAlreadyAdded.contains(entry.getFullUrl())) { theResourcesAlreadyAdded.add(entry.getFullUrl()); theAggregatedBundle.getEntry().add(entry); } } }
private static void addInitialUrlsToSet(Bundle theBundle, Set<String> theResourcesAlreadyAdded) { for (Bundle.Entry entry : theBundle.getEntry()) { theResourcesAlreadyAdded.add(entry.getFullUrl()); } }
public static void main(String[] args) throws Exception { FhirContext ctx = FhirContext.forDstu2(); String fileName = "src/main/resources/vs/dstu2/all-valuesets-bundle.xml"; FileReader fr = new FileReader(fileName); Bundle b = ctx.newXmlParser().parseResource(Bundle.class, fr); for (Entry nextEntry : b.getEntry()) { BaseResource nextRes = (BaseResource) nextEntry.getResource(); nextRes.setText(new NarrativeDt()); } File f = new File(fileName); OutputStreamWriter fw = new OutputStreamWriter(new FileOutputStream(f, false), "UTF-8"); ctx.newXmlParser().encodeResourceToWriter(b, fw); fw.close(); ourLog.info("Fixed {} valuesets", b.getEntry().size()); }
private void filterBundle(ca.uhn.fhir.model.dstu2.resource.Bundle theBundle) { for (Iterator<Entry> iter = theBundle.getEntry().iterator(); iter.hasNext(); ) { IBaseResource next = iter.next().getResource(); for (IIdType nextExclude : myExcludes) { if (nextExclude.hasResourceType() && nextExclude.toUnqualifiedVersionless().getValue().equals(next.getIdElement().toUnqualifiedVersionless().getValue())) { iter.remove(); continue; } else if (nextExclude.getIdPart().equals(next.getIdElement().getIdPart())) { iter.remove(); continue; } } } }
public static void main(String[] args) throws Exception { FhirContext ctx = FhirContext.forDstu2(); String serverBase = "http://fhirtest.uhn.ca/baseDstu2"; IGenericClient client = ctx.newRestfulGenericClient(serverBase); // use RelatedPerson because there aren't that many on the server Bundle bundle = client.search().forResource(RelatedPerson.class).returnBundle(Bundle.class).execute(); BundleFetcher.fetchRestOfBundle(client, bundle); if (bundle.getTotal() != bundle.getEntry().size()) { System.out.println("Counts didn't match! Expected " + bundle.getTotal() + " but bundle only had " + bundle.getEntry().size() + " entries!"); } // IParser parser = ctx.newXmlParser().setPrettyPrint(true); // System.out.println(parser.encodeResourceToString(bundle)); } }
if ("dstu2".equals(myVersion)) { ca.uhn.fhir.model.dstu2.resource.Bundle bundle = newXmlParser.parseResource(ca.uhn.fhir.model.dstu2.resource.Bundle.class, vs); for (Entry nextEntry : bundle.getEntry()) { ca.uhn.fhir.model.dstu2.resource.ValueSet nextVs = (ca.uhn.fhir.model.dstu2.resource.ValueSet) nextEntry.getResource(); parseValueSet(nextVs);
@Override protected void preProcessResourceForStorage(Bundle theResource) { super.preProcessResourceForStorage(theResource); Set<String> allowedBundleTypes = getConfig().getBundleTypesAllowedForStorage(); if (!allowedBundleTypes.contains(defaultString(theResource.getType()))) { String message = "Unable to store a Bundle resource on this server with a Bundle.type value of: " + (theResource.getType() != null ? theResource.getType() : "(missing)"); throw new UnprocessableEntityException(message); } for (Entry next : theResource.getEntry()) { next.setFullUrl((String)null); } }
((IResource) input).getText().getStatus().setValueAsString((String) null); if (input instanceof Bundle) { for (Entry nextEntry : ((Bundle) input).getEntry()) { if (nextEntry.getResource() != null) { nextEntry.getResource().getText().getDiv().setValueAsString((String) null);
@Override public List<IBaseResource> toListOfResources() { ArrayList<IBaseResource> retVal = new ArrayList<IBaseResource>(); for (Entry next : myBundle.getEntry()) { if (next.getResource() != null) { retVal.add(next.getResource()); } else if (next.getResponse().getLocationElement().isEmpty() == false) { IdDt id = new IdDt(next.getResponse().getLocation()); String resourceType = id.getResourceType(); if (isNotBlank(resourceType)) { IResource res = (IResource) myContext.getResourceDefinition(resourceType).newInstance(); res.setId(id); retVal.add(res); } } } return retVal; }
public static void simpleExample() { // START SNIPPET: simple // We're connecting to a DSTU1 compliant server in this example FhirContext ctx = FhirContext.forDstu2(); String serverBase = "http://fhirtest.uhn.ca/baseDstu2"; IGenericClient client = ctx.newRestfulGenericClient(serverBase); // Perform a search Bundle results = client .search() .forResource(Patient.class) .where(Patient.FAMILY.matches().value("duck")) .returnBundle(ca.uhn.fhir.model.dstu2.resource.Bundle.class) .execute(); System.out.println("Found " + results.getEntry().size() + " patients named 'duck'"); // END SNIPPET: simple }
private Bundle batch(final RequestDetails theRequestDetails, Bundle theRequest) { ourLog.info("Beginning batch with {} resources", theRequest.getEntry().size()); long start = System.currentTimeMillis(); for (final Entry nextRequestEntry : theRequest.getEntry()) { Entry subResponseEntry = nextResponseBundle.getEntry().get(0); resp.addEntry(subResponseEntry); subResponseEntry.setResource(nextResponseBundle.getEntry().get(0).getResource());
ourLog.info("Beginning {} with {} resources", theActionName, theRequest.getEntry().size()); List<Entry> getEntries = new ArrayList<Entry>(); IdentityHashMap<Entry, Integer> originalRequestOrder = new IdentityHashMap<Entry, Integer>(); for (int i = 0; i < theRequest.getEntry().size(); i++) { originalRequestOrder.put(theRequest.getEntry().get(i), i); response.addEntry(); if (theRequest.getEntry().get(i).getRequest().getMethodElement().getValueAsEnum() == HTTPVerbEnum.GET) { getEntries.add(theRequest.getEntry().get(i)); Collections.sort(theRequest.getEntry(), new TransactionSorter()); Entry nextReqEntry = getEntries.get(i); Integer originalOrder = originalRequestOrder.get(nextReqEntry); Entry nextRespEntry = response.getEntry().get(originalOrder); int numEntries = theRequest.getEntry().size(); long delayPer = delay / numEntries; ourLog.info("{} completed in {}ms ({} entries at {}ms per entry)", new Object[] {theActionName, delay, numEntries, delayPer});
int total = bundle.getEntry().size(); int count = 1; for (Entry i : bundle.getEntry()) { ValueSet next = (ValueSet) i.getResource(); next.setId(next.getIdElement().toUnqualifiedVersionless()); total = bundle.getEntry().size(); count = 1; for (Entry i : bundle.getEntry()) { ValueSet next = (ValueSet) i.getResource(); next.setId(next.getIdElement().toUnqualifiedVersionless()); total = bundle.getEntry().size(); count = 1; for (Entry i : bundle.getEntry()) { ValueSet next = (ValueSet) i.getResource(); next.setId(next.getIdElement().toUnqualifiedVersionless());
Set<String> fullIds = new HashSet<String>(); for (Iterator<Entry> iterator = bundle.getEntry().iterator(); iterator.hasNext(); ) { Entry next = iterator.next(); for (Iterator<Entry> iterator = bundle.getEntry().iterator(); iterator.hasNext(); ) { Entry next = iterator.next(); if (next.getResource().getId().getIdPart() != null) { for (Entry next : bundle.getEntry()) { List<ResourceReferenceInfo> refs = ctx.newTerser().getAllResourceReferences(next.getResource()); for (ResourceReferenceInfo nextRef : refs) { System.gc(); ourLog.info("Final bundle: {} entries", bundle.getEntry().size());
for (Entry next : bundle.getEntry()) { ValueSet nextVs = (ValueSet) next.getResource(); myNameToValueSetUrl.put(nextVs.getName(), nextVs.getUrl());
for (int i = 0; i < theRequest.getEntry().size(); i++) { ourLog.debug("Processed {} non-GET entries out of {}", i, theRequest.getEntry().size()); Entry nextReqEntry = theRequest.getEntry().get(i); IResource res = nextReqEntry.getResource(); IdDt nextResourceId = null; Entry nextRespEntry = theResponse.getEntry().get(theOriginalRequestOrder.get(nextReqEntry)); for (Entry nextEntry : theRequest.getEntry()) { if (nextEntry.getRequest().getMethodElement().getValueAsEnum() == HTTPVerbEnum.POST) { String matchUrl = nextEntry.getRequest().getIfNoneExist();
/** * Gets the first repetition for <b>entry</b> (), * creating it if it does not already exist. * * <p> * <b>Definition:</b> * An entry in a bundle resource - will either contain a resource, or information about a resource (transactions and history only) * </p> */ public Entry getEntryFirstRep() { if (getEntry().isEmpty()) { return addEntry(); } return getEntry().get(0); }
private <T extends IResource> Collection<T> asCollection(Bundle results) { List<T> list = new ArrayList<>(); for (Bundle.Entry entry : results.getEntry()) { list.add((T) entry.getResource()); } return list; }
/** * Adds and returns a new value for <b>entry</b> () * * <p> * <b>Definition:</b> * An entry in a bundle resource - will either contain a resource, or information about a resource (transactions and history only) * </p> */ public Entry addEntry() { Entry newType = new Entry(); getEntry().add(newType); return newType; }
@Override protected void preProcessResourceForStorage(Bundle theResource) { super.preProcessResourceForStorage(theResource); Set<String> allowedBundleTypes = getConfig().getBundleTypesAllowedForStorage(); if (!allowedBundleTypes.contains(defaultString(theResource.getType()))) { String message = "Unable to store a Bundle resource on this server with a Bundle.type value of: " + (theResource.getType() != null ? theResource.getType() : "(missing)"); throw new UnprocessableEntityException(message); } for (Entry next : theResource.getEntry()) { next.setFullUrl((String)null); } }