apiVersion: camel.apache.org/v1alpha1
kind: Kamelet
metadata:
  name: fhir-sink
  annotations:
    camel.apache.org/kamelet.support.level: "Stable"
    camel.apache.org/catalog.version: "3.21.0"
    camel.apache.org/kamelet.icon: "data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAxOTUuMiAzMDAiPjxzdHlsZT48L3N0eWxlPjxnIGlkPSJMYXllcl8yIj48bGluZWFyR3JhZGllbnQgaWQ9IlNWR0lEXzFfIiBncmFkaWVudFVuaXRzPSJ1c2VyU3BhY2VPblVzZSIgeDE9IjYyLjY0NCIgeTE9IjI2OC4yMDEiIHgyPSIzMC43MjEiIHkyPSI4Ny4xNTUiPjxzdG9wIG9mZnNldD0iLjE1NCIgc3RvcC1jb2xvcj0iI2ZmZTQwZSIvPjxzdG9wIG9mZnNldD0iLjkxIiBzdG9wLWNvbG9yPSIjZTEwZTE5Ii8+PC9saW5lYXJHcmFkaWVudD48cGF0aCBkPSJNNzkuNiA3OC41bC00NCAzOC41Uy04IDE1MS43IDEuMyAyMDUuOWMwIDAgMi45IDI5LjIgNDMuMyA2NS41IDAgMC0zMy00MS4xLTI2LjYtOTAuMlM3OS4zIDgzLjcgNzkuNiA3OC41eiIgZmlsbD0idXJsKCNTVkdJRF8xXykiLz48bGluZWFyR3JhZGllbnQgaWQ9IlNWR0lEXzJfIiBncmFkaWVudFVuaXRzPSJ1c2VyU3BhY2VPblVzZSIgeDE9Ijg0LjI3MiIgeTE9IjI5OC4xNjciIHgyPSI4NC4yNzIiIHkyPSIwIj48c3RvcCBvZmZzZXQ9Ii4xNTQiIHN0b3AtY29sb3I9IiNmZmU0MGUiLz48c3RvcCBvZmZzZXQ9Ii4xOTciIHN0b3AtY29sb3I9IiNmZWRiMGUiLz48c3RvcCBvZmZzZXQ9Ii4yNjciIHN0b3AtY29sb3I9IiNmYWMzMTAiLz48c3RvcCBvZmZzZXQ9Ii4zNTU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wLWNvbG9yPSIjZTMzZTE5Ii8+PC9saW5lYXJHcmFkaWVudD48cGF0aCBkPSJNNzkuMyAyODQuMnMtMjEuOC0yMi4xLTkuMy03My44IDU2LjYtNDYuMiA1My4zLTE0OS44YzAgMC05IDQ2LjItMzcuNiA2OC4zLTI4LjUgMjIuMi02NC44IDk1LTYuNCAxNTUuM3oiIGZpbGw9InVybCgjU1ZHSURfNV8pIi8+PGxpbmVhckdyYWRpZW50IGlkPSJTVkdJRF82XyIgZ3JhZGllbnRVbml0cz0idXNlclNwYWNlT25Vc2UiIHgxPSI5My42OTMiIHkxPSIyNjkuMjI5IiB4Mj0iOTMuNjkzIiB5Mj0iMi45NDgiPjxzdG9wIG9mZnNldD0iLjA3MyIgc3RvcC1jb2xvcj0iI2ZmZjhkYSIvPjxzdG9wIG9mZnNldD0iLjI0OCIgc3RvcC1jb2xvcj0iI2ZmZjNhMCIvPjxzdG9wIG9mZnNldD0iLjQ0IiBzdG9wLWNvbG9yPSIjZmZlZDY3Ii8+PHN0b3Agb2Zmc2V0PSIuNjE5IiBzdG9wLWNvbG9yPSIjZmZlOTNiIi8+PHN0b3Agb2Zmc2V0PSIuNzc3IiBzdG9wLWNvbG9yPSIjZmZlNjFiIi8+PHN0b3Agb2Zmc2V0PSIuOTA5IiBzdG9wLWNvbG9yPSIjZmZlNTA3Ii8+PHN0b3Agb2Zmc2V0PSIxIiBzdG9wLWNvbG9yPSIjZmZlNDAwIi8+PC9saW5lYXJHcmFkaWVudD48cGF0aCBkPSJNMTM3LjcgMi45czEzLjggMzguMi0yMS44IDkzLjEtODQgOTItNDguMSAxNzMuMmMwIDAtMzUuNC00NS41LTEzLjktOTcuNSAyNi43LTY0LjEgOTYuMi05Ny41IDgzLjgtMTY4Ljh6IiBmaWxsPSJ1cmwoI1NWR0lEXzZfKSIvPjwvZz48L3N2Zz4="
    camel.apache.org/provider: "Apache Software Foundation"
    camel.apache.org/kamelet.group: "FHIR"
    camel.apache.org/kamelet.namespace: "API"
  labels:
    camel.apache.org/kamelet.type: "sink"
