# entry[].resource.text.div
/// url = 'http://hl7.org/fhir/StructureMap/ElementDefinition5to4B'
/// name = 'ElementDefinition5to4B'
/// title = 'FML Conversion for ElementDefinition: R5 to R4B'
/// status = 'active'

conceptmap "AggregationMode" {
  prefix s = "http://hl7.org/fhir/resource-aggregation-mode"
  prefix t = "http://hl7.org/fhir/4.3/resource-aggregation-mode"

  s:contained - t:contained
  s:referenced - t:referenced
  s:bundled - t:bundled
}

conceptmap "BindingStrength" {
  prefix s = "http://hl7.org/fhir/binding-strength"
  prefix t = "http://hl7.org/fhir/4.3/binding-strength"

  s:required - t:required
  s:extensible - t:extensible
  s:preferred - t:preferred
  s:example - t:example
}

conceptmap "ConstraintSeverity" {
  prefix s = "http://hl7.org/fhir/constraint-severity"
  prefix t = "http://hl7.org/fhir/4.3/constraint-severity"

  s:error - t:error
  s:warning - t:warning
}

conceptmap "DiscriminatorType" {
  prefix s = "http://hl7.org/fhir/discriminator-type"
  prefix t = "http://hl7.org/fhir/4.3/discriminator-type"

  s:value - t:value
  s:exists - t:exists
  s:pattern - t:pattern
  s:type - t:type
  s:profile - t:profile
}

conceptmap "PropertyRepresentation" {
  prefix s = "http://hl7.org/fhir/property-representation"
  prefix t = "http://hl7.org/fhir/4.3/property-representation"

  s:xmlAttr - t:xmlAttr
  s:xmlText - t:xmlText
  s:typeAttr - t:typeAttr
  s:cdaText - t:cdaText
  s:xhtml - t:xhtml
}

conceptmap "ReferenceVersionRules" {
  prefix s = "http://hl7.org/fhir/reference-version-rules"
  prefix t = "http://hl7.org/fhir/4.3/reference-version-rules"

  s:either - t:either
  s:independent - t:independent
  s:specific - t:specific
}

conceptmap "SlicingRules" {
  prefix s = "http://hl7.org/fhir/resource-slicing-rules"
  prefix t = "http://hl7.org/fhir/4.3/resource-slicing-rules"

  s:closed - t:closed
  s:open - t:open
  s:openAtEnd - t:openAtEnd
}

uses "http://hl7.org/fhir/StructureDefinition/ElementDefinition" alias ElementDefinitionR5 as source
uses "http://hl7.org/fhir/4.3/StructureDefinition/ElementDefinition" alias ElementDefinitionR4B as target

imports "http://hl7.org/fhir/StructureMap/*5to4B"

group ElementDefinition(source src : ElementDefinitionR5, target tgt : ElementDefinitionR4B) extends Element <<type+>> {
  src.modifierExtension -> tgt.modifierExtension;
  src.path -> tgt.path;
  src.representation as v -> tgt.representation = translate(v, '#PropertyRepresentation', 'code');
  src.sliceName -> tgt.sliceName;
  src.sliceIsConstraining -> tgt.sliceIsConstraining;
  src.label -> tgt.label;
  src.code -> tgt.code;
  src.slicing as s -> tgt.slicing as t then ElementDefinitionSlicing(s, t);
  src.short -> tgt.short;
  src.definition -> tgt.definition;
  src.comment -> tgt.comment;
  src.requirements -> tgt.requirements;
  src.alias -> tgt.alias;
  src.min -> tgt.min;
  src.max -> tgt.max;
  src.base as s -> tgt.base as t then ElementDefinitionBase(s, t);
  src.contentReference -> tgt.contentReference;
  src.type as s -> tgt.type as t then ElementDefinitionType(s, t);
  src.defaultValue : base64Binary -> tgt.defaultValue;
  src.defaultValue : boolean -> tgt.defaultValue;
  src.defaultValue : canonical -> tgt.defaultValue;
  src.defaultValue : code -> tgt.defaultValue;
  src.defaultValue : date -> tgt.defaultValue;
  src.defaultValue : dateTime -> tgt.defaultValue;
  src.defaultValue : decimal -> tgt.defaultValue;
  src.defaultValue : id -> tgt.defaultValue;
  src.defaultValue : instant -> tgt.defaultValue;
  src.defaultValue : integer -> tgt.defaultValue;
  src.defaultValue : integer64 -> tgt.defaultValue;
  src.defaultValue : markdown -> tgt.defaultValue;
  src.defaultValue : oid -> tgt.defaultValue;
  src.defaultValue : positiveInt -> tgt.defaultValue;
  src.defaultValue : string -> tgt.defaultValue;
  src.defaultValue : time -> tgt.defaultValue;
  src.defaultValue : unsignedInt -> tgt.defaultValue;
  src.defaultValue : uri -> tgt.defaultValue;
  src.defaultValue : url -> tgt.defaultValue;
  src.defaultValue : uuid -> tgt.defaultValue;
  src.defaultValue : Address -> tgt.defaultValue;
  src.defaultValue : Age -> tgt.defaultValue;
  src.defaultValue : Annotation -> tgt.defaultValue;
  src.defaultValue : Attachment -> tgt.defaultValue;
  src.defaultValue : CodeableConcept -> tgt.defaultValue;
  src.defaultValue : CodeableReference -> tgt.defaultValue;
  src.defaultValue : Coding -> tgt.defaultValue;
  src.defaultValue : ContactPoint -> tgt.defaultValue;
  src.defaultValue : Count -> tgt.defaultValue;
  src.defaultValue : Distance -> tgt.defaultValue;
  src.defaultValue : Duration -> tgt.defaultValue;
  src.defaultValue : HumanName -> tgt.defaultValue;
  src.defaultValue : Identifier -> tgt.defaultValue;
  src.defaultValue : Money -> tgt.defaultValue;
  src.defaultValue : Period -> tgt.defaultValue;
  src.defaultValue : Quantity -> tgt.defaultValue;
  src.defaultValue : Range -> tgt.defaultValue;
  src.defaultValue : Ratio -> tgt.defaultValue;
  src.defaultValue : RatioRange -> tgt.defaultValue;
  src.defaultValue : Reference -> tgt.defaultValue;
  src.defaultValue : SampledData -> tgt.defaultValue;
  src.defaultValue : Signature -> tgt.defaultValue;
  src.defaultValue : Timing -> tgt.defaultValue;
  src.defaultValue : ContactDetail -> tgt.defaultValue;
  src.defaultValue : DataRequirement -> tgt.defaultValue;
  src.defaultValue : Expression -> tgt.defaultValue;
  src.defaultValue : ParameterDefinition -> tgt.defaultValue;
  src.defaultValue : RelatedArtifact -> tgt.defaultValue;
  src.defaultValue : TriggerDefinition -> tgt.defaultValue;
  src.defaultValue : UsageContext -> tgt.defaultValue;
  src.defaultValue : Dosage -> tgt.defaultValue; // src.defaultValue : Availability -> tgt.defaultValue;
  src.defaultValue : Meta -> tgt.defaultValue;
  src.meaningWhenMissing -> tgt.meaningWhenMissing;
  src.orderMeaning -> tgt.orderMeaning;
  src.fixed : base64Binary -> tgt.fixed;
  src.fixed : boolean -> tgt.fixed;
  src.fixed : canonical -> tgt.fixed;
  src.fixed : code -> tgt.fixed;
  src.fixed : date -> tgt.fixed;
  src.fixed : dateTime -> tgt.fixed;
  src.fixed : decimal -> tgt.fixed;
  src.fixed : id -> tgt.fixed;
  src.fixed : instant -> tgt.fixed;
  src.fixed : integer -> tgt.fixed;
  src.fixed : integer64 -> tgt.fixed;
  src.fixed : markdown -> tgt.fixed;
  src.fixed : oid -> tgt.fixed;
  src.fixed : positiveInt -> tgt.fixed;
  src.fixed : string -> tgt.fixed;
  src.fixed : time -> tgt.fixed;
  src.fixed : unsignedInt -> tgt.fixed;
  src.fixed : uri -> tgt.fixed;
  src.fixed : url -> tgt.fixed;
  src.fixed : uuid -> tgt.fixed;
  src.fixed : Address -> tgt.fixed;
  src.fixed : Age -> tgt.fixed;
  src.fixed : Annotation -> tgt.fixed;
  src.fixed : Attachment -> tgt.fixed;
  src.fixed : CodeableConcept -> tgt.fixed;
  src.fixed : CodeableReference -> tgt.fixed;
  src.fixed : Coding -> tgt.fixed;
  src.fixed : ContactPoint -> tgt.fixed;
  src.fixed : Count -> tgt.fixed;
  src.fixed : Distance -> tgt.fixed;
  src.fixed : Duration -> tgt.fixed;
  src.fixed : HumanName -> tgt.fixed;
  src.fixed : Identifier -> tgt.fixed;
  src.fixed : Money -> tgt.fixed;
  src.fixed : Period -> tgt.fixed;
  src.fixed : Quantity -> tgt.fixed;
  src.fixed : Range -> tgt.fixed;
  src.fixed : Ratio -> tgt.fixed;
  src.fixed : RatioRange -> tgt.fixed;
  src.fixed : Reference -> tgt.fixed;
  src.fixed : SampledData -> tgt.fixed;
  src.fixed : Signature -> tgt.fixed;
  src.fixed : Timing -> tgt.fixed;
  src.fixed : ContactDetail -> tgt.fixed;
  src.fixed : DataRequirement -> tgt.fixed;
  src.fixed : Expression -> tgt.fixed;
  src.fixed : ParameterDefinition -> tgt.fixed;
  src.fixed : RelatedArtifact -> tgt.fixed;
  src.fixed : TriggerDefinition -> tgt.fixed;
  src.fixed : UsageContext -> tgt.fixed;
  src.fixed : Dosage -> tgt.fixed; // src.fixed : Availability -> tgt.fixed;
  src.fixed : Meta -> tgt.fixed;
  src.pattern : base64Binary -> tgt.pattern;
  src.pattern : boolean -> tgt.pattern;
  src.pattern : canonical -> tgt.pattern;
  src.pattern : code -> tgt.pattern;
  src.pattern : date -> tgt.pattern;
  src.pattern : dateTime -> tgt.pattern;
  src.pattern : decimal -> tgt.pattern;
  src.pattern : id -> tgt.pattern;
  src.pattern : instant -> tgt.pattern;
  src.pattern : integer -> tgt.pattern;
  src.pattern : integer64 -> tgt.pattern;
  src.pattern : markdown -> tgt.pattern;
  src.pattern : oid -> tgt.pattern;
  src.pattern : positiveInt -> tgt.pattern;
  src.pattern : string -> tgt.pattern;
  src.pattern : time -> tgt.pattern;
  src.pattern : unsignedInt -> tgt.pattern;
  src.pattern : uri -> tgt.pattern;
  src.pattern : url -> tgt.pattern;
  src.pattern : uuid -> tgt.pattern;
  src.pattern : Address -> tgt.pattern;
  src.pattern : Age -> tgt.pattern;
  src.pattern : Annotation -> tgt.pattern;
  src.pattern : Attachment -> tgt.pattern;
  src.pattern : CodeableConcept -> tgt.pattern;
  src.pattern : CodeableReference -> tgt.pattern;
  src.pattern : Coding -> tgt.pattern;
  src.pattern : ContactPoint -> tgt.pattern;
  src.pattern : Count -> tgt.pattern;
  src.pattern : Distance -> tgt.pattern;
  src.pattern : Duration -> tgt.pattern;
  src.pattern : HumanName -> tgt.pattern;
  src.pattern : Identifier -> tgt.pattern;
  src.pattern : Money -> tgt.pattern;
  src.pattern : Period -> tgt.pattern;
  src.pattern : Quantity -> tgt.pattern;
  src.pattern : Range -> tgt.pattern;
  src.pattern : Ratio -> tgt.pattern;
  src.pattern : RatioRange -> tgt.pattern;
  src.pattern : Reference -> tgt.pattern;
  src.pattern : SampledData -> tgt.pattern;
  src.pattern : Signature -> tgt.pattern;
  src.pattern : Timing -> tgt.pattern;
  src.pattern : ContactDetail -> tgt.pattern;
  src.pattern : DataRequirement -> tgt.pattern;
  src.pattern : Expression -> tgt.pattern;
  src.pattern : ParameterDefinition -> tgt.pattern;
  src.pattern : RelatedArtifact -> tgt.pattern;
  src.pattern : TriggerDefinition -> tgt.pattern;
  src.pattern : UsageContext -> tgt.pattern;
  src.pattern : Dosage -> tgt.pattern; // src.pattern : Availability -> tgt.pattern;
  src.pattern : Meta -> tgt.pattern;
  src.example as s -> tgt.example as t then ElementDefinitionExample(s, t);
  src.minValue : date -> tgt.minValue;
  src.minValue : dateTime -> tgt.minValue;
  src.minValue : instant -> tgt.minValue;
  src.minValue : time -> tgt.minValue;
  src.minValue : decimal -> tgt.minValue;
  src.minValue : integer -> tgt.minValue;
  src.minValue : integer64 -> tgt.minValue;
  src.minValue : positiveInt -> tgt.minValue;
  src.minValue : unsignedInt -> tgt.minValue;
  src.minValue : Quantity -> tgt.minValue;
  src.maxValue : date -> tgt.maxValue;
  src.maxValue : dateTime -> tgt.maxValue;
  src.maxValue : instant -> tgt.maxValue;
  src.maxValue : time -> tgt.maxValue;
  src.maxValue : decimal -> tgt.maxValue;
  src.maxValue : integer -> tgt.maxValue;
  src.maxValue : integer64 -> tgt.maxValue;
  src.maxValue : positiveInt -> tgt.maxValue;
  src.maxValue : unsignedInt -> tgt.maxValue;
  src.maxValue : Quantity -> tgt.maxValue;
  src.maxLength -> tgt.maxLength;
  src.condition -> tgt.condition;
  src.constraint as s -> tgt.constraint as t then ElementDefinitionConstraint(s, t);
  src.mustSupport -> tgt.mustSupport; // src.mustHaveValue -> tgt.mustHaveValue;
  src.isModifier -> tgt.isModifier;
  src.isModifierReason -> tgt.isModifierReason;
  src.isSummary -> tgt.isSummary;
  src.binding as s -> tgt.binding as t then ElementDefinitionBinding(s, t);
  src.mapping as s -> tgt.mapping as t then ElementDefinitionMapping(s, t);
}

