Select to view content in your preferred language

Dashboard Table Expression to return only particular values

250
0
03-27-2024 11:50 AM
Shubhreet
Regular Contributor

Hello Esri Community,

I am trying to create a sample dashboard for collecting real-time data for outbreaks from healthcare facilities. A facility might report more than one outbreak by submitting multiple survey123 forms (on same or different days). One of my survey questions asks the user "if the site is in outbreak?" which has three options to select:

  • Select 'Yes' if you are reporting a new outbreak or an update to any previously reported outbreak.
  • Select 'Free of a previously reported outbreak' if the site is no longer experiencing a previously reported outbreak while there might still be any other active outbreaks.
  • Select 'No' if the site is completely free of all the previously reported outbreaks.

Based on the option chosen by the user some relevant questions pop-up further. Please note that the users may not submit data on regular basis but only when there is a change in relation to the previously reported outbreaks or if there is a new outbreak to report.

Within my dashboard I am trying to include a table to show the names of facilities with their reported active outbreaks (This does not include the facilities which do not have or no longer have an active outbreak). A facility may appear in more than one row since it may have reported more than one active outbreak. Since there is no direct way to pull such information in the dashboard, I am trying to use an expression where I have grouped the responses by facility name and complete outbreak name. 

 

var portal = Portal('https://www.arcgis.com/');
var fs = FeatureSetByPortalItem(
  portal,
  '4fdb27f2078b4a04bd141a7e9dd05db',
  0,
  [
    'facility_name_',
    'ObjectID',
    'is_the_site_in_outbreak',
    'date_and_time_of_data_submissio',
    'date_outbreak_declared',
    'CompleteOutbreakName',
    'attack_rate',
    'number_of_residents_deceased',
    '_vaccination_rate',
  ],
  false
);


var fs_gp = (GroupBy(fs, [
{ name: 'facility_name_', expression: 'facility_name_'},
{ name: 'CompleteOutbreakName', expression: 'CompleteOutbreakName'}
] ,
[   {name: 'RecentUpdate', expression: 'date_and_time_of_data_submissio', STATISTIC: 'MAX'},{name: 'MaxObjID', expression: 'ObjectID', STATISTIC: 'MAX'}]));
 
