private static int loadBundle(String server, Bundle b, int size, int start, int end) throws URISyntaxException { System.out.println("Post to "+server+". size = "+Integer.toString(size)+", start = "+Integer.toString(start)+", total = "+Integer.toString(b.getEntry().size())); FHIRToolingClient client = new FHIRToolingClient(server); int c = start; if (end == -1) end = b.getEntry().size(); while (c < end) { Bundle bt = new Bundle(); bt.setType(BundleType.BATCH); bt.setId(UUID.randomUUID().toString().toLowerCase()); for (int i = c; i < Math.min(b.getEntry().size(), c+size); i++) { BundleEntryComponent be = bt.addEntry(); be.setResource(b.getEntry().get(i).getResource()); be.getRequest().setMethod(HTTPVerb.PUT); be.getRequest().setUrl(be.getResource().getResourceType().toString()+"/"+be.getResource().getId()); Bundle resp = client.transaction(bt); for (int i = 0; i < resp.getEntry().size(); i++) { BundleEntryComponent t = resp.getEntry().get(i); if (!t.getResponse().getStatus().startsWith("2")) { System.out.println("failed status at "+Integer.toString(i)+": "+t.getResponse().getStatus());
@Override public void addRootPropertiesToBundle(String theId, String theServerBase, String theLinkSelf, String theLinkPrev, String theLinkNext, Integer theTotalResults, BundleTypeEnum theBundleType, IPrimitiveType<Date> theLastUpdated) { ensureBundle(); myBase = theServerBase; if (myBundle.getIdElement().isEmpty()) { myBundle.setId(theId); } if (myBundle.getIdElement().isEmpty()) { myBundle.setId(UUID.randomUUID().toString()); } if (myBundle.getMeta().getLastUpdated() == null && theLastUpdated != null) { myBundle.getMeta().getLastUpdatedElement().setValueAsString(theLastUpdated.getValueAsString()); } if (!hasLink(Constants.LINK_SELF, myBundle) && isNotBlank(theLinkSelf)) { myBundle.addLink().setRelation(Constants.LINK_SELF).setUrl(theLinkSelf); } if (!hasLink(Constants.LINK_NEXT, myBundle) && isNotBlank(theLinkNext)) { myBundle.addLink().setRelation(Constants.LINK_NEXT).setUrl(theLinkNext); } if (!hasLink(Constants.LINK_PREVIOUS, myBundle) && isNotBlank(theLinkPrev)) { myBundle.addLink().setRelation(Constants.LINK_PREVIOUS).setUrl(theLinkPrev); } if (myBundle.getTypeElement().isEmpty() && theBundleType != null) { myBundle.getTypeElement().setValueAsString(theBundleType.getCode()); } if (myBundle.getTotalElement().isEmpty() && theTotalResults != null) { myBundle.getTotalElement().setValue(theTotalResults); } }
public org.hl7.fhir.instance.model.Bundle convertBundle(org.hl7.fhir.r4.model.Bundle src) throws FHIRException { if (src == null || src.isEmpty()) return null; org.hl7.fhir.instance.model.Bundle tgt = new org.hl7.fhir.instance.model.Bundle(); copyResource(src, tgt); tgt.setType(convertBundleType(src.getType())); if (src.hasTotal()) tgt.setTotal(src.getTotal()); for (org.hl7.fhir.r4.model.Bundle.BundleLinkComponent t : src.getLink()) tgt.addLink(convertBundleLinkComponent(t)); for (org.hl7.fhir.r4.model.Bundle.BundleEntryComponent t : src.getEntry()) tgt.addEntry(convertBundleEntryComponent(t)); if (src.hasSignature()) tgt.setSignature(convertSignature(src.getSignature())); return tgt; }
@Override public Base makeProperty(int hash, String name) throws FHIRException { switch (hash) { case -1618432855: return getIdentifier(); case 3575610: return getTypeElement(); case 55126294: return getTimestampElement(); case 110549828: return getTotalElement(); case 3321850: return addLink(); case 96667762: return addEntry(); case 1073584312: return getSignature(); default: return super.makeProperty(hash, name); } }
@Override public List<Bundle.BundleEntryComponent> getEntries(Bundle theRequest) { return theRequest.getEntry(); }
public org.hl7.fhir.r4.model.Bundle convertBundle(org.hl7.fhir.instance.model.Bundle src) throws FHIRException { if (src == null || src.isEmpty()) return null; org.hl7.fhir.r4.model.Bundle tgt = new org.hl7.fhir.r4.model.Bundle(); copyResource(src, tgt); tgt.setType(convertBundleType(src.getType())); if (src.hasTotal()) tgt.setTotal(src.getTotal()); for (org.hl7.fhir.instance.model.Bundle.BundleLinkComponent t : src.getLink()) tgt.addLink(convertBundleLinkComponent(t)); for (org.hl7.fhir.instance.model.Bundle.BundleEntryComponent t : src.getEntry()) tgt.addEntry(convertBundleEntryComponent(t)); tgt.setSignature(convertSignature(src.getSignature())); return tgt; }
@Override public Base setProperty(int hash, String name, Base value) throws FHIRException { switch (hash) { case -1618432855: // identifier this.identifier = castToIdentifier(value); // Identifier return value; case 3575610: // type value = new BundleTypeEnumFactory().fromType(castToCode(value)); this.type = (Enumeration) value; // Enumeration<BundleType> return value; case 55126294: // timestamp this.timestamp = castToInstant(value); // InstantType return value; case 110549828: // total this.total = castToUnsignedInt(value); // UnsignedIntType return value; case 3321850: // link this.getLink().add((BundleLinkComponent) value); // BundleLinkComponent return value; case 96667762: // entry this.getEntry().add((BundleEntryComponent) value); // BundleEntryComponent return value; case 1073584312: // signature this.signature = castToSignature(value); // Signature return value; default: return super.setProperty(hash, name, value); } }
@Override public void initializeBundleFromResourceList(String theAuthor, List<? extends IBaseResource> theResources, String theServerBase, String theCompleteUrl, int theTotalResults, BundleTypeEnum theBundleType) { myBundle = new Bundle(); myBundle.setId(UUID.randomUUID().toString()); myBundle.getMeta().setLastUpdated(new Date()); myBundle.addLink().setRelation(Constants.LINK_FHIR_BASE).setUrl(theServerBase); myBundle.addLink().setRelation(Constants.LINK_SELF).setUrl(theCompleteUrl); myBundle.getTypeElement().setValueAsString(theBundleType.getCode()); BundleEntryComponent nextEntry = myBundle.addEntry(); myBundle.getTotalElement().setValue(theTotalResults);
@SuppressWarnings("unchecked") private org.hl7.fhir.r4.model.Bundle getBundleFromFileR4(Integer limit, File inputFile, FhirContext ctx) throws IOException, UnsupportedEncodingException { org.hl7.fhir.r4.model.Bundle bundle = new org.hl7.fhir.r4.model.Bundle(); bundle.setType(org.hl7.fhir.r4.model.Bundle.BundleType.TRANSACTION); org.hl7.fhir.r4.model.Bundle.BundleEntryComponent entry = bundle.addEntry(); entry.getRequest().setMethod(org.hl7.fhir.r4.model.Bundle.HTTPVerb.POST); entry.setResource((org.hl7.fhir.r4.model.Resource) nextResource); continue; org.hl7.fhir.r4.model.Bundle.BundleEntryComponent entry = bundle.addEntry(); entry.getRequest().setMethod(org.hl7.fhir.r4.model.Bundle.HTTPVerb.POST); entry.setResource((org.hl7.fhir.r4.model.Resource) parsed);
public Bundle process(String sourceFile) throws FileNotFoundException, SAXException, IOException, ParserConfigurationException { this.definitions = sourceFile; log("Begin. Produce Loinc CDEs in "+dest+" from "+definitions); loadLoinc(); log("LOINC loaded"); now = DateTimeType.now(); bundle = new Bundle(); bundle.setType(BundleType.COLLECTION); bundle.setId("http://hl7.org/fhir/commondataelement/loinc"); bundle.setMeta(new Meta().setLastUpdatedElement(InstantType.now())); processLoincCodes(); return bundle; }
@Override public void addEntry(Bundle theBundle, Bundle.BundleEntryComponent theEntry) { theBundle.addEntry(theEntry); }
/** * Returns a bundle containing all resources in the dataset. This should be used * with caution for large datasets, since the returned bundle will include all data. * * @param dataset a dataset of FHIR resoruces * @return a bundle containing those resources. */ public static Bundle toBundle(Dataset<? extends Resource> dataset) { List<Resource> resources = (List<Resource>) dataset.collectAsList(); Bundle bundle = new Bundle(); for (Resource resource : resources) { bundle.addEntry().setResource(resource); } return bundle; }
private void ensureBundle() { if (myBundle == null) { myBundle = new Bundle(); } }
public void process() throws FHIRFormatError, IOException, XmlPullParserException, SAXException, ParserConfigurationException { log("Begin. Produce Loinc CDEs in "+dest+" from "+definitions); loadLoinc(); log("LOINC loaded"); now = DateTimeType.now(); bundle = new Bundle(); bundle.setId("http://hl7.org/fhir/commondataelement/loinc"); bundle.setMeta(new Meta().setLastUpdatedElement(InstantType.now())); processLoincCodes(); if (dest != null) { log("Saving..."); saveBundle(); } log("Done"); }
@Override public Base addChild(String name) throws FHIRException { if (name.equals("identifier")) { this.identifier = new Identifier(); return this.identifier; } else if (name.equals("type")) { throw new FHIRException("Cannot call addChild on a primitive type Bundle.type"); } else if (name.equals("timestamp")) { throw new FHIRException("Cannot call addChild on a primitive type Bundle.timestamp"); } else if (name.equals("total")) { throw new FHIRException("Cannot call addChild on a primitive type Bundle.total"); } else if (name.equals("link")) { return addLink(); } else if (name.equals("entry")) { return addEntry(); } else if (name.equals("signature")) { this.signature = new Signature(); return this.signature; } else return super.addChild(name); }
public Bundle copy() { Bundle dst = new Bundle(); copyValues(dst); dst.identifier = identifier == null ? null : identifier.copy(); dst.type = type == null ? null : type.copy(); dst.timestamp = timestamp == null ? null : timestamp.copy(); dst.total = total == null ? null : total.copy(); if (link != null) { dst.link = new ArrayList<BundleLinkComponent>(); for (BundleLinkComponent i : link) dst.link.add(i.copy()); }; if (entry != null) { dst.entry = new ArrayList<BundleEntryComponent>(); for (BundleEntryComponent i : entry) dst.entry.add(i.copy()); }; dst.signature = signature == null ? null : signature.copy(); return dst; }
/** * Validates bundle type, meta data and consistency of contained resources * * @param bundle transaction bundle */ protected void validateTransactionBundle(Bundle bundle) { if (!Bundle.BundleType.TRANSACTION.equals(bundle.getType())) { throw FhirUtils.unprocessableEntity( OperationOutcome.IssueSeverity.ERROR, OperationOutcome.IssueType.INVALID, null, null, "Bundle type must be %s, but was %s", Bundle.BundleType.TRANSACTION.toCode(), bundle.getType().toCode()); } List<CanonicalType> profiles = bundle.getMeta().getProfile(); if (profiles.isEmpty() || !Iti65Constants.ITI65_PROFILE.equals(profiles.get(0).getValue())) { throw FhirUtils.unprocessableEntity( OperationOutcome.IssueSeverity.ERROR, OperationOutcome.IssueType.INVALID, null, null, "Request bundle must have profile", Iti65Constants.ITI65_PROFILE); } }