group ElementDefinitionSlicing(source src, target tgt) extends Element {
  src.discriminator as s -> tgt.discriminator as t then ElementDefinitionSlicingDiscriminator(s, t);
  src.description -> tgt.description;
  src.ordered -> tgt.ordered;
  src.rules as v -> tgt.rules = translate(v, '#SlicingRules', 'code');
}

group ElementDefinitionSlicingDiscriminator(source src, target tgt) extends Element {
  src.type as v -> tgt.type = translate(v, '#DiscriminatorType', 'code');
  src.path -> tgt.path;
}

group ElementDefinitionBase(source src, target tgt) extends Element {
  src.path -> tgt.path;
  src.min -> tgt.min;
  src.max -> tgt.max;
}

group ElementDefinitionType(source src, target tgt) extends Element {
  src.code -> tgt.code;
  src.profile -> tgt.profile;
  src.targetProfile -> tgt.targetProfile;
  src.aggregation as v -> tgt.aggregation = translate(v, '#AggregationMode', 'code');
  src.versioning as v -> tgt.versioning = translate(v, '#ReferenceVersionRules', 'code');
}

group ElementDefinitionExample(source src, target tgt) extends Element {
  src.label -> tgt.label;
  src.value : base64Binary -> tgt.value;
  src.value : boolean -> tgt.value;
  src.value : canonical -> tgt.value;
  src.value : code -> tgt.value;
  src.value : date -> tgt.value;
  src.value : dateTime -> tgt.value;
  src.value : decimal -> tgt.value;
  src.value : id -> tgt.value;
  src.value : instant -> tgt.value;
  src.value : integer -> tgt.value;
  src.value : integer64 -> tgt.value;
  src.value : markdown -> tgt.value;
  src.value : oid -> tgt.value;
  src.value : positiveInt -> tgt.value;
  src.value : string -> tgt.value;
  src.value : time -> tgt.value;
  src.value : unsignedInt -> tgt.value;
  src.value : uri -> tgt.value;
  src.value : url -> tgt.value;
  src.value : uuid -> tgt.value;
  src.value : Address -> tgt.value;
  src.value : Age -> tgt.value;
  src.value : Annotation -> tgt.value;
  src.value : Attachment -> tgt.value;
  src.value : CodeableConcept -> tgt.value;
  src.value : CodeableReference -> tgt.value;
  src.value : Coding -> tgt.value;
  src.value : ContactPoint -> tgt.value;
  src.value : Count -> tgt.value;
  src.value : Distance -> tgt.value;
  src.value : Duration -> tgt.value;
  src.value : HumanName -> tgt.value;
  src.value : Identifier -> tgt.value;
  src.value : Money -> tgt.value;
  src.value : Period -> tgt.value;
  src.value : Quantity -> tgt.value;
  src.value : Range -> tgt.value;
  src.value : Ratio -> tgt.value;
  src.value : RatioRange -> tgt.value;
  src.value : Reference -> tgt.value;
  src.value : SampledData -> tgt.value;
  src.value : Signature -> tgt.value;
  src.value : Timing -> tgt.value;
  src.value : ContactDetail -> tgt.value;
  src.value : DataRequirement -> tgt.value;
  src.value : Expression -> tgt.value;
  src.value : ParameterDefinition -> tgt.value;
  src.value : RelatedArtifact -> tgt.value;
  src.value : TriggerDefinition -> tgt.value;
  src.value : UsageContext -> tgt.value;
  src.value : Dosage -> tgt.value; // src.value : Availability -> tgt.value;
  src.value : Meta -> tgt.value;
}

group ElementDefinitionConstraint(source src, target tgt) extends Element {
  src.key -> tgt.key;
  src.requirements -> tgt.requirements;
  src.severity as v -> tgt.severity = translate(v, '#ConstraintSeverity', 'code');
  src.human -> tgt.human; // src.suppress -> tgt.suppress;
  src.expression -> tgt.expression;
  src.source -> tgt.source;
}

group ElementDefinitionBinding(source src, target tgt) extends Element {
  src.strength as v -> tgt.strength = translate(v, '#BindingStrength', 'code');
  src.description -> tgt.description;
  src.valueSet -> tgt.valueSet;
}

group ElementDefinitionMapping(source src, target tgt) extends Element {
  src.identity -> tgt.identity;
  src.language -> tgt.language;
  src.map -> tgt.map;
  src.comment -> tgt.comment;
}

# entry[].resource.title
FML Conversion for ElementDefinition: R5 to R4B

# entry[].resource.group[].rule[].documentation
src.pattern : Availability -> tgt.pattern;

# entry[].resource.text.div
/// url = 'http://hl7.org/fhir/StructureMap/Address5to4'
/// name = 'Address5to4'
/// title = 'FML Conversion for Address: R5 to R4'
/// status = 'active'

conceptmap "AddressType" {
  prefix s = "http://hl7.org/fhir/address-type"
  prefix t = "http://hl7.org/fhir/4.0/address-type"

  s:postal - t:postal
  s:physical - t:physical
  s:both - t:both
}

conceptmap "AddressUse" {
  prefix s = "http://hl7.org/fhir/address-use"
  prefix t = "http://hl7.org/fhir/4.0/address-use"

  s:home - t:home
  s:work - t:work
  s:temp - t:temp
  s:old - t:old
  s:billing - t:billing
}

uses "http://hl7.org/fhir/StructureDefinition/Address" alias AddressR5 as source
uses "http://hl7.org/fhir/4.0/StructureDefinition/Address" alias AddressR4 as target

imports "http://hl7.org/fhir/StructureMap/*5to4"

group Address(source src : AddressR5, target tgt : AddressR4) extends Element <<type+>> {
  src.use as v -> tgt.use = translate(v, '#AddressUse', 'code');
  src.type as v -> tgt.type = translate(v, '#AddressType', 'code');
  src.text -> tgt.text;
  src.line -> tgt.line;
  src.city -> tgt.city;
  src.district -> tgt.district;
  src.state -> tgt.state;
  src.postalCode -> tgt.postalCode;
  src.country -> tgt.country;
  src.period -> tgt.period;
}

# entry[].resource.text.div
/// url = 'http://hl7.org/fhir/StructureMap/Composition5to4'
/// name = 'Composition5to4'
/// title = 'FML Conversion for Composition: R5 to R4'
/// status = 'active'

conceptmap "CompositionStatus" {
  prefix s = "http://hl7.org/fhir/composition-status"
  prefix t = "http://hl7.org/fhir/4.0/composition-status"

  s:preliminary - t:preliminary
  s:final - t:final
  s:amended - t:amended
  s:"entered-in-error" - t:"entered-in-error"
}

uses "http://hl7.org/fhir/StructureDefinition/Composition" alias CompositionR5 as source
uses "http://hl7.org/fhir/4.0/StructureDefinition/Composition" alias CompositionR4 as target

imports "http://hl7.org/fhir/StructureMap/*5to4"

group Composition(source src : CompositionR5, target tgt : CompositionR4) extends DomainResource <<type+>> {
  src.identifier -> tgt.identifier; // src.url -> tgt.url;
  src.status as v -> tgt.status = translate(v, '#CompositionStatus', 'code'); // src.version -> tgt.version;
  src.type -> tgt.type;
  src.category -> tgt.category;
  src.subject -> tgt.subject;
  src.encounter -> tgt.encounter;
  src.date -> tgt.date;
  src.author -> tgt.author; // src.useContext -> tgt.useContext;
  src.title -> tgt.title; // src.name -> tgt.name;
  src.attester as s -> tgt.attester as t then CompositionAttester(s, t); // src.note -> tgt.note;
  src.custodian -> tgt.custodian;
  src.relatesTo as s -> tgt.relatesTo as t then CompositionRelatesTo(s, t);
  src.event as s -> tgt.event as t then CompositionEvent(s, t);
  src.section as s -> tgt.section as t then CompositionSection(s, t);
}

group CompositionAttester(source src, target tgt) extends BackboneElement {
  src.mode as s -> tgt then {
    s.coding as sc where s.system = 'http://hl7.org/fhir/composition-attestation-mode' -> tgt then {
      sc.code -> tgt.mode;
    };
  };
  src.time -> tgt.time;
  src.party -> tgt.party;
}

group CompositionEvent(source src, target tgt) extends BackboneElement {
  src.period -> tgt.period; // src.code -> tgt.code;
  src.detail -> tgt.detail;
}

group CompositionRelatesTo(source src, target tgt) extends Element {
  src.type where src.type in ('replaces' | 'transforms' | 'signs' | 'appends') -> tgt.code;
  src.resourceReference -> tgt.target;
}

group CompositionSection(source src, target tgt) extends BackboneElement {
  src.title -> tgt.title;
  src.code -> tgt.code;
  src.author -> tgt.author;
  src.focus -> tgt.focus;
  src.text -> tgt.text;
  src.orderedBy -> tgt.orderedBy; // src.mode as v -> tgt.mode = translate(v, '#SectionMode', 'code');
  src.entry -> tgt.entry;
  src.emptyReason -> tgt.emptyReason;
}

# entry[].resource.title
FML Conversion for Composition: R5 to R4

# entry[].resource.group[].rule[].source[].condition
src.type in ('replaces' | 'transforms' | 'signs' | 'appends')

# entry[].resource.group[].rule[].documentation
src.mode as v -> tgt.mode = translate(v, '#SectionMode', 'code');

# entry[].resource.text.div
/// url = 'http://hl7.org/fhir/StructureMap/Contributor5to4B'
/// name = 'Contributor5to4B'
/// title = 'FML Conversion for Contributor: R5 to R4B'
/// status = 'active'

conceptmap "ContributorType" {
  prefix s = "http://hl7.org/fhir/contributor-type"
  prefix t = "http://hl7.org/fhir/4.3/contributor-type"

  s:author - t:author
  s:editor - t:editor
  s:reviewer - t:reviewer
  s:endorser - t:endorser
}

uses "http://hl7.org/fhir/StructureDefinition/Contributor" alias ContributorR5 as source
uses "http://hl7.org/fhir/4.3/StructureDefinition/Contributor" alias ContributorR4B as target

imports "http://hl7.org/fhir/StructureMap/*5to4B"

group Contributor(source src : ContributorR5, target tgt : ContributorR4B) extends Element <<type+>> {
  src.type as v -> tgt.type = translate(v, '#ContributorType', 'code');
  src.name -> tgt.name;
  src.contact -> tgt.contact;
}

# entry[].resource.title
FML Conversion for Contributor: R5 to R4B

# entry[].resource.text.div
/// url = 'http://hl7.org/fhir/StructureMap/PlanDefinition5to4'
/// name = 'PlanDefinition5to4'
/// title = 'FML Conversion for PlanDefinition: R5 to R4'
/// status = 'active'

conceptmap "ActionCardinalityBehavior" {
  prefix s = "http://hl7.org/fhir/action-cardinality-behavior"
  prefix t = "http://hl7.org/fhir/4.0/action-cardinality-behavior"

  s:single - t:single
  s:multiple - t:multiple
}

conceptmap "ActionConditionKind" {
  prefix s = "http://hl7.org/fhir/action-condition-kind"
  prefix t = "http://hl7.org/fhir/4.0/action-condition-kind"

  s:applicability - t:applicability
  s:start - t:start
  s:stop - t:stop
}

conceptmap "ActionGroupingBehavior" {
  prefix s = "http://hl7.org/fhir/action-grouping-behavior"
  prefix t = "http://hl7.org/fhir/4.0/action-grouping-behavior"

  s:"visual-group" - t:"visual-group"
  s:"logical-group" - t:"logical-group"
  s:"sentence-group" - t:"sentence-group"
}

conceptmap "ActionPrecheckBehavior" {
  prefix s = "http://hl7.org/fhir/action-precheck-behavior"
  prefix t = "http://hl7.org/fhir/4.0/action-precheck-behavior"

  s:yes - t:yes
  s:no - t:no
}

conceptmap "ActionRelationshipType" {
  prefix s = "http://hl7.org/fhir/action-relationship-type"
  prefix t = "http://hl7.org/fhir/4.0/action-relationship-type"

  s:before - t:before
  s:"before-start" - t:"before-start"
  s:"before-end" - t:"before-end"
  s:concurrent - t:concurrent
  s:"concurrent-with-start" - t:"concurrent-with-start"
  s:"concurrent-with-end" - t:"concurrent-with-end"
  s:after - t:after
  s:"after-start" - t:"after-start"
  s:"after-end" - t:"after-end"
}

conceptmap "ActionRequiredBehavior" {
  prefix s = "http://hl7.org/fhir/action-required-behavior"
  prefix t = "http://hl7.org/fhir/4.0/action-required-behavior"

  s:must - t:must
  s:could - t:could
  s:"must-unless-documented" - t:"must-unless-documented"
}

conceptmap "ActionSelectionBehavior" {
  prefix s = "http://hl7.org/fhir/action-selection-behavior"
  prefix t = "http://hl7.org/fhir/4.0/action-selection-behavior"

  s:any - t:any
  s:all - t:all
  s:"all-or-none" - t:"all-or-none"
  s:"exactly-one" - t:"exactly-one"
  s:"at-most-one" - t:"at-most-one"
  s:"one-or-more" - t:"one-or-more"
}

conceptmap "ActivityParticipantType" {
  prefix s = "http://hl7.org/fhir/action-participant-type"
  prefix t = "http://hl7.org/fhir/4.0/action-participant-type"

  s:device - t:device
  s:patient - t:patient
  s:practitioner - t:practitioner
  s:relatedperson - t:"related-person"
}

conceptmap "PublicationStatus" {
  prefix s = "http://hl7.org/fhir/publication-status"
  prefix t = "http://hl7.org/fhir/4.0/publication-status"

  s:draft - t:draft
  s:active - t:active
  s:retired - t:retired
  s:unknown - t:unknown
}

conceptmap "RequestPriority" {
  prefix s = "http://hl7.org/fhir/request-priority"
  prefix t = "http://hl7.org/fhir/4.0/request-priority"

  s:routine - t:routine
  s:urgent - t:urgent
  s:asap - t:asap
  s:stat - t:stat
}

uses "http://hl7.org/fhir/StructureDefinition/PlanDefinition" alias PlanDefinitionR5 as source
uses "http://hl7.org/fhir/4.0/StructureDefinition/PlanDefinition" alias PlanDefinitionR4 as target

imports "http://hl7.org/fhir/StructureMap/*5to4"

