This repository has been archived by the owner on Jan 9, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 639
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* patient notes migration Tied to #32 in hospitalrun-frontend * mislabeled name of the file * Removed old _id from migrated data because it is not needed Also, this field was causing confusion. * Changed to use bulk update and fixed various issues.
- Loading branch information
1 parent
73b7aef
commit 282eb40
Showing
3 changed files
with
45 additions
and
2 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,6 @@ start.sh | |
|
||
stop.sh | ||
|
||
newrelic.js | ||
|
||
newrelic_agent.log | ||
|
||
newrelic.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
var config = require('../config.js'); | ||
var nano = require('nano')(config.couchAuthDbURL); | ||
var maindb = nano.use('main'); | ||
var uuid = require('node-uuid'); | ||
var recordsToUpdate = []; | ||
|
||
maindb.list({startkey: 'visit_', endkey: 'visit_\uffff', include_docs: true}, function(err, results) { | ||
if (!err) { | ||
results.rows.forEach(function(result) { | ||
var visitDoc = result.doc.data; | ||
if (visitDoc !== null && visitDoc.notes && !visitDoc.patientNotes) { | ||
var noteUuid = uuid.v4(); | ||
var visitId = result.doc._id.substr(8); | ||
var patientNote = { | ||
_id: 'patientNote_2_' + noteUuid, | ||
data: { | ||
content: visitDoc.notes, | ||
createdBy: 'system', | ||
date: new Date(), | ||
noteType: 'General', | ||
patient: visitDoc.patient, | ||
visit: visitId | ||
} | ||
}; | ||
recordsToUpdate.push(patientNote); | ||
result.doc.data.patientNotes = [noteUuid]; | ||
recordsToUpdate.push(result.doc); | ||
} | ||
}); | ||
if (recordsToUpdate.length > 0) { | ||
maindb.bulk({ docs: recordsToUpdate}, function(err, results) { | ||
if (err) { | ||
console.log('Error updating patient notes records.', err); | ||
} else { | ||
console.log('Success updating patient notes records.', JSON.stringify(results, null, 2)); | ||
} | ||
}); | ||
} | ||
} else { | ||
console.log('ERROR fetching visit records', err); | ||
} | ||
}); |
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