{ "resourceType" : "StructureMap", "id" : "OrfQrToBundle", "text" : { "status" : "generated", "div" : "
\r\nmap "http://fhir.ch/ig/ch-orf/StructureMap/OrfQrToBundle" = "OrfQrToBundle"\r\n\r\n// ORF QuestionnaireResponse to Bundle\r\n// 2021-01-11 Oliver Egger\r\n// QRF Questionnaire: http://fhir.ch/ig/ch-orf/Questionnaire-order-referral-form.html\r\n// QRF QuestionnaireResponse: http://fhir.ch/ig/ch-orf/QuestionnaireResponse-order-referral-form.xml.html\r\n// Bundle: http://fhir.ch/ig/ch-orf/StructureDefinition-ch-orf-document.html\r\n\r\nuses "http://hl7.org/fhir/StructureDefinition/QuestionnaireResponse" alias QuestionnaireResponseSource as source\r\nuses "http://hl7.org/fhir/StructureDefinition/Bundle" alias Bundle as target\r\nuses "http://hl7.org/fhir/StructureDefinition/Composition" alias Composition as target\r\nuses "http://hl7.org/fhir/StructureDefinition/Patient" alias Patient as target\r\nuses "http://hl7.org/fhir/StructureDefinition/RelatedPerson" alias RelatedPerson as target\r\nuses "http://hl7.org/fhir/StructureDefinition/Organization" alias Organization as target\r\nuses "http://hl7.org/fhir/StructureDefinition/Practitioner" alias Practitioner as target\r\nuses "http://hl7.org/fhir/StructureDefinition/PractitionerRole" alias PractitionerRole as target\r\nuses "http://hl7.org/fhir/StructureDefinition/ServiceRequest" alias ServiceRequest as target\r\nuses "http://hl7.org/fhir/StructureDefinition/Extension" alias Extension as target\r\nuses "http://hl7.org/fhir/StructureDefinition/EpisodeOfCare" alias EpisodeOfCare as target\r\nuses "http://hl7.org/fhir/StructureDefinition/QuestionnaireResponse" alias QuestionnaireResponse as target\r\n\r\ngroup OrfQrToBundle(source qr : QuestionnaireResponseSource, target bundle : Bundle) {\r\n qr -> bundle.identifier as documentIdentifier, documentIdentifier.system = 'urn:ietf:rfc:3986', uuid() as uuidDoc, documentIdentifier.value = append('urn:uuid:', uuidDoc) "documentIdentifier";\r\n qr -> bundle.entry as e, e.resource = create('Composition') as composition, composition.id = uuid() as uuid, e.fullUrl = append('urn:uuid:', uuid), bundle.entry as e2, bundle.timestamp = (now()) as timestamp, composition.date = timestamp, composition.title = 'Order and Referral by Form', composition.type as type, type.coding as coding, coding.code = '419891008', coding.system = 'http://snomed.info/sct', composition.category as category, category.coding as coding, coding.code = '721963009', coding.system = 'http://snomed.info/sct', e2.resource = create('Patient') as patient, patient.id = uuid() as uuid2, e2.fullUrl = append('urn:uuid:', uuid2), bundle.entry as e4, e4.resource = create('QuestionnaireResponse') as questionnaireresp then {\r\n qr then QuestionnaireResponseMap(qr, questionnaireresp) "questionnaireresp";\r\n qr -> questionnaireresp.id = uuid() as uuid4, e4.fullUrl = append('urn:uuid:', uuid4), bundle.entry as e5, e5.resource = create('ServiceRequest') as servicerequest, servicerequest.id = uuid() as uuid5, e5.fullUrl = append('urn:uuid:', uuid5) then QrToBundle(qr, patient, questionnaireresp, servicerequest, composition, bundle) "orfbundle";\r\n } "OrfQrToBundle";\r\n}\r\n\r\ngroup QuestionnaireResponseMap(source src, target tgt : QuestionnaireResponse) {\r\n src.identifier as value -> tgt.identifier = value;\r\n src.basedOn as value -> tgt.basedOn = value;\r\n src.partOf as value -> tgt.partOf = value;\r\n src.questionnaire as value -> tgt.questionnaire = value;\r\n src.status as value -> tgt.status = value;\r\n src.subject as value -> tgt.subject = value;\r\n src.encounter as value -> tgt.encounter = value;\r\n src.authored as value -> tgt.authored = value;\r\n src.author as value -> tgt.author = value;\r\n src.source as value -> tgt.source = value;\r\n src.item as value -> tgt.item = value;\r\n}\r\n\r\ngroup QrToGroups(source qr : QuestionnaireResponseSource, target patient : Patient, target bundle : Bundle, target composition : Composition, target serviceRequest : ServiceRequest) {\r\n qr.item as grp where linkId = 'order' then OrderItems(grp, bundle, composition, serviceRequest) "grporder";\r\n qr.item as grp where linkId = 'receiver' then ReceiverInit(grp, bundle, composition, serviceRequest) "receiver";\r\n qr.item as grp where linkId = 'initiator' then InitiatorInit(grp, bundle, patient, composition, serviceRequest) "grpinitiator";\r\n qr.item as grp where linkId = 'patient' then PatientItems(grp, bundle, patient, composition, serviceRequest) "grppatient";\r\n qr.item as grp where linkId = 'requestedEncounter' then RequestedEncounterItems(grp, bundle, patient, serviceRequest) "grprequestedencounter";\r\n qr.item as grp where linkId = 'coverage' then Coverage(grp, bundle, patient, serviceRequest) "grprequestedencounter";\r\n qr.item as grp where linkId = 'sender' then SenderAuthorInit(grp, bundle, composition, serviceRequest) "grpsender";\r\n qr.item as grp where linkId = 'receiverCopy' then ReceiverCopy(grp, bundle, patient, composition, serviceRequest) "receiverCopy";\r\n qr.item as grp where linkId = 'appointment' then Appointment(grp, bundle, composition, serviceRequest) "appointment";\r\n qr.item as grp where linkId = 'previousResults' then PreviousResults(grp, bundle, serviceRequest) "previousResults";\r\n qr.item as grp where linkId = 'antecedentEpisodeOfCare' then AntecedentEpisodeOfCareInit(grp, bundle, patient, composition) "AntecedentEpisodeOfCareInit";\r\n qr.item as grp where linkId = 'consent' then Consent(grp, bundle, composition) "consent";\r\n qr.item as grp where linkId = 'note' then Note(grp, serviceRequest) "note";\r\n}\r\n\r\ngroup OrderItems(source src, target bundle : Bundle, target composition, target serviceRequest : ServiceRequest) {\r\n src.item as item where ((linkId.value = 'order.precedentDocumentIdentifier') and answer.exists()) -> composition.extension as ext, ext.url = 'http://fhir.ch/ig/ch-orf/StructureDefinition/ch-orf-precedentdocument', ext.value = create('Identifier') as value, value.system = 'urn:ietf:rfc:3986', value.value = ('urn:uuid:' + %item.answer.value) "orderPrecedentDocumentIdentifier";\r\n src.item as item where ((linkId.value = 'order.placerOrderIdentifier') and answer.exists()) -> serviceRequest.identifier as value share placer, value.type as type, type.coding as coding, coding.system = 'http://terminology.hl7.org/CodeSystem/v2-0203', coding.code = 'PLAC', value.value = (%item.answer.value) "orderPlacerOrderIdentifier";\r\n src.item as item where ((linkId.value = 'order.placerOrderIdentifierDomain') and answer.exists()) -> serviceRequest.identifier as value share placer, value.system = (%item.answer.value) "orderPlacerOrderIdentifierDomain";\r\n src.item as item where ((linkId.value = 'order.fillerOrderIdentifier') and answer.exists()) -> serviceRequest.identifier as value share filler, value.type as type, type.coding as coding, coding.system = 'http://terminology.hl7.org/CodeSystem/v2-0203', coding.code = 'FILL', value.value = (%item.answer.value) "orderFillerOrderIdentifier";\r\n src.item as item where ((linkId.value = 'order.fillerOrderIdentifierDomain') and answer.exists()) -> serviceRequest.identifier as value share filler, value.system = (%item.answer.value) "orderFillerOrderIdentifierDomain";\r\n src.item as item where ((linkId.value = 'order.authoredOn') and answer.exists()) -> serviceRequest.authoredOn = (%item.answer.value);\r\n src.item as item where ((linkId.value = 'order.priority') and answer.exists()) -> serviceRequest.priority = (%item.answer.value);\r\n src.item as item where (linkId.value = 'order.notificationContactDocument') then {\r\n item -> bundle.entry as e4, e4.resource = create('PractitionerRole') as practitionerRoleDataEnterer, practitionerRoleDataEnterer.id = uuid() as uuid4, e4.fullUrl = append('urn:uuid:', uuid4), composition.extension as extension, bundle.entry as e5, e5.resource = create('Practitioner') as practitionerDataEnterer, practitionerDataEnterer.id = uuid() as uuid5, e5.fullUrl = append('urn:uuid:', uuid5), practitionerRoleDataEnterer.practitioner = create('Reference') as reference, reference.reference = append('urn:uuid:', uuid5) then {\r\n item then UrgentNotificationContactForRequestItems(item, practitionerRoleDataEnterer, practitionerDataEnterer) "data";\r\n item then ExtOrfUrgentNotificationContactForRequest(item, practitionerRoleDataEnterer, extension) "extension";\r\n } "orderNotificationContactDocumentItems";\r\n } "ordeNnotificationContactDocument";\r\n src.item as item where (linkId.value = 'order.notificationContactDocumentResponse') then {\r\n item -> bundle.entry as e4, e4.resource = create('PractitionerRole') as practitionerRoleDataEnterer, practitionerRoleDataEnterer.id = uuid() as uuid4, e4.fullUrl = append('urn:uuid:', uuid4), composition.extension as extension, bundle.entry as e5, e5.resource = create('Practitioner') as practitionerDataEnterer, practitionerDataEnterer.id = uuid() as uuid5, e5.fullUrl = append('urn:uuid:', uuid5), practitionerRoleDataEnterer.practitioner = create('Reference') as reference, reference.reference = append('urn:uuid:', uuid5) then {\r\n item then UrgentNotificationContactForResponseItems(item, practitionerRoleDataEnterer, practitionerDataEnterer) "data";\r\n item then ExtOrfUrgentNotificationContactForResponse(item, practitionerRoleDataEnterer, extension) "extension";\r\n } "orderNotificationContactDocumentResponseItems";\r\n } "orderNotificationContactDocumentResponse";\r\n}\r\n\r\ngroup UrgentNotificationContactForRequestPractitionerItems(source src, target practitioner : Practitioner) {\r\n src.item as item where ((linkId.value = 'order.notificationContactDocument.practitioner.familyName') and answer.exists()) -> practitioner.name as name share practitionerName, name.family = (%item.answer.value);\r\n src.item as item where ((linkId.value = 'order.notificationContactDocument.practitioner.givenName') and answer.exists()) -> practitioner.name as name share practitionerName, name.given = (%item.answer.value);\r\n src.item as item where ((linkId.value = 'order.notificationContactDocument.practitioner.title') and answer.exists()) -> practitioner.name as name share practitionerName, name.prefix = (%item.answer.value) as prefix, prefix.extension as ext, ext.url = 'http://hl7.org/fhir/StructureDefinition/iso21090-EN-qualifier', ext.value = create('code') as value, value.value = 'AC' "senderAuthorPractitionerTitle";\r\n src.item as item where ((linkId.value = 'order.notificationContactDocument.practitioner.phone') and answer.exists()) -> practitioner.telecom as value, value.system = 'phone', value.value = (%item.answer.value) "senderAuthorPractitionerPhone";\r\n src.item as item where ((linkId.value = 'order.notificationContactDocument.practitioner.email') and answer.exists()) -> practitioner.telecom as value, value.system = 'email', value.value = (%item.answer.value) "senderAuthorPractitionerEmail";\r\n}\r\n\r\ngroup UrgentNotificationContactForRequestItems(source src, target practitionerRole : PractitionerRole, target practitioner : Practitioner) {\r\n src.item as item where (linkId.value = 'order.notificationContactDocument.practitioner') then UrgentNotificationContactForRequestPractitionerItems(item, practitioner);\r\n}\r\n\r\ngroup ExtOrfUrgentNotificationContactForRequest(source src, target practitionerRole : PractitionerRole, target ext : Extension) {\r\n src -> ext.url = 'http://fhir.ch/ig/ch-orf/StructureDefinition/ch-orf-urgentnoficationcontactforthisdocument' "url";\r\n src -> ext.value = create('Reference') as reference, reference.reference = ('urn:uuid:' + %practitionerRole.id) "practitionerRole";\r\n}\r\n\r\ngroup UrgentNotificationContactForResponsePractitionerItems(source src, target practitioner : Practitioner) {\r\n src.item as item where ((linkId.value = 'order.notificationContactDocumentResponse.practitioner.familyName') and answer.exists()) -> practitioner.name as name share practitionerName, name.family = (%item.answer.value);\r\n src.item as item where ((linkId.value = 'order.notificationContactDocumentResponse.practitioner.givenName') and answer.exists()) -> practitioner.name as name share practitionerName, name.given = (%item.answer.value);\r\n src.item as item where ((linkId.value = 'order.notificationContactDocumentResponse.practitioner.title') and answer.exists()) -> practitioner.name as name share practitionerName, name.prefix = (%item.answer.value) as prefix, prefix.extension as ext, ext.url = 'http://hl7.org/fhir/StructureDefinition/iso21090-EN-qualifier', ext.value = create('code') as value, value.value = 'AC' "senderAuthorPractitionerTitle";\r\n src.item as item where ((linkId.value = 'order.notificationContactDocumentResponse.practitioner.phone') and answer.exists()) -> practitioner.telecom as value, value.system = 'phone', value.value = (%item.answer.value) "senderAuthorPractitionerPhone";\r\n src.item as item where ((linkId.value = 'order.notificationContactDocumentResponse.practitioner.email') and answer.exists()) -> practitioner.telecom as value, value.system = 'email', value.value = (%item.answer.value) "senderAuthorPractitionerEmail";\r\n}\r\n\r\ngroup UrgentNotificationContactForResponseItems(source src, target practitionerRole : PractitionerRole, target practitioner : Practitioner) {\r\n src.item as item where (linkId.value = 'order.notificationContactDocumentResponse.practitioner') then UrgentNotificationContactForResponsePractitionerItems(item, practitioner);\r\n}\r\n\r\ngroup ExtOrfUrgentNotificationContactForResponse(source src, target practitionerRole : PractitionerRole, target ext : Extension) {\r\n src -> ext.url = 'http://fhir.ch/ig/ch-orf/StructureDefinition/ch-orf-urgentnoficationcontactfortheresponsetothisdocument' "url";\r\n src -> ext.value = create('Reference') as reference, reference.reference = ('urn:uuid:' + %practitionerRole.id) "practitionerRole";\r\n}\r\n\r\ngroup ReceiverPractitionerItems(source src, target practitioner : Practitioner) {\r\n src.item as item where ((linkId.value = 'receiver.practitioner.familyName') and answer.exists()) -> practitioner.name as name share practitionerName, name.family = (%item.answer.value);\r\n src.item as item where ((linkId.value = 'receiver.practitioner.givenName') and answer.exists()) -> practitioner.name as name share practitionerName, name.given = (%item.answer.value);\r\n src.item as item where ((linkId.value = 'receiver.practitioner.title') and answer.exists()) -> practitioner.name as name share practitionerName, name.prefix = (%item.answer.value) as prefix, prefix.extension as ext, ext.url = 'http://hl7.org/fhir/StructureDefinition/iso21090-EN-qualifier', ext.value = create('code') as value, value.value = 'AC' "receiverPractitionerTitle";\r\n src.item as item where ((linkId.value = 'receiver.practitioner.gln') and answer.exists()) -> practitioner.identifier as value, value.system = 'urn:oid:2.51.1.3', value.value = (%item.answer.value) "receiverPractitionerGln";\r\n src.item as item where ((linkId.value = 'receiver.practitioner.zsr') and answer.exists()) -> practitioner.identifier as value, value.system = 'urn:oid:2.16.756.5.30.1.123.100.2.1.1', value.value = (%item.answer.value) "receiverPractitionerZsr";\r\n src.item as item where ((linkId.value = 'receiver.practitioner.phone') and answer.exists()) -> practitioner.telecom as value, value.system = 'phone', value.value = (%item.answer.value) "receiverPractitionerPhone";\r\n src.item as item where ((linkId.value = 'receiver.practitioner.email') and answer.exists()) -> practitioner.telecom as value, value.system = 'email', value.value = (%item.answer.value) "receiverPractitionerEmail";\r\n}\r\n\r\ngroup ReceiverOrganizationItems(source src, target organization : Organization) {\r\n src.item as item where ((linkId.value = 'receiver.organization.name') and answer.exists()) -> organization.name = (%item.answer.value);\r\n src.item as item where ((linkId.value = 'receiver.organization.gln') and answer.exists()) -> organization.identifier as value, value.system = 'urn:oid:2.51.1.3', value.value = (%item.answer.value) "receiverOrganizationGln";\r\n src.item as item where ((linkId.value = 'receiver.organization.zsr') and answer.exists()) -> organization.identifier as value, value.system = 'urn:oid:2.16.756.5.30.1.123.100.2.1.1', value.value = (%item.answer.value) "receiverOrganizationZsr";\r\n src.item as item where ((linkId.value = 'receiver.organization.streetAddressLine') and answer.exists()) -> organization.address as address share orgAddress then {\r\n item.answer as answer -> address.line = (%answer.value) "receiverOrganizationStreetAddressLine";\r\n } "itemAnswer";\r\n src.item as item where ((linkId.value = 'receiver.organization.postalCode') and answer.exists()) -> organization.address as address share orgAddress, address.postalCode = (%item.answer.value) "receiverOrganizationPostalCode";\r\n src.item as item where ((linkId.value = 'receiver.organization.city') and answer.exists()) -> organization.address as address share orgAddress, address.city = (%item.answer.value) "receiverOrganizationCity";\r\n src.item as item where ((linkId.value = 'receiver.organization.country') and answer.exists()) -> organization.address as address share orgAddress, address.country = (%item.answer.value) "receiverOrganizationCountry";\r\n}\r\n\r\ngroup ReceiverItems(source src, target bundle : Bundle, target practitionerRole : PractitionerRole) {\r\n src.item as item where (linkId.value = 'receiver.practitioner') -> bundle.entry as e2, e2.resource = create('Practitioner') as practitioner, practitioner.id = uuid() as uuid2, practitionerRole.practitioner = create('Reference') as reference, reference.reference = append('urn:uuid:', uuid2), e2.fullUrl = append('urn:uuid:', uuid2) then ReceiverPractitionerItems(item, practitioner);\r\n src.item as item where (linkId.value = 'receiver.organization') -> bundle.entry as e3, e3.resource = create('Organization') as organization, organization.id = uuid() as uuid3, practitionerRole.organization = create('Reference') as reference, reference.reference = append('urn:uuid:', uuid3), e3.fullUrl = append('urn:uuid:', uuid3) then ReceiverOrganizationItems(item, organization);\r\n}\r\n\r\ngroup Consent(source src, target bundle : Bundle, target composition : Composition) {\r\n src.item as item where ((linkId.value = 'consent.statement') and answer.exists()) -> bundle.entry as e, e.resource = create('Consent') as consent, consent.status = 'active', consent.scope as scope, scope.coding as coding, coding.code = 'treatment', coding.system = 'http://terminology.hl7.org/CodeSystem/consentscope', consent.category as category, category.coding as coding, coding.code = '59284-0', coding.system = 'http://loinc.org', consent.policyRule as policyRule, policyRule.coding as coding, coding.code = '385432009', coding.system = 'http://snomed.info/sct', consent.id = uuid() as uuid, e.fullUrl = append('urn:uuid:', uuid), composition.extension as ext, ext.url = 'http://fhir.ch/ig/ch-orf/StructureDefinition/ch-orf-patientconsent', ext.value = create('Reference') as reference, consent.extension as extcode, extcode.url = 'http://fhir.ch/ig/ch-orf/StructureDefinition/ch-orf-consentcode', extcode.value = create('CodeableConcept') as cc, cc.coding = (%item.answer.value), reference.reference = append('urn:uuid:', uuid) then {\r\n item.answer as answer then {\r\n answer.item as item where ((linkId.value = 'consent.statement.note') and answer.exists()) -> consent.extension as extnote, extnote.url = 'http://fhir.ch/ig/ch-orf/StructureDefinition/ch-orf-consentnote', extnote.value = (%item.answer.value) "consentStatementNote";\r\n } "itemAnswer";\r\n } "consentStatement";\r\n}\r\n\r\ngroup ReceiverInit(source src, target bundle : Bundle, target composition : Composition, target serviceRequest : ServiceRequest) {\r\n src -> bundle.entry as e, e.resource = create('PractitionerRole') as practitionerRole, practitionerRole.id = uuid() as uuid, e.fullUrl = append('urn:uuid:', uuid), composition.extension as ext, ext.url = 'http://fhir.ch/ig/ch-orf/StructureDefinition/ch-orf-receiver', ext.value = create('Reference') as reference, reference.reference = append('urn:uuid:', uuid) then ReceiverItems(src, bundle, practitionerRole) "receiver";\r\n}\r\n\r\ngroup InitiatorItems(source src, target bundle : Bundle, target patient : Patient, target ext : Extension) {\r\n src.item as item where ((linkId.value = 'initiator.personalrelation') and answer.exists()) -> ext.extension as extension, extension.url = 'ch-orf-personalrelation', extension.value = (%item.answer.value) "Initiatorpersonalrelation";\r\n src.item as item where ((linkId.value = 'initiator.legalrelation') and answer.exists()) -> ext.extension as extension, extension.url = 'ch-orf-legalrelation', extension.value = (%item.answer.value) "Initiatorlegalrelation";\r\n src.item as item where (linkId = 'initiator.practitionerRole') -> bundle.entry as e4, e4.resource = create('PractitionerRole') as practitionerrole, ext.extension as extension, practitionerrole.id = uuid() as uuid4, extension.url = 'ch-orf-personorganization', extension.value = create('Reference') as reference, reference.reference = append('urn:uuid:', uuid4), e4.fullUrl = append('urn:uuid:', uuid4) then {\r\n item then InitiatorPractitionerRoleItems(item, bundle, practitionerrole) "data";\r\n } "InitiatorPractitionerRoleItems";\r\n src.item as item where (linkId = 'initiator.relatedPerson') -> bundle.entry as e4, e4.resource = create('RelatedPerson') as relatedPerson, ext.extension as extension, extension.url = 'ch-orf-personorganization', extension.value = create('Reference') as reference, relatedPerson.id = uuid() as uuid4, reference.reference = append('urn:uuid:', uuid4), relatedPerson.patient as reference, reference.reference = ('urn:uuid:' + %patient.id), e4.fullUrl = append('urn:uuid:', uuid4) then {\r\n item then InitiatorRelatedPersonItems(item, relatedPerson) "data";\r\n } "InitiatorelatedPerson";\r\n}\r\n\r\ngroup InitiatorRelatedPersonItems(source src, target relatedPerson : RelatedPerson) {\r\n src.item as item where ((linkId.value = 'initiator.relatedPerson.familyName') and answer.exists()) -> relatedPerson.name as name share name, name.family = (%item.answer.value);\r\n src.item as item where ((linkId.value = 'initiator.relatedPerson.givenName') and answer.exists()) -> relatedPerson.name as name share name, name.given = (%item.answer.value);\r\n src.item as item where ((linkId.value = 'initiator.relatedPerson.phone') and answer.exists()) then {\r\n item.answer as answer -> relatedPerson.telecom as value, value.system = 'phone', value.value = (%answer.value) "InitiatorelatedPersonPhone";\r\n } "Phone";\r\n src.item as item where ((linkId.value = 'initiator.relatedPerson.email') and answer.exists()) -> relatedPerson.telecom as value, value.system = 'email', value.value = (%item.answer.value) "InitiatorelatedPersonEmail";\r\n src.item as item where ((linkId.value = 'initiator.relatedPerson.streetAddressLine') and answer.exists()) -> relatedPerson.address as address share orgAddress then {\r\n item.answer as answer -> address.line = (%answer.value) "InitiatorelatedPersonStreetAddressLine";\r\n } "itemAnswer";\r\n src.item as item where ((linkId.value = 'initiator.relatedPerson.postalCode') and answer.exists()) -> relatedPerson.address as address share orgAddress, address.postalCode = (%item.answer.value) "InitiatorelatedPersonPostalCode";\r\n src.item as item where ((linkId.value = 'initiator.relatedPerson.city') and answer.exists()) -> relatedPerson.address as address share orgAddress, address.city = (%item.answer.value) "InitiatorelatedPersonCity";\r\n src.item as item where ((linkId.value = 'initiator.relatedPerson.country') and answer.exists()) -> relatedPerson.address as address share orgAddress, address.country = (%item.answer.value) "InitiatorelatedPersonCountry";\r\n}\r\n\r\ngroup InitiatorPractitionerRoleItems(source src, target bundle : Bundle, target practitionerRole : PractitionerRole) {\r\n src.item as item where (linkId.value = 'initiator.practitionerRole.practitioner') -> bundle.entry as e2, e2.resource = create('Practitioner') as practitioner, practitioner.id = uuid() as uuid2, practitionerRole.practitioner = create('Reference') as reference, reference.reference = append('urn:uuid:', uuid2), e2.fullUrl = append('urn:uuid:', uuid2) then InitiatorPractitionerItems(item, practitioner);\r\n src.item as item where (linkId.value = 'initiator.practitionerRole.organization') -> bundle.entry as e3, e3.resource = create('Organization') as organization, organization.id = uuid() as uuid3, practitionerRole.organization = create('Reference') as reference, reference.reference = append('urn:uuid:', uuid3), e3.fullUrl = append('urn:uuid:', uuid3) then InitiatorOrganizationItems(item, organization);\r\n}\r\n\r\ngroup InitiatorPractitionerItems(source src, target practitioner : Practitioner) {\r\n src.item as item where ((linkId.value = 'initiator.practitionerRole.practitioner.familyName') and answer.exists()) -> practitioner.name as name share practitionerName, name.family = (%item.answer.value);\r\n src.item as item where ((linkId.value = 'initiator.practitionerRole.practitioner.givenName') and answer.exists()) -> practitioner.name as name share practitionerName, name.given = (%item.answer.value);\r\n src.item as item where ((linkId.value = 'initiator.practitionerRole.practitioner.title') and answer.exists()) -> practitioner.name as name share practitionerName, name.prefix = (%item.answer.value) as prefix, prefix.extension as ext, ext.url = 'http://hl7.org/fhir/StructureDefinition/iso21090-EN-qualifier', ext.value = create('code') as value, value.value = 'AC' "InitiatorractitionerRolePractitionerTitle";\r\n src.item as item where ((linkId.value = 'initiator.practitionerRole.practitioner.phone') and answer.exists()) -> practitioner.telecom as value, value.system = 'phone', value.value = (%item.answer.value) "InitiatorractitionerRolePractitionerPhone";\r\n src.item as item where ((linkId.value = 'initiator.practitionerRole.practitioner.email') and answer.exists()) -> practitioner.telecom as value, value.system = 'email', value.value = (%item.answer.value) "InitiatorractitionerRolePractitionerEmail";\r\n src.item as item where ((linkId.value = 'initiator.practitionerRole.practitioner.gln') and answer.exists()) -> practitioner.identifier as value, value.system = 'urn:oid:2.51.1.3', value.value = (%item.answer.value) "receiverPractitionerGln";\r\n src.item as item where ((linkId.value = 'initiator.practitionerRole.practitioner.zsr') and answer.exists()) -> practitioner.identifier as value, value.system = 'urn:oid:2.16.756.5.30.1.123.100.2.1.1', value.value = (%item.answer.value) "receiverPractitionerZsr";\r\n}\r\n\r\ngroup InitiatorOrganizationItems(source src, target organization : Organization) {\r\n src.item as item where ((linkId.value = 'initiator.practitionerRole.organization.name') and answer.exists()) -> organization.name = (%item.answer.value);\r\n src.item as item where ((linkId.value = 'initiator.practitionerRole.organization.streetAddressLine') and answer.exists()) -> organization.address as address share orgAddress then {\r\n item.answer as answer -> address.line = (%answer.value) "InitiatorractitionerRoleOrganizationStreetAddressLine";\r\n } "itemAnswer";\r\n src.item as item where ((linkId.value = 'initiator.practitionerRole.organization.postalCode') and answer.exists()) -> organization.address as address share orgAddress, address.postalCode = (%item.answer.value) "InitiatorractitionerRoleOrganizationPostalCode";\r\n src.item as item where ((linkId.value = 'initiator.practitionerRole.organization.city') and answer.exists()) -> organization.address as address share orgAddress, address.city = (%item.answer.value) "InitiatorractitionerRoleOrganizationCity";\r\n src.item as item where ((linkId.value = 'initiator.practitionerRole.organization.country') and answer.exists()) -> organization.address as address share orgAddress, address.country = (%item.answer.value) "InitiatorractitionerRoleOrganizationCountry";\r\n}\r\n\r\ngroup FamilyDoctorInit(source src, target bundle : Bundle, target patient : Patient, target composition : Composition, target serviceRequest : ServiceRequest) {\r\n src -> bundle.entry as e4, e4.resource = create('PractitionerRole') as practitionerRole, practitionerRole.id = uuid() as uuid4, patient.generalPractitioner = create('Reference') as gp, gp.reference = append('urn:uuid:', uuid4), e4.fullUrl = append('urn:uuid:', uuid4) then {\r\n src.item as item where (linkId.value = 'familydoctor.practitioner') -> bundle.entry as e2, e2.resource = create('Practitioner') as practitioner, practitioner.id = uuid() as uuid2, practitionerRole.practitioner = create('Reference') as reference, reference.reference = append('urn:uuid:', uuid2), e2.fullUrl = append('urn:uuid:', uuid2) then FamilyDoctorPractitionerItems(item, practitioner);\r\n src.item as item where (linkId.value = 'familydoctor.organization') -> bundle.entry as e3, e3.resource = create('Organization') as organization, organization.id = uuid() as uuid3, practitionerRole.organization = create('Reference') as reference, reference.reference = append('urn:uuid:', uuid3), e3.fullUrl = append('urn:uuid:', uuid3) then FamilyDoctorOrganizationItems(item, organization);\r\n } "FamilyDoctorInit";\r\n}\r\n\r\ngroup FamilyDoctorPractitionerItems(source src, target practitioner : Practitioner) {\r\n src.item as item where ((linkId.value = 'familydoctor.practitioner.familyName') and answer.exists()) -> practitioner.name as name share practitionerName, name.family = (%item.answer.value);\r\n src.item as item where ((linkId.value = 'familydoctor.practitioner.givenName') and answer.exists()) -> practitioner.name as name share practitionerName, name.given = (%item.answer.value);\r\n src.item as item where ((linkId.value = 'familydoctor.practitioner.gln') and answer.exists()) -> practitioner.identifier as value, value.system = 'urn:oid:2.51.1.3', value.value = (%item.answer.value) "familydoctorPractitionerGln";\r\n src.item as item where ((linkId.value = 'familydoctor.practitioner.zsr') and answer.exists()) -> practitioner.identifier as value, value.system = 'urn:oid:2.16.756.5.30.1.123.100.2.1.1', value.value = (%item.answer.value) "familydoctorPractitionerZsr";\r\n src.item as item where ((linkId.value = 'familydoctor.practitioner.title') and answer.exists()) -> practitioner.name as name share practitionerName, name.prefix = (%item.answer.value) as prefix, prefix.extension as ext, ext.url = 'http://hl7.org/fhir/StructureDefinition/iso21090-EN-qualifier', ext.value = create('code') as value, value.value = 'AC' "familydoctorPractitionerTitle";\r\n src.item as item where ((linkId.value = 'familydoctor.practitioner.phone') and answer.exists()) -> practitioner.telecom as value, value.system = 'phone', value.value = (%item.answer.value) "familydoctorPractitionerPhone";\r\n src.item as item where ((linkId.value = 'familydoctor.practitioner.email') and answer.exists()) -> practitioner.telecom as value, value.system = 'email', value.value = (%item.answer.value) "familydoctorPractitionerEmail";\r\n}\r\n\r\ngroup FamilyDoctorOrganizationItems(source src, target organization : Organization) {\r\n src.item as item where ((linkId.value = 'familydoctor.organization.name') and answer.exists()) -> organization.name = (%item.answer.value);\r\n src.item as item where ((linkId.value = 'familydoctor.organization.streetAddressLine') and answer.exists()) -> organization.address as address share orgAddress then {\r\n item.answer as answer -> address.line = (%answer.value) "familydoctorOrganizationStreetAddressLine";\r\n } "itemAnswer";\r\n src.item as item where ((linkId.value = 'familydoctor.organization.postalCode') and answer.exists()) -> organization.address as address share orgAddress, address.postalCode = (%item.answer.value) "familydoctorOrganizationPostalCode";\r\n src.item as item where ((linkId.value = 'familydoctor.organization.city') and answer.exists()) -> organization.address as address share orgAddress, address.city = (%item.answer.value) "familydoctorOrganizationCity";\r\n src.item as item where ((linkId.value = 'familydoctor.organization.country') and answer.exists()) -> organization.address as address share orgAddress, address.country = (%item.answer.value) "familydoctorOrganizationCountry";\r\n src.item as item where ((linkId.value = 'familydoctor.organization.gln') and answer.exists()) -> organization.identifier as value, value.system = 'urn:oid:2.51.1.3', value.value = (%item.answer.value) "familydoctorOrganizationGln";\r\n src.item as item where ((linkId.value = 'familydoctor.organization.zsr') and answer.exists()) -> organization.identifier as value, value.system = 'urn:oid:2.16.756.5.30.1.123.100.2.1.1', value.value = (%item.answer.value) "familydoctorOrganizationZsr";\r\n}\r\n\r\ngroup AntecedentEpisodeOfCareInit(source src, target bundle : Bundle, target patient : Patient, target composition : Composition) {\r\n src -> composition.extension as ext, ext.url = 'http://fhir.ch/ig/ch-orf/StructureDefinition/ch-orf-antecedentepisodeofcare', bundle.entry as e4, e4.resource = create('EpisodeOfCare') as episodeofcare, episodeofcare.id = uuid() as uuid4, e4.fullUrl = ('urn:uuid:' + %uuid4), episodeofcare.status = 'finished', ext.value = create('Reference') as ref, ref.reference = ('urn:uuid:' + %episodeofcare.id) then AntecedentEpisodeOfCareItems(src, bundle, patient, episodeofcare) "AntecedentEpisodeOfCareItems";\r\n}\r\n\r\ngroup AntecedentEpisodeOfCareItems(source src, target bundle : Bundle, target tgt : Patient, target episodeofcare : EpisodeOfCare) {\r\n src.item as item where ((linkId.value = 'antecedentEpisodeOfCare.start') and answer.exists()) -> episodeofcare.statusHistory as statusHistory, statusHistory.status = 'finished', statusHistory.period as period, period.start = (%item.answer.value), period.end = (%item.answer.value) then {\r\n src.item as iteme where ((linkId.value = 'antecedentEpisodeOfCare.end') and answer.exists()) -> period.end = (%iteme.answer.value) "antecedentEpisodeOfCareEndNotSameAsStart";\r\n } "antecedentEpisodeOfCareRequestedPeriodStart";\r\n src.item as item where (linkId.value = 'antecedentEpisodeOfCare.managingOrganization') -> bundle.entry as e3, e3.resource = create('Organization') as organization, organization.id = uuid() as uuid3, e3.fullUrl = append('urn:uuid:', uuid3), episodeofcare.patient = create('Reference') as reference, reference.reference = ('urn:uuid:' + %tgt.id), episodeofcare.managingOrganization = create('Reference') as reference, reference.reference = append('urn:uuid:', uuid3) then AntecedentEpisodeOfCareOrganizationItems(item, organization) "antecedentEpisodeOfCareManagingOrganization";\r\n}\r\n\r\ngroup AntecedentEpisodeOfCareOrganizationItems(source src, target organization : Organization) {\r\n src.item as item where ((linkId.value = 'antecedentEpisodeOfCare.managingOrganization.name') and answer.exists()) -> organization.name = (%item.answer.value);\r\n src.item as item where ((linkId.value = 'antecedentEpisodeOfCare.managingOrganization.streetAddressLine') and answer.exists()) -> organization.address as address share orgAddress then {\r\n item.answer as answer -> address.line = (%answer.value) "antecedentEpisodeOfCareorganizationStreetAddressLine";\r\n } "itemAnswer";\r\n src.item as item where ((linkId.value = 'antecedentEpisodeOfCare.managingOrganization.postalCode') and answer.exists()) -> organization.address as address share orgAddress, address.postalCode = (%item.answer.value) "senderAuthorOrganizationPostalCode";\r\n src.item as item where ((linkId.value = 'antecedentEpisodeOfCare.managingOrganization.city') and answer.exists()) -> organization.address as address share orgAddress, address.city = (%item.answer.value) "senderAuthorOrganizationCity";\r\n src.item as item where ((linkId.value = 'antecedentEpisodeOfCare.managingOrganization.country') and answer.exists()) -> organization.address as address share orgAddress, address.country = (%item.answer.value) "senderAuthorOrganizationCountry";\r\n}\r\n\r\ngroup InitiatorInit(source src, target bundle : Bundle, target patient : Patient, target composition : Composition, target serviceRequest : ServiceRequest) {\r\n src -> composition.extension as ext, ext.url = 'http://fhir.ch/ig/ch-orf/StructureDefinition/ch-orf-initiator' then InitiatorItems(src, bundle, patient, ext) "receiver";\r\n}\r\n\r\ngroup PatientItems(source src, target bundle : Bundle, target tgt : Patient, target composition : Composition, target serviceRequest : ServiceRequest) {\r\n src.item as grp where linkId = 'familydoctor' then FamilyDoctorInit(grp, bundle, tgt, composition, serviceRequest) "grpfamily";\r\n src.item as item then PatientItems(item, bundle, tgt, composition, serviceRequest);\r\n src.item as item where ((linkId.value = 'patient.familyName') and answer.exists()) -> tgt.name as name share patientName, name.family = (%item.answer.value);\r\n src.item as item where ((linkId.value = 'patient.maidenName') and answer.exists()) -> tgt.name as name, name.use = 'maiden', name.family = (%item.answer.value);\r\n src.item as item where ((linkId.value = 'patient.givenName') and answer.exists()) -> tgt.name as name share patientName, name.given = (%item.answer.value);\r\n src.item as item where ((linkId.value = 'patient.localPid') and answer.exists()) -> tgt.identifier as value share localpid, value.type as type, type.coding as coding, coding.system = 'http://terminology.hl7.org/CodeSystem/v2-0203', coding.code = 'MR', value.value = (%item.answer.value) "PatientLocalPid";\r\n src.item as item where ((linkId.value = 'patient.localPidDomain') and answer.exists()) -> tgt.identifier as value share localpid, value.system = (%item.answer.value) "PatientLocalPidDomain";\r\n src.item as item where ((linkId.value = 'patient.birthDate') and answer.exists()) -> tgt.birthDate = (%item.answer.value);\r\n src.item as item where ((linkId.value = 'patient.gender') and answer.exists()) -> tgt.gender = (%item.answer.value);\r\n src.item as item where ((linkId.value = 'patient.maritalStatus') and answer.exists()) then {\r\n item.answer as answer then {\r\n answer.value : Coding as coding -> tgt.maritalStatus as maritalStatus, maritalStatus.coding = coding "maritalStatus";\r\n };\r\n } "patientMaritalStatus";\r\n src.item as item where ((linkId.value = 'patient.phone') and answer.exists()) then {\r\n item.answer as answer -> tgt.telecom as value, value.system = 'phone', value.value = (%answer.value) "PatientPhone";\r\n } "PatientPhone";\r\n src.item as item where ((linkId.value = 'patient.email') and answer.exists()) -> tgt.telecom as value, value.system = 'email', value.value = (%item.answer.value) "PatientEmail";\r\n src.item as item where ((linkId.value = 'patient.streetAddressLine') and answer.exists()) -> tgt.address as address share orgAddress then {\r\n item.answer as answer -> address.line = (%answer.value) "PatientStreetAddressLine";\r\n } "itemAnswer";\r\n src.item as item where ((linkId.value = 'patient.postalCode') and answer.exists()) -> tgt.address as address share orgAddress, address.postalCode = (%item.answer.value) "PatientPostalCode";\r\n src.item as item where ((linkId.value = 'patient.city') and answer.exists()) -> tgt.address as address share orgAddress, address.city = (%item.answer.value) "PatientCity";\r\n src.item as item where ((linkId.value = 'patient.country') and answer.exists()) -> tgt.address as address share orgAddress, address.country = (%item.answer.value) "PatientCountry";\r\n src.item as item where ((linkId.value = 'patient.languageOfCorrespondence') and answer.exists()) then {\r\n item.answer as answer then {\r\n answer.value : Coding as coding -> tgt.communication as communication, communication.preferred = true, communication.language as language, language.coding = coding "languageOfCorrespondence";\r\n };\r\n } "PatientLanguageOfCorrespondence";\r\n src.item as item where (linkId.value = 'patient.contactperson') -> tgt.contact as contact then {\r\n item.item as item where ((linkId.value = 'patient.contactperson.familyName') and answer.exists()) -> contact.name as name share contactName, name.family = (%item.answer.value);\r\n item.item as item where ((linkId.value = 'patient.contactperson.givenName') and answer.exists()) -> contact.name as name share contactName, name.given = (%item.answer.value);\r\n src.item as item where ((linkId.value = 'patient.contactperson.phone') and answer.exists()) then {\r\n item.answer as answer -> tgt.telecom as value, value.system = 'phone', value.value = (%answer.value) "PatientPhone";\r\n } "PatientContactpersonPhone";\r\n item.item as item where ((linkId.value = 'patient.contactperson.email') and answer.exists()) -> contact.telecom as value, value.system = 'email', value.value = (%item.answer.value) "PatientEmail";\r\n item.item as item where ((linkId.value = 'patient.contactperson.relationship') and answer.exists()) -> contact.relationship as relationship, relationship.text = (%item.answer.value) "PatientContactpersonRelationship";\r\n } "contact";\r\n}\r\n\r\ngroup RequestedEncounterItems(source src, target bundle : Bundle, target patient : Patient, target serviceRequest : ServiceRequest) {\r\n src -> bundle.entry as e4, e4.resource = create('Encounter') as encounter, encounter.id = uuid() as uuid4, e4.fullUrl = ('urn:uuid:' + %uuid4), encounter.status = 'planned', serviceRequest.extension as extension, encounter.subject = create('Reference') as subject, subject.reference = ('urn:uuid:' + %patient.id), extension.url = 'http://fhir.ch/ig/ch-orf/StructureDefinition/ch-orf-requestedencounterdetails', extension.value = create('Reference') as reference, reference.reference = ('urn:uuid:' + %uuid4) then {\r\n src.item as item where ((linkId.value = 'requestedEncounter.class') and answer.exists()) -> encounter.class = (%item.answer.value) "requestedEncounterClass";\r\n src.item as item where ((linkId.value = 'requestedEncounter.desiredAccommodation') and answer.exists()) -> encounter.extension as extension, extension.url = 'http://fhir.ch/ig/ch-orf/StructureDefinition/ch-orf-desiredaccommodation', extension.value = (%item.answer.value) "requestedEncounterDesiredAccommodation";\r\n } "RequestedEncounterItems";\r\n}\r\n\r\ngroup Coverage(source src, target bundle : Bundle, target patient : Patient, target serviceRequest : ServiceRequest) {\r\n // coverage.beneficiary\r\n // coverage.beneficiary.ahvn13\r\n src.item as item where where(linkId.value = 'coverage.beneficiary') then {\r\n item.item as item where ((linkId.value = 'coverage.beneficiary.ahvn13') and answer.exists()) -> patient.identifier as identifier, identifier.system = 'urn:oid:2.16.756.5.32', identifier.value = (%item.answer.value) "coverageBeneficiaryAhvn13";\r\n } "coverageBeneficiary";\r\n // coverage.kvg\r\n // coverage.kvg.name\r\n // coverage.kvg.insuranceCardNumber\r\n src.item as item where where(linkId.value = 'coverage.kvg') -> bundle.entry as e4, e4.resource = create('Coverage') as coverage, coverage.id = uuid() as uuid4, e4.fullUrl = ('urn:uuid:' + %uuid4), serviceRequest.insurance as insurance, insurance.reference = ('urn:uuid:' + %uuid4), coverage.status = 'active', coverage.beneficiary = create('Reference') as subject, subject.reference = ('urn:uuid:' + %patient.id), coverage.type as type, type.coding as coding, coding.system = 'http://fhir.ch/ig/ch-orf/CodeSystem/ch-orf-cs-coveragetype', coding.code = 'KVG' then {\r\n item.item as item where ((linkId.value = 'coverage.kvg.name') and answer.exists()) -> coverage.payor as payor, payor.reference as refcontained, refcontained.value = '#org', coverage.contained = create('Organization') as organization, organization.id = 'org', organization.name = (%item.answer.value) "coverageKvgName";\r\n item.item as item where ((linkId.value = 'coverage.kvg.insuranceCardNumber') and answer.exists()) -> coverage.identifier as identifier, identifier.type as typeid, typeid.coding as coding, coding.system = 'http://fhir.ch/ig/ch-orf/CodeSystem/ch-orf-cs-coverageidentifiertype', coding.code = 'VeKa', identifier.value = (%item.answer.value) "coverageKvgInsuranceCardNumber";\r\n } "coveragekvg";\r\n // coverage.uvg\tUnfallversicherung (nach UVG)\t0..1\tgroup\t\tDefinition: Coverage.type\r\n // coverage.uvg.name\tName der Versicherung\t0..1\tstring\t\tDefinition: Coverage.payor\r\n // coverage.uvg.claimNumber\tSchadennummer\t0..1\tstring\t\tDefinition: Coverage.identifier\r\n src.item as item where where(linkId.value = 'coverage.uvg') -> bundle.entry as e4, e4.resource = create('Coverage') as coverage, coverage.id = uuid() as uuid4, e4.fullUrl = ('urn:uuid:' + %uuid4), serviceRequest.insurance as insurance, insurance.reference = ('urn:uuid:' + %uuid4), coverage.status = 'active', coverage.beneficiary = create('Reference') as subject, subject.reference = ('urn:uuid:' + %patient.id), coverage.type as type, type.coding as coding, coding.system = 'http://fhir.ch/ig/ch-orf/CodeSystem/ch-orf-cs-coveragetype', coding.code = 'UVG' then {\r\n item.item as item where ((linkId.value = 'coverage.uvg.name') and answer.exists()) -> coverage.payor as payor, payor.reference as refcontained, refcontained.value = '#org', coverage.contained = create('Organization') as organization, organization.id = 'org', organization.name = (%item.answer.value) "coverageUvgName";\r\n item.item as item where ((linkId.value = 'coverage.uvg.claimNumber') and answer.exists()) -> coverage.identifier as identifier, identifier.type as typeid, typeid.coding as coding, coding.system = 'http://fhir.ch/ig/ch-orf/CodeSystem/ch-orf-cs-coverageidentifiertype', coding.code = 'Claim', identifier.value = (%item.answer.value) "coverageUvgClaimNumber";\r\n } "coverageuvg";\r\n // coverage.vvg\tZusatzversicherung (nach VVG)\t0..1\tgroup\t\tDefinition: Coverage.type\r\n // coverage.vvg.name\tName der Versicherung\t0..1\tstring\t\tDefinition: Coverage.payor\r\n // coverage.vvg.insuranceCardNumber\tKennnummer der Versichertenkarte\t0..1\tstring\t\tDefinition: Coverage.identifier\r\n src.item as item where where(linkId.value = 'coverage.vvg') -> bundle.entry as e4, e4.resource = create('Coverage') as coverage, coverage.id = uuid() as uuid4, e4.fullUrl = ('urn:uuid:' + %uuid4), serviceRequest.insurance as insurance, insurance.reference = ('urn:uuid:' + %uuid4), coverage.status = 'active', coverage.beneficiary = create('Reference') as subject, subject.reference = ('urn:uuid:' + %patient.id), coverage.type as type, type.coding as coding, coding.system = 'http://fhir.ch/ig/ch-orf/CodeSystem/ch-orf-cs-coveragetype', coding.code = 'VVG' then {\r\n item.item as item where ((linkId.value = 'coverage.vvg.name') and answer.exists()) -> coverage.payor as payor, payor.reference as refcontained, refcontained.value = '#org', coverage.contained = create('Organization') as organization, organization.id = 'org', organization.name = (%item.answer.value) "coverageVvgName";\r\n item.item as item where ((linkId.value = 'coverage.vvg.insuranceCardNumber') and answer.exists()) -> coverage.identifier as identifier, identifier.type as typeid, typeid.coding as coding, coding.system = 'http://fhir.ch/ig/ch-orf/CodeSystem/ch-orf-cs-coverageidentifiertype', coding.code = 'VeKa', identifier.value = (%item.answer.value) "coverageVvgInsuranceCardNumber";\r\n } "coveragevvg";\r\n // coverage.iv\tInvalidenversicherung (IV)\t0..1\tgroup\t\tDefinition: Coverage.type\r\n // coverage.iv.verfuegungsnummer\r\n src.item as item where where(linkId.value = 'coverage.iv') -> bundle.entry as e4, e4.resource = create('Coverage') as coverage, coverage.id = uuid() as uuid4, e4.fullUrl = ('urn:uuid:' + %uuid4), serviceRequest.insurance as insurance, insurance.reference = ('urn:uuid:' + %uuid4), coverage.status = 'active', coverage.beneficiary = create('Reference') as subject, subject.reference = ('urn:uuid:' + %patient.id), coverage.type as type, type.coding as coding, coding.system = 'http://fhir.ch/ig/ch-orf/CodeSystem/ch-orf-cs-coveragetype', coding.code = 'IVG' then {\r\n item.item as item where ((linkId.value = 'coverage.iv.verfuegungsnummer') and answer.exists()) -> coverage.identifier as identifier, identifier.type as typeid, typeid.coding as coding, coding.system = 'http://fhir.ch/ig/ch-orf/CodeSystem/ch-orf-cs-coverageidentifiertype', coding.code = 'IV', identifier.value = (%item.answer.value), coverage.payor as payor, payor.reference as refcontained, refcontained.value = '#org', coverage.contained = create('Organization') as organization, organization.id = 'org', organization.name = 'IV' "coverageivverfuegungsnummer";\r\n } "coverageiv";\r\n // coverage.mv\tMilitärversicherung (MV)\t0..1\tgroup\t\tDefinition: Coverage.type\r\n // coverage.mv.versichertennummer\r\n src.item as item where where(linkId.value = 'coverage.mv') -> bundle.entry as e4, e4.resource = create('Coverage') as coverage, coverage.id = uuid() as uuid4, e4.fullUrl = ('urn:uuid:' + %uuid4), serviceRequest.insurance as insurance, insurance.reference = ('urn:uuid:' + %uuid4), coverage.status = 'active', coverage.beneficiary = create('Reference') as subject, subject.reference = ('urn:uuid:' + %patient.id), coverage.type as type, type.coding as coding, coding.system = 'http://fhir.ch/ig/ch-orf/CodeSystem/ch-orf-cs-coveragetype', coding.code = 'MVG' then {\r\n item.item as item where ((linkId.value = 'coverage.mv.versichertennummer') and answer.exists()) -> coverage.identifier as identifier, identifier.type as typeid, typeid.coding as coding, coding.system = 'http://fhir.ch/ig/ch-orf/CodeSystem/ch-orf-cs-coverageidentifiertype', coding.code = 'MV', identifier.value = (%item.answer.value), coverage.payor as payor, payor.reference as refcontained, refcontained.value = '#org', coverage.contained = create('Organization') as organization, organization.id = 'org', organization.name = 'MV' "coveragemvversichertennummer";\r\n } "coveragemv";\r\n // coverage.self\tSelbstzahler\t0..1\tgroup\t\tDefinition: Coverage.type\r\n // coverage.self.familyName\tName\t0..1\tstring\t\tDefinition: Coverage.payor\r\n // coverage.self.givenName\tVorname\t0..1\tstring\t\tDefinition: Coverage.payor\r\n src.item as item where where(linkId.value = 'coverage.self') then {\r\n item.item as item where ((linkId.value = 'coverage.self.patient') and answer.exists() and answer.value) -> bundle.entry as e4, e4.resource = create('Coverage') as coverage, coverage.id = uuid() as uuid4, e4.fullUrl = ('urn:uuid:' + %uuid4), serviceRequest.insurance as insurance, insurance.reference = ('urn:uuid:' + %uuid4), coverage.status = 'active', coverage.beneficiary = create('Reference') as subject, subject.reference = ('urn:uuid:' + %patient.id), coverage.type as type, type.coding as coding, coding.system = 'http://fhir.ch/ig/ch-orf/CodeSystem/ch-orf-cs-coveragetype', coding.code = 'Self', coverage.payor as subject, subject.reference = ('urn:uuid:' + %patient.id) "payor";\r\n item.item as item2 where ((linkId.value = 'coverage.self.patientRelatedPerson') and answer.exists() and answer.value) then {\r\n item.item as item where (linkId.value = 'coverage.self.relatedPerson') -> bundle.entry as e5, e5.resource = create('Coverage') as coverage, coverage.id = uuid() as uuid4, e5.fullUrl = ('urn:uuid:' + %uuid4), serviceRequest.insurance as insurance, insurance.reference = ('urn:uuid:' + %uuid4), coverage.status = 'active', coverage.beneficiary = create('Reference') as subject, subject.reference = ('urn:uuid:' + %patient.id), coverage.type as type, type.coding as coding, coding.system = 'http://fhir.ch/ig/ch-orf/CodeSystem/ch-orf-cs-coveragetype', coding.code = 'Self', bundle.entry as e6, e6.resource = create('RelatedPerson') as relatedPerson, relatedPerson.id = uuid() as uuid6, e6.fullUrl = append('urn:uuid:', uuid6), coverage.payor as subject, subject.reference = ('urn:uuid:' + %relatedPerson.id), relatedPerson.patient as reference, reference.reference = ('urn:uuid:' + %patient.id) then CoverageRelatedPersonItems(item, relatedPerson) "coverageselfrelatedPerson";\r\n } "coverageselfpatientrelated";\r\n } "self";\r\n // coverage.other\tAnderer Kostenträger\t0..1\tgroup\t\tDefinition: Coverage.type\r\n // coverage.other.name\tName des Kostenträgers\t0..1\tstring\t\tDefinition: Coverage.payor\r\n // coverage.other.id\tBeliebige ID\t0..1\tstring\t\tDefinition: Coverage.identifier\r\n // coverage.other.id.note TODO\r\n src.item as item where where(linkId.value = 'coverage.other') -> bundle.entry as e4, e4.resource = create('Coverage') as coverage, coverage.id = uuid() as uuid4, e4.fullUrl = ('urn:uuid:' + %uuid4), serviceRequest.insurance as insurance, insurance.reference = ('urn:uuid:' + %uuid4), coverage.status = 'active', coverage.beneficiary = create('Reference') as subject, subject.reference = ('urn:uuid:' + %patient.id), coverage.type as type, type.coding as coding, coding.system = 'http://fhir.ch/ig/ch-orf/CodeSystem/ch-orf-cs-coveragetype', coding.code = 'Other' then {\r\n item.item as item where ((linkId.value = 'coverage.other.name') and answer.exists()) -> coverage.payor as payor, payor.reference as refcontained, refcontained.value = '#org', coverage.contained = create('Organization') as organization, organization.id = 'org', organization.name = (%item.answer.value) "coverageOtherName";\r\n item.item as item where ((linkId.value = 'coverage.other.id') and answer.exists()) -> coverage.identifier as identifier, identifier.value = (%item.answer.value) "coverageOtherId";\r\n } "coveragevvg";\r\n}\r\n\r\ngroup CoverageRelatedPersonItems(source src, target relatedPerson : RelatedPerson) {\r\n src.item as item where ((linkId.value = 'coverage.self.relatedPerson.familyName') and answer.exists()) -> relatedPerson.name as name share name, name.family = (%item.answer.value);\r\n src.item as item where ((linkId.value = 'coverage.self.relatedPerson.givenName') and answer.exists()) -> relatedPerson.name as name share name, name.given = (%item.answer.value);\r\n src.item as item where ((linkId.value = 'coverage.self.relatedPerson.phone') and answer.exists()) then {\r\n item.answer as answer -> relatedPerson.telecom as value, value.system = 'phone', value.value = (%answer.value) "coverageSelfRelatedPersonPhone";\r\n } "Phone";\r\n src.item as item where ((linkId.value = 'coverage.self.relatedPerson.email') and answer.exists()) -> relatedPerson.telecom as value, value.system = 'email', value.value = (%item.answer.value) "coverageSelfRelatedPersonEmail";\r\n src.item as item where ((linkId.value = 'coverage.self.relatedPerson.streetAddressLine') and answer.exists()) -> relatedPerson.address as address share orgAddress then {\r\n item.answer as answer -> address.line = (%answer.value) "coverageSelfRelatedPersonStreetAddressLine";\r\n } "itemAnswer";\r\n src.item as item where ((linkId.value = 'coverage.self.relatedPerson.postalCode') and answer.exists()) -> relatedPerson.address as address share orgAddress, address.postalCode = (%item.answer.value) "coverageSelfRelatedPersonPostalCode";\r\n src.item as item where ((linkId.value = 'coverage.self.relatedPerson.city') and answer.exists()) -> relatedPerson.address as address share orgAddress, address.city = (%item.answer.value) "coverageSelfRelatedPersonCity";\r\n src.item as item where ((linkId.value = 'coverage.self.relatedPerson.country') and answer.exists()) -> relatedPerson.address as address share orgAddress, address.country = (%item.answer.value) "coverageSelfRelatedPersonCountry";\r\n}\r\n\r\ngroup SenderAuthorPractitionerItems(source src, target practitioner : Practitioner) {\r\n src.item as item where ((linkId.value = 'sender.author.practitioner.familyName') and answer.exists()) -> practitioner.name as name share practitionerName, name.family = (%item.answer.value);\r\n src.item as item where ((linkId.value = 'sender.author.practitioner.givenName') and answer.exists()) -> practitioner.name as name share practitionerName, name.given = (%item.answer.value);\r\n src.item as item where ((linkId.value = 'sender.author.practitioner.title') and answer.exists()) -> practitioner.name as name share practitionerName, name.prefix = (%item.answer.value) as prefix, prefix.extension as ext, ext.url = 'http://hl7.org/fhir/StructureDefinition/iso21090-EN-qualifier', ext.value = create('code') as value, value.value = 'AC' "senderAuthorPractitionerTitle";\r\n src.item as item where ((linkId.value = 'sender.author.practitioner.gln') and answer.exists()) -> practitioner.identifier as value, value.system = 'urn:oid:2.51.1.3', value.value = (%item.answer.value) "senderAuthorPractitionerGln";\r\n src.item as item where ((linkId.value = 'sender.author.practitioner.zsr') and answer.exists()) -> practitioner.identifier as value, value.system = 'urn:oid:2.16.756.5.30.1.123.100.2.1.1', value.value = (%item.answer.value) "senderAuthorPractitionerZsr";\r\n src.item as item where ((linkId.value = 'sender.author.practitioner.phone') and answer.exists()) -> practitioner.telecom as value, value.system = 'phone', value.value = (%item.answer.value) "senderAuthorPractitionerPhone";\r\n src.item as item where ((linkId.value = 'sender.author.practitioner.email') and answer.exists()) -> practitioner.telecom as value, value.system = 'email', value.value = (%item.answer.value) "senderAuthorPractitionerEmail";\r\n}\r\n\r\ngroup SenderAuthorOrganizationItems(source src, target organization : Organization) {\r\n src.item as item where ((linkId.value = 'sender.author.organization.name') and answer.exists()) -> organization.name = (%item.answer.value);\r\n src.item as item where ((linkId.value = 'sender.author.organization.gln') and answer.exists()) -> organization.identifier as value, value.system = 'urn:oid:2.51.1.3', value.value = (%item.answer.value) "senderAuthorOrganizationGln";\r\n src.item as item where ((linkId.value = 'sender.author.organization.zsr') and answer.exists()) -> organization.identifier as value, value.system = 'urn:oid:2.16.756.5.30.1.123.100.2.1.1', value.value = (%item.answer.value) "senderAuthorOrganizationZsr";\r\n src.item as item where ((linkId.value = 'sender.author.organization.streetAddressLine') and answer.exists()) -> organization.address as address share orgAddress then {\r\n item.answer as answer -> address.line = (%answer.value) "senderAuthorOrganizationStreetAddressLine";\r\n } "itemAnswer";\r\n src.item as item where ((linkId.value = 'sender.author.organization.postalCode') and answer.exists()) -> organization.address as address share orgAddress, address.postalCode = (%item.answer.value) "senderAuthorOrganizationPostalCode";\r\n src.item as item where ((linkId.value = 'sender.author.organization.city') and answer.exists()) -> organization.address as address share orgAddress, address.city = (%item.answer.value) "senderAuthorOrganizationCity";\r\n src.item as item where ((linkId.value = 'sender.author.organization.country') and answer.exists()) -> organization.address as address share orgAddress, address.country = (%item.answer.value) "senderAuthorOrganizationCountry";\r\n}\r\n\r\ngroup SenderAuthorItems(source src, target practitionerRole : PractitionerRole, target practitioner : Practitioner, target organization : Organization) {\r\n src.item as item where (linkId.value = 'sender.author.practitioner') then SenderAuthorPractitionerItems(item, practitioner);\r\n src.item as item where (linkId.value = 'sender.author.organization') then SenderAuthorOrganizationItems(item, organization);\r\n}\r\n\r\ngroup SenderDataEntererPractitionerItems(source src, target practitioner : Practitioner) {\r\n src.item as item where ((linkId.value = 'sender.dataenterer.practitioner.familyName') and answer.exists()) -> practitioner.name as name share practitionerName, name.family = (%item.answer.value);\r\n src.item as item where ((linkId.value = 'sender.dataenterer.practitioner.givenName') and answer.exists()) -> practitioner.name as name share practitionerName, name.given = (%item.answer.value);\r\n src.item as item where ((linkId.value = 'sender.dataenterer.practitioner.phone') and answer.exists()) -> practitioner.telecom as value, value.system = 'phone', value.value = (%item.answer.value) "senderAuthorPractitionerPhone";\r\n src.item as item where ((linkId.value = 'sender.dataenterer.practitioner.email') and answer.exists()) -> practitioner.telecom as value, value.system = 'email', value.value = (%item.answer.value) "senderAuthorPractitionerEmail";\r\n}\r\n\r\ngroup SenderDataEntererItems(source src, target practitionerRole : PractitionerRole, target practitioner : Practitioner, target organization : Organization) {\r\n src.item as item where (linkId.value = 'sender.dataenterer.practitioner') then SenderDataEntererPractitionerItems(item, practitioner);\r\n}\r\n\r\ngroup ChExtEprDataEnterer(source src, target practitionerRole : PractitionerRole, target ext : Extension) {\r\n src -> ext.url = 'http://fhir.ch/ig/ch-core/StructureDefinition/ch-ext-epr-dataenterer' "url";\r\n src -> ext.extension as ext, ext.url = 'enterer', ext.value = create('Reference') as reference, reference.reference = ('urn:uuid:' + %practitionerRole.id) "practitionerRole";\r\n}\r\n\r\ngroup SenderAuthorInit(source src, target bundle : Bundle, target composition : Composition, target serviceRequest : ServiceRequest) {\r\n src -> bundle.entry as e, e.resource = create('PractitionerRole') as practitionerRole, practitionerRole.id = uuid() as uuid, e.fullUrl = append('urn:uuid:', uuid), bundle.entry as e2, e2.resource = create('Practitioner') as practitioner, practitioner.id = uuid() as uuid2, e2.fullUrl = append('urn:uuid:', uuid2), bundle.entry as e3, e3.resource = create('Organization') as organization, organization.id = uuid() as uuid3, e3.fullUrl = append('urn:uuid:', uuid3), composition.author = create('Reference') as reference, reference.reference = append('urn:uuid:', uuid), serviceRequest.requester = create('Reference') as reference, reference.reference = append('urn:uuid:', uuid), practitionerRole.practitioner = create('Reference') as reference, reference.reference = append('urn:uuid:', uuid2), practitionerRole.organization = create('Reference') as reference, reference.reference = append('urn:uuid:', uuid3) then {\r\n src.item as item where (linkId.value = 'sender.author') then SenderAuthorItems(item, practitionerRole, practitioner, organization) "senderAuthor";\r\n src.item as item where (linkId.value = 'sender.dataenterer') then {\r\n item -> bundle.entry as e4, e4.resource = create('PractitionerRole') as practitionerRoleDataEnterer, practitionerRoleDataEnterer.id = uuid() as uuid4, e4.fullUrl = append('urn:uuid:', uuid4), composition.extension as extension, bundle.entry as e5, e5.resource = create('Practitioner') as practitionerDataEnterer, practitionerDataEnterer.id = uuid() as uuid5, e5.fullUrl = append('urn:uuid:', uuid5), practitionerRoleDataEnterer.practitioner = create('Reference') as reference, reference.reference = append('urn:uuid:', uuid5), practitionerRoleDataEnterer.organization = create('Reference') as reference, reference.reference = append('urn:uuid:', uuid3) then {\r\n item then SenderDataEntererItems(item, practitionerRoleDataEnterer, practitionerDataEnterer, organization) "data";\r\n item then ChExtEprDataEnterer(item, practitionerRoleDataEnterer, extension) "extension";\r\n } "senderDataentererItems";\r\n } "senderDataenterer";\r\n } "sender";\r\n}\r\n\r\ngroup ReceiverCopyRelatedPersonItems(source src, target relatedPerson : RelatedPerson) {\r\n src.item as item where ((linkId.value = 'receiverCopy.relatedPerson.familyName') and answer.exists()) -> relatedPerson.name as name share name, name.family = (%item.answer.value);\r\n src.item as item where ((linkId.value = 'receiverCopy.relatedPerson.givenName') and answer.exists()) -> relatedPerson.name as name share name, name.given = (%item.answer.value);\r\n src.item as item where ((linkId.value = 'receiverCopy.relatedPerson.phone') and answer.exists()) then {\r\n item.answer as answer -> relatedPerson.telecom as value, value.system = 'phone', value.value = (%answer.value) "receiverCopyRelatedPersonPhone";\r\n } "Phone";\r\n src.item as item where ((linkId.value = 'receiverCopy.relatedPerson.email') and answer.exists()) -> relatedPerson.telecom as value, value.system = 'email', value.value = (%item.answer.value) "receiverCopyRelatedPersonEmail";\r\n src.item as item where ((linkId.value = 'receiverCopy.relatedPerson.streetAddressLine') and answer.exists()) -> relatedPerson.address as address share orgAddress then {\r\n item.answer as answer -> address.line = (%answer.value) "receiverCopyRelatedPersonStreetAddressLine";\r\n } "itemAnswer";\r\n src.item as item where ((linkId.value = 'receiverCopy.relatedPerson.postalCode') and answer.exists()) -> relatedPerson.address as address share orgAddress, address.postalCode = (%item.answer.value) "receiverCopyRelatedPersonPostalCode";\r\n src.item as item where ((linkId.value = 'receiverCopy.relatedPerson.city') and answer.exists()) -> relatedPerson.address as address share orgAddress, address.city = (%item.answer.value) "receiverCopyRelatedPersonCity";\r\n src.item as item where ((linkId.value = 'receiverCopy.relatedPerson.country') and answer.exists()) -> relatedPerson.address as address share orgAddress, address.country = (%item.answer.value) "receiverCopyRelatedPersonCountry";\r\n}\r\n\r\ngroup ReceiverCopyPractitionerItems(source src, target practitioner : Practitioner) {\r\n src.item as item where ((linkId.value = 'receiverCopy.practitionerRole.practitioner.familyName') and answer.exists()) -> practitioner.name as name share practitionerName, name.family = (%item.answer.value);\r\n src.item as item where ((linkId.value = 'receiverCopy.practitionerRole.practitioner.givenName') and answer.exists()) -> practitioner.name as name share practitionerName, name.given = (%item.answer.value);\r\n src.item as item where ((linkId.value = 'receiverCopy.practitionerRole.practitioner.title') and answer.exists()) -> practitioner.name as name share practitionerName, name.prefix = (%item.answer.value) as prefix, prefix.extension as ext, ext.url = 'http://hl7.org/fhir/StructureDefinition/iso21090-EN-qualifier', ext.value = create('code') as value, value.value = 'AC' "receiverCopyPractitionerRolePractitionerTitle";\r\n src.item as item where ((linkId.value = 'receiverCopy.practitionerRole.practitioner.phone') and answer.exists()) -> practitioner.telecom as value, value.system = 'phone', value.value = (%item.answer.value) "receiverCopyPractitionerRolePractitionerPhone";\r\n src.item as item where ((linkId.value = 'receiverCopy.practitionerRole.practitioner.email') and answer.exists()) -> practitioner.telecom as value, value.system = 'email', value.value = (%item.answer.value) "receiverCopyPractitionerRolePractitionerEmail";\r\n}\r\n\r\ngroup ReceiverCopyOrganizationItems(source src, target organization : Organization) {\r\n src.item as item where ((linkId.value = 'receiverCopy.practitionerRole.organization.name') and answer.exists()) -> organization.name = (%item.answer.value);\r\n src.item as item where ((linkId.value = 'receiverCopy.practitionerRole.organization.streetAddressLine') and answer.exists()) -> organization.address as address share orgAddress then {\r\n item.answer as answer -> address.line = (%answer.value) "receiverCopyPractitionerRoleOrganizationStreetAddressLine";\r\n } "itemAnswer";\r\n src.item as item where ((linkId.value = 'receiverCopy.practitionerRole.organization.postalCode') and answer.exists()) -> organization.address as address share orgAddress, address.postalCode = (%item.answer.value) "receiverCopyPractitionerRoleOrganizationPostalCode";\r\n src.item as item where ((linkId.value = 'receiverCopy.practitionerRole.organization.city') and answer.exists()) -> organization.address as address share orgAddress, address.city = (%item.answer.value) "receiverCopyPractitionerRoleOrganizationCity";\r\n src.item as item where ((linkId.value = 'receiverCopy.practitionerRole.organization.country') and answer.exists()) -> organization.address as address share orgAddress, address.country = (%item.answer.value) "receiverCopyPractitionerRoleOrganizationCountry";\r\n}\r\n\r\ngroup ReceiverCopyPractitionerRoleItems(source src, target bundle : Bundle, target practitionerRole : PractitionerRole) {\r\n src.item as item where (linkId.value = 'receiverCopy.practitionerRole.practitioner') -> bundle.entry as e2, e2.resource = create('Practitioner') as practitioner, practitioner.id = uuid() as uuid2, practitionerRole.practitioner = create('Reference') as reference, reference.reference = append('urn:uuid:', uuid2), e2.fullUrl = append('urn:uuid:', uuid2) then ReceiverCopyPractitionerItems(item, practitioner);\r\n src.item as item where (linkId.value = 'receiverCopy.practitionerRole.organization') -> bundle.entry as e3, e3.resource = create('Organization') as organization, organization.id = uuid() as uuid3, practitionerRole.organization = create('Reference') as reference, reference.reference = append('urn:uuid:', uuid3), e3.fullUrl = append('urn:uuid:', uuid3) then ReceiverCopyOrganizationItems(item, organization);\r\n}\r\n\r\ngroup ExtOrfCopyReceiverPatient(source src, target patient : Patient, target ext : Extension) {\r\n src -> ext.url = 'http://fhir.ch/ig/ch-orf/StructureDefinition/ch-orf-copyreceiver' "url";\r\n src -> ext.value = create('Reference') as reference, reference.reference = ('urn:uuid:' + %patient.id) "patient";\r\n}\r\n\r\ngroup ExtOrfCopyReceiverPractitionerRole(source src, target res : PractitionerRole, target ext : Extension) {\r\n src -> ext.url = 'http://fhir.ch/ig/ch-orf/StructureDefinition/ch-orf-copyreceiver' "url";\r\n src -> ext.value = create('Reference') as reference, reference.reference = ('urn:uuid:' + %res.id) "organization";\r\n}\r\n\r\ngroup ExtOrfCopyReceiverRelatedPerson(source src, target res : RelatedPerson, target ext : Extension) {\r\n src -> ext.url = 'http://fhir.ch/ig/ch-orf/StructureDefinition/ch-orf-copyreceiver' "url";\r\n src -> ext.value = create('Reference') as reference, reference.reference = ('urn:uuid:' + %res.id) "organization";\r\n}\r\n\r\ngroup ReceiverCopy(source grp, target bundle : Bundle, target patient : Patient, target composition : Composition, target serviceRequest : ServiceRequest) {\r\n grp.item as item where (linkId = 'receiverCopy.practitionerRole') -> bundle.entry as e4, e4.resource = create('PractitionerRole') as practitionerrole, composition.extension as extension, practitionerrole.id = uuid() as uuid4, e4.fullUrl = append('urn:uuid:', uuid4) then {\r\n item then ReceiverCopyPractitionerRoleItems(item, bundle, practitionerrole) "data";\r\n item then ExtOrfCopyReceiverPractitionerRole(item, practitionerrole, extension) "extension";\r\n } "receiverCopyPractitionerRole1";\r\n grp.item as item where (linkId = 'receiverCopy.patient') -> composition.extension as extension then {\r\n item then ExtOrfCopyReceiverPatient(item, patient, extension) "extension";\r\n } "receiverCopyPatient";\r\n grp.item as item where (linkId = 'receiverCopy.relatedPerson') -> bundle.entry as e4, e4.resource = create('RelatedPerson') as relatedPerson, composition.extension as extension, relatedPerson.id = uuid() as uuid4, relatedPerson.patient as reference, reference.reference = ('urn:uuid:' + %patient.id), e4.fullUrl = append('urn:uuid:', uuid4) then {\r\n item then ReceiverCopyRelatedPersonItems(item, relatedPerson) "data";\r\n item then ExtOrfCopyReceiverRelatedPerson(item, relatedPerson, extension) "extension";\r\n } "receiverCopyRelatedPerson";\r\n}\r\n\r\ngroup Appointment(source grp, target bundle : Bundle, target composition : Composition, target serviceRequest : ServiceRequest) {\r\n grp -> bundle.entry as e4, e4.resource = create('Appointment') as appointment, appointment.id = uuid() as uuid4, e4.fullUrl = ('urn:uuid:' + %uuid4), serviceRequest.extension as extension, extension.url = 'http://fhir.ch/ig/ch-orf/StructureDefinition/ch-orf-locationandtime', extension.value = create('Reference') as reference, reference.reference = ('urn:uuid:' + %uuid4) then {\r\n grp.item as item where ((linkId.value = 'appointment.status') and (answer.value = 'proposed')) -> appointment.status = (%item.answer.value) then {\r\n grp.item as itemp where (linkId.value = 'appointment.requestedPeriod') then {\r\n itemp.item as item2 where ((linkId.value = 'appointment.requestedPeriod.start') and answer.exists()) -> appointment.requestedPeriod as requestedPeriod, requestedPeriod.start = (%item2.answer.value), requestedPeriod.end = (%item2.answer.value) then {\r\n itemp.item as item3 where ((linkId.value = 'appointment.requestedPeriod.end') and answer.exists()) -> requestedPeriod.end = (%item3.answer.value) "appointmentRequestedPeriodendifnotsameasstart";\r\n } "appointmentRequestedPeriodStart";\r\n } "appointmentRequestedPeriod";\r\n } "proposed";\r\n grp.item as item where ((linkId.value = 'appointment.status') and ((answer.value = 'pending') or (answer.value = 'booked'))) -> appointment.status = (%item.answer.value) then {\r\n grp.item as itemp where (linkId.value = 'appointment.requestedPeriod') then {\r\n itemp.item as item2 where ((linkId.value = 'appointment.requestedPeriod.start') and answer.exists()) -> appointment.start = (%item2.answer.value), appointment.end = (%item2.answer.value) then {\r\n itemp.item as item3 where ((linkId.value = 'appointment.requestedPeriod.end') and answer.exists()) -> appointment.end = (%item3.answer.value) "appointmentendifnotsameasstart";\r\n } "appointmentStart";\r\n } "appointmentStartend";\r\n } "pendingorbooked";\r\n grp.item as item where ((linkId.value = 'appointment.patientInstruction') and answer.exists()) -> appointment.patientInstruction = (%item.answer.value) "appointmentPatientInstruction";\r\n grp.item as item where (linkId.value = 'appointment.location') then {\r\n item -> bundle.entry as e5, e5.resource = create('Location') as location, location.id = uuid() as uuid5, e5.fullUrl = ('urn:uuid:' + %uuid5), appointment.participant as participant, participant.status = 'tentative', participant.actor = create('Reference') as actor, actor.reference = ('urn:uuid:' + %location.id) then {\r\n item.item as item3 where ((linkId.value = 'appointment.location.name') and answer.exists()) -> location.name = (%item3.answer.value);\r\n item.item as item3 where ((linkId.value = 'appointment.location.phone') and answer.exists()) -> location.telecom as value, value.system = 'phone', value.value = (%item3.answer.value) "appointmentLocationPhone";\r\n item.item as item3 where ((linkId.value = 'appointment.location.email') and answer.exists()) -> location.telecom as value, value.system = 'email', value.value = (%item3.answer.value) "appointmentLocationEmail";\r\n item.item as item3 where ((linkId.value = 'appointment.location.streetAddressLine') and answer.exists()) -> location.address as address share orgAddress then {\r\n item.answer as answer -> address.line = (%answer.value) "line";\r\n } "appointmentLocationStreetAddressLine";\r\n item.item as item3 where ((linkId.value = 'appointment.location.postalCode') and answer.exists()) -> location.address as address share orgAddress, address.postalCode = (%item3.answer.value) "appointmentLocationPostalCode";\r\n item.item as item3 where ((linkId.value = 'appointment.location.city') and answer.exists()) -> location.address as address share orgAddress, address.city = (%item3.answer.value) "appointmentlocationCity";\r\n item.item as item3 where ((linkId.value = 'appointment.location.country') and answer.exists()) -> location.address as address share orgAddress, address.country = (%item3.answer.value) "appointmentLocationCountry";\r\n } "location";\r\n } "appointmentLocation";\r\n } "Appointment";\r\n}\r\n\r\ngroup PreviousResults(source grp, target bundle : Bundle, target serviceRequest : ServiceRequest) {\r\n grp.item as item where ((linkId = 'previousResults.attachment') and answer.exists()) then {\r\n item.answer as answer then {\r\n answer.value : Attachment as attachment -> bundle.entry as e, e.resource = create('Media') as media, media.id = uuid() as uuid, media.status = 'completed', e.fullUrl = append('urn:uuid:', uuid), media.content = attachment, serviceRequest.supportingInfo as supportingInfo, supportingInfo.reference = ('urn:uuid:' + %uuid) "media";\r\n };\r\n };\r\n}\r\n\r\ngroup Note(source grp, target serviceRequest : ServiceRequest) {\r\n grp.item as item where ((linkId = 'note.text') and answer.exists()) -> serviceRequest.note as note, note.text = (%item.answer.value) "noteText";\r\n}\r\n\r\ngroup QrToBundle(source qr : QuestionnaireResponseSource, target patient : Patient, target questionnaireresp : QuestionnaireResponse, target servicerequest : ServiceRequest, target composition : Composition, target bundle : Bundle) {\r\n // group QrToBundle(source qr : QuestionnaireResponseSource, target q: Questionnaire, target patient : Patient, target questionnaireresp: QuestionnaireResponse, target servicerequest: ServiceRequest, target composition : Composition, target bundle : Bundle) {\r\n qr -> bundle.id = uuid() "id";\r\n qr -> bundle.type = 'document' "type";\r\n qr then OrfComposition(qr, composition, patient, questionnaireresp, servicerequest, bundle) "composition";\r\n qr then QrToGroups(qr, patient, bundle, composition, servicerequest) "qrgroups";\r\n}\r\n\r\n// group OrfComposition(source qr : QuestionnaireResponseSource, target q: Questionnaire, target tgt : Composition, target patient: Patient, target questionnaireresp: QuestionnaireResponse, target servicerequest: ServiceRequest, target bundle : Bundle) {\r\ngroup OrfComposition(source qr : QuestionnaireResponseSource, target tgt : Composition, target patient : Patient, target questionnaireresp : QuestionnaireResponse, target servicerequest : ServiceRequest, target bundle : Bundle) {\r\n qr -> tgt.status = 'final' "status";\r\n qr -> tgt.subject = create('Reference') as reference, reference.reference = ('urn:uuid:' + %patient.id) "subject";\r\n qr -> tgt.section as tgtSection, tgtSection.title = 'Order-Referral', tgtSection.code as code, code.coding as coding, coding.system = 'http://loinc.org', coding.code = '93037-0', coding.display = 'Portable medical order form', tgtSection.entry = create('Reference') as reference, reference.reference = ('urn:uuid:' + %questionnaireresp.id), tgtSection.entry = create('Reference') as reference, reference.reference = ('urn:uuid:' + %servicerequest.id) "sections";\r\n // ,\r\n // tgtSection.entry = create('Reference') as reference, reference.reference = (%q.url) "sections";\r\n qr -> servicerequest.status = 'active', servicerequest.intent = 'order', servicerequest.subject = create('Reference') as reference, reference.reference = ('urn:uuid:' + %patient.id) "servicerequest";\r\n}\r\n\r\n