Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package inClass20.inClass20;
- import java.awt.List;
- import java.io.IOException;
- import java.time.LocalDateTime;
- import java.util.ArrayList;
- import javax.swing.JOptionPane;
- import edu.unl.cse.soft160.rest_connector.connector.ObservationRecord;
- import edu.unl.cse.soft160.rest_connector.connector.OpenMRSConnection;
- import edu.unl.cse.soft160.rest_connector.connector.PatientRecord;
- public class LongitudinalHeartRate {
- public static void main(String... arguments) throws IOException {
- String serverURI = JOptionPane.showInputDialog("Enter OpenMRS Server URI");
- String username = JOptionPane.showInputDialog("Enter username");
- String password = JOptionPane.showInputDialog("Enter password");
- String patientID = "";
- // System.out.println(
- // "System test for retrieving biographical data and observations for
- // patient 10000X on the default server:");
- // System.out.println();
- // OpenMRSConnection connection = new
- // OpenMRSConnection("localhost:8080", "admin", "Admin123");
- OpenMRSConnection connection;
- if (serverURI == null || username == null || password == null) {
- JOptionPane.showMessageDialog(null, "no report");
- }
- try {
- connection = new OpenMRSConnection(serverURI, username, password);
- } catch (java.net.ProtocolException e) {
- JOptionPane.showMessageDialog(null, "Invalid credentials.");
- return;
- } catch (java.net.ConnectException e) {
- JOptionPane.showMessageDialog(null, "Could not contact server");
- return;
- } catch (java.io.FileNotFoundException e) {
- JOptionPane.showMessageDialog(null, "Could not contact server");
- return;
- } catch (java.lang.NullPointerException e) {
- return;
- }
- try {
- patientID = JOptionPane.showInputDialog("Enter patient ID");
- // PatientRecord patientRecord =
- // connection.getPatientRecord("10000X");
- double hr = 0;
- double secondToLasthr = 0;
- ArrayList<LocalDateTime>timesList = new ArrayList<LocalDateTime>();
- ArrayList<String>hrList = new ArrayList<String>();
- LocalDateTime last = LocalDateTime.MIN;
- LocalDateTime secondToLast = LocalDateTime.MIN;
- int count = 0;
- PatientRecord patientRecord = connection.getPatientRecord(patientID);
- for (ObservationRecord observationRecord : connection.getObservationRecords(patientRecord.getUUID())) {
- // String suffix = observationRecord.getMeasurement() == null ?
- // : " = " + observationRecord.getMeasurement().toString();
- if (observationRecord.getConcept().equals("Pulse")) {
- if (last.isBefore(observationRecord.getTimestamp())) {
- timesList.add(observationRecord.getTimestamp());
- hrList.add(observationRecord.getMeasurement().toString());
- count++;
- }
- }
- //"Patient [ID]'s heart rate has changed by [HR] beats per minute between [FIRST_TIMESTAMP] and [SECOND_TIMESTAMP]."
- }
- if (count < 2) {
- System.out.println("Only one measurement taken. No change in heart rate");
- } else {
- hr = Double.parseDouble(hrList.get(hrList.size() - 1));
- secondToLasthr = Double.parseDouble(hrList.get(hrList.size() - 2));
- last = (LocalDateTime) timesList.get(timesList.size() - 1);
- secondToLast = (LocalDateTime) timesList.get(timesList.size() - 2);
- System.out.println("Patient " + patientID + "'s heart rate has changed by " + (hr - secondToLasthr) + " beats per minute "
- + "between " + secondToLast + " and " + last);
- }
- } catch (IllegalArgumentException e) {
- JOptionPane.showMessageDialog(null,
- "Patient ID " + patientID + " is malformed; it should be alphanumeric.");
- return;
- } catch (java.lang.NullPointerException e) {
- JOptionPane.showMessageDialog(null, "no report");
- return;
- }
- // System.out.println(" UUID: " + patientRecord.getUUID());
- // System.out.println(" Family Name: " + patientRecord.getFamilyName());
- // System.out.println(" Given Name: " + patientRecord.getGivenName());
- // System.out.println(" Birth Date: " + patientRecord.getBirthDate());
- // System.out.println(" Deceased: " + patientRecord.getDeceased());
- // System.out.println(" Location: " + patientRecord.getLocation());
- // System.out.println();
- // System.out.println("(Output should match data accessible for patient
- // " + patientID
- // + " through the patient dashboard.)");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement