diff --git a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/advisors/impl/BaseAdvisor_43_50.java b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/advisors/impl/BaseAdvisor_43_50.java index e774ce69d..2a205c4a6 100644 --- a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/advisors/impl/BaseAdvisor_43_50.java +++ b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/advisors/impl/BaseAdvisor_43_50.java @@ -31,7 +31,10 @@ public class BaseAdvisor_43_50 extends BaseAdvisor50 convertSubscriptionStatus(org.hl7.fhir.r5.model.Enumeration src) { + org.hl7.fhir.r4b.model.Enumerations.SubscriptionStatusEnumFactory enumFactory = new org.hl7.fhir.r4b.model.Enumerations.SubscriptionStatusEnumFactory(); + switch(src.getValue()) { + case ACTIVE: return new org.hl7.fhir.r4b.model.Enumeration<>(enumFactory, org.hl7.fhir.r4b.model.Enumerations.SubscriptionStatus.ACTIVE); + case ERROR: return new org.hl7.fhir.r4b.model.Enumeration<>(enumFactory, org.hl7.fhir.r4b.model.Enumerations.SubscriptionStatus.ERROR); + case ENTEREDINERROR: return new org.hl7.fhir.r4b.model.Enumeration<>(enumFactory, org.hl7.fhir.r4b.model.Enumerations.SubscriptionStatus.ERROR); + case OFF: return new org.hl7.fhir.r4b.model.Enumeration<>(enumFactory, org.hl7.fhir.r4b.model.Enumerations.SubscriptionStatus.OFF); + case REQUESTED: return new org.hl7.fhir.r4b.model.Enumeration<>(enumFactory, org.hl7.fhir.r4b.model.Enumerations.SubscriptionStatus.REQUESTED); + case NULL: return new org.hl7.fhir.r4b.model.Enumeration<>(enumFactory, org.hl7.fhir.r4b.model.Enumerations.SubscriptionStatus.NULL); + } + return null; + } + + private static org.hl7.fhir.r4b.model.Enumeration convertSubscriptionNotificationType(org.hl7.fhir.r5.model.Enumeration src) { + org.hl7.fhir.r4b.model.SubscriptionStatus.SubscriptionNotificationTypeEnumFactory enumFactory = new org.hl7.fhir.r4b.model.SubscriptionStatus.SubscriptionNotificationTypeEnumFactory(); + switch(src.getValue()) { + case EVENTNOTIFICATION: return new org.hl7.fhir.r4b.model.Enumeration<>(enumFactory, org.hl7.fhir.r4b.model.SubscriptionStatus.SubscriptionNotificationType.EVENTNOTIFICATION); + case HANDSHAKE: return new org.hl7.fhir.r4b.model.Enumeration<>(enumFactory, org.hl7.fhir.r4b.model.SubscriptionStatus.SubscriptionNotificationType.HANDSHAKE); + case HEARTBEAT: return new org.hl7.fhir.r4b.model.Enumeration<>(enumFactory, org.hl7.fhir.r4b.model.SubscriptionStatus.SubscriptionNotificationType.HEARTBEAT); + case QUERYEVENT: return new org.hl7.fhir.r4b.model.Enumeration<>(enumFactory, org.hl7.fhir.r4b.model.SubscriptionStatus.SubscriptionNotificationType.QUERYEVENT); + case QUERYSTATUS: return new org.hl7.fhir.r4b.model.Enumeration<>(enumFactory, org.hl7.fhir.r4b.model.SubscriptionStatus.SubscriptionNotificationType.QUERYSTATUS); + case NULL: return new org.hl7.fhir.r4b.model.Enumeration<>(enumFactory, org.hl7.fhir.r4b.model.SubscriptionStatus.SubscriptionNotificationType.NULL); + } + return null; + } + + + public static org.hl7.fhir.r5.model.SubscriptionStatus convertSubscriptionStatus(org.hl7.fhir.r4b.model.SubscriptionStatus src) { + if (src == null) + return null; + org.hl7.fhir.r5.model.SubscriptionStatus tgt = new org.hl7.fhir.r5.model.SubscriptionStatus(); + ConversionContext43_50.INSTANCE.getVersionConvertor_43_50().copyResource(src, tgt); + ConversionContext43_50.INSTANCE.getVersionConvertor_43_50().copyDomainResource(src, tgt); + + if (src.hasType()) + { + tgt.setTypeElement(convertSubscriptionNotificationType(src.getTypeElement())); + } + if (src.hasStatus()) { + tgt.setStatusElement(convertSubscriptionStatus(src.getStatusElement())); + } + if (src.hasEventsSinceSubscriptionStart()) { + org.hl7.fhir.r5.model.Integer64Type value = new org.hl7.fhir.r5.model.Integer64Type(); + value.fromStringValue(src.getEventsSinceSubscriptionStartElement().getValueAsString()); + tgt.setEventsSinceSubscriptionStartElement(value); + } + if (src.hasNotificationEvent()) { + for (org.hl7.fhir.r4b.model.SubscriptionStatus.SubscriptionStatusNotificationEventComponent element : src.getNotificationEvent()) { + tgt.addNotificationEvent(convertSubscriptionStatusNotificationEventComponent(element)); + } + } + if (src.hasSubscription()) { + tgt.setSubscription(Reference43_50.convertReference(src.getSubscription())); + } + if (src.hasTopic()) { + tgt.setTopicElement(Canonical43_50.convertCanonical(src.getTopicElement())); + } + return tgt; + } + + private static org.hl7.fhir.r5.model.SubscriptionStatus.SubscriptionStatusNotificationEventComponent convertSubscriptionStatusNotificationEventComponent(org.hl7.fhir.r4b.model.SubscriptionStatus.SubscriptionStatusNotificationEventComponent src) { + org.hl7.fhir.r5.model.SubscriptionStatus.SubscriptionStatusNotificationEventComponent tgt = new org.hl7.fhir.r5.model.SubscriptionStatus.SubscriptionStatusNotificationEventComponent(); + if (src.hasEventNumber()) { + tgt.setEventNumberElement(Integer64_43_50.convertStringToInteger64(src.getEventNumberElement())); + } + if (src.hasFocus()) { + tgt.setFocus(Reference43_50.convertReference(src.getFocus())); + } + return tgt; + } + + private static org.hl7.fhir.r5.model.Enumeration convertSubscriptionStatus(org.hl7.fhir.r4b.model.Enumeration src) { + org.hl7.fhir.r5.model.Enumerations.SubscriptionStatusCodesEnumFactory enumFactory = new org.hl7.fhir.r5.model.Enumerations.SubscriptionStatusCodesEnumFactory(); + switch(src.getValue()) { + case ACTIVE: return new org.hl7.fhir.r5.model.Enumeration<>(enumFactory, org.hl7.fhir.r5.model.Enumerations.SubscriptionStatusCodes.ACTIVE); + case ERROR: return new org.hl7.fhir.r5.model.Enumeration<>(enumFactory, org.hl7.fhir.r5.model.Enumerations.SubscriptionStatusCodes.ERROR); + case OFF: return new org.hl7.fhir.r5.model.Enumeration<>(enumFactory, org.hl7.fhir.r5.model.Enumerations.SubscriptionStatusCodes.OFF); + case REQUESTED: return new org.hl7.fhir.r5.model.Enumeration<>(enumFactory, org.hl7.fhir.r5.model.Enumerations.SubscriptionStatusCodes.REQUESTED); + case NULL: return new org.hl7.fhir.r5.model.Enumeration<>(enumFactory, org.hl7.fhir.r5.model.Enumerations.SubscriptionStatusCodes.NULL); + } + return null; + } + + private static org.hl7.fhir.r5.model.Enumeration convertSubscriptionNotificationType(org.hl7.fhir.r4b.model.Enumeration src) { + org.hl7.fhir.r5.model.SubscriptionStatus.SubscriptionNotificationTypeEnumFactory enumFactory = new org.hl7.fhir.r5.model.SubscriptionStatus.SubscriptionNotificationTypeEnumFactory(); + switch(src.getValue()) { + case EVENTNOTIFICATION: return new org.hl7.fhir.r5.model.Enumeration<>(enumFactory, org.hl7.fhir.r5.model.SubscriptionStatus.SubscriptionNotificationType.EVENTNOTIFICATION); + case HANDSHAKE: return new org.hl7.fhir.r5.model.Enumeration<>(enumFactory, org.hl7.fhir.r5.model.SubscriptionStatus.SubscriptionNotificationType.HANDSHAKE); + case HEARTBEAT: return new org.hl7.fhir.r5.model.Enumeration<>(enumFactory, org.hl7.fhir.r5.model.SubscriptionStatus.SubscriptionNotificationType.HEARTBEAT); + case QUERYEVENT: return new org.hl7.fhir.r5.model.Enumeration<>(enumFactory, org.hl7.fhir.r5.model.SubscriptionStatus.SubscriptionNotificationType.QUERYEVENT); + case QUERYSTATUS: return new org.hl7.fhir.r5.model.Enumeration<>(enumFactory, org.hl7.fhir.r5.model.SubscriptionStatus.SubscriptionNotificationType.QUERYSTATUS); + case NULL: return new org.hl7.fhir.r5.model.Enumeration<>(enumFactory, org.hl7.fhir.r5.model.SubscriptionStatus.SubscriptionNotificationType.NULL); + } + return null; + } +} diff --git a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv43_50/resources43_50/SubscriptionTopic43_50.java b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv43_50/resources43_50/SubscriptionTopic43_50.java new file mode 100644 index 000000000..9f332f18a --- /dev/null +++ b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv43_50/resources43_50/SubscriptionTopic43_50.java @@ -0,0 +1,473 @@ +package org.hl7.fhir.convertors.conv43_50.resources43_50; + +import org.hl7.fhir.convertors.context.ConversionContext43_50; +import org.hl7.fhir.convertors.conv43_50.datatypes43_50.general43_50.CodeableConcept43_50; +import org.hl7.fhir.convertors.conv43_50.datatypes43_50.general43_50.Identifier43_50; +import org.hl7.fhir.convertors.conv43_50.datatypes43_50.general43_50.Period43_50; +import org.hl7.fhir.convertors.conv43_50.datatypes43_50.metadata43_50.ContactDetail43_50; +import org.hl7.fhir.convertors.conv43_50.datatypes43_50.metadata43_50.UsageContext43_50; +import org.hl7.fhir.convertors.conv43_50.datatypes43_50.primitive43_50.*; +import org.hl7.fhir.r4b.model.SubscriptionTopic; + +import java.util.List; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +public class SubscriptionTopic43_50 { + public static org.hl7.fhir.r4b.model.SubscriptionTopic convertSubscriptionTopic(org.hl7.fhir.r5.model.SubscriptionTopic src) { + if (src == null) + return null; + org.hl7.fhir.r4b.model.SubscriptionTopic tgt = new org.hl7.fhir.r4b.model.SubscriptionTopic(); + ConversionContext43_50.INSTANCE.getVersionConvertor_43_50().copyResource(src, tgt); + ConversionContext43_50.INSTANCE.getVersionConvertor_43_50().copyDomainResource(src, tgt); + if (src.hasUrl()) + tgt.setUrlElement(Uri43_50.convertUri(src.getUrlElement())); + for (org.hl7.fhir.r5.model.Identifier t : src.getIdentifier()) + tgt.addIdentifier(Identifier43_50.convertIdentifier(t)); + if (src.hasTitle()) + tgt.setTitleElement(String43_50.convertString(src.getTitleElement())); + for (org.hl7.fhir.r5.model.CanonicalType t : src.getDerivedFrom()) + tgt.getDerivedFrom().add(Canonical43_50.convertCanonical(t)); + if (src.hasStatus()) + tgt.setStatusElement(Enumerations43_50.convertPublicationStatus(src.getStatusElement())); + if (src.hasVersion()) + tgt.setVersionElement(String43_50.convertString(src.getVersionElement())); + if (src.hasTitle()) + tgt.setTitleElement(String43_50.convertString(src.getTitleElement())); + if (src.hasStatus()) + tgt.setStatusElement(Enumerations43_50.convertPublicationStatus(src.getStatusElement())); + if (src.hasExperimental()) + tgt.setExperimentalElement(Boolean43_50.convertBoolean(src.getExperimentalElement())); + if (src.hasDate()) + tgt.setDateElement(DateTime43_50.convertDateTime(src.getDateElement())); + if (src.hasPublisher()) + tgt.setPublisherElement(String43_50.convertString(src.getPublisherElement())); + for (org.hl7.fhir.r5.model.ContactDetail t : src.getContact()) + tgt.addContact(ContactDetail43_50.convertContactDetail(t)); + if (src.hasDescription()) + tgt.setDescriptionElement(MarkDown43_50.convertMarkdown(src.getDescriptionElement())); + for (org.hl7.fhir.r5.model.UsageContext t : src.getUseContext()) + tgt.addUseContext(UsageContext43_50.convertUsageContext(t)); + for (org.hl7.fhir.r5.model.CodeableConcept t : src.getJurisdiction()) + tgt.addJurisdiction(CodeableConcept43_50.convertCodeableConcept(t)); + if (src.hasPurpose()) + tgt.setPurposeElement(MarkDown43_50.convertMarkdown(src.getPurposeElement())); + if (src.hasCopyright()) + tgt.setCopyrightElement(MarkDown43_50.convertMarkdown(src.getCopyrightElement())); + if (src.hasCopyrightLabel()) { + tgt.addExtension("http://hl7.org/fhir/5.0/StructureDefinition/extension-SubscriptionTopic.copyrightLabel", String43_50.convertString(src.getCopyrightLabelElement())); + } + if (src.hasName()) { + tgt.addExtension("http://hl7.org/fhir/5.0/StructureDefinition/extension-SubscriptionTopic.name", String43_50.convertString(src.getNameElement())); + } + if (src.hasApprovalDate()) + tgt.setApprovalDateElement(Date43_50.convertDate(src.getApprovalDateElement())); + if (src.hasLastReviewDate()) + tgt.setLastReviewDateElement(Date43_50.convertDate(src.getLastReviewDateElement())); + if (src.hasEffectivePeriod()) + tgt.setEffectivePeriod(Period43_50.convertPeriod(src.getEffectivePeriod())); + for(org.hl7.fhir.r5.model.SubscriptionTopic.SubscriptionTopicResourceTriggerComponent triggerComponent : src.getResourceTrigger()) { + tgt.addResourceTrigger(convertResourceTrigger(triggerComponent));} + for (org.hl7.fhir.r5.model.SubscriptionTopic.SubscriptionTopicCanFilterByComponent canFilterByComponent : src.getCanFilterBy()) { + tgt.addCanFilterBy(convertCanFilterBy(canFilterByComponent)); + } + for (org.hl7.fhir.r5.model.SubscriptionTopic.SubscriptionTopicEventTriggerComponent eventTrigger : src.getEventTrigger()) { + tgt.addEventTrigger(convertEventTrigger(eventTrigger)); + } + for (org.hl7.fhir.r5.model.SubscriptionTopic.SubscriptionTopicNotificationShapeComponent notificationShape : src.getNotificationShape()) { + tgt.addNotificationShape(convertNotificationShape(notificationShape)); + } + return tgt; + } + + private static SubscriptionTopic.SubscriptionTopicEventTriggerComponent convertEventTrigger(org.hl7.fhir.r5.model.SubscriptionTopic.SubscriptionTopicEventTriggerComponent src) { + org.hl7.fhir.r4b.model.SubscriptionTopic.SubscriptionTopicEventTriggerComponent tgt = new org.hl7.fhir.r4b.model.SubscriptionTopic.SubscriptionTopicEventTriggerComponent(); + if (src.hasDescription()) { + tgt.setDescriptionElement(MarkDown43_50.convertMarkdown(src.getDescriptionElement())); + } + if (src.hasEvent()) { + tgt.setEvent(CodeableConcept43_50.convertCodeableConcept(src.getEvent())); + } + if (src.hasResource()) { + tgt.setResourceElement(Uri43_50.convertUri(src.getResourceElement())); + } + return tgt; + } + + private static org.hl7.fhir.r4b.model.SubscriptionTopic.SubscriptionTopicNotificationShapeComponent convertNotificationShape(org.hl7.fhir.r5.model.SubscriptionTopic.SubscriptionTopicNotificationShapeComponent src) { + org.hl7.fhir.r4b.model.SubscriptionTopic.SubscriptionTopicNotificationShapeComponent tgt = new org.hl7.fhir.r4b.model.SubscriptionTopic.SubscriptionTopicNotificationShapeComponent(); + if (src.hasResource()) { + tgt.setResourceElement(Uri43_50.convertUri(src.getResourceElement())); + } + if (src.hasInclude()) { + tgt.setInclude(src.getInclude().stream().map(String43_50::convertString).collect(Collectors.toList())); + } + if (src.hasRevInclude()) { + tgt.setRevInclude(src.getRevInclude().stream().map(String43_50::convertString).collect(Collectors.toList())); + } + return tgt; + } + + private static org.hl7.fhir.r4b.model.SubscriptionTopic.SubscriptionTopicCanFilterByComponent convertCanFilterBy(org.hl7.fhir.r5.model.SubscriptionTopic.SubscriptionTopicCanFilterByComponent src) { + org.hl7.fhir.r4b.model.SubscriptionTopic.SubscriptionTopicCanFilterByComponent tgt = new org.hl7.fhir.r4b.model.SubscriptionTopic.SubscriptionTopicCanFilterByComponent(); + if (src.hasDescription()) { + tgt.setDescriptionElement(MarkDown43_50.convertMarkdown(src.getDescriptionElement())); + } + if (src.hasResource()) { + tgt.setResourceElement(Uri43_50.convertUri(src.getResourceElement())); + } + if (src.hasFilterParameter()) { + tgt.setFilterParameterElement(String43_50.convertString(src.getFilterParameterElement())); + } + if (src.hasFilterDefinition()) { + // TODO r4b spec has this, but the Java model does not + } + if (src.hasModifier() || src.hasComparator()) { + List> tgtModifiers = convertR5ModifierToR4BModifier(src.getModifier()); + + List> tgtComparatorModifiers = convertR5ComparatorToR4BModifier(src.getComparator()); + + tgt.setModifier(Stream.concat(tgtModifiers.stream(), tgtComparatorModifiers.stream()) + .collect(Collectors.toList())); + } + + return tgt; + } + + private static List> convertR5ComparatorToR4BModifier(List> srcList) { + return srcList.stream().map(SubscriptionTopic43_50::convertR5ComparatorToR4BModifier).filter(x -> x != null).collect(Collectors.toList()); + } + + private static org.hl7.fhir.r4b.model.Enumeration convertR5ComparatorToR4BModifier(org.hl7.fhir.r5.model.Enumeration src){ + org.hl7.fhir.r4b.model.SubscriptionTopic.SubscriptionSearchModifierEnumFactory enumFactory = new org.hl7.fhir.r4b.model.SubscriptionTopic.SubscriptionSearchModifierEnumFactory(); + switch(src.getValue()) { + case NULL: return new org.hl7.fhir.r4b.model.Enumeration<>(enumFactory, org.hl7.fhir.r4b.model.SubscriptionTopic.SubscriptionSearchModifier.NULL); + case EQ: return new org.hl7.fhir.r4b.model.Enumeration<>(enumFactory, org.hl7.fhir.r4b.model.SubscriptionTopic.SubscriptionSearchModifier.EQ); + case NE: return new org.hl7.fhir.r4b.model.Enumeration<>(enumFactory, org.hl7.fhir.r4b.model.SubscriptionTopic.SubscriptionSearchModifier.NE); + case GT: return new org.hl7.fhir.r4b.model.Enumeration<>(enumFactory, org.hl7.fhir.r4b.model.SubscriptionTopic.SubscriptionSearchModifier.GT); + case LT: return new org.hl7.fhir.r4b.model.Enumeration<>(enumFactory, org.hl7.fhir.r4b.model.SubscriptionTopic.SubscriptionSearchModifier.LT); + case GE: return new org.hl7.fhir.r4b.model.Enumeration<>(enumFactory, org.hl7.fhir.r4b.model.SubscriptionTopic.SubscriptionSearchModifier.GE); + case LE: return new org.hl7.fhir.r4b.model.Enumeration<>(enumFactory, org.hl7.fhir.r4b.model.SubscriptionTopic.SubscriptionSearchModifier.LE); + case SA: return new org.hl7.fhir.r4b.model.Enumeration<>(enumFactory, org.hl7.fhir.r4b.model.SubscriptionTopic.SubscriptionSearchModifier.SA); + case EB: return new org.hl7.fhir.r4b.model.Enumeration<>(enumFactory, org.hl7.fhir.r4b.model.SubscriptionTopic.SubscriptionSearchModifier.EB); + case AP: return new org.hl7.fhir.r4b.model.Enumeration<>(enumFactory, org.hl7.fhir.r4b.model.SubscriptionTopic.SubscriptionSearchModifier.AP); + } + return null; + } + + private static List> convertR5ModifierToR4BModifier(List> srcList) { + return srcList.stream().map(SubscriptionTopic43_50::convertR5ModifierToR4BModifier).filter(x -> x != null).collect(Collectors.toList()); + } + + private static org.hl7.fhir.r4b.model.Enumeration convertR5ModifierToR4BModifier(org.hl7.fhir.r5.model.Enumeration src){ + org.hl7.fhir.r4b.model.SubscriptionTopic.SubscriptionSearchModifierEnumFactory enumFactory = new org.hl7.fhir.r4b.model.SubscriptionTopic.SubscriptionSearchModifierEnumFactory(); + switch(src.getValue()) { + case NULL: return new org.hl7.fhir.r4b.model.Enumeration<>(enumFactory, org.hl7.fhir.r4b.model.SubscriptionTopic.SubscriptionSearchModifier.NULL); + case IN: return new org.hl7.fhir.r4b.model.Enumeration<>(enumFactory, org.hl7.fhir.r4b.model.SubscriptionTopic.SubscriptionSearchModifier.IN); + case NOTIN: return new org.hl7.fhir.r4b.model.Enumeration<>(enumFactory, org.hl7.fhir.r4b.model.SubscriptionTopic.SubscriptionSearchModifier.NOTIN); + case BELOW: return new org.hl7.fhir.r4b.model.Enumeration<>(enumFactory, org.hl7.fhir.r4b.model.SubscriptionTopic.SubscriptionSearchModifier.BELOW); + case ABOVE: return new org.hl7.fhir.r4b.model.Enumeration<>(enumFactory, org.hl7.fhir.r4b.model.SubscriptionTopic.SubscriptionSearchModifier.ABOVE); + case OFTYPE: return new org.hl7.fhir.r4b.model.Enumeration<>(enumFactory, org.hl7.fhir.r4b.model.SubscriptionTopic.SubscriptionSearchModifier.OFTYPE); + } + return null; + } + private static org.hl7.fhir.r4b.model.SubscriptionTopic.SubscriptionTopicResourceTriggerComponent convertResourceTrigger(org.hl7.fhir.r5.model.SubscriptionTopic.SubscriptionTopicResourceTriggerComponent src) { + org.hl7.fhir.r4b.model.SubscriptionTopic.SubscriptionTopicResourceTriggerComponent tgt = new org.hl7.fhir.r4b.model.SubscriptionTopic.SubscriptionTopicResourceTriggerComponent(); + ConversionContext43_50.INSTANCE.getVersionConvertor_43_50().copyBackboneElement(src, tgt); + if (src.hasDescription()) { + tgt.setDescriptionElement(MarkDown43_50.convertMarkdown(src.getDescriptionElement())); + } + if (src.hasResource()) { + tgt.setResourceElement(Uri43_50.convertUri(src.getResourceElement())); + } + if (src.hasSupportedInteraction()) { + for (org.hl7.fhir.r5.model.Enumeration srcItem : src.getSupportedInteraction()) { + org.hl7.fhir.r4b.model.Enumeration newElement = tgt.addSupportedInteractionElement(); + newElement.setValue(convertInteractionTrigger(srcItem.getValue())); + } + } + if (src.hasQueryCriteria()) { + tgt.setQueryCriteria(convertResourceTriggerQueryCriteriaComponent(src.getQueryCriteria())); + } + if (src.hasFhirPathCriteria()) { + tgt.setFhirPathCriteriaElement(String43_50.convertString(src.getFhirPathCriteriaElement())); + } + return tgt; + } + + private static org.hl7.fhir.r4b.model.SubscriptionTopic.SubscriptionTopicResourceTriggerQueryCriteriaComponent convertResourceTriggerQueryCriteriaComponent(org.hl7.fhir.r5.model.SubscriptionTopic.SubscriptionTopicResourceTriggerQueryCriteriaComponent src) { + org.hl7.fhir.r4b.model.SubscriptionTopic.SubscriptionTopicResourceTriggerQueryCriteriaComponent tgt = new org.hl7.fhir.r4b.model.SubscriptionTopic.SubscriptionTopicResourceTriggerQueryCriteriaComponent(); + if (src.hasPrevious()) { + tgt.setPreviousElement(String43_50.convertString(src.getPreviousElement())); + } + if (src.hasResultForCreate()) { + tgt.setResultForCreateElement(convertCriteriaNotExistsBehavior(src.getResultForCreateElement())); + } + if (src.hasCurrent()) { + tgt.setCurrentElement(String43_50.convertString(src.getCurrentElement())); + } + if (src.hasResultForDelete()) { + tgt.setResultForDeleteElement(convertCriteriaNotExistsBehavior(src.getResultForDeleteElement())); + } + if (src.hasRequireBoth()) { + tgt.setRequireBothElement(Boolean43_50.convertBoolean(src.getRequireBothElement())); + } + + return tgt; + } + + private static org.hl7.fhir.r4b.model.Enumeration convertCriteriaNotExistsBehavior(org.hl7.fhir.r5.model.Enumeration src) { + org.hl7.fhir.r4b.model.SubscriptionTopic.CriteriaNotExistsBehaviorEnumFactory enumFactory = new org.hl7.fhir.r4b.model.SubscriptionTopic.CriteriaNotExistsBehaviorEnumFactory(); + switch(src.getValue()) { + case TESTFAILS: return new org.hl7.fhir.r4b.model.Enumeration<>(enumFactory, org.hl7.fhir.r4b.model.SubscriptionTopic.CriteriaNotExistsBehavior.TESTFAILS); + case TESTPASSES: return new org.hl7.fhir.r4b.model.Enumeration<>(enumFactory, org.hl7.fhir.r4b.model.SubscriptionTopic.CriteriaNotExistsBehavior.TESTPASSES); + case NULL: return new org.hl7.fhir.r4b.model.Enumeration<>(enumFactory, org.hl7.fhir.r4b.model.SubscriptionTopic.CriteriaNotExistsBehavior.NULL); + } + return null; + } + + private static org.hl7.fhir.r4b.model.SubscriptionTopic.InteractionTrigger convertInteractionTrigger(org.hl7.fhir.r5.model.SubscriptionTopic.InteractionTrigger value) { + switch(value) { + case CREATE : return org.hl7.fhir.r4b.model.SubscriptionTopic.InteractionTrigger.CREATE; + case UPDATE: return org.hl7.fhir.r4b.model.SubscriptionTopic.InteractionTrigger.UPDATE; + case DELETE: return org.hl7.fhir.r4b.model.SubscriptionTopic.InteractionTrigger.DELETE; + case NULL: return org.hl7.fhir.r4b.model.SubscriptionTopic.InteractionTrigger.NULL; + } + return null; + } + + + + public static org.hl7.fhir.r5.model.SubscriptionTopic convertSubscriptionTopic(org.hl7.fhir.r4b.model.SubscriptionTopic src) { + if (src == null) + return null; + org.hl7.fhir.r5.model.SubscriptionTopic tgt = new org.hl7.fhir.r5.model.SubscriptionTopic(); + ConversionContext43_50.INSTANCE.getVersionConvertor_43_50().copyResource(src, tgt); + ConversionContext43_50.INSTANCE.getVersionConvertor_43_50().copyDomainResource(src, tgt); + + if (src.hasExtension("http://hl7.org/fhir/5.0/StructureDefinition/extension-SubscriptionTopic.name")) { + tgt.setNameElement(String43_50.convertString((org.hl7.fhir.r4b.model.StringType) src.getExtensionByUrl("http://hl7.org/fhir/5.0/StructureDefinition/extension-SubscriptionTopic.name").getValue())); + } + if (src.hasExtension("http://hl7.org/fhir/5.0/StructureDefinition/extension-SubscriptionTopic.copyrightLabel")) { + tgt.setCopyrightLabelElement(String43_50.convertString((org.hl7.fhir.r4b.model.StringType) src.getExtensionByUrl("http://hl7.org/fhir/5.0/StructureDefinition/extension-SubscriptionTopic.copyrightLabel").getValue())); + } + if (src.hasUrl()) + tgt.setUrlElement(Uri43_50.convertUri(src.getUrlElement())); + for (org.hl7.fhir.r4b.model.Identifier t : src.getIdentifier()) + tgt.addIdentifier(Identifier43_50.convertIdentifier(t)); + if (src.hasTitle()) + tgt.setTitleElement(String43_50.convertString(src.getTitleElement())); + for (org.hl7.fhir.r4b.model.CanonicalType t : src.getDerivedFrom()) + tgt.getDerivedFrom().add(Canonical43_50.convertCanonical(t)); + if (src.hasStatus()) + tgt.setStatusElement(Enumerations43_50.convertPublicationStatus(src.getStatusElement())); + if (src.hasVersion()) + tgt.setVersionElement(String43_50.convertString(src.getVersionElement())); + if (src.hasTitle()) + tgt.setTitleElement(String43_50.convertString(src.getTitleElement())); + if (src.hasStatus()) + tgt.setStatusElement(Enumerations43_50.convertPublicationStatus(src.getStatusElement())); + if (src.hasExperimental()) + tgt.setExperimentalElement(Boolean43_50.convertBoolean(src.getExperimentalElement())); + if (src.hasDate()) + tgt.setDateElement(DateTime43_50.convertDateTime(src.getDateElement())); + if (src.hasPublisher()) + tgt.setPublisherElement(String43_50.convertString(src.getPublisherElement())); + for (org.hl7.fhir.r4b.model.ContactDetail t : src.getContact()) + tgt.addContact(ContactDetail43_50.convertContactDetail(t)); + if (src.hasDescription()) + tgt.setDescriptionElement(MarkDown43_50.convertMarkdown(src.getDescriptionElement())); + for (org.hl7.fhir.r4b.model.UsageContext t : src.getUseContext()) + tgt.addUseContext(UsageContext43_50.convertUsageContext(t)); + for (org.hl7.fhir.r4b.model.CodeableConcept t : src.getJurisdiction()) + tgt.addJurisdiction(CodeableConcept43_50.convertCodeableConcept(t)); + if (src.hasPurpose()) + tgt.setPurposeElement(MarkDown43_50.convertMarkdown(src.getPurposeElement())); + if (src.hasCopyright()) + tgt.setCopyrightElement(MarkDown43_50.convertMarkdown(src.getCopyrightElement())); + if (src.hasApprovalDate()) + tgt.setApprovalDateElement(Date43_50.convertDate(src.getApprovalDateElement())); + if (src.hasLastReviewDate()) + tgt.setLastReviewDateElement(Date43_50.convertDate(src.getLastReviewDateElement())); + if (src.hasEffectivePeriod()) + tgt.setEffectivePeriod(Period43_50.convertPeriod(src.getEffectivePeriod())); + for(org.hl7.fhir.r4b.model.SubscriptionTopic.SubscriptionTopicResourceTriggerComponent triggerComponent : src.getResourceTrigger()) { + tgt.addResourceTrigger(convertResourceTrigger(triggerComponent)); + } + for (org.hl7.fhir.r4b.model.SubscriptionTopic.SubscriptionTopicEventTriggerComponent eventTrigger : src.getEventTrigger()) { + tgt.addEventTrigger(convertEventTrigger(eventTrigger)); + } + for (org.hl7.fhir.r4b.model.SubscriptionTopic.SubscriptionTopicCanFilterByComponent canFilterByComponent : src.getCanFilterBy()) { + tgt.addCanFilterBy(convertCanFilterBy(canFilterByComponent)); + } + for (org.hl7.fhir.r4b.model.SubscriptionTopic.SubscriptionTopicNotificationShapeComponent notificationShape : src.getNotificationShape()) { + tgt.addNotificationShape(convertNotificationShape(notificationShape)); + } + return tgt; + } + + private static org.hl7.fhir.r5.model.SubscriptionTopic.SubscriptionTopicNotificationShapeComponent convertNotificationShape(org.hl7.fhir.r4b.model.SubscriptionTopic.SubscriptionTopicNotificationShapeComponent src) { + org.hl7.fhir.r5.model.SubscriptionTopic.SubscriptionTopicNotificationShapeComponent tgt = new org.hl7.fhir.r5.model.SubscriptionTopic.SubscriptionTopicNotificationShapeComponent(); + if (src.hasResource()) { + tgt.setResourceElement(Uri43_50.convertUri(src.getResourceElement())); + } + if (src.hasInclude()) { + tgt.setInclude(src.getInclude().stream().map(String43_50::convertString).collect(Collectors.toList())); + } + if (src.hasRevInclude()) { + tgt.setRevInclude(src.getRevInclude().stream().map(String43_50::convertString).collect(Collectors.toList())); + } + return tgt; + + } + + private static org.hl7.fhir.r5.model.SubscriptionTopic.SubscriptionTopicEventTriggerComponent convertEventTrigger(org.hl7.fhir.r4b.model.SubscriptionTopic.SubscriptionTopicEventTriggerComponent src) { + org.hl7.fhir.r5.model.SubscriptionTopic.SubscriptionTopicEventTriggerComponent tgt = new org.hl7.fhir.r5.model.SubscriptionTopic.SubscriptionTopicEventTriggerComponent(); + if (src.hasDescription()) { + tgt.setDescriptionElement(MarkDown43_50.convertMarkdown(src.getDescriptionElement())); + } + if (src.hasEvent()) { + tgt.setEvent(CodeableConcept43_50.convertCodeableConcept(src.getEvent())); + } + if (src.hasResource()) { + tgt.setResourceElement(Uri43_50.convertUri(src.getResourceElement())); + } + return tgt; + } + + private static org.hl7.fhir.r5.model.SubscriptionTopic.SubscriptionTopicCanFilterByComponent convertCanFilterBy(org.hl7.fhir.r4b.model.SubscriptionTopic.SubscriptionTopicCanFilterByComponent src) { + org.hl7.fhir.r5.model.SubscriptionTopic.SubscriptionTopicCanFilterByComponent tgt = new org.hl7.fhir.r5.model.SubscriptionTopic.SubscriptionTopicCanFilterByComponent(); + if (src.hasDescription()) { + tgt.setDescriptionElement(MarkDown43_50.convertMarkdown(src.getDescriptionElement())); + } + if (src.hasResource()) { + tgt.setResourceElement(Uri43_50.convertUri(src.getResourceElement())); + } + if (src.hasFilterParameter()) { + tgt.setFilterParameterElement(String43_50.convertString(src.getFilterParameterElement())); + } + + if (src.hasModifier()) { + List> tgtModifiers = convertR4BModifierToR5Modifier(src.getModifier()); + tgt.setModifier(tgtModifiers); + + List> tgtComparators = covertR4BModifierToR5Comparator(src.getModifier()); + tgt.setComparator(tgtComparators); + } + + return tgt; + } + + private static List> covertR4BModifierToR5Comparator(List> srcList) { + return srcList.stream().map(SubscriptionTopic43_50::convertR4BModifierToR5Comparator).filter(x -> x != null).collect(Collectors.toList()); + } + + + private static org.hl7.fhir.r5.model.Enumeration convertR4BModifierToR5Comparator(org.hl7.fhir.r4b.model.Enumeration src) { + org.hl7.fhir.r5.model.Enumerations.SearchComparatorEnumFactory enumFactory = new org.hl7.fhir.r5.model.Enumerations.SearchComparatorEnumFactory(); + switch(src.getValue()) { + case NULL: return new org.hl7.fhir.r5.model.Enumeration<>(enumFactory, org.hl7.fhir.r5.model.Enumerations.SearchComparator.NULL); + case EQ: return new org.hl7.fhir.r5.model.Enumeration<>(enumFactory, org.hl7.fhir.r5.model.Enumerations.SearchComparator.EQ); + case NE: return new org.hl7.fhir.r5.model.Enumeration<>(enumFactory, org.hl7.fhir.r5.model.Enumerations.SearchComparator.NE); + case GT: return new org.hl7.fhir.r5.model.Enumeration<>(enumFactory, org.hl7.fhir.r5.model.Enumerations.SearchComparator.GT); + case LT: return new org.hl7.fhir.r5.model.Enumeration<>(enumFactory, org.hl7.fhir.r5.model.Enumerations.SearchComparator.LT); + case GE: return new org.hl7.fhir.r5.model.Enumeration<>(enumFactory, org.hl7.fhir.r5.model.Enumerations.SearchComparator.GE); + case LE: return new org.hl7.fhir.r5.model.Enumeration<>(enumFactory, org.hl7.fhir.r5.model.Enumerations.SearchComparator.LE); + case SA: return new org.hl7.fhir.r5.model.Enumeration<>(enumFactory, org.hl7.fhir.r5.model.Enumerations.SearchComparator.SA); + case EB: return new org.hl7.fhir.r5.model.Enumeration<>(enumFactory, org.hl7.fhir.r5.model.Enumerations.SearchComparator.EB); + case AP: return new org.hl7.fhir.r5.model.Enumeration<>(enumFactory, org.hl7.fhir.r5.model.Enumerations.SearchComparator.AP); + } + return null; + } + + private static List> convertR4BModifierToR5Modifier( + List + > srcList) { + return srcList.stream().map(SubscriptionTopic43_50::convertR4BModifierToR5Modifier).filter(x -> x != null).collect(Collectors.toList()); + } + private static org.hl7.fhir.r5.model.Enumeration convertR4BModifierToR5Modifier(org.hl7.fhir.r4b.model.Enumeration src) { + org.hl7.fhir.r5.model.Enumerations.SearchModifierCodeEnumFactory enumFactory = new org.hl7.fhir.r5.model.Enumerations.SearchModifierCodeEnumFactory(); + switch(src.getValue()) { + case NULL: + return new org.hl7.fhir.r5.model.Enumeration<>(enumFactory, org.hl7.fhir.r5.model.Enumerations.SearchModifierCode.NULL); + case IN: + return new org.hl7.fhir.r5.model.Enumeration<>(enumFactory, org.hl7.fhir.r5.model.Enumerations.SearchModifierCode.IN); + case NOTIN: + return new org.hl7.fhir.r5.model.Enumeration<>(enumFactory, org.hl7.fhir.r5.model.Enumerations.SearchModifierCode.NOTIN); + case BELOW: + return new org.hl7.fhir.r5.model.Enumeration<>(enumFactory, org.hl7.fhir.r5.model.Enumerations.SearchModifierCode.BELOW); + case ABOVE: + return new org.hl7.fhir.r5.model.Enumeration<>(enumFactory, org.hl7.fhir.r5.model.Enumerations.SearchModifierCode.ABOVE); + case OFTYPE: + return new org.hl7.fhir.r5.model.Enumeration<>(enumFactory, org.hl7.fhir.r5.model.Enumerations.SearchModifierCode.OFTYPE); + } + return null; + } + + private static org.hl7.fhir.r5.model.SubscriptionTopic.SubscriptionTopicResourceTriggerComponent convertResourceTrigger(org.hl7.fhir.r4b.model.SubscriptionTopic.SubscriptionTopicResourceTriggerComponent src) { + org.hl7.fhir.r5.model.SubscriptionTopic.SubscriptionTopicResourceTriggerComponent tgt = new org.hl7.fhir.r5.model.SubscriptionTopic.SubscriptionTopicResourceTriggerComponent(); + ConversionContext43_50.INSTANCE.getVersionConvertor_43_50().copyBackboneElement(src, tgt); + if (src.hasDescription()) { + tgt.setDescriptionElement(MarkDown43_50.convertMarkdown(src.getDescriptionElement())); + } + if (src.hasResource()) { + tgt.setResourceElement(Uri43_50.convertUri(src.getResourceElement())); + } + if (src.hasSupportedInteraction()) { + for (org.hl7.fhir.r4b.model.Enumeration srcItem : src.getSupportedInteraction()) { + org.hl7.fhir.r5.model.Enumeration tgtElement = tgt.addSupportedInteractionElement(); + tgtElement.setValue(convertInteractionTrigger(srcItem.getValue())); + } + } + if (src.hasQueryCriteria()) { + tgt.setQueryCriteria(convertResourceTriggerQueryCriteriaComponent(src.getQueryCriteria())); + } + if (src.hasFhirPathCriteria()) { + tgt.setFhirPathCriteriaElement(String43_50.convertString(src.getFhirPathCriteriaElement())); + } + return tgt; + + } + + private static org.hl7.fhir.r5.model.SubscriptionTopic.SubscriptionTopicResourceTriggerQueryCriteriaComponent convertResourceTriggerQueryCriteriaComponent(org.hl7.fhir.r4b.model.SubscriptionTopic.SubscriptionTopicResourceTriggerQueryCriteriaComponent src) { + org.hl7.fhir.r5.model.SubscriptionTopic.SubscriptionTopicResourceTriggerQueryCriteriaComponent tgt = new org.hl7.fhir.r5.model.SubscriptionTopic.SubscriptionTopicResourceTriggerQueryCriteriaComponent(); + if (src.hasPrevious()) { + tgt.setPreviousElement(String43_50.convertString(src.getPreviousElement())); + } + if (src.hasResultForCreate()) { + tgt.setResultForCreateElement(convertCriteriaNotExistsBehavior(src.getResultForCreateElement())); + } + if (src.hasCurrent()) { + tgt.setCurrentElement(String43_50.convertString(src.getCurrentElement())); + } + if (src.hasResultForDelete()) { + tgt.setResultForDeleteElement(convertCriteriaNotExistsBehavior(src.getResultForDeleteElement())); + } + if (src.hasRequireBoth()) { + tgt.setRequireBothElement(Boolean43_50.convertBoolean(src.getRequireBothElement())); + } + return tgt; + } + + private static org.hl7.fhir.r5.model.Enumeration convertCriteriaNotExistsBehavior(org.hl7.fhir.r4b.model.Enumeration src) { + org.hl7.fhir.r5.model.SubscriptionTopic.CriteriaNotExistsBehaviorEnumFactory enumFactory = new org.hl7.fhir.r5.model.SubscriptionTopic.CriteriaNotExistsBehaviorEnumFactory(); + switch(src.getValue()) { + + case TESTFAILS: return new org.hl7.fhir.r5.model.Enumeration<>(enumFactory, org.hl7.fhir.r5.model.SubscriptionTopic.CriteriaNotExistsBehavior.TESTFAILS); + case TESTPASSES: return new org.hl7.fhir.r5.model.Enumeration<>(enumFactory, org.hl7.fhir.r5.model.SubscriptionTopic.CriteriaNotExistsBehavior.TESTPASSES); + case NULL: return new org.hl7.fhir.r5.model.Enumeration<>(enumFactory, org.hl7.fhir.r5.model.SubscriptionTopic.CriteriaNotExistsBehavior.NULL); + } + return null; + } + + private static org.hl7.fhir.r5.model.SubscriptionTopic.InteractionTrigger convertInteractionTrigger(org.hl7.fhir.r4b.model.SubscriptionTopic.InteractionTrigger value) { + switch(value) { + case CREATE : return org.hl7.fhir.r5.model.SubscriptionTopic.InteractionTrigger.CREATE; + case UPDATE: return org.hl7.fhir.r5.model.SubscriptionTopic.InteractionTrigger.UPDATE; + case DELETE: return org.hl7.fhir.r5.model.SubscriptionTopic.InteractionTrigger.DELETE; + case NULL: return org.hl7.fhir.r5.model.SubscriptionTopic.InteractionTrigger.NULL; + } + return null; + + } +} diff --git a/org.hl7.fhir.convertors/src/test/java/org/hl7/fhir/convertors/conv43_50/SubscriptionStatus43_50Test.java b/org.hl7.fhir.convertors/src/test/java/org/hl7/fhir/convertors/conv43_50/SubscriptionStatus43_50Test.java new file mode 100644 index 000000000..0cc5d437d --- /dev/null +++ b/org.hl7.fhir.convertors/src/test/java/org/hl7/fhir/convertors/conv43_50/SubscriptionStatus43_50Test.java @@ -0,0 +1,53 @@ +package org.hl7.fhir.convertors.conv43_50; + +import org.hl7.fhir.convertors.factory.VersionConvertorFactory_43_50; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; + +import static org.junit.jupiter.api.Assertions.assertTrue; + +public class SubscriptionStatus43_50Test { + + @Test + @DisplayName("Test r5 -> r4 SubscriptionTopic conversion.") + public void testR5_R4b() throws IOException { + InputStream r5_input = this.getClass().getResourceAsStream("/subscription_status_50.json"); + + org.hl7.fhir.r5.model.SubscriptionStatus r5_actual = (org.hl7.fhir.r5.model.SubscriptionStatus) new org.hl7.fhir.r5.formats.JsonParser().parse(r5_input); + org.hl7.fhir.r4b.model.Resource r4b_conv = VersionConvertorFactory_43_50.convertResource(r5_actual); + + org.hl7.fhir.r4b.formats.JsonParser r4b_parser = new org.hl7.fhir.r4b.formats.JsonParser(); + + ByteArrayOutputStream stream = new ByteArrayOutputStream(); + r4b_parser.compose(stream, r4b_conv); + + org.hl7.fhir.r4b.model.Resource r4b_streamed = new org.hl7.fhir.r4b.formats.JsonParser().parse(new ByteArrayInputStream(stream.toByteArray())); + org.hl7.fhir.r5.model.Resource r5_conv = VersionConvertorFactory_43_50.convertResource(r4b_streamed); + + assertTrue(r5_actual.equalsDeep(r5_conv), "should be the same"); + } + + @Test + @DisplayName("Test r4b -> r5 SubscriptionTopic conversion.") + public void testR4b_R5() throws IOException { + InputStream r4b_input = this.getClass().getResourceAsStream("/subscription_status_43.json"); + + org.hl7.fhir.r4b.model.SubscriptionStatus r4b_actual = (org.hl7.fhir.r4b.model.SubscriptionStatus) new org.hl7.fhir.r4b.formats.JsonParser().parse(r4b_input); + org.hl7.fhir.r5.model.Resource r5_conv = VersionConvertorFactory_43_50.convertResource(r4b_actual); + + org.hl7.fhir.r5.formats.JsonParser r5_parser = new org.hl7.fhir.r5.formats.JsonParser(); + + ByteArrayOutputStream stream = new ByteArrayOutputStream(); + r5_parser.compose(stream, r5_conv); + + org.hl7.fhir.r5.model.Resource r5_streamed = new org.hl7.fhir.r5.formats.JsonParser().parse(new ByteArrayInputStream(stream.toByteArray())); + org.hl7.fhir.r4b.model.Resource r4b_conv = VersionConvertorFactory_43_50.convertResource(r5_streamed); + + assertTrue(r4b_actual.equalsDeep(r4b_conv), "should be the same"); + } +} diff --git a/org.hl7.fhir.convertors/src/test/java/org/hl7/fhir/convertors/conv43_50/SubscriptionTopic43_50Test.java b/org.hl7.fhir.convertors/src/test/java/org/hl7/fhir/convertors/conv43_50/SubscriptionTopic43_50Test.java new file mode 100644 index 000000000..88ae2e51d --- /dev/null +++ b/org.hl7.fhir.convertors/src/test/java/org/hl7/fhir/convertors/conv43_50/SubscriptionTopic43_50Test.java @@ -0,0 +1,53 @@ +package org.hl7.fhir.convertors.conv43_50; + +import org.hl7.fhir.convertors.factory.VersionConvertorFactory_43_50; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; + +import static org.junit.jupiter.api.Assertions.assertTrue; + +public class SubscriptionTopic43_50Test { + + @Test + @DisplayName("Test r5 -> r4b SubscriptionTopic conversion.") + public void testR5_R4b() throws IOException { + InputStream r5_input = this.getClass().getResourceAsStream("/subscription_topic_50.json"); + + org.hl7.fhir.r5.model.SubscriptionTopic r5_actual = (org.hl7.fhir.r5.model.SubscriptionTopic) new org.hl7.fhir.r5.formats.JsonParser().parse(r5_input); + org.hl7.fhir.r4b.model.Resource r4b_conv = VersionConvertorFactory_43_50.convertResource(r5_actual); + + org.hl7.fhir.r4b.formats.JsonParser r4b_parser = new org.hl7.fhir.r4b.formats.JsonParser(); + + ByteArrayOutputStream stream = new ByteArrayOutputStream(); + r4b_parser.compose(stream, r4b_conv); + + org.hl7.fhir.r4b.model.Resource r4b_streamed = new org.hl7.fhir.r4b.formats.JsonParser().parse(new ByteArrayInputStream(stream.toByteArray())); + org.hl7.fhir.r5.model.Resource r5_conv = VersionConvertorFactory_43_50.convertResource(r4b_streamed); + + assertTrue(r5_actual.equalsDeep(r5_conv), "should be the same"); + } + + @Test + @DisplayName("Test r4b -> r5 SubscriptionTopic conversion.") + public void testR4b_R5() throws IOException { + InputStream r4b_input = this.getClass().getResourceAsStream("/subscription_topic_43.json"); + + org.hl7.fhir.r4b.model.SubscriptionTopic r4b_actual = (org.hl7.fhir.r4b.model.SubscriptionTopic) new org.hl7.fhir.r4b.formats.JsonParser().parse(r4b_input); + org.hl7.fhir.r5.model.Resource r5_conv = VersionConvertorFactory_43_50.convertResource(r4b_actual); + + org.hl7.fhir.r5.formats.JsonParser r5_parser = new org.hl7.fhir.r5.formats.JsonParser(); + + ByteArrayOutputStream stream = new ByteArrayOutputStream(); + r5_parser.compose(stream, r5_conv); + + org.hl7.fhir.r5.model.Resource r5_streamed = new org.hl7.fhir.r5.formats.JsonParser().parse(new ByteArrayInputStream(stream.toByteArray())); + org.hl7.fhir.r4b.model.Resource r4b_conv = VersionConvertorFactory_43_50.convertResource(r5_streamed); + + assertTrue(r4b_actual.equalsDeep(r4b_conv), "should be the same"); + } +} diff --git a/org.hl7.fhir.convertors/src/test/resources/subscription_status_43.json b/org.hl7.fhir.convertors/src/test/resources/subscription_status_43.json new file mode 100644 index 000000000..c8c92fc05 --- /dev/null +++ b/org.hl7.fhir.convertors/src/test/resources/subscription_status_43.json @@ -0,0 +1,16 @@ +{ + "resourceType": "SubscriptionStatus", + "status": "active", + "type": "event-notification", + "eventsSinceSubscriptionStart": "1", + "notificationEvent": [ { + "eventNumber": "1", + "focus": { + "reference": "Encounter/3" + } + } ], + "subscription": { + "reference": "Subscription/2" + }, + "topic": "http://example.com/topic/test" +} \ No newline at end of file diff --git a/org.hl7.fhir.convertors/src/test/resources/subscription_status_50.json b/org.hl7.fhir.convertors/src/test/resources/subscription_status_50.json new file mode 100644 index 000000000..47b7410f0 --- /dev/null +++ b/org.hl7.fhir.convertors/src/test/resources/subscription_status_50.json @@ -0,0 +1,18 @@ +{ + "resourceType" : "SubscriptionStatus", + "id" : "example", + "text" : { + "status" : "generated", + "div" : "

Generated Narrative: SubscriptionStatus

Resource SubscriptionStatus "example"

status: active

type: event-notification

eventsSinceSubscriptionStart: 1000

NotificationEvents

-EventNumber
*1000

subscription: http://example.org/FHIR/R5/Subscription/123

topic: http://example.org/FHIR/R5/SubscriptionTopic/admission

" + }, + "status" : "active", + "type" : "event-notification", + "eventsSinceSubscriptionStart" : "1000", + "notificationEvent" : [{ + "eventNumber" : "1000" + }], + "subscription" : { + "reference" : "http://example.org/FHIR/R5/Subscription/123" + }, + "topic" : "http://example.org/FHIR/R5/SubscriptionTopic/admission" +} \ No newline at end of file diff --git a/org.hl7.fhir.convertors/src/test/resources/subscription_topic_43.json b/org.hl7.fhir.convertors/src/test/resources/subscription_topic_43.json new file mode 100644 index 000000000..a22ef6dd2 --- /dev/null +++ b/org.hl7.fhir.convertors/src/test/resources/subscription_topic_43.json @@ -0,0 +1,19 @@ +{ + "resourceType": "SubscriptionTopic", + "id": "1", + "meta": { + "versionId": "1", + "lastUpdated": "2023-04-13T19:11:45.601-04:00" + }, + "url": "http://example.com/topic/test", + "status": "active", + "resourceTrigger": [ { + "resource": "Encounter", + "supportedInteraction": [ "create" ], + "queryCriteria": { + "previous": "Encounter?status=planned", + "current": "Encounter?status=finished", + "requireBoth": true + } + } ] +} \ No newline at end of file diff --git a/org.hl7.fhir.convertors/src/test/resources/subscription_topic_50.json b/org.hl7.fhir.convertors/src/test/resources/subscription_topic_50.json new file mode 100644 index 000000000..0a607ecd9 --- /dev/null +++ b/org.hl7.fhir.convertors/src/test/resources/subscription_topic_50.json @@ -0,0 +1,118 @@ +{ + "resourceType" : "SubscriptionTopic", + "id" : "example", + "text" : { + "status" : "generated", + "div" : "

Generated Narrative: SubscriptionTopic

Resource SubscriptionTopic "example"

url: http://example.org/FHIR/R5/SubscriptionTopic/example

identifier: id:\u00a0urn:uuid:1caa02ba-051b-4602-8856-65921748ae76

version: 1.0.0-beta.1

title: example

status: draft

date: 2019-01-01

description: Example topic for completed encounters

resourceTrigger

description: An Encounter has been completed

resource: Encounter

supportedInteraction: update

QueryCriteria

-PreviousResultForCreateCurrentResultForDeleteRequireBoth
*status:not=completedtest-passesstatus=completedtest-failstrue

fhirPathCriteria: (%previous.empty() | (%previous.status != 'completed')) and (%current.status = 'completed')

canFilterBy

description: Filter based on the subject of an encounter.

resource: Encounter

filterParameter: subject

canFilterBy

description: Filter based on the group membership of the subject of an encounter.

resource: Encounter

filterParameter: _in

canFilterBy

description: Filter based on the length of an encounter.

resource: Encounter

filterParameter: length

comparator: gt, lt, ge, le

canFilterBy

description: Filter based on the account for billing an encounter.

resource: Encounter

filterParameter: account

modifier: missing, not, identifier

NotificationShapes

-ResourceInclude
*EncounterEncounter:patient&iterate=Patient.link, Encounter:practitioner, Encounter:service-provider, Encounter:account, Encounter:diagnosis, Encounter:observation, Encounter:location
" + }, + "url" : "http://example.org/FHIR/R5/SubscriptionTopic/example", + "identifier" : [{ + "system" : "urn:ietf:rfc:3986", + "value" : "urn:uuid:1caa02ba-051b-4602-8856-65921748ae76" + }], + "name" : "my topic name", + "version" : "1.0.0-beta.1", + "title" : "example", + "status" : "draft", + "experimental" : true, + "date" : "2019-01-01", + "publisher" : "Somebody McSomeoneson", + "contact" : [ + { "contact" : "Somebody McSomeoneson"} + ], + "description" : "Example topic for completed encounters", + "useContext" : [ + { + "code": { + "system": "http://hl7.org/fhir/usage-context-type", + "code": "focus" + }, + "valueCodeableConcept": { + "coding": [ + { + "system": "http://snomed.info/sct", + "code": "306206005", + "display": "Referral to service (procedure)" + } + ] + } + } + ], + "jurisdiction": [ + { + "coding": [ + { + "system": "urn:iso:std:iso:3166", + "code": "US", + "display": "United States of America (the)" + } + ] + } + ], + "purpose" : "Some purpose description [link](http://someplace.somewhere)", + "copyright": "Some copyright info [link](http://someplace.somewhere)", + "copyrightLabel": "A copyright label", + "resourceTrigger" : [{ + "description" : "An Encounter has been completed", + "resource" : "http://hl7.org/fhir/StructureDefinition/Encounter", + "supportedInteraction" : ["update"], + "queryCriteria" : { + "previous" : "status:not=completed", + "resultForCreate" : "test-passes", + "current" : "status=completed", + "resultForDelete" : "test-fails", + "requireBoth" : true + }, + "fhirPathCriteria" : "(%previous.empty() | (%previous.status != 'completed')) and (%current.status = 'completed')" + }], + "eventTrigger" : [{ + "description" : "Patient admission is covered by HL7v2 ADT^A01", + "event" : { + "coding" : [{ + "system" : "http://terminology.hl7.org/CodeSystem/v2-0003", + "code" : "A01", + "display" : "ADT/ACK - Admit/visit notification" + }] + }, + "resource" : "http://hl7.org/fhir/StructureDefinition/Encounter" + }], + "canFilterBy" : [{ + "description" : "Filter based on the subject of an encounter.", + "resource" : "Encounter", + "filterParameter" : "subject" + }, + { + "description" : "Filter based on the group membership of the subject of an encounter.", + "resource" : "Encounter", + "filterParameter" : "_in" + }, + { + "description" : "Filter based on the length of an encounter.", + "resource" : "Encounter", + "filterParameter" : "length", + "comparator" : ["gt", + "lt", + "ge", + "le"] + }, + { + "description" : "Filter based on the account for billing an encounter.", + "resource" : "Encounter", + "filterParameter" : "account", + "modifier" : [ + "not-in" + ] + } + ], + "notificationShape" : [{ + "resource" : "Encounter", + "include" : ["Encounter:patient&iterate=Patient.link", + "Encounter:practitioner", + "Encounter:service-provider", + "Encounter:account", + "Encounter:diagnosis", + "Encounter:observation", + "Encounter:location"], + "revInclude" : ["Encounter:subject"] + }] +} \ No newline at end of file