group PlanDefinition(source src : PlanDefinitionR5, target tgt : PlanDefinitionR4) extends DomainResource <<type+>> {
  src.url -> tgt.url;
  src.identifier -> tgt.identifier;
  src.version -> tgt.version;
  src.name -> tgt.name; // src.versionAlgorithm : string -> tgt.versionAlgorithm;
  src.title -> tgt.title;
  src.subtitle -> tgt.subtitle;
  src.type -> tgt.type;
  src.status as v -> tgt.status = translate(v, '#PublicationStatus', 'code');
  src.experimental -> tgt.experimental;
  src.subject as s where code = 'Patient' ->  tgt.subject = create('CodeableConcept') as tc,  tc.coding = create('Coding') as tcc,  tcc.system = 'http://hl7.org/fhir/resource-types',  tcc.code = 'Patient',  tcc.display = 'Patient';
  src.subject as s where code = 'Practitioner' ->  tgt.subject = create('CodeableConcept') as tc,  tc.coding = create('Coding') as tcc,  tcc.system = 'http://hl7.org/fhir/resource-types',  tcc.code = 'Patient',  tcc.display = 'Practitioner';
  src.subject as s where code = 'Organization' ->  tgt.subject = create('CodeableConcept') as tc,  tc.coding = create('Coding') as tcc,  tcc.system = 'http://hl7.org/fhir/resource-types',  tcc.code = 'Patient',  tcc.display = 'Organization';
  src.subject as s where code = 'Location' ->  tgt.subject = create('CodeableConcept') as tc,  tc.coding = create('Coding') as tcc,  tcc.system = 'http://hl7.org/fhir/resource-types',  tcc.code = 'Patient',  tcc.display = 'Location';
  src.subject as s where code = 'Device' ->  tgt.subject = create('CodeableConcept') as tc,  tc.coding = create('Coding') as tcc,  tcc.system = 'http://hl7.org/fhir/resource-types',  tcc.code = 'Patient',  tcc.display = 'Device';
  src.subject : Reference -> tgt.subject;
  src.date -> tgt.date; // src.subject : canonical -> tgt.subject;
  src.publisher -> tgt.publisher;
  src.contact -> tgt.contact;
  src.description -> tgt.description;
  src.useContext -> tgt.useContext;
  src.jurisdiction -> tgt.jurisdiction;
  src.purpose -> tgt.purpose;
  src.usage -> tgt.usage;
  src.copyright -> tgt.copyright;
  src.approvalDate -> tgt.approvalDate; // src.copyrightLabel -> tgt.copyrightLabel;
  src.lastReviewDate -> tgt.lastReviewDate;
  src.effectivePeriod -> tgt.effectivePeriod;
  src.topic -> tgt.topic;
  src.author -> tgt.author;
  src.editor -> tgt.editor;
  src.reviewer -> tgt.reviewer;
  src.endorser -> tgt.endorser;
  src.relatedArtifact -> tgt.relatedArtifact;
  src.library -> tgt.library;
  src.goal as s -> tgt.goal as t then PlanDefinitionGoal(s, t);
  src.action as s -> tgt.action as t then PlanDefinitionAction(s, t); // src.actor as s -> tgt.actor as t then PlanDefinitionActor(s,t);
}

group PlanDefinitionGoal(source src, target tgt) extends BackboneElement {
  src.category -> tgt.category;
  src.description -> tgt.description;
  src.priority -> tgt.priority;
  src.start -> tgt.start;
  src.addresses -> tgt.addresses;
  src.documentation -> tgt.documentation;
  src.target as s -> tgt.target as t then PlanDefinitionGoalTarget(s, t);
}

group PlanDefinitionGoalTarget(source src, target tgt) extends BackboneElement {
  src.measure -> tgt.measure;
  src.detail : Quantity -> tgt.detail;
  src.detail : Range -> tgt.detail;
  src.detail : CodeableConcept -> tgt.detail;
  src.due -> tgt.due; // src.detail : string -> tgt.detail;
}

// group PlanDefinitionActor(source src, target tgt) extends BackboneElement {
// src.title -> tgt.title;
// src.description -> tgt.description;
// src.option as s -> tgt.option as t then PlanDefinitionActorOption(s,t);
// }
// group PlanDefinitionActorOption(source src, target tgt) extends BackboneElement {
// src.type as v -> tgt.type = translate(v, '#ActivityParticipantType', 'code');
// src.typeCanonical -> tgt.typeCanonical;
// src.typeReference -> tgt.typeReference;
// src.role -> tgt.role;
// }
group PlanDefinitionAction(source src, target tgt) extends BackboneElement {
  src.linkId -> tgt.id;
  src.prefix -> tgt.prefix;
  src.title -> tgt.title;
  src.description -> tgt.description;
  src.textEquivalent -> tgt.textEquivalent;
  src.priority as v -> tgt.priority = translate(v, '#RequestPriority', 'code');
  src.code -> tgt.code;
  src.reason -> tgt.reason;
  src.documentation -> tgt.documentation;
  src.goalId -> tgt.goalId;
  src.subject as s where code = 'Patient' ->  tgt.subject = create('CodeableConcept') as tc,  tc.coding = create('Coding') as tcc,  tcc.system = 'http://hl7.org/fhir/resource-types',  tcc.code = 'Patient',  tcc.display = 'Patient';
  src.subject as s where code = 'Practitioner' ->  tgt.subject = create('CodeableConcept') as tc,  tc.coding = create('Coding') as tcc,  tcc.system = 'http://hl7.org/fhir/resource-types',  tcc.code = 'Patient',  tcc.display = 'Practitioner';
  src.subject as s where code = 'Organization' ->  tgt.subject = create('CodeableConcept') as tc,  tc.coding = create('Coding') as tcc,  tcc.system = 'http://hl7.org/fhir/resource-types',  tcc.code = 'Patient',  tcc.display = 'Organization';
  src.subject as s where code = 'Location' ->  tgt.subject = create('CodeableConcept') as tc,  tc.coding = create('Coding') as tcc,  tcc.system = 'http://hl7.org/fhir/resource-types',  tcc.code = 'Patient',  tcc.display = 'Location';
  src.subject as s where code = 'Device' ->  tgt.subject = create('CodeableConcept') as tc,  tc.coding = create('Coding') as tcc,  tcc.system = 'http://hl7.org/fhir/resource-types',  tcc.code = 'Patient',  tcc.display = 'Device';
  src.subject : Reference -> tgt.subject;
  src.trigger -> tgt.trigger; // src.subject : canonical -> tgt.subject;
  src.condition as s -> tgt.condition as t then PlanDefinitionActionCondition(s, t);
  src.input as s -> tgt.input = r.requirement;
  src.output as s -> tgt.output = r.requirement;
  src.relatedAction as s -> tgt.relatedAction as t then PlanDefinitionActionRelatedAction(s, t);
  src.timing : Age -> tgt.timing;
  src.timing : Duration -> tgt.timing;
  src.timing : Range -> tgt.timing;
  src.timing : Timing -> tgt.timing;
  src.participant as s -> tgt.participant as t then PlanDefinitionActionParticipant(s, t); // src.location -> tgt.location;
  src.type -> tgt.type;
  src.groupingBehavior as v -> tgt.groupingBehavior = translate(v, '#ActionGroupingBehavior', 'code');
  src.selectionBehavior as v -> tgt.selectionBehavior = translate(v, '#ActionSelectionBehavior', 'code');
  src.requiredBehavior as v -> tgt.requiredBehavior = translate(v, '#ActionRequiredBehavior', 'code');
  src.precheckBehavior as v -> tgt.precheckBehavior = translate(v, '#ActionPrecheckBehavior', 'code');
  src.cardinalityBehavior as v -> tgt.cardinalityBehavior = translate(v, '#ActionCardinalityBehavior', 'code');
  src.definition : canonical -> tgt.definition;
  src.definition : uri -> tgt.definition;
  src.transform -> tgt.transform;
  src.dynamicValue as s -> tgt.dynamicValue as t then PlanDefinitionActionDynamicValue(s, t);
}

group PlanDefinitionActionCondition(source src, target tgt) extends BackboneElement {
  src.kind as v -> tgt.kind = translate(v, '#ActionConditionKind', 'code');
  src.expression -> tgt.expression;
}

group PlanDefinitionActionRelatedAction(source src, target tgt) extends BackboneElement {
  src.targetId -> tgt.actionId;
  src.relationship as v -> tgt.relationship = translate(v, '#ActionRelationshipType', 'code');
  src.endRelationship as v -> tgt.relationship = translate(v, '#ActionRelationshipType', 'code');
  src.offset : Duration -> tgt.offset;
  src.offset : Range -> tgt.offset;
}

group PlanDefinitionActionParticipant(source src, target tgt) extends BackboneElement {
  src.type as v -> tgt.type = translate(v, '#ActivityParticipantType', 'code'); // src.actorId -> tgt.actorId;
  src.role -> tgt.role; // src.typeCanonical -> tgt.typeCanonical;
}

group PlanDefinitionActionDynamicValue(source src, target tgt) extends BackboneElement {
  src.path -> tgt.path;
  src.expression -> tgt.expression;
}

# entry[].resource.title
FML Conversion for PlanDefinition: R5 to R4

# entry[].resource.group[].rule[].documentation
src.actor as s -> tgt.actor as t then PlanDefinitionActor(s,t);

# entry[].resource.group[].documentation
group PlanDefinitionActor(source src, target tgt) extends BackboneElement {
src.title -> tgt.title;
src.description -> tgt.description;
src.option as s -> tgt.option as t then PlanDefinitionActorOption(s,t);
}
group PlanDefinitionActorOption(source src, target tgt) extends BackboneElement {
src.type as v -> tgt.type = translate(v, '#ActivityParticipantType', 'code');
src.typeCanonical -> tgt.typeCanonical;
src.typeReference -> tgt.typeReference;
src.role -> tgt.role;
}

# entry[].resource.text.div
/// url = 'http://hl7.org/fhir/StructureMap/ClinicalImpression5to4B'
/// name = 'ClinicalImpression5to4B'
/// title = 'FML Conversion for ClinicalImpression: R5 to R4B'
/// status = 'draft'

conceptmap "ClinicalImpressionStatus" {
  prefix s = "http://hl7.org/fhir/event-status"
  prefix t = "http://hl7.org/fhir/4.3/event-status"

  s:preparation - t:preparation
  s:"in-progress" - t:"in-progress"
  s:"not-done" - t:"not-done"
  s:"on-hold" - t:"on-hold"
  s:stopped - t:stopped
  s:completed - t:completed
  s:"entered-in-error" - t:"entered-in-error"
  s:unknown - t:unknown
}

uses "http://hl7.org/fhir/StructureDefinition/ClinicalImpression" alias ClinicalImpressionR5 as source
uses "http://hl7.org/fhir/4.3/StructureDefinition/ClinicalImpression" alias ClinicalImpressionR4B as target

imports "http://hl7.org/fhir/StructureMap/*5to4B"

group ClinicalImpression(source src : ClinicalImpressionR5, target tgt : ClinicalImpressionR4B) extends DomainResource <<type+>> {
  src.identifier -> tgt.identifier;
  src.status as v -> tgt.status = translate(v, '#ClinicalImpressionStatus', 'code');
  src.statusReason -> tgt.statusReason;
  src.description -> tgt.description;
  src.subject -> tgt.subject;
  src.encounter -> tgt.encounter;
  src.effective : dateTime -> tgt.effective;
  src.effective : Period -> tgt.effective;
  src.date -> tgt.date;
  src.performer -> tgt.assessor;
  src.previous -> tgt.previous;
  src.problem -> tgt.problem;
  src.protocol -> tgt.protocol; // src.changePattern -> tgt.changePattern;
  src.summary -> tgt.summary;
  src.finding as s -> tgt.finding as t then ClinicalImpressionFinding(s, t);
  src.prognosisCodeableConcept -> tgt.prognosisCodeableConcept;
  src.prognosisReference -> tgt.prognosisReference;
  src.supportingInfo -> tgt.supportingInfo;
  src.note -> tgt.note;
}

group ClinicalImpressionFinding(source src, target tgt) extends BackboneElement {
  src.item -> tgt.itemCodeableConcept;
  src.item -> tgt.itemReference;
  src.basis -> tgt.basis;
}

# entry[].resource.title
FML Conversion for ClinicalImpression: R5 to R4B

# entry[].resource.text.div
/// url = 'http://hl7.org/fhir/StructureMap/CompartmentDefinition5to4B'
/// name = 'CompartmentDefinition5to4B'
/// title = 'FML Conversion for CompartmentDefinition: R5 to R4B'
/// status = 'active'

conceptmap "CompartmentType" {
  prefix s = "http://hl7.org/fhir/compartment-type"
  prefix t = "http://hl7.org/fhir/4.3/compartment-type"

  s:Patient - t:Patient
  s:Encounter - t:Encounter
  s:RelatedPerson - t:RelatedPerson
  s:Practitioner - t:Practitioner
  s:Device - t:Device
}

conceptmap "PublicationStatus" {
  prefix s = "http://hl7.org/fhir/publication-status"
  prefix t = "http://hl7.org/fhir/4.3/publication-status"

  s:draft - t:draft
  s:active - t:active
  s:retired - t:retired
  s:unknown - t:unknown
}

uses "http://hl7.org/fhir/StructureDefinition/CompartmentDefinition" alias CompartmentDefinitionR5 as source
uses "http://hl7.org/fhir/4.3/StructureDefinition/CompartmentDefinition" alias CompartmentDefinitionR4B as target

imports "http://hl7.org/fhir/StructureMap/*5to4B"

group CompartmentDefinition(source src : CompartmentDefinitionR5, target tgt : CompartmentDefinitionR4B) extends DomainResource <<type+>> {
  src.url -> tgt.url;
  src.version -> tgt.version;
  src.name -> tgt.name; // src.versionAlgorithm : string -> tgt.versionAlgorithm;
  src.status as v -> tgt.status = translate(v, '#PublicationStatus', 'code'); // src.title -> tgt.title;
  src.experimental -> tgt.experimental;
  src.date -> tgt.date;
  src.publisher -> tgt.publisher;
  src.contact -> tgt.contact;
  src.description -> tgt.description;
  src.useContext -> tgt.useContext;
  src.purpose -> tgt.purpose;
  src.code as v -> tgt.code = translate(v, '#CompartmentType', 'code');
  src.search -> tgt.search;
  src.resource as s -> tgt.resource as t then CompartmentDefinitionResource(s, t);
}

group CompartmentDefinitionResource(source src, target tgt) extends BackboneElement {
  src.code -> tgt.code;
  src.param -> tgt.param;
  src.documentation -> tgt.documentation;
}

# entry[].resource.title
FML Conversion for CompartmentDefinition: R5 to R4B

# entry[].resource.text.div
/// url = 'http://hl7.org/fhir/StructureMap/Period5to4B'
/// name = 'Period5to4B'
/// title = 'FML Conversion for Period: R5 to R4B'
/// status = 'active'

uses "http://hl7.org/fhir/StructureDefinition/Period" alias PeriodR5 as source
uses "http://hl7.org/fhir/4.3/StructureDefinition/Period" alias PeriodR4B as target

imports "http://hl7.org/fhir/StructureMap/*5to4B"

group Period(source src : PeriodR5, target tgt : PeriodR4B) extends Element <<type+>> {
  src.start -> tgt.start;
  src.end -> tgt.end;
}

# entry[].resource.text.div
/// url = 'http://hl7.org/fhir/StructureMap/PaymentNotice5to4B'
/// name = 'PaymentNotice5to4B'
/// title = 'FML Conversion for PaymentNotice: R5 to R4B'
/// status = 'active'

conceptmap "PaymentNoticeStatus" {
  prefix s = "http://hl7.org/fhir/fm-status"
  prefix t = "http://hl7.org/fhir/4.3/fm-status"

  s:active - t:active
  s:cancelled - t:cancelled
  s:draft - t:draft
  s:"entered-in-error" - t:"entered-in-error"
}

uses "http://hl7.org/fhir/StructureDefinition/PaymentNotice" alias PaymentNoticeR5 as source
uses "http://hl7.org/fhir/4.3/StructureDefinition/PaymentNotice" alias PaymentNoticeR4B as target

imports "http://hl7.org/fhir/StructureMap/*5to4B"

group PaymentNotice(source src : PaymentNoticeR5, target tgt : PaymentNoticeR4B) extends DomainResource <<type+>> {
  src.identifier -> tgt.identifier;
  src.status as v -> tgt.status = translate(v, '#PaymentNoticeStatus', 'code');
  src.request -> tgt.request;
  src.response -> tgt.response;
  src.created -> tgt.created;
  src.reporter -> tgt.provider;
  src.payment -> tgt.payment;
  src.paymentDate -> tgt.paymentDate;
  src.payee -> tgt.payee;
  src.recipient -> tgt.recipient;
  src.amount -> tgt.amount;
  src.paymentStatus -> tgt.paymentStatus;
}

# entry[].resource.title
FML Conversion for PaymentNotice: R5 to R4B

# entry[].resource.text.div
/// url = 'http://hl7.org/fhir/StructureMap/Age5to4B'
/// name = 'Age5to4B'
/// title = 'FML Conversion for Age: R5 to R4B'
/// status = 'active'

uses "http://hl7.org/fhir/StructureDefinition/Age" alias AgeR5 as source
uses "http://hl7.org/fhir/4.3/StructureDefinition/Age" alias AgeR4B as target

imports "http://hl7.org/fhir/StructureMap/*5to4B"

group Age(source src : AgeR5, target tgt : AgeR4B) extends Quantity <<type+>> {
}

# entry[].resource.text.div
/// url = 'http://hl7.org/fhir/StructureMap/ObservationDefinition4Bto5'
/// name = 'ObservationDefinition4Bto5'
/// title = 'FML Conversion for ObservationDefinition: R4B to R5'
/// status = 'active'

conceptmap "AdministrativeGender" {
  prefix s = "http://hl7.org/fhir/4.3/administrative-gender"
  prefix t = "http://hl7.org/fhir/administrative-gender"

  s:male - t:male
  s:female - t:female
  s:other - t:other
  s:unknown - t:unknown
}

conceptmap "ObservationDataType" {
  prefix s = "http://hl7.org/fhir/4.3/permitted-data-type"
  prefix t = "http://hl7.org/fhir/permitted-data-type"

  s:Quantity - t:Quantity
  s:CodeableConcept - t:CodeableConcept
  s:string - t:string
  s:boolean - t:boolean
  s:integer - t:integer
  s:Range - t:Range
  s:Ratio - t:Ratio
  s:SampledData - t:SampledData
  s:time - t:time
  s:dateTime - t:dateTime
  s:Period - t:Period
}

conceptmap "ObservationRangeCategory" {
  prefix s = "http://hl7.org/fhir/4.3/observation-range-category"
  prefix t = "http://hl7.org/fhir/observation-range-category"

  s:reference - t:reference
  s:critical - t:critical
  s:absolute - t:absolute
}

conceptmap "PublicationStatus" {
  prefix s = "http://hl7.org/fhir/4.3/publication-status"
  prefix t = "http://hl7.org/fhir/publication-status"

  s:draft - t:draft
  s:active - t:active
  s:retired - t:retired
  s:unknown - t:unknown
}