spec:
  definition:
    title: FHIR Sink
    description: |-
      Forward data to a Fhir endpoint.
    required:
    - serverUrl
    - methodName
    type: object
    properties:
      apiName:
        title: API Name
        description: "What kind of operation to perform"
        type: string
        enum:  ["CAPABILITIES", "CREATE", "DELETE", "HISTORY", "LOAD_PAGE", "META", "OPERATION", "PATCH", "READ", "SEARCH", "TRANSACTION", "UPDATE", "VALIDATE"]
      methodName:
        title: Method Name
        description: "What sub operation to use for the selected operation."
        type: string
      encoding:
        title: Encoding
        description: "Encoding to use for all request. One of: [JSON] [XML]."
        type: string
        default: "JSON"
      fhirVersion:
        title: Fhir Version
        description: "The FHIR Version to use."
        type: string
        enum:  ["DSTU2", "DSTU2_HL7ORG", "DSTU2_1", "DSTU3", "R4", "R5"]
        default: "R4"
      log:
        title: Log
        description: "Will log every requests and responses."
        type: boolean
        x-descriptors:
        - 'urn:alm:descriptor:com.tectonic.ui:checkbox'
        default: false
      prettyPrint:
        title: Pretty Print
        description: "Pretty print all request."
        type: boolean
        x-descriptors:
        - 'urn:alm:descriptor:com.tectonic.ui:checkbox'
        default: false
      serverUrl:
        title: Server URL
        description: The FHIR server base URL.
        type: string
      lazyStartProducer:
        title: Lazy Start Producer
        description: "Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing."
        type: boolean
        x-descriptors:
        - 'urn:alm:descriptor:com.tectonic.ui:checkbox'
        default: false
      proxyHost:
        title: Proxy Host
        description: The proxy host.
        type: string
      proxyPassword:
        title: Proxy Password
        description: The proxy password.
        type: string
        format: password
        x-descriptors:
        - urn:alm:descriptor:com.tectonic.ui:password
        - urn:camel:group:credentials
      proxyPort:
        title: Proxy Port
        description: The proxy port.
        type: integer
      proxyUser:
        title: Proxy User
        description: The proxy username.
        type: string
        x-descriptors:
        - urn:camel:group:credentials
      accessToken:
        title: Access Token
        description: OAuth access token.
        type: string
        format: password
        x-descriptors:
        - urn:alm:descriptor:com.tectonic.ui:password
        - urn:camel:group:credentials
      username:
        title: Username
        description: Username to use for basic authentication.
        type: string
        x-descriptors:
        - urn:camel:group:credentials
      password:
        title: Password
        description: Password to use for basic authentication.
        type: string
        format: password
        x-descriptors:
        - urn:alm:descriptor:com.tectonic.ui:password
        - urn:camel:group:credentials
  dependencies:  
  - "camel:fhir"
  - "camel:core"
  - "camel:kamelet"
  template:
    from:
      uri: kamelet:source
      steps:
      - choice:
          precondition: true
          when:
            - simple: "${properties:encoding} =~ 'JSON'"
              steps:
                - unmarshal:
                    fhirJson:
                      fhir-version: "{{fhirVersion}}"
                      pretty-print: "{{prettyPrint}}"                     
            - simple: "${properties:encoding} =~ 'XML'"
              steps:
                - unmarshal:
                    fhirXml:
                      fhir-version: "{{fhirVersion}}"
                      pretty-print: "{{prettyPrint}}"            
      - to: 
          uri: "fhir://{{apiName}}/{{methodName}}"
          parameters: 
            serverUrl: "{{serverUrl}}"
            inBody: "resource"
            encoding: "{{encoding}}"
            fhirVersion: "{{fhirVersion}}"
            log: "{{log}}"
            prettyPrint: "{{prettyPrint}}"
            lazyStartProducer: "{{lazyStartProducer}}"
            proxyHost: "{{?proxyHost}}"
            proxyPassword: "{{?proxyPassword}}"
            proxyPort: "{{?proxyPort}}"
            proxyUser: "{{?proxyUser}}"
            accessToken: "{{?accessToken}}"
            username: "{{?username}}"
            password: "{{?password}}"