function(doc) {
    if(doc.doc_type === "CommCareCase" && doc.type === "wisepill_device") {
        emit([doc.name], null);
    }
}

function(doc) {
    if(doc.doc_type === "CommCareCase" && doc.type === "wisepill_device" && !doc.closed) {
        emit([doc.name], null);
    }
}

Include only open cases in wisepill view
Include only open cases in wisepill view
