@Override public IPrimitiveType<Date> getLastUpdated(IBaseResource theResource) { return ResourceMetadataKeyEnum.UPDATED.get((IResource) theResource); }
tags.addTag(Tag.HL7_ORG_FHIR_TAG, "http://foo/tag1.html", "Some tag"); tags.addTag(Tag.HL7_ORG_FHIR_TAG, "http://foo/tag2.html", "Another tag"); ResourceMetadataKeyEnum.TAG_LIST.put(patient, tags); ResourceMetadataKeyEnum.LINK_ALTERNATE.put(patient, linkAlternate); String linkSearch = "Patient?name=smith&name=john"; ResourceMetadataKeyEnum.LINK_SEARCH.put(patient, linkSearch); ResourceMetadataKeyEnum.PUBLISHED.put(patient, pubDate); InstantDt updatedDate = new InstantDt("2014-07-12T11:22:27Z"); ResourceMetadataKeyEnum.UPDATED.put(patient, updatedDate); ResourceMetadataKeyEnum.TITLE.put(patient, title);
private static String getStringFromMetadataOrNullIfNone(Map<ResourceMetadataKeyEnum<?>, Object> theResourceMetadata, ResourceMetadataKeyEnum<String> theKey) { Object retValObj = theResourceMetadata.get(theKey); if (retValObj == null) { return null; } else if (retValObj instanceof String) { if (StringUtils.isBlank(((String) retValObj))) { return null; } return (String) retValObj; } throw new InternalErrorException("Found an object of type '" + retValObj.getClass().getCanonicalName() + "' in resource metadata for key " + theKey.name() + " - Expected " + String.class.getCanonicalName()); }
@Override public void addRootPropertiesToBundle(String theId, String theServerBase, String theLinkSelf, String theLinkPrev, String theLinkNext, Integer theTotalResults, BundleTypeEnum theBundleType, IPrimitiveType<Date> theLastUpdated) { myBase = theServerBase; if (myBundle.getIdElement().isEmpty()) { myBundle.setId(theId); } if (myBundle.getId().isEmpty()) { myBundle.setId(UUID.randomUUID().toString()); } if (ResourceMetadataKeyEnum.UPDATED.get(myBundle) == null) { ResourceMetadataKeyEnum.UPDATED.put(myBundle, (InstantDt) theLastUpdated); } 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); } }
private static IdDt getIdFromMetadataOrNullIfNone(Map<ResourceMetadataKeyEnum<?>, Object> theResourceMetadata, ResourceMetadataKeyEnum<?> theKey) { return toId(theKey, theResourceMetadata.get(theKey)); }
@Override public IBaseCoding addSecurity() { List<BaseCodingDt> tagList = ResourceMetadataKeyEnum.SECURITY_LABELS.get(BaseResource.this); if (tagList == null) { tagList = new ArrayList<BaseCodingDt>(); ResourceMetadataKeyEnum.SECURITY_LABELS.put(BaseResource.this, tagList); } CodingDt tag = new CodingDt(); tagList.add(tag); return tag; }
private static List<IdDt> getIdListFromMetadataOrNullIfNone(Map<ResourceMetadataKeyEnum<?>, Object> theResourceMetadata, ResourceMetadataKeyEnum<?> theKey) { Object retValObj = theResourceMetadata.get(theKey); if (retValObj == null) { return null; } else if (retValObj instanceof List) { List<?> retValList = (List<?>) retValObj; for (Object next : retValList) { if (!(next instanceof IdDt)) { List<IdDt> retVal = new ArrayList<IdDt>(); for (Object nextVal : retValList) { retVal.add(toId(theKey, nextVal)); } return Collections.unmodifiableList(retVal); } } @SuppressWarnings("unchecked") List<IdDt> retVal = (List<IdDt>) retValList; return Collections.unmodifiableList(retVal); } else { return Collections.singletonList(toId(theKey, retValObj)); } }
protected static <T> List<T> extractMetadataListNotNull(IResource resource, ResourceMetadataKeyEnum<List<T>> key) { List<? extends T> securityLabels = key.get(resource); if (securityLabels == null) { securityLabels = Collections.emptyList(); } return new ArrayList<>(securityLabels); }
@Override public IBaseMetaType addProfile(String theProfile) { ArrayList<IdDt> newTagList = new ArrayList<IdDt>(); List<IdDt> existingTagList = ResourceMetadataKeyEnum.PROFILES.get(BaseResource.this); if (existingTagList != null) { newTagList.addAll(existingTagList); } ResourceMetadataKeyEnum.PROFILES.put(BaseResource.this, newTagList); IdDt tag = new IdDt(theProfile); newTagList.add(tag); return this; }
ResourceMetadataKeyEnum.VERSION.put((IResource) theResource, versionIdPart); } else { BaseRuntimeChildDefinition metaChild = myFhirContext.getResourceDefinition(myResourceType).getChildByName("meta");
@SuppressWarnings("unchecked") private static <T extends Enum<?>> T getEnumFromMetadataOrNullIfNone(Map<ResourceMetadataKeyEnum<?>, Object> theResourceMetadata, ResourceMetadataKeyEnum<T> theKey, Class<T> theEnumType, IValueSetEnumBinder<T> theBinder) { Object retValObj = theResourceMetadata.get(theKey); if (retValObj == null) { return null; } else if (theEnumType.equals(retValObj.getClass())) { return (T) retValObj; } else if (retValObj instanceof String) { return theBinder.fromCodeString((String) retValObj); } throw new InternalErrorException("Found an object of type '" + retValObj.getClass().getCanonicalName() + "' in resource metadata for key " + theKey.name() + " - Expected " + InstantDt.class.getCanonicalName()); }
private static IdDt getIdFromMetadataOrNullIfNone(Map<ResourceMetadataKeyEnum<?>, Object> theResourceMetadata, ResourceMetadataKeyEnum<?> theKey) { return toId(theKey, theResourceMetadata.get(theKey)); }
public static IPrimitiveType<Date> extractLastUpdatedFromResource(IBaseResource theResource) { IPrimitiveType<Date> lastUpdated = null; if (theResource instanceof IResource) { lastUpdated = ResourceMetadataKeyEnum.UPDATED.get((IResource) theResource); } else if (theResource instanceof IAnyResource) { lastUpdated = new InstantDt(theResource.getMeta().getLastUpdated()); } return lastUpdated; }
@Override public IBaseMetaType addProfile(String theProfile) { ArrayList<IdDt> newTagList = new ArrayList<IdDt>(); List<IdDt> existingTagList = ResourceMetadataKeyEnum.PROFILES.get(BaseResource.this); if (existingTagList != null) { newTagList.addAll(existingTagList); } ResourceMetadataKeyEnum.PROFILES.put(BaseResource.this, newTagList); IdDt tag = new IdDt(theProfile); newTagList.add(tag); return this; }
@Search public List<Patient> getAllPatients() { ArrayList<Patient> retVal = new ArrayList<Patient>(); // Create a patient to return Patient patient = new Patient(); patient.setId("Patient/123"); patient.addName().addFamily("Smith").addGiven("John"); // Create a tag list and add it to the resource TagList tags = new TagList(); ResourceMetadataKeyEnum.TAG_LIST.put(patient, tags); // Add some tags to the list tags.addTag(Tag.HL7_ORG_FHIR_TAG, "http://foo/tag1.html", "Some tag"); tags.addTag(Tag.HL7_ORG_FHIR_TAG, "http://foo/tag2.html", "Another tag"); return retVal; } // END SNIPPET: serverMethod
private static InstantDt getInstantFromMetadataOrNullIfNone(Map<ResourceMetadataKeyEnum<?>, Object> theResourceMetadata, ResourceMetadataKeyEnum<InstantDt> theKey) { Object retValObj = theResourceMetadata.get(theKey); if (retValObj == null) { return null; } else if (retValObj instanceof Date) { return new InstantDt((Date) retValObj); } else if (retValObj instanceof InstantDt) { if (((InstantDt) retValObj).isEmpty()) { return null; } return (InstantDt) retValObj; } throw new InternalErrorException("Found an object of type '" + retValObj.getClass().getCanonicalName() + "' in resource metadata for key " + theKey.name() + " - Expected " + InstantDt.class.getCanonicalName()); }
private static List<IdDt> getIdListFromMetadataOrNullIfNone(Map<ResourceMetadataKeyEnum<?>, Object> theResourceMetadata, ResourceMetadataKeyEnum<?> theKey) { Object retValObj = theResourceMetadata.get(theKey); if (retValObj == null) { return null; } else if (retValObj instanceof List) { List<?> retValList = (List<?>) retValObj; for (Object next : retValList) { if (!(next instanceof IdDt)) { List<IdDt> retVal = new ArrayList<IdDt>(); for (Object nextVal : retValList) { retVal.add(toId(theKey, nextVal)); } return Collections.unmodifiableList(retVal); } } @SuppressWarnings("unchecked") List<IdDt> retVal = (List<IdDt>) retValList; return Collections.unmodifiableList(retVal); } else { return Collections.singletonList(toId(theKey, retValObj)); } }
@SuppressWarnings("unused") public void getResourceTags() { // START SNIPPET: getResourceTags IGenericClient client = FhirContext.forDstu2().newRestfulGenericClient("http://fhir.healthintersections.com.au/open"); Patient p = client.read(Patient.class, "1"); // Retrieve the list of tags from the resource metadata TagList tags = ResourceMetadataKeyEnum.TAG_LIST.get(p); // tags may be null if no tags were read in if (tags == null) { System.out.println("No tags!"); } else { // You may iterate over all the tags for (Tag next : tags) { System.out.println(next.getScheme() + " - " + next.getTerm()); } // You may also get a list of tags matching a given scheme List<Tag> someTags = tags.getTagsWithScheme("http://hl7.org/fhir/tag"); // Or a specific tag (by scheme and term) Tag specificTag = tags.getTag("http://hl7.org/fhir/tag", "http://foo"); } // END SNIPPET: getResourceTags }
@Override public IBaseCoding addSecurity() { List<BaseCodingDt> tagList = ResourceMetadataKeyEnum.SECURITY_LABELS.get(BaseResource.this); if (tagList == null) { tagList = new ArrayList<BaseCodingDt>(); ResourceMetadataKeyEnum.SECURITY_LABELS.put(BaseResource.this, tagList); } CodingDt tag = new CodingDt(); tagList.add(tag); return asBaseCoding(tag); }
ResourceMetadataKeyEnum.VERSION.put(res, Long.toString(theEntity.getVersion())); ResourceMetadataKeyEnum.PUBLISHED.put(res, theEntity.getPublished()); ResourceMetadataKeyEnum.UPDATED.put(res, theEntity.getUpdated()); IDao.RESOURCE_PID.put(res, theEntity.getId()); ResourceMetadataKeyEnum.TAG_LIST.put(res, tagList); ResourceMetadataKeyEnum.SECURITY_LABELS.put(res, toBaseCodingList(securityLabels)); ResourceMetadataKeyEnum.PROFILES.put(res, profiles);