Groovy web console

subscribe to the feed Subscribe
to this
site
homework (via #groovywebconsole)
tweet this snippet Tweet
this
script

homework

Published 4 months ago by Tony Drago
Actions  ➤ Edit in console Back to console Show/hide line numbers View recent scripts
def sys1data2 = [    "patientinfo": ["accountname": "123457900", "account_no": "ACC64", "phone": "4075551212", "website": "somewebiste.com"], 
    "orginfo": ["accountname": "123457900", "account": "ACC64", "phe": "4075551212", "website": "somewebiste.com"]
]

def replaceKeysWith = [
     "orginfo": ["accountname": "accname", "account_no": "accnum", "phone": "phonenum", "website": "webadd", "phe": "pho", "account": "pid"], 
     "patientinfo": ["accountname": "accname", "account_no": "accnum", "phone": "phonenum", "website": "webadd", "phe": "pho", "account": "pid"]
]
 
 
def replacements = [
    "patientinfo": [:],
    "orginfo": [:]
]
 
def replace(Map source1, Map source2, Map target) {
    source1.each {key, value ->
       
        String newValue = null
       
        source2.each {replaceKey, replaceValue ->
            if (key == replaceKey) {
                newValue = replaceValue
            }
        }

        target[key] = newValue ?: value   
    }
}

replace(sys1data2.patientinfo, replaceKeysWith.patientinfo, replacements.patientinfo)
replace(sys1data2.orginfo, replaceKeysWith.orginfo, replacements.orginfo)


replacements