uses "http://hl7.org/fhir/4.3/StructureDefinition/ObservationDefinition" alias ObservationDefinitionR4B as source
uses "http://hl7.org/fhir/StructureDefinition/ObservationDefinition" alias ObservationDefinitionR5 as target

imports "http://hl7.org/fhir/StructureMap/*4Bto5"

group ObservationDefinition(source src : ObservationDefinitionR4B, target tgt : ObservationDefinitionR5) extends DomainResource <<type+>> {
  src.identifier -> tgt.identifier; // src.url -> tgt.url;
  src.category -> tgt.category; // src.version -> tgt.version;
  src.code -> tgt.code;
  src.permittedDataType as v -> tgt.permittedDataType = translate(v, '#ObservationDataType', 'code');
  src.multipleResultsAllowed -> tgt.multipleResultsAllowed;
  src.method -> tgt.method; // src.bodySite -> tgt.bodySite;
  src.preferredReportName -> tgt.preferredReportName; // src.specimen -> tgt.specimen;
  src.quantitativeDetails as s -> tgt then ObservationDefinitionQuantitativeDetails(s, tgt);
  src.qualifiedInterval as s -> tgt.qualifiedValue as t then ObservationDefinitionQualifiedValue(s, t);
  src.validCodedValueSet as s ->  tgt.qualifiedValue as t,  t.validCodedValueSet = s;
  src.normalCodedValueSet as s ->  tgt.qualifiedValue as t,  t.normalCodedValueSet = s;
  src.abnormalCodedValueSet as s ->  tgt.qualifiedValue as t,  t.abnormalCodedValueSet = s;
  src.criticalCodedValueSet as s ->  tgt.qualifiedValue as t,  t.criticalCodedValueSet = s;
}

group ObservationDefinitionQuantitativeDetails(source src, target tgt) extends BackboneElement {
  src.customaryUnit as s -> tgt then {
    s.coding -> tgt.permittedUnit;
  };
  src.unit as s -> tgt then {
    s.coding -> tgt.permittedUnit;
  };
}

group ObservationDefinitionQualifiedValue(source src, target tgt) extends BackboneElement {
  src.context -> tgt.context;
  src.appliesTo -> tgt.appliesTo;
  src.gender as v -> tgt.gender = translate(v, '#AdministrativeGender', 'code');
  src.age -> tgt.age;
  src.gestationalAge -> tgt.gestationalAge;
  src.condition -> tgt.condition;
  src.category as v -> tgt.rangeCategory = translate(v, '#ObservationRangeCategory', 'code');
  src.range -> tgt.range;
}

# entry[].resource.title
FML Conversion for ObservationDefinition: R4B to R5

# entry[].resource.text.div
/// url = 'http://hl7.org/fhir/StructureMap/Practitioner4Bto5'
/// name = 'Practitioner4Bto5'
/// title = 'FML Conversion for Practitioner: R4B to R5'
/// status = 'active'

conceptmap "AdministrativeGender" {
  prefix s = "http://hl7.org/fhir/4.3/administrative-gender"
  prefix t = "http://hl7.org/fhir/administrative-gender"

  s:male - t:male
  s:female - t:female
  s:other - t:other
  s:unknown - t:unknown
}

uses "http://hl7.org/fhir/4.3/StructureDefinition/Practitioner" alias PractitionerR4B as source
uses "http://hl7.org/fhir/StructureDefinition/Practitioner" alias PractitionerR5 as target

imports "http://hl7.org/fhir/StructureMap/*4Bto5"

group Practitioner(source src : PractitionerR4B, target tgt : PractitionerR5) extends DomainResource <<type+>> {
  src.identifier -> tgt.identifier;
  src.active -> tgt.active;
  src.name -> tgt.name;
  src.telecom -> tgt.telecom;
  src.gender as v -> tgt.gender = translate(v, '#AdministrativeGender', 'code');
  src.birthDate -> tgt.birthDate;
  src.address -> tgt.address; // src.deceased : boolean -> tgt.deceased;
  src.photo -> tgt.photo;
  src.qualification as s -> tgt.qualification as t then PractitionerQualification(s, t);
  src.communication as s ->  tgt.communication as t,  t.language = s;
}

group PractitionerQualification(source src, target tgt) extends BackboneElement {
  src.identifier -> tgt.identifier;
  src.code -> tgt.code;
  src.period -> tgt.period;
  src.issuer -> tgt.issuer;
}

# entry[].resource.title
FML Conversion for Practitioner: R4B to R5

# entry[].resource.text.div
/// url = 'http://hl7.org/fhir/StructureMap/StructureDefinition4to5'
/// name = 'StructureDefinition4to5'
/// title = 'FML Conversion for StructureDefinition: R4 to R5'
/// status = 'active'

conceptmap "ExtensionContextType" {
  prefix s = "http://hl7.org/fhir/4.0/extension-context-type"
  prefix t = "http://hl7.org/fhir/extension-context-type"

  s:fhirpath - t:fhirpath
  s:element - t:element
  s:extension - t:extension
}

conceptmap "PublicationStatus" {
  prefix s = "http://hl7.org/fhir/4.0/publication-status"
  prefix t = "http://hl7.org/fhir/publication-status"

  s:draft - t:draft
  s:active - t:active
  s:retired - t:retired
  s:unknown - t:unknown
}

conceptmap "StructureDefinitionKind" {
  prefix s = "http://hl7.org/fhir/4.0/structure-definition-kind"
  prefix t = "http://hl7.org/fhir/structure-definition-kind"

  s:"primitive-type" - t:"primitive-type"
  s:"complex-type" - t:"complex-type"
  s:resource - t:resource
  s:logical - t:logical
}

conceptmap "TypeDerivationRule" {
  prefix s = "http://hl7.org/fhir/4.0/type-derivation-rule"
  prefix t = "http://hl7.org/fhir/type-derivation-rule"

  s:specialization - t:specialization
  s:constraint - t:constraint
}

uses "http://hl7.org/fhir/4.0/StructureDefinition/StructureDefinition" alias StructureDefinitionR4 as source
uses "http://hl7.org/fhir/StructureDefinition/StructureDefinition" alias StructureDefinitionR5 as target

imports "http://hl7.org/fhir/StructureMap/*4to5"

group StructureDefinition(source src : StructureDefinitionR4, target tgt : StructureDefinitionR5) extends DomainResource <<type+>> {
  src.url -> tgt.url;
  src.identifier -> tgt.identifier;
  src.version -> tgt.version;
  src.name -> tgt.name; // src.versionAlgorithm : string -> tgt.versionAlgorithm;
  src.title -> tgt.title;
  src.status as v -> tgt.status = translate(v, '#PublicationStatus', 'code');
  src.experimental -> tgt.experimental;
  src.date -> tgt.date;
  src.publisher -> tgt.publisher;
  src.contact -> tgt.contact;
  src.description -> tgt.description;
  src.useContext -> tgt.useContext;
  src.jurisdiction -> tgt.jurisdiction;
  src.purpose -> tgt.purpose;
  src.copyright -> tgt.copyright;
  src.keyword -> tgt.keyword; // src.copyrightLabel -> tgt.copyrightLabel;
  src.fhirVersion -> tgt.fhirVersion;
  src.mapping as s -> tgt.mapping as t then StructureDefinitionMapping(s, t);
  src.kind as v -> tgt.kind = translate(v, '#StructureDefinitionKind', 'code');
  src.abstract -> tgt.abstract;
  src.context as s -> tgt.context as t then StructureDefinitionContext(s, t);
  src.contextInvariant -> tgt.contextInvariant;
  src.type -> tgt.type;
  src.baseDefinition -> tgt.baseDefinition;
  src.derivation as v -> tgt.derivation = translate(v, '#TypeDerivationRule', 'code');
  src.snapshot as s -> tgt.snapshot as t then StructureDefinitionSnapshot(s, t);
  src.differential as s -> tgt.differential as t then StructureDefinitionDifferential(s, t);
}

group StructureDefinitionMapping(source src, target tgt) extends BackboneElement {
  src.identity -> tgt.identity;
  src.uri -> tgt.uri;
  src.name -> tgt.name;
  src.comment -> tgt.comment;
}

group StructureDefinitionContext(source src, target tgt) extends BackboneElement {
  src.type as v -> tgt.type = translate(v, '#ExtensionContextType', 'code');
  src.expression -> tgt.expression;
}

group StructureDefinitionSnapshot(source src, target tgt) extends BackboneElement {
  src.element -> tgt.element;
}

group StructureDefinitionDifferential(source src, target tgt) extends BackboneElement {
  src.element -> tgt.element;
}

# entry[].resource.title
FML Conversion for StructureDefinition: R4 to R5

# entry[].resource.text.div
/// url = 'http://hl7.org/fhir/StructureMap/MetadataResource4to5'
/// name = 'MetadataResource4to5'
/// title = 'FML Conversion for MetadataResource: R4 to R5'
/// status = 'active'

uses "http://hl7.org/fhir/4.0/StructureDefinition/MetadataResource" alias MetadataResourceR4 as source
uses "http://hl7.org/fhir/StructureDefinition/MetadataResource" alias MetadataResourceR5 as target

imports "http://hl7.org/fhir/StructureMap/*4to5"

group MetadataResource(source src : MetadataResourceR4, target tgt : MetadataResourceR5) extends DomainResource <<type+>> {
}

# entry[].resource.title
FML Conversion for MetadataResource: R4 to R5

# entry[].resource.text.div
/// url = 'http://hl7.org/fhir/StructureMap/Binary5to4'
/// name = 'Binary5to4'
/// title = 'FML Conversion for Binary: R5 to R4'
/// status = 'active'

uses "http://hl7.org/fhir/StructureDefinition/Binary" alias BinaryR5 as source
uses "http://hl7.org/fhir/4.0/StructureDefinition/Binary" alias BinaryR4 as target

