var model = {};
model.users = {users:
[
  {
    id: 1,
    username: "Alex",
    hash: "password",
    salt: "1",
    location: "30332",
    display_name: "Alex Admin",
    type: "admin"
  }
  ,
  {
    id: 2,
    username: "danielle",
    hash: "password",
    salt: "1",
    location: "30332",
    display_name: "Danielle Doctor",
    type: "admin",
    permissions: [
      {
        user: 1,
        level: "owner"
      }
    ]
  }
  ,
  {
    id: 3,
    username: "nick",
    hash: "password",
    salt: "1",
    location: "30332",
    display_name: "Nick Nurse",
    type: "physician",
    permissions: [
      {
        user: 2,
        level: "owner"
      },
      {
        user: 1,
        level: "edit"
      }
    ]
  }
]};


model.reminders = {reminder:[
  {
  id: 1,
  heading: "Add Physicians",
  content: "Need to add the Physicians to the app",
  owner: 1
  },
  {
  id: 2,
  heading: "Add Patients",
  content: "Need to add the Patients to the app",
  owner: 2
  }
]}

model.patients = {patient:[
  {
  id: 1,
  name: "Pete Patient",
  DOB: "01/01/1991",
  permissions: [
    {
      user: 2,
      level: "owner"
    },
    {
      user: 1,
      level: "edit"
    }
  ]
  }
]}

model.charts = {chart:[
  {
    title: "basic test intake",
    questions: [
      {
        text: "How do you feel today?",
        type: "paragraph",
        answer: "Describe your body feel in general terms."
      },
      {
        text: "Why did you come in?",
        type: "paragraph",
        validation: ["nonempty"],
        answer: "Describe your motivation for coming in"
      }
    ],
    permissions: [
      {
        user: 2,
        level: "owner"
      },
      {
        user: 1,
        level: "edit"
      }
    ]
  }
]}

model.chartfill = {chartfill:[
  {
    title: "Bob's intake",
    patient: 1,
    questions: [
      {
        text: "How do you feel today?",
        type: "paragraph",
        answer: "Felt okay until I fell."
      },
      {
        text: "Why did you come in?",
        type: "paragraph",
        validation: ["nonempty"],
        answer: "I fell and my arm is now swollen."
      }
    ],
    permissions: [
      {
        user: 2,
        level: "owner"
      },
      {
        user: 1,
        level: "edit"
      }
    ]
  }
]
}

@@ -26,16 +26,8 @@
 rs =
- %7Busers:
 %0A%5B%0A 
@@ -720,17 +720,16 @@
  %5D%0A  %7D%0A%5D
-%7D
 ;%0A%0A%0Amode
@@ -746,18 +746,8 @@
 s = 
-%7Breminder:
 %5B%0A  
@@ -956,25 +956,24 @@
 ner: 2%0A  %7D%0A%5D
-%7D
 %0A%0Amodel.pati
@@ -983,17 +983,8 @@
 s = 
-%7Bpatient:
 %5B%0A  
@@ -1153,33 +1153,32 @@
 %0A    %7D%0A  %5D%0A  %7D%0A%5D
-%7D
 %0A%0Amodel.charts =
@@ -1182,20 +1182,24 @@
 s = 
-%7Bchart:%5B%0A  %7B
+%5B%0A  %7B%0A    id: 1,
 %0A   
@@ -1709,17 +1709,16 @@
  %5D%0A  %7D%0A%5D
-%7D
 %0A%0Amodel.
@@ -1733,24 +1733,24 @@
 l = 
-%7Bchartfill:%5B%0A  %7B
+%5B%0A  %7B%0A    id: 1,
 %0A   
@@ -2249,10 +2249,385 @@
 %5D%0A  %7D%0A%5D%0A
+%0A%0A// how to search by id%0Afunction findchart(n)%7B%0A  return model.charts.find(x =%3E x.id === n)%0A%7D%0A%0A// how to return only with permissions%0Afunction allows(permissions, user)%7B%0A  // given a permissions array, return if the user is present%0A  return length(permissions.find(x =%3E x.user === n)) %3E 0;%0A%7D%0Afunction allowedchart(n)%7B%0A  return model.chart.find(x =%3E allows(x.permissions, n))%0A
 %7D%0A

add find functions to model