 
           (recur next-el-loc deconstruction))))))
 
-(defn whole-node
-  "No deconstruction performed"
-  [file-path el-loc]
-  [[file-path (cdx/indent-str (cz/node el-loc))]])
-
 (defmethod mi/deconstruct-node :default [_ file-path el-loc]
-  (whole-node file-path el-loc))
+  [[file-path (cdx/indent-str (cz/node el-loc))]]) ;; just return whole node
 
 (defmethod mi/deconstruct-node :global-scripts [_ file-path el-loc]
   (deconstruct-node

  (:require [clojure.data.xml :as cdx]
            [clojure.data.zip :as cdz]
            [clojure.data.zip.xml :as cdzx]
            [clojure.string :as cs]
            [clojure.tools.logging :as log]
            [clojure.zip :as cz]
            [mirthsync.actions :as ma]
            [mirthsync.files :as mf]
            [mirthsync.interfaces :as mi]
            [clojure.data.xml :as xml])
  (:import java.io.File))

(defn- api-element-id

     (when-let [name-loc (cdzx/xml1-> el-loc :entry :string)]
       [(cdzx/text name-loc) (cz/right name-loc)]))))

(defn name-script-sequence
  "Take a script loc to find and build the script name."
  [prefix loc]
  (str prefix
       (cdzx/xml1-> loc cz/up :sequenceNumber cdzx/text)
       (cdzx/xml1-> loc cz/up :name cdzx/text (fn [x]
                                                (if (= x "")
                                                  nil
                                                  (str "-" x))))))

(defn this-tag=
  "Returns a query predicate that matches if the current exact node is a tag named
  tagname."
  [tagname]
  (fn [loc]
    (when (= tagname (:tag (cz/node loc)))
      loc)))

(def channel-deconstructors
  [[(partial name-script-sequence "destinationConnector-filter-step-")
    #(cdzx/xml1-> %
                  (this-tag= :com.mirth.connect.plugins.javascriptrule.JavaScriptRule)
                  :script
                  [cz/up cz/up cz/up :filter cz/up :destinationConnectors])]

   [(fn [loc] (let [destname (apply cdzx/xml1-> loc (flatten [(repeat 4 cz/up) :name cdzx/text]))]
                (str "destinationConnector-" destname "-" (name-script-sequence "transformer-step-" loc))))
    #(cdzx/xml1-> %
                  (this-tag= :com.mirth.connect.plugins.javascriptstep.JavaScriptStep)
                  :script
                  [cz/up cz/up cz/up :transformer cz/up :connector cz/up :destinationConnectors])]

   [(fn [loc] (let [destname (apply cdzx/xml1-> loc (flatten [(repeat 4 cz/up) :name cdzx/text]))]
                (str "destinationConnector-" destname "-" (name-script-sequence "responseTransformer-step-" loc))))
    #(cdzx/xml1-> %
                  (this-tag= :com.mirth.connect.plugins.javascriptstep.JavaScriptStep)
                  :script
                  [cz/up cz/up cz/up :responseTransformer cz/up :connector cz/up :destinationConnectors])]

   [(partial name-script-sequence "sourceConnector-transformer-step-")
    #(cdzx/xml1-> %
                  (this-tag= :com.mirth.connect.plugins.javascriptstep.JavaScriptStep)
                  :script
                  [cz/up cz/up cz/up :transformer cz/up :sourceConnector])]

   [(partial name-script-sequence "sourceConnector-filter-step-")
    #(cdzx/xml1-> %
                  (this-tag= :com.mirth.connect.plugins.javascriptrule.JavaScriptRule)
                  :script
                  [cz/up cz/up cz/up :filter cz/up :sourceConnector])]

   [(fn [loc] (let [name (cdzx/xml1-> loc cz/up cz/up :name cdzx/text)]
                (str "sourceConnector" (when-not (cs/blank? name)
                                         (str "-" name)))))
    #(cdzx/xml1-> % (this-tag= :script) [cz/up :properties cz/up :sourceConnector])]

   [(fn [loc] (let [name (cdzx/xml1-> loc cz/up cz/up :name cdzx/text)]
                (str "connector" (when-not (cs/blank? name)
                                         (str "-" name)))))
    #(cdzx/xml1-> % (this-tag= :script) [cz/up :properties cz/up :connector])]

   [(fn [_] "PreprocessingScript")
    #(cdzx/xml1-> % (this-tag= :preprocessingScript))]

   [(fn [_] "PostprocessingScript")
    #(cdzx/xml1-> % (this-tag= :postprocessingScript))]

   [(fn [_] "DeployScript")
    #(cdzx/xml1-> % (this-tag= :deployScript))]

   [(fn [_] "UndeployScript")
    #(cdzx/xml1-> % (this-tag= :undeployScript))]])


(defmethod mi/deconstruct-node :channels [_ file-path el-loc]
  (deconstruct-node
