Last active
September 23, 2016 13:20
-
-
Save SCdF/5f69c26d2fd8546c3d02060b6119827f to your computer and use it in GitHub Desktop.
touch-patientless-reports.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env /srv/software/medic-core/v1.6.1/x64/bin/node | |
var http = require('http'); | |
var request = function(options, postData, callback) { | |
if (!callback) { | |
callback = postData; | |
postData = null; | |
} | |
var req = http.request(options, function(res) { | |
var body = ''; | |
res.on('data', function(data) { | |
body += data; | |
}); | |
res.on('end', function() { | |
callback(JSON.parse(body)); | |
}); | |
}); | |
if (postData) { | |
req.write(postData); | |
} | |
req.end(); | |
}; | |
var CREDS = 'admin:pass'; | |
function touch(url, callback) { | |
console.log('Checking', url); | |
request({ | |
port: 5984, | |
auth: CREDS, | |
path: url + '?include_docs=true', | |
headers: { | |
'Content-Type': 'application/json', | |
}}, function(results) { | |
console.log('Results returned'); | |
var docs = { | |
docs: results.rows.map(function(row) { | |
return row.doc; | |
}) | |
}; | |
console.log('Found ' + docs.docs.length + ' docs in need'); | |
if (docs.docs.length) { | |
var docsBody = JSON.stringify(docs); | |
request({ | |
method: 'POST', | |
port: 5984, | |
auth: CREDS, | |
path: '/medic/_bulk_docs', | |
headers: { | |
'Content-Type': 'application/json' | |
} | |
}, docsBody, function(results) { | |
console.log('Done:', results); | |
callback(); | |
}); | |
} else { | |
console.log('Done!'); | |
callback(); | |
} | |
}); | |
} | |
touch('/medic/_design/refresh-reports/_view/reportsWithNoPatientId', function() { | |
touch('/medic/_design/refresh-reports/_view/reportsWithNoClinic', function() {}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment