PTSD PAL

by kulkaann24 in Workshop > Tools

104 Views, 1 Favorites, 0 Comments

PTSD PAL

Screenshot 2024-01-11 at 1.40.48 PM.png

I chose this project because I am very familiar with the affect of PTSD and what it does to veterans and wanted to try to find a solution that when having a ptsd attack at night it will send some noise or vibration to wake you up. As many of my friends are veterans and active duty soldiers that have suffered from severe PTSD attacks at night and have not only accidentally hurt themselves but others as well if not woken up properly, I created this in an attempt to make their lives easier.

Supplies

Apple Watch or Iphone

Laptop

code.org account


Screenshot 2024-01-11 at 1.58.57 PM.png

on code.org create your account

Screenshot 2024-01-11 at 1.59.35 PM.png

Go to app lab

Screenshot 2024-01-11 at 1.40.48 PM.png

Add the first screen and text box

Screenshot 2024-01-11 at 1.53.26 PM.png

Add the textbox on screen one to the code

Screenshot 2024-01-11 at 1.47.09 PM.png

After that, insert the following code.

Screenshot 2024-01-11 at 2.03.19 PM.png

Then hit new screen on the design menu and create screen two

repeat step three and four and six

Then prep your code and insert the following code.


 hideElement("introlabel");

 setScreen("screen2");

 onEvent("HelpLabel", "click", function( ) {

 

console.log("HelpLabel clicked!");

 

setScreen("screen4");

 

onEvent("SetUp", "click", function( ) {

open("https://onlineheartbeat.com");

import HealthKit drawChartFromRecords();

class HeartRateTracker {

  let healthStore HKHealthStore();

  func requestAuthorization() {

    let typesToRead: Set<HKObjectType> = [HKObjectType.quantityType(forIdentifier: .heartRate)!]

    healthStore.requestAuthorization(toShare: nil, read: typesToRead) { (success, error) in

      if success {

        print("HealthKit authorization granted.")

        self.startTrackingHeartRate()

      } else {

        print("HealthKit authorization denied.")

      }

    }

  }

   

  func startTrackingHeartRate() {

    guard HKHealthStore.isHealthDataAvailable() else {

      print("Health data is not available on this device.")

      return

    }

     

    let heartRateType = HKQuantityType.quantityType(forIdentifier: .heartRate)!

     

    let query = HKObserverQuery(sampleType: heartRateType, predicate: nil) { (query, completionHandler, error) in

      if let error = error {

        print("Error observing heart rate changes: \(error.localizedDescription)")

        return

      }

       

      // Handle heart rate changes here

      self.fetchLatestHeartRate()

       

      completionHandler()

    }

     

    healthStore.execute(query)

    healthStore.enableBackgroundDelivery(for: heartRateType, frequency: .immediate) { (success, error) in

      if success {

        print("Background delivery enabled for heart rate changes.")

      } else {

        print("Error enabling background delivery: \(error?.localizedDescription ?? "")")

      }

    }

  }

   

  func fetchLatestHeartRate() {

    let heartRateType = HKQuantityType.quantityType(forIdentifier: .heartRate)!

     

    let query = HKSampleQuery(sampleType: heartRateType, predicate: nil, limit: 1, sortDescriptors: nil) { (query, samples, error) in

      if let error = error {

        print("Error fetching heart rate samples: \(error.localizedDescription)")

        return

      }

       

      guard let heartRateSample = samples?.first as? HKQuantitySample else {

        print("No heart rate data available.")

        return

      }

       

      let heartRateUnit = HKUnit.count().unitDivided(by: HKUnit.minute())

      let heartRateValue = heartRateSample.quantity.doubleValue(for: heartRateUnit)

       

      print("Latest Heart Rate: \(heartRateValue) bpm")

    }

     

    healthStore.execute(query)

  }

}


// Example usage:

let heartRateTracker = HeartRateTracker()

heartRateTracker.requestAuthorization()


Screenshot 2024-01-11 at 2.07.25 PM.png
Screenshot 2024-01-11 at 2.10.46 PM.png

create the button that starts sending you to the health app

Screenshot 2024-01-11 at 1.55.19 PM.png
Screenshot 2024-01-11 at 1.54.26 PM.png
Screenshot 2024-01-11 at 1.52.11 PM.png

once you finish the code connect to iPhone or Apple Watch and you're set