imports "http://hl7.org/fhir/StructureMap/*5to4"

group Binary(source src : BinaryR5, target tgt : BinaryR4) extends Resource <<type+>> {
  src.contentType -> tgt.contentType;
  src.securityContext -> tgt.securityContext;
  src.data -> tgt.data;
}

# entry[].resource.text.div
/// url = 'http://hl7.org/fhir/StructureMap/EnrollmentResponse4to5'
/// name = 'EnrollmentResponse4to5'
/// title = 'FML Conversion for EnrollmentResponse: R4 to R5'
/// status = 'active'

conceptmap "EnrollmentOutcome" {
  prefix s = "http://hl7.org/fhir/4.0/remittance-outcome"
  prefix t = "http://hl7.org/fhir/enrollment-outcome"

  s:queued - t:queued
  s:complete - t:complete
  s:error - t:error
  s:partial - t:partial
}

conceptmap "EnrollmentResponseStatus" {
  prefix s = "http://hl7.org/fhir/4.0/fm-status"
  prefix t = "http://hl7.org/fhir/fm-status"

  s:active - t:active
  s:cancelled - t:cancelled
  s:draft - t:draft
  s:"entered-in-error" - t:"entered-in-error"
}

uses "http://hl7.org/fhir/4.0/StructureDefinition/EnrollmentResponse" alias EnrollmentResponseR4 as source
uses "http://hl7.org/fhir/StructureDefinition/EnrollmentResponse" alias EnrollmentResponseR5 as target

imports "http://hl7.org/fhir/StructureMap/*4to5"

group EnrollmentResponse(source src : EnrollmentResponseR4, target tgt : EnrollmentResponseR5) extends DomainResource <<type+>> {
  src.identifier -> tgt.identifier;
  src.status as v -> tgt.status = translate(v, '#EnrollmentResponseStatus', 'code');
  src.request -> tgt.request;
  src.outcome as v -> tgt.outcome = translate(v, '#EnrollmentOutcome', 'code');
  src.disposition -> tgt.disposition;
  src.created -> tgt.created;
  src.organization -> tgt.organization;
  src.requestProvider -> tgt.requestProvider;
}

# entry[].resource.title
FML Conversion for EnrollmentResponse: R4 to R5

# entry[].resource.text.div
/// url = 'http://hl7.org/fhir/StructureMap/ImplementationGuide4Bto5'
/// name = 'ImplementationGuide4Bto5'
/// title = 'FML Conversion for ImplementationGuide: R4B to R5'
/// status = 'active'

conceptmap "GuidePageGeneration" {
  prefix s = "http://hl7.org/fhir/4.3/guide-page-generation"
  prefix t = "http://hl7.org/fhir/guide-page-generation"

  s:html - t:html
  s:markdown - t:markdown
  s:xml - t:xml
  s:generated - t:generated
}

conceptmap "PublicationStatus" {
  prefix s = "http://hl7.org/fhir/4.3/publication-status"
  prefix t = "http://hl7.org/fhir/publication-status"

  s:draft - t:draft
  s:active - t:active
  s:retired - t:retired
  s:unknown - t:unknown
}

conceptmap "SPDXLicense" {
  prefix s = "http://hl7.org/fhir/4.3/spdx-license"
  prefix t = "http://hl7.org/fhir/spdx-license"

  s:"not-open-source" - t:"not-open-source"
  s:"0BSD" - t:"0BSD"
  s:AAL - t:AAL
  s:Abstyles - t:Abstyles
  s:"Adobe-2006" - t:"Adobe-2006"
  s:"Adobe-Glyph" - t:"Adobe-Glyph"
  s:ADSL - t:ADSL
  s:"AFL-1.1" - t:"AFL-1.1"
  s:"AFL-1.2" - t:"AFL-1.2"
  s:"AFL-2.0" - t:"AFL-2.0"
  s:"AFL-2.1" - t:"AFL-2.1"
  s:"AFL-3.0" - t:"AFL-3.0"
  s:Afmparse - t:Afmparse
  s:"AGPL-1.0-only" - t:"AGPL-1.0-only"
  s:"AGPL-1.0-or-later" - t:"AGPL-1.0-or-later"
  s:"AGPL-3.0-only" - t:"AGPL-3.0-only"
  s:"AGPL-3.0-or-later" - t:"AGPL-3.0-or-later"
  s:Aladdin - t:Aladdin
  s:AMDPLPA - t:AMDPLPA
}

uses "http://hl7.org/fhir/4.3/StructureDefinition/ImplementationGuide" alias ImplementationGuideR4B as source
uses "http://hl7.org/fhir/StructureDefinition/ImplementationGuide" alias ImplementationGuideR5 as target

imports "http://hl7.org/fhir/StructureMap/*4Bto5"

group ImplementationGuide(source src : ImplementationGuideR4B, target tgt : ImplementationGuideR5) extends DomainResource <<type+>> {
  src.url -> tgt.url;
  src.version -> tgt.version; // src.identifier -> tgt.identifier;
  src.name -> tgt.name; // src.versionAlgorithm : string -> tgt.versionAlgorithm;
  src.title -> tgt.title;
  src.status as v -> tgt.status = translate(v, '#PublicationStatus', 'code');
  src.experimental -> tgt.experimental;
  src.date -> tgt.date;
  src.publisher -> tgt.publisher;
  src.contact -> tgt.contact;
  src.description -> tgt.description;
  src.useContext -> tgt.useContext;
  src.jurisdiction -> tgt.jurisdiction;
  src.copyright -> tgt.copyright; // src.purpose -> tgt.purpose;
  src.packageId -> tgt.packageId; // src.copyrightLabel -> tgt.copyrightLabel;
  src.license as v -> tgt.license = translate(v, '#SPDXLicense', 'code');
  src.fhirVersion -> tgt.fhirVersion;
  src.dependsOn as s -> tgt.dependsOn as t then ImplementationGuideDependsOn(s, t);
  src.global as s -> tgt.global as t then ImplementationGuideGlobal(s, t);
  src.definition as s -> tgt.definition as t then ImplementationGuideDefinition(s, t);
  src.manifest as s -> tgt.manifest as t then ImplementationGuideManifest(s, t);
}

group ImplementationGuideDependsOn(source src, target tgt) extends BackboneElement {
  src.uri -> tgt.uri;
  src.packageId -> tgt.packageId;
  src.version -> tgt.version;
}

group ImplementationGuideGlobal(source src, target tgt) extends BackboneElement {
  src.type -> tgt.type;
  src.profile -> tgt.profile;
}

group ImplementationGuideDefinition(source src, target tgt) extends BackboneElement {
  src.grouping as s -> tgt.grouping as t then ImplementationGuideDefinitionGrouping(s, t);
  src.resource as s -> tgt.resource as t then ImplementationGuideDefinitionResource(s, t);
  src.page as s -> tgt.page as t then ImplementationGuideDefinitionPage(s, t);
  src.parameter as s -> tgt.parameter as t then ImplementationGuideDefinitionParameter(s, t);
  src.template as s -> tgt.template as t then ImplementationGuideDefinitionTemplate(s, t);
}

group ImplementationGuideDefinitionGrouping(source src, target tgt) extends BackboneElement {
  src.name -> tgt.name;
  src.description -> tgt.description;
}

group ImplementationGuideDefinitionResource(source src, target tgt) extends BackboneElement {
  src.reference -> tgt.reference;
  src.fhirVersion as v -> tgt.fhirVersion = translate(v, '#FHIRVersion', 'code');
  src.name -> tgt.name;
  src.description -> tgt.description;
  src.example : boolean -> tgt.isExample;
  src.example : canonical -> tgt.profile;
  src.groupingId -> tgt.groupingId;
}

group ImplementationGuideDefinitionPage(source src, target tgt) extends BackboneElement {
  src.name : url -> tgt.source;
  src.name : url -> tgt.name; // src.name : Reference -> tgt.source; - this wasn't used?
  src.title -> tgt.title;
  src.generation as v -> tgt.generation = translate(v, '#GuidePageGeneration', 'code');
  src.page as s -> tgt.page as t then ImplementationGuideDefinitionPage(s, t);
}

group ImplementationGuideDefinitionParameter(source src, target tgt) extends BackboneElement {
  src.code as s ->  tgt.code as t,  t.system = 'http://hl7.org/fhir/guide-parameter-code',  t.code = s;
  src.value -> tgt.value;
}

group ImplementationGuideDefinitionTemplate(source src, target tgt) extends BackboneElement {
  src.code -> tgt.code;
  src.source -> tgt.source;
  src.scope -> tgt.scope;
}

group ImplementationGuideManifest(source src, target tgt) extends BackboneElement {
  src.rendering -> tgt.rendering;
  src.resource as s -> tgt.resource as t then ImplementationGuideManifestResource(s, t);
  src.page as s -> tgt.page as t then ImplementationGuideManifestPage(s, t);
  src.image -> tgt.image;
  src.other -> tgt.other;
}

group ImplementationGuideManifestResource(source src, target tgt) extends BackboneElement {
  src.reference -> tgt.reference;
  src.example : boolean -> tgt.isExample;
  src.example : canonical -> tgt.profile;
  src.relativePath -> tgt.relativePath;
}

group ImplementationGuideManifestPage(source src, target tgt) extends BackboneElement {
  src.name -> tgt.name;
  src.title -> tgt.title;
  src.anchor -> tgt.anchor;
}

# entry[].resource.title
FML Conversion for ImplementationGuide: R4B to R5

# entry[].resource.group[].rule[].documentation
src.name : Reference -> tgt.source; - this wasn't used?