var unwanted_output = [];
var feat;
for(var i in fs_gp) {
 
  console(i); //Please see results of this console function below the script. 
  var id1 = i.MaxObjID;
  var filtered_fs = Filter(fs, "ObjectID = @id1") //to fetch the complete data of grouped features/facilities       (fs_gp) by linking to the original featureset (fs)

  for (var j in filtered_fs) {
 
   //below is the code to identify the facilities that are no longer in active outbreaks which includes submissions for  "is_the_site_in_outbreak?" = "No" or "Free of previously reported outbreak" and also includes any submission(s) for those facilities with same complete outbreak names reported prior. 
 
    if(j.is_the_site_in_outbreak=="No" || j.is_the_site_in_outbreak=="Free of a previously reported outbreak"  ){
      var completename = j.CompleteOutbreakName;
      var date1 = j.date_and_time_of_data_submissio;
      var facility = j.facility_name_;
      var filter2 = Filter(filtered_fs, "facility_name_=@facility AND CompleteOutbreakName=@completename           AND date_and_time_of_data_submissio<@date1");
 
      for (var k in filter2){
        feat = {
          "attributes": {
            FacilityName : k.facility_name_,
            DateTimeofSubmission : k.date_and_time_of_data_submissio,
            RecentUpdate: k.RecentUpdate,
            OutbreakStatus: k.is_the_site_in_outbreak,
            dateoutbreakdeclared: k.date_outbreak_declared,
            attackrate: k.attack_rate,
            numberofresidentsdeceased: k.number_of_residents_deceased,
            vaccinationrate: k._vaccination_rate,
            ObjID: i.MaxObjID,
            CompleteOutbreakName:k.CompleteOutbreakName,
        }
      }
    }
    Push(unwanted_output, feat);
 
 
Until here, I intend to identify the facilities that are no longer in active outbreaks as 'unwanted_output' featureset and after this I am looking to subtract 'unwanted_output' featureset from the featureset returned by console(i) as shown below. My final output must contain the records in pink as selected from output of console(i) below.
 
Unfortunately, I am not able to receive any output for 'unwanted_output' featureset. Kindly advice if there is any error in my code. Additionally, please advise on how can I subtract 'unwanted_output' featureset from the featureset returned by console(i). I understand that at the end of the final code I will need to use dictionary function to get the output in dashboard table. Please ignore any indentation mistakes here as I was not able to maintain right indentation while typing the code. 
 
 
Thank You in advance. 
 
/////////////////////////////////////////////////////////////////////////////////////////////////////
 Output of console(i):

{"geometry":null,"attributes":{"facility_name_":"Actionmarguerite (Saint-Bonifac","CompleteOutbreakName":"Respiratory Influenza B","is_the_site_in_outbreak":"Yes","RecentUpdate":"2023-08-28T18:13:00.000Z","MaxObjID":86,"ROW__ID":86}}

{"geometry":null,"attributes":{"facility_name_":"Actionmarguerite (St. Joseph) I","CompleteOutbreakName":"Other Pediculosis_","is_the_site_in_outbreak":"Yes","RecentUpdate":"2023-08-03T17:54:00.000Z","MaxObjID":72,"ROW__ID":72}}

{"geometry":null,"attributes":{"facility_name_":"Actionmarguerite (St. Joseph) I","CompleteOutbreakName":"Other Pediculosis_","is_the_site_in_outbreak":"Yes","RecentUpdate":"2023-07-21T18:16:00.000Z","MaxObjID":58,"ROW__ID":58}}

{"geometry":null,"attributes":{"facility_name_":"Arborg PCH","CompleteOutbreakName":"Gastrointestinal Norovirus","is_the_site_in_outbreak":"Yes","RecentUpdate":"2023-08-29T16:48:00.000Z","MaxObjID":88,"ROW__ID":88}}

{"geometry":null,"attributes":{"facility_name_":"Arborg PCH","CompleteOutbreakName":"Respiratory Influenza A","is_the_site_in_outbreak":"Yes","RecentUpdate":"2024-03-15T18:22:00.000Z","MaxObjID":91,"ROW__ID":47}}

{"geometry":null,"attributes":{"facility_name_":"Arborg PCH","CompleteOutbreakName":"Respiratory Measles","is_the_site_in_outbreak":"Yes","RecentUpdate":"2023-08-28T18:12:00.000Z","MaxObjID":85,"ROW__ID":27}}

{"geometry":null,"attributes":{"facility_name_":"Arborg PCH","CompleteOutbreakName":"Respiratory Influenza A","is_the_site_in_outbreak":"Yes","RecentUpdate":"2023-07-24T18:03:00.000Z","MaxObjID":45,"ROW__ID":45}}

{"geometry":null,"attributes":{"facility_name_":"Ashern Personal Care Home","CompleteOutbreakName":"Gastrointestinal Norovirus","is_the_site_in_outbreak":"Yes","RecentUpdate":"2023-07-31T18:05:00.000Z","MaxObjID":49,"ROW__ID":48}}

{"geometry":null,"attributes":{"facility_name_":"Beacon Hill Lodge","CompleteOutbreakName":"Gastrointestinal Campylobacter","is_the_site_in_outbreak":"Yes","RecentUpdate":"2024-03-25T16:03:00.000Z","MaxObjID":95,"ROW__ID":95}}

{"geometry":null,"attributes":{"facility_name_":"Beacon Hill Lodge","CompleteOutbreakName":"Respiratory Human Rhinovirus","is_the_site_in_outbreak":"Yes","RecentUpdate":"2024-03-18T14:54:00.000Z","MaxObjID":92,"ROW__ID":92}}

{"geometry":null,"attributes":{"facility_name_":"Calvary Place Personal Care Home","CompleteOutbreakName":"Respiratory Human Rhinovirus","is_the_site_in_outbreak":"Yes","RecentUpdate":"2024-03-21T14:01:00.000Z","MaxObjID":93,"ROW__ID":93}}

{"geometry":null,"attributes":{"facility_name_":"Concordia Place","CompleteOutbreakName":"Antibiotic Resistant Organism ( MRSA","is_the_site_in_outbreak":"Yes","RecentUpdate":"2024-03-26T00:22:00.000Z","MaxObjID":96,"ROW__ID":96}}

{"geometry":null,"attributes":{"facility_name_":"Concordia Place","CompleteOutbreakName":"Other Scabies","is_the_site_in_outbreak":"Free of a previously reported outbreak","RecentUpdate":"2024-03-26T01:30:00.000Z","MaxObjID":97,"ROW__ID":97}}

{"geometry":null,"attributes":{"facility_name_":"Concordia Place","CompleteOutbreakName":"Other Scabies","is_the_site_in_outbreak":"Yes","RecentUpdate":"2023-07-24T18:07:00.000Z","MaxObjID":52,"ROW__ID":52}}

{"geometry":null,"attributes":{"facility_name_":"Concordia Place","CompleteOutbreakName":"Respiratory Covid-19","is_the_site_in_outbreak":"Yes","RecentUpdate":"2023-08-03T18:27:00.000Z","MaxObjID":75,"ROW__ID":75}}

{"geometry":null,"attributes":{"facility_name_":"Dakota Oyate Lodge","CompleteOutbreakName":"Antibiotic Resistant Organism ( C. auris","is_the_site_in_outbreak":"Yes","RecentUpdate":"2023-07-25T18:09:00.000Z","MaxObjID":54,"ROW__ID":54}}

{"geometry":null,"attributes":{"facility_name_":"Dauphin Personal Care Home","CompleteOutbreakName":null,"is_the_site_in_outbreak":"No","RecentUpdate":"2023-08-03T18:34:00.000Z","MaxObjID":76,"ROW__ID":76}}

{"geometry":null,"attributes":{"facility_name_":"Dauphin Personal Care Home","CompleteOutbreakName":"Gastrointestinal Norovirus","is_the_site_in_outbreak":"Yes","RecentUpdate":"2023-08-01T23:13:00.000Z","MaxObjID":70,"ROW__ID":70}}

{"geometry":null,"attributes":{"facility_name_":"Deer Lodge Centre","CompleteOutbreakName":"Respiratory Human Enterovirus","is_the_site_in_outbreak":"Yes","RecentUpdate":"2024-03-21T17:39:00.000Z","MaxObjID":94,"ROW__ID":94}}

{"geometry":null,"attributes":{"facility_name_":"Dr. Gendreau Memorial PCH","CompleteOutbreakName":"Antibiotic Resistant Organism ( CPE","is_the_site_in_outbreak":"Yes","RecentUpdate":"2023-07-24T18:09:00.000Z","MaxObjID":55,"ROW__ID":55}}

{"geometry":null,"attributes":{"facility_name_":"Dr. Gendreau Memorial PCH","CompleteOutbreakName":"Antibiotic Resistant Organism ( LR-VRE","is_the_site_in_outbreak":"Yes","RecentUpdate":"2023-08-03T18:36:00.000Z","MaxObjID":77,"ROW__ID":56}}

{"geometry":null,"attributes":{"facility_name_":"Heritage Lodge","CompleteOutbreakName":"Respiratory Other","is_the_site_in_outbreak":"Yes","RecentUpdate":"2023-08-03T18:41:00.000Z","MaxObjID":78,"ROW__ID":57}}

{"geometry":null,"attributes":{"facility_name_":"Lions Prairie Manor","CompleteOutbreakName":"Gastrointestinal C. difficile","is_the_site_in_outbreak":"Yes","RecentUpdate":"2023-08-14T16:58:00.000Z","MaxObjID":82,"ROW__ID":82}}

{"geometry":null,"attributes":{"facility_name_":"Minnedosa PCH","CompleteOutbreakName":null,"is_the_site_in_outbreak":"No","RecentUpdate":"2023-08-01T17:11:00.000Z","MaxObjID":69,"ROW__ID":69}}

{"geometry":null,"attributes":{"facility_name_":"Minnedosa PCH","CompleteOutbreakName":"Gastrointestinal E. coli","is_the_site_in_outbreak":"Yes","RecentUpdate":"2023-08-03T18:43:00.000Z","MaxObjID":79,"ROW__ID":71}}

{"geometry":null,"attributes":{"facility_name_":"Minnedosa PCH","CompleteOutbreakName":"Respiratory Covid-19","is_the_site_in_outbreak":"Yes","RecentUpdate":"2023-07-31T18:19:00.000Z","MaxObjID":60,"ROW__ID":59}}

{"geometry":null,"attributes":{"facility_name_":"Northern Lights Manor_","CompleteOutbreakName":null,"is_the_site_in_outbreak":"No","RecentUpdate":"2023-08-03T18:48:00.000Z","MaxObjID":80,"ROW__ID":80}}

{"geometry":null,"attributes":{"facility_name_":"Northern Lights Manor_","CompleteOutbreakName":"Respiratory Influenza B","is_the_site_in_outbreak":"Yes","RecentUpdate":"2023-07-25T18:20:00.000Z","MaxObjID":61,"ROW__ID":61}}

{"geometry":null,"attributes":{"facility_name_":"Northern Spirit Manor","CompleteOutbreakName":"Antibiotic Resistant Organism ( AMR-GNB","is_the_site_in_outbreak":"Yes","RecentUpdate":"2023-07-25T18:21:00.000Z","MaxObjID":62,"ROW__ID":62}}

{"geometry":null,"attributes":{"facility_name_":"Pinaow Wachi Inc.","CompleteOutbreakName":null,"is_the_site_in_outbreak":"No","RecentUpdate":"2023-08-03T18:23:00.000Z","MaxObjID":66,"ROW__ID":66}}

{"geometry":null,"attributes":{"facility_name_":"Pinaow Wachi Inc.","CompleteOutbreakName":"Gastrointestinal Norovirus","is_the_site_in_outbreak":"Yes","RecentUpdate":"2023-11-01T17:44:00.000Z","MaxObjID":90,"ROW__ID":90}}

{"geometry":null,"attributes":{"facility_name_":"Pinaow Wachi Inc.","CompleteOutbreakName":"Other Scabies","is_the_site_in_outbreak":"Yes","RecentUpdate":"2023-07-25T18:23:00.000Z","MaxObjID":65,"ROW__ID":65}}

{"geometry":null,"attributes":{"facility_name_":"Salem Home Inc","CompleteOutbreakName":"Antibiotic Resistant Organism ( AMR-GNB ","is_the_site_in_outbreak":"Free of a previously reported outbreak","RecentUpdate":"2024-03-26T15:55:00.000Z","MaxObjID":98,"ROW__ID":98}}

{"geometry":null,"attributes":{"facility_name_":"Salem Home Inc","CompleteOutbreakName":"Antibiotic Resistant Organism ( AMR-GNB","is_the_site_in_outbreak":"Yes","RecentUpdate":"2023-08-02T18:22:00.000Z","MaxObjID":64,"ROW__ID":63}}

{"geometry":null,"attributes":{"facility_name_":"Salem Home Inc","CompleteOutbreakName":"Respiratory Covid-19 ","is_the_site_in_outbreak":"Yes","RecentUpdate":"2024-03-26T15:55:00.000Z","MaxObjID":99,"ROW__ID":99}}

 
 
 
 
0 Kudos
0 Replies