@Override public int compare(BundleEntryComponent theO1, BundleEntryComponent theO2) { if (theO1.getResource() == null && theO2.getResource() == null) { return 0; } if (theO1.getResource() == null) { return 1; } if (theO2.getResource() == null) { return -1; } // StructureDefinition, then OperationDefinition, then CompartmentDefinition return theO2.getResource().getClass().getName().compareTo(theO1.getResource().getClass().getName()); } });
private void filterBundle(org.hl7.fhir.dstu3.model.Bundle theBundle) { for (Iterator<BundleEntryComponent> 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; } } } }
private void loadStructureDefinitions(FhirContext theContext, Map<String, StructureDefinition> theCodeSystems, String theClasspath) { ourLog.info("Loading structure definitions from classpath: {}", theClasspath); InputStream valuesetText = DefaultProfileValidationSupport.class.getResourceAsStream(theClasspath); if (valuesetText != null) { InputStreamReader reader = new InputStreamReader(valuesetText, Charsets.UTF_8); Bundle bundle = theContext.newXmlParser().parseResource(Bundle.class, reader); for (BundleEntryComponent next : bundle.getEntry()) { if (next.getResource() instanceof StructureDefinition) { StructureDefinition nextSd = (StructureDefinition) next.getResource(); nextSd.getText().setDivAsString(""); String system = nextSd.getUrl(); if (isNotBlank(system)) { theCodeSystems.put(system, nextSd); } } } } else { ourLog.warn("Unable to load resource: {}", theClasspath); } }
@Override public IBaseResource getResource(Bundle.BundleEntryComponent theBundleEntry) { return theBundleEntry.getResource(); }
private <T extends IBaseResource> Collection<T> asCollection(Bundle results) { List<T> list = new ArrayList<>(); for (Bundle.BundleEntryComponent entry : results.getEntry()) { list.add((T) entry.getResource()); } return list; }
private Set<NamingSystem> setOfNamingSystems(Bundle bundle) { return bundle.getEntry().stream() .map(bec -> (NamingSystem) bec.getResource()) .collect(Collectors.toSet()); }
@Test public void testSendIti67WithPatientReference() { Bundle result = sendManually(referencePatientReferenceParameter()); assertEquals(Bundle.BundleType.SEARCHSET, result.getType()); assertEquals(ResourceType.Bundle, result.getResourceType()); assertEquals(1, result.getTotal()); DocumentReference p = (DocumentReference) result.getEntry().get(0).getResource(); assertEquals("63ab1c29-4225-11e6-9b33-0050569b0094", p.getIdElement().getIdPart()); }
@Test public void testSendIti66WithPatientReference() { Bundle result = sendManually(manifestPatientReferenceParameter()); assertEquals(Bundle.BundleType.SEARCHSET, result.getType()); assertEquals(ResourceType.Bundle, result.getResourceType()); assertEquals(1, result.getTotal()); DocumentManifest p = (DocumentManifest) result.getEntry().get(0).getResource(); assertEquals("9bc72458-49b0-11e6-8a1c-3c1620524153", p.getIdElement().getIdPart()); }
count = 1; for (BundleEntryComponent i : bundle.getEntry()) { org.hl7.fhir.dstu3.model.Resource next = i.getResource(); next.setId(next.getIdElement().toUnqualifiedVersionless()); count = 1; for (BundleEntryComponent i : bundle.getEntry()) { org.hl7.fhir.dstu3.model.Resource next = i.getResource(); next.setId(next.getIdElement().toUnqualifiedVersionless()); count = 1; for (BundleEntryComponent i : bundle.getEntry()) { org.hl7.fhir.dstu3.model.Resource next = i.getResource(); if (next.getIdElement().isIdPartValidLong()) { next.setIdElement(new IdType("v2-" + next.getIdElement().getIdPart()));
if ("Subscription".equals(next.getResource().getResourceType()) || "DataElement".equals(next.getResource().getResourceType()) || "OperationOutcome".equals(next.getResource().getResourceType()) || "OperationDefinition".equals(next.getResource().getResourceType())) { ourLog.info("Skipping " + next.getResource().getResourceType() + " example"); iterator.remove(); } else { IdDt resourceId = new IdDt(next.getResource().getResourceType() + "/EX" + next.getResource().getIdElement().getIdPart()); if (!fullIds.add(resourceId.toUnqualifiedVersionless().getValue())) { ourLog.info("Discarding duplicate resource: " + resourceId.getValue()); next.getResource().setId(resourceId); } else { ourLog.info("Discarding resource with not explicit ID"); for (Iterator<BundleEntryComponent> iterator = bundle.getEntry().iterator(); iterator.hasNext(); ) { BundleEntryComponent next = iterator.next(); if (next.getResource().getIdElement().getIdPart() != null) { String nextId = next.getResource().getIdElement().getValue(); next.getRequest().setMethod(HTTPVerb.PUT); next.getRequest().setUrl(nextId); List<ResourceReferenceInfo> refs = ctx.newTerser().getAllResourceReferences(next.getResource()); for (ResourceReferenceInfo nextRef : refs) {
org.hl7.fhir.dstu3.model.Resource next = i.getResource(); next.setId(next.getIdElement().toUnqualifiedVersionless()); if (next instanceof CapabilityStatement) {
MyPatient pat0 = (MyPatient) bundle.getEntry().get(0).getResource(); MyPatient historyPatient0 = (MyPatient) bundle.getEntry().get(0).getResource();
org.hl7.fhir.dstu3.model.ConceptMap conceptMap = (org.hl7.fhir.dstu3.model.ConceptMap) response.getEntryFirstRep().getResource(); convertConceptMapToCsv(conceptMap); } else {
if (next.getResource() instanceof CodeSystem) { CodeSystem nextValueSet = (CodeSystem) next.getResource(); nextValueSet.getText().setDivAsString(""); String system = nextValueSet.getUrl(); theCodeSystems.put(system, nextValueSet); } else if (next.getResource() instanceof ValueSet) { ValueSet nextValueSet = (ValueSet) next.getResource(); nextValueSet.getText().setDivAsString(""); String system = nextValueSet.getUrl();
private static void copy(FhirContext theCtx, IGenericClient theTarget, String theResType, List<IBaseResource> theQueued, Set<String> theSent, Bundle theReceived) { for (Bundle.BundleEntryComponent nextEntry : theReceived.getEntry()) { Resource nextResource = nextEntry.getResource(); nextResource.setId(theResType + "/" + "CR-" + nextResource.getIdElement().getIdPart()); boolean haveUnsentReference = false; for (ResourceReferenceInfo nextRefInfo : theCtx.newTerser().getAllResourceReferences(nextResource)) { IIdType nextRef = nextRefInfo.getResourceReference().getReferenceElement(); if (nextRef.hasIdPart()) { String newRef = nextRef.getResourceType() + "/" + "CR-" + nextRef.getIdPart(); ourLog.info("Changing reference {} to {}", nextRef.getValue(), newRef); nextRefInfo.getResourceReference().setReference(newRef); if (!theSent.contains(newRef)) { haveUnsentReference = true; } } } if (haveUnsentReference) { ourLog.info("Queueing {} for delivery after", nextResource.getId()); theQueued.add(nextResource); continue; } IIdType newId = theTarget .update() .resource(nextResource) .execute() .getId(); ourLog.info("Copied resource {} and got ID {}", nextResource.getId(), newId); theSent.add(nextResource.getIdElement().toUnqualifiedVersionless().getValue()); } }
public org.hl7.fhir.instance.model.Bundle.BundleEntryComponent convertBundleEntryComponent(org.hl7.fhir.dstu3.model.Bundle.BundleEntryComponent src) throws FHIRException { if (src == null || src.isEmpty()) return null; if (advisor.ignoreEntry(src)) return null; org.hl7.fhir.instance.model.Bundle.BundleEntryComponent tgt = new org.hl7.fhir.instance.model.Bundle.BundleEntryComponent(); copyElement(src, tgt); for (org.hl7.fhir.dstu3.model.Bundle.BundleLinkComponent t : src.getLink()) tgt.addLink(convertBundleLinkComponent(t)); tgt.setFullUrl(src.getFullUrl()); org.hl7.fhir.instance.model.Resource res = advisor.convert(src.getResource()); if (res == null) res = convertResource(src.getResource()); tgt.setResource(res); if (src.hasSearch()) tgt.setSearch(convertBundleEntrySearchComponent(src.getSearch())); if (src.hasRequest()) tgt.setRequest(convertBundleEntryRequestComponent(src.getRequest())); if (src.hasResponse()) tgt.setResponse(convertBundleEntryResponseComponent(src.getResponse())); return tgt; }
private ElementDefinition resolveType(String type) { if (logical != null) for (BundleEntryComponent be : logical.getEntry()) { if (be.hasResource() && be.getResource() instanceof StructureDefinition) { StructureDefinition sd = (StructureDefinition) be.getResource(); if (sd.getId().equals(type)) return sd.getSnapshot().getElement().get(0); } } String url = "http://hl7.org/fhir/StructureDefinition/" + type; long t = System.nanoTime(); StructureDefinition sd = context.fetchResource(StructureDefinition.class, url); sdTime = sdTime + (System.nanoTime() - t); if (sd == null || !sd.hasSnapshot()) return null; else return sd.getSnapshot().getElement().get(0); }
private StructureDefinition getProfileForType(String type) { if (logical != null) for (BundleEntryComponent be : logical.getEntry()) { if (be.hasResource() && be.getResource() instanceof StructureDefinition) { StructureDefinition sd = (StructureDefinition) be.getResource(); if (sd.getId().equals(type)) return sd; } } long t = System.nanoTime(); try { return context.fetchResource(StructureDefinition.class, "http://hl7.org/fhir/StructureDefinition/" + type); } finally { sdTime = sdTime + (System.nanoTime() - t); } }
public static org.hl7.fhir.dstu2016may.model.Bundle.BundleEntryComponent convertBundleEntryComponent(org.hl7.fhir.dstu3.model.Bundle.BundleEntryComponent src) throws FHIRException { if (src == null || src.isEmpty()) return null; org.hl7.fhir.dstu2016may.model.Bundle.BundleEntryComponent tgt = new org.hl7.fhir.dstu2016may.model.Bundle.BundleEntryComponent(); copyElement(src, tgt); for (org.hl7.fhir.dstu3.model.Bundle.BundleLinkComponent t : src.getLink()) tgt.addLink(convertBundleLinkComponent(t)); if (src.hasFullUrl()) tgt.setFullUrl(src.getFullUrl()); tgt.setResource(convertResource(src.getResource())); tgt.setSearch(convertBundleEntrySearchComponent(src.getSearch())); tgt.setRequest(convertBundleEntryRequestComponent(src.getRequest())); tgt.setResponse(convertBundleEntryResponseComponent(src.getResponse())); return tgt; }
@Override public IBaseResource getResource(Bundle.BundleEntryComponent theBundleEntry) { return theBundleEntry.getResource(); }