# entry[].resource.text.div
/// url = 'http://hl7.org/fhir/StructureMap/Immunization5to4'
/// name = 'Immunization5to4'
/// title = 'FML Conversion for Immunization: R5 to R4'
/// status = 'active'

uses "http://hl7.org/fhir/StructureDefinition/Immunization" alias ImmunizationR5 as source
uses "http://hl7.org/fhir/4.0/StructureDefinition/Immunization" alias ImmunizationR4 as target

imports "http://hl7.org/fhir/StructureMap/*5to4"

group Immunization(source src : ImmunizationR5, target tgt : ImmunizationR4) extends DomainResource <<type+>> {
  src.identifier -> tgt.identifier;
  src.status -> tgt.status; // src.basedOn -> tgt.basedOn;
  src.statusReason -> tgt.statusReason;
  src.vaccineCode -> tgt.vaccineCode;
  src.manufacturer -> tgt.manufacturer; // src.administeredProduct -> tgt.administeredProduct;
  src.lotNumber -> tgt.lotNumber;
  src.expirationDate -> tgt.expirationDate;
  src.patient -> tgt.patient;
  src.encounter -> tgt.encounter;
  src.occurrence : dateTime -> tgt.occurrence; // src.supportingInformation -> tgt.supportingInformation;
  src.occurrence : string -> tgt.occurrence;
  src.primarySource -> tgt.primarySource;
  src.location -> tgt.location; // src.informationSource -> tgt.informationSource;
  src.site -> tgt.site;
  src.route -> tgt.route;
  src.doseQuantity -> tgt.doseQuantity;
  src.performer as s -> tgt.performer as t then ImmunizationPerformer(s, t);
  src.note -> tgt.note;
  src.reason -> tgt.reasonCode;
  src.reason -> tgt.reasonReference;
  src.isSubpotent -> tgt.isSubpotent;
  src.subpotentReason -> tgt.subpotentReason;
  src.programEligibility as s -> tgt then {
    s.program -> tgt.programEligibility;
  };
  src.fundingSource -> tgt.fundingSource;
  src.reaction as s -> tgt.reaction as t then ImmunizationReaction(s, t);
  src.protocolApplied as s -> tgt.protocolApplied as t then ImmunizationProtocolApplied(s, t);
}

group ImmunizationPerformer(source src, target tgt) extends BackboneElement {
  src.function -> tgt.function;
  src.actor -> tgt.actor;
}

// group ImmunizationProgramEligibility(source src, target tgt) extends BackboneElement {
// src.program -> tgt.program;
// src.programStatus -> tgt.programStatus;
// }
group ImmunizationReaction(source src, target tgt) extends BackboneElement {
  src.date -> tgt.date;
  src.manifestation -> tgt.detail;
  src.reported -> tgt.reported;
}

group ImmunizationProtocolApplied(source src, target tgt) extends BackboneElement {
  src.series -> tgt.series;
  src.authority -> tgt.authority;
  src.targetDisease -> tgt.targetDisease;
  src.doseNumber -> tgt.doseNumber;
  src.seriesDoses -> tgt.seriesDoses;
}

# entry[].resource.title
FML Conversion for Immunization: R5 to R4

# entry[].resource.group[].documentation
group ImmunizationProgramEligibility(source src, target tgt) extends BackboneElement {
src.program -> tgt.program;
src.programStatus -> tgt.programStatus;
}

# entry[].resource.text.div
/// url = 'http://hl7.org/fhir/StructureMap/ClinicalUseDefinition5to4B'
/// name = 'ClinicalUseDefinition5to4B'
/// title = 'FML Conversion for ClinicalUseDefinition: R5 to R4B'
/// status = 'active'

conceptmap "ClinicalUseDefinitionType" {
  prefix s = "http://hl7.org/fhir/clinical-use-definition-type"
  prefix t = "http://hl7.org/fhir/4.3/clinical-use-definition-type"

  s:indication - t:indication
  s:contraindication - t:contraindication
  s:interaction - t:interaction
  s:"undesirable-effect" - t:"undesirable-effect"
  s:warning - t:warning
}

uses "http://hl7.org/fhir/StructureDefinition/ClinicalUseDefinition" alias ClinicalUseDefinitionR5 as source
uses "http://hl7.org/fhir/4.3/StructureDefinition/ClinicalUseDefinition" alias ClinicalUseDefinitionR4B as target

imports "http://hl7.org/fhir/StructureMap/*5to4B"

group ClinicalUseDefinition(source src : ClinicalUseDefinitionR5, target tgt : ClinicalUseDefinitionR4B) extends DomainResource <<type+>> {
  src.identifier -> tgt.identifier;
  src.type as v -> tgt.type = translate(v, '#ClinicalUseDefinitionType', 'code');
  src.category -> tgt.category;
  src.subject -> tgt.subject;
  src.status -> tgt.status;
  src.contraindication as s -> tgt.contraindication as t then ClinicalUseDefinitionContraindication(s, t);
  src.indication as s -> tgt.indication as t then ClinicalUseDefinitionIndication(s, t);
  src.interaction as s -> tgt.interaction as t then ClinicalUseDefinitionInteraction(s, t);
  src.population -> tgt.population;
  src.undesirableEffect as s -> tgt.undesirableEffect as t then ClinicalUseDefinitionUndesirableEffect(s, t); // src.library -> tgt.library;
  src.warning as s -> tgt.warning as t then ClinicalUseDefinitionWarning(s, t);
}

group ClinicalUseDefinitionContraindication(source src, target tgt) extends BackboneElement {
  src.diseaseSymptomProcedure -> tgt.diseaseSymptomProcedure;
  src.diseaseStatus -> tgt.diseaseStatus;
  src.comorbidity -> tgt.comorbidity;
  src.indication -> tgt.indication;
  src.otherTherapy as s -> tgt.otherTherapy as t then ClinicalUseDefinitionContraindicationOtherTherapy(s, t); // src.applicability -> tgt.applicability;
}

group ClinicalUseDefinitionContraindicationOtherTherapy(source src, target tgt) extends BackboneElement {
  src.relationshipType -> tgt.relationshipType;
  src.treatment -> tgt.therapy;
}

group ClinicalUseDefinitionIndication(source src, target tgt) extends BackboneElement {
  src.diseaseSymptomProcedure -> tgt.diseaseSymptomProcedure;
  src.diseaseStatus -> tgt.diseaseStatus;
  src.comorbidity -> tgt.comorbidity;
  src.intendedEffect -> tgt.intendedEffect;
  src.duration : Range -> tgt.duration;
  src.duration : string -> tgt.duration;
  src.undesirableEffect -> tgt.undesirableEffect;
}

group ClinicalUseDefinitionInteraction(source src, target tgt) extends BackboneElement {
  src.interactant as s -> tgt.interactant as t then ClinicalUseDefinitionInteractionInteractant(s, t);
  src.type -> tgt.type;
  src.effect -> tgt.effect;
  src.incidence -> tgt.incidence;
  src.management -> tgt.management;
}

group ClinicalUseDefinitionInteractionInteractant(source src, target tgt) extends BackboneElement {
  src.item : Reference -> tgt.item;
  src.item : CodeableConcept -> tgt.item;
}

group ClinicalUseDefinitionUndesirableEffect(source src, target tgt) extends BackboneElement {
  src.symptomConditionEffect -> tgt.symptomConditionEffect;
  src.classification -> tgt.classification;
  src.frequencyOfOccurrence -> tgt.frequencyOfOccurrence;
}

group ClinicalUseDefinitionWarning(source src, target tgt) extends BackboneElement {
  src.description -> tgt.description;
  src.code -> tgt.code;
}

# entry[].resource.title
FML Conversion for ClinicalUseDefinition: R5 to R4B

# entry[].resource.text.div
/// url = 'http://hl7.org/fhir/StructureMap/DetectedIssue5to4B'
/// name = 'DetectedIssue5to4B'
/// title = 'FML Conversion for DetectedIssue: R5 to R4B'
/// status = 'active'

conceptmap "DetectedIssueSeverity" {
  prefix s = "http://hl7.org/fhir/detectedissue-severity"
  prefix t = "http://hl7.org/fhir/4.3/detectedissue-severity"

  s:high - t:high
  s:moderate - t:moderate
  s:low - t:low
}

uses "http://hl7.org/fhir/StructureDefinition/DetectedIssue" alias DetectedIssueR5 as source
uses "http://hl7.org/fhir/4.3/StructureDefinition/DetectedIssue" alias DetectedIssueR4B as target

imports "http://hl7.org/fhir/StructureMap/*5to4B"

group DetectedIssue(source src : DetectedIssueR5, target tgt : DetectedIssueR4B) extends DomainResource <<type+>> {
  src.identifier -> tgt.identifier;
  src.status -> tgt.status;
  src.code -> tgt.code; // src.category -> tgt.category;
  src.severity as v -> tgt.severity = translate(v, '#DetectedIssueSeverity', 'code');
  src.subject -> tgt.patient;
  src.identified : dateTime -> tgt.identified; // src.encounter -> tgt.encounter;
  src.identified : Period -> tgt.identified;
  src.author -> tgt.author;
  src.implicated -> tgt.implicated;
  src.evidence as s -> tgt.evidence as t then DetectedIssueEvidence(s, t);
  src.detail -> tgt.detail;
  src.reference -> tgt.reference;
  src.mitigation as s -> tgt.mitigation as t then DetectedIssueMitigation(s, t);
}

group DetectedIssueEvidence(source src, target tgt) extends BackboneElement {
  src.code -> tgt.code;
  src.detail -> tgt.detail;
}

group DetectedIssueMitigation(source src, target tgt) extends BackboneElement {
  src.action -> tgt.action;
  src.date -> tgt.date;
  src.author -> tgt.author;
}

# entry[].resource.title
FML Conversion for DetectedIssue: R5 to R4B