<file_sep>'use strict';

var app = angular.module('Lab');

app.controller('LabTechController', [ '$scope', '$rootScope', 'LabTechService', 
                                      function($scope, $rootScope, LabTechService) {
	$scope.logout = "true";
	$scope.name = $rootScope.name;
	$scope.person = $rootScope.person;
	$scope.getAllOrders = function () {
		LabTechService.GetAllOrders(function (data) {
			$scope.orders = data;
		})
	}
	
	$scope.selectOrder = function (order) {
		$scope.order = order;
	}
	
	$scope.updateOrder = function () {
		$scope.order.assignedTo = $scope.person;
		
		LabTechService.UpdateOrder($scope.order, function (data) {
			
		})
	}
	
} ]);
<file_sep>'use strict';
 
var app = angular.module('Nurse');
 
app.factory('NurseService',
    ['Base64', '$http', '$cookieStore', '$rootScope', '$timeout',
    function (Base64, $http, $cookieStore, $rootScope, $timeout) {
        var service = {};

        service.AddPatient = function (patient, callback) {

            $http.post('http://localhost:8080/Assignment4_REST/rest/nurse/registerPatient', patient)
                .success(function (data, status) {
                    callback(data);
                });
            	
        };
        return service;
    }]);

app.factory('ListPatientsService',
	    ['Base64', '$http', '$cookieStore', '$rootScope', '$timeout',
	    function (Base64, $http, $cookieStore, $rootScope, $timeout) {
	        var service = {};

	        service.GetDiagnosis = function (callback) {
	        	$http.get('http://localhost:8080/Assignment4_REST/rest/doctor/getDiagnosis')
	            .success(function (data, status) {
	                callback(data);
	            });
			}
	        
	        service.GenerateList = function (diagnosis, callback) {
	        	$http.post('http://localhost:8080/Assignment4_REST/rest/nurse/generateList', diagnosis)
	            .success(function (data, status) {
	                callback(data);
	            });
			}
	        
	        return service;
	    }]);

app.factory('SearchPatientService',
	    ['Base64', '$http', '$cookieStore', '$rootScope', '$timeout',
	    function (Base64, $http, $cookieStore, $rootScope, $timeout) {
	        var service = {};

	        service.GetPatient = function (pId, callback) {

	            $http.get('http://localhost:8080/Assignment4_REST/rest/nurse/searchPatient/' + pId)
	                .success(function (data, status) {
	                    callback(data);
	                });
	            	
	        };
	        
	        service.SendEmail = function (patient, callback) {
	        	$http.post('http://localhost:8080/Assignment4_REST/rest/notify/send', patient)
                .success(function (data, status) {
                    callback(data);
                });
			}
	        
	        service.TransferPatient = function (patient, callback) {
	        	$http.post('http://localhost:8080/Assignment4_REST/rest/notify/transfer', patient)
                .success(function (data, status) {
                    callback(data);
                });
			}
	        
	        service.AddEncounter = function(encounter, callback) {
	        	encounter.activeMeds = encounter.activeMeds.split(",");
	        	encounter.allergies = encounter.allergies.split(",");
	        	encounter.symptoms = encounter.symptoms.split(",");
	        	encounter.status = "Open";
	        	$http.post('http://localhost:8080/Assignment4_REST/rest/nurse/addEncounter', encounter)
                .success(function (data, status) {
                    callback(data);
                });
			}
	        return service;
	    }]);<file_sep>package edu.neu.test;

import java.util.ArrayList;

import org.hibernate.Session;
import org.hibernate.Transaction;

import edu.neu.bean.DiagnosisBean;
import edu.neu.bean.DrugBean;
import edu.neu.bean.LabPersonBean;
import edu.neu.bean.PersonBean;
import edu.neu.bean.RoleBean;
import edu.neu.bean.UserAccountBean;
import edu.neu.hibernate.HibernateUtil;


public class TestMain {

	public static void main(String[] args) {

		Session session = HibernateUtil.getSessionFactory().openSession();
		
		Transaction t = session.beginTransaction();
		
		RoleBean docRole = new RoleBean();
		docRole.setRoleName("Doctor");
		
		RoleBean nurseRole = new RoleBean();
		nurseRole.setRoleName("Nurse");
		
		RoleBean labRole = new RoleBean();
		labRole.setRoleName("LabTechnician");
		
		PersonBean person = new PersonBean();
		person.setName("<NAME>");
		
		UserAccountBean ua = new UserAccountBean();
		ua.setUsername("abhinavpunj");
		ua.setPassword("<PASSWORD>");
		ua.setPerson(person);
		ua.setRole(docRole);
		
		PersonBean nurse = new PersonBean();
		nurse.setName("Nurse");
		
		UserAccountBean ua2 = new UserAccountBean();
		ua2.setUsername("nurse");
		ua2.setPassword("<PASSWORD>");
		ua2.setPerson(nurse);
		ua2.setRole(nurseRole);
		
		LabPersonBean lab = new LabPersonBean();
		lab.setName("lab");
		
		UserAccountBean ua3 = new UserAccountBean();
		ua3.setUsername("lab");
		ua3.setPassword("<PASSWORD>50983cd24fb0d6963f7d28e17f72");
		ua3.setPerson(lab);
		ua3.setRole(labRole);
		
		DrugBean d1 = new DrugBean();
		d1.setDrugName("drug1");
		d1.setComponents(new ArrayList<String>());
		d1.getComponents().add("sulphur");
		d1.getComponents().add("paracetamol");
		
		DrugBean d2 = new DrugBean();
		d2.setDrugName("drug2");
		d2.setComponents(new ArrayList<String>());
		d2.getComponents().add("ibuprofen");
		
		DrugBean d3 = new DrugBean();
		d3.setDrugName("drug3");
		d3.setComponents(new ArrayList<String>());
		d3.getComponents().add("sulphur");
		d3.getComponents().add("morphine");
		
		DiagnosisBean db1 = new DiagnosisBean();
		db1.setDiagnosisName("Cancer");
		db1.setEduLink("http://www.cancer.gov/");
		
		DiagnosisBean db2 = new DiagnosisBean();
		db2.setDiagnosisName("High Cholestrol");
		db2.setEduLink("http://www.nhlbi.nih.gov/health/resources/heart/heart-cholesterol-hbc-what-html");
		
		DiagnosisBean db3 = new DiagnosisBean();
		db3.setDiagnosisName("Influenza");
		db3.setEduLink("http://www.cdc.gov/flu/");
		
		DiagnosisBean db4 = new DiagnosisBean();
		db4.setDiagnosisName("Migraine");
		db4.setEduLink("http://www.webmd.com/migraines-headaches/");
		
		session.save(db1);
		session.save(db2);
		session.save(db3);
		session.save(db4);
		
		session.save(docRole);
		session.save(nurseRole);
		session.save(labRole);
		session.save(person);
		session.save(nurse);
		session.save(lab);
		session.save(ua);
		session.save(ua2);
		session.save(ua3);
		
		session.save(d1);
		session.save(d2);
		session.save(d3);
		
		t.commit();
		session.close();
		//after close session detach state
		System.out.println("success");

	}

}
<file_sep>$(document).ready(function(){
	var sPageURL = window.location.search.substring(1);
    var sURLVariables = sPageURL.split('&');
    var personId = 0;
    var key;
    for (var i = 0; i < sURLVariables.length; i++)
    {
    	var sParameterName = sURLVariables[i].split('=');
    	if (sParameterName[0] == 'personId')
    	{
    		personId = sParameterName[1];
    	}
    	else if(sParameterName[0] == 'AUTH_KEY')
    	{
    		key = sParameterName[1];
    	}
	}
    
    var perJson = {
    		personId : personId
    };
    $.ajax({
		type : 'POST',
		contentType : 'application/json',
		url : "http://localhost:8080/Assignment4_REST/rest/doctor",
		dataType : "json",
		data : JSON.stringify(perJson),
		beforeSend: function (xhr) {
            /////   Authorization header////////
              xhr.setRequestHeader("AUTH_KEY", key);
          },
		success : function(data) {
			var val = JSON.stringify(data);
			var json = $.parseJSON(val);
			$('#drName').append(json.name);
			var list = $("#patientList");
			for(var i=0; i<json.patients.length; i++){
				list.append('<a href="Doctor-PatientProfile.jsp?doctorId=' + 
						personId + '&patientId=' + json.patients[i].patientId + 
						'" class="list-group-item">' + json.patients[i].patientId +':' + json.patients[i].name + '</a>');
			}
		},
		error : function(er) {
			alert("error");
		},
		failure : function(errormsg) {
			alert(errormsg);
		}
	});
});<file_sep>'use strict';
 
angular.module('Authentication')
 
.controller('LoginController',
    ['$scope', '$rootScope', '$location', 'AuthenticationService',
    function ($scope, $rootScope, $location, AuthenticationService) {
        // reset login status
        AuthenticationService.ClearCredentials();

        $scope.login = function () {
            $scope.dataLoading = true;
            AuthenticationService.Login($scope.username, $scope.password, function(data, headers) {
                if(data.personId > 0) {
                    AuthenticationService.SetCredentials($scope.username, $scope.password, headers);
                    $location.path('/' +  headers('AUTH_KEY'));
                    $rootScope.name = data.name;
                    $rootScope.patients = data.patients;
                    $rootScope.personId = data.personId;
                    $rootScope.person = data;
                } else {
                    $scope.error = response.message;
                    $scope.dataLoading = false;
                }
            });
        };
    }]);
<file_sep>package edu.neu.controller;

import java.util.ArrayList;
import java.util.Date;

import javax.annotation.security.RolesAllowed;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

import com.mysql.fabric.xmlrpc.base.Data;

import edu.neu.bean.DiagnosisBean;
import edu.neu.bean.EncounterBean;
import edu.neu.bean.PatientBean;
import edu.neu.hibernate.PatientDAO;

@Controller
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Path("/nurse")
public class NurseController {

	@Autowired
	PatientDAO patientDao;
	
	@POST
	@RolesAllowed("nurse")
	@Path("/registerPatient")
	public void registerPatient(PatientBean patient)
	{
		patientDao.createPatient(patient);
	}
	
	@GET
	@Path("/searchPatient/{pId}")
	@RolesAllowed("nurse")
	public PatientBean searchPatient(@PathParam(value = "pId") int patientId)
	{
		PatientBean patient = new PatientBean();
		patient.setPatientId(patientId);

		patient = patientDao.searchPatient(patient);
		
		return patient;
	}
	
	@POST
	@Path("/addEncounter")
	@RolesAllowed("nurse")
	public void addEncounter(EncounterBean encounter)
	{
		patientDao.addEncounterData(encounter);
	}
	
	@POST
	@Path("/generateList")
	@RolesAllowed("nurse")
	public ArrayList<String> generatePatientList(DiagnosisBean diagnosis)
	{
		return patientDao.generateList(diagnosis);
	}
		
	
}
<file_sep>package edu.neu.security;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;


public class HashEncode {

	public enum ALGO{
		MD5("MD5");
		
		public String algo;
		
		private ALGO(String algo) {
			this.algo = algo;
		}
		
		@Override
		public String toString() {
			return algo;
		}
	}
	
	private HashEncode(){
		
	}
	
	public static String generateHash(String msg, ALGO algo){
		String hash = null;
		
		MessageDigest digest = null;
		try {
			digest = MessageDigest.getInstance(algo.toString());
		} catch (NoSuchAlgorithmException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		byte[] hashedBytes = digest.digest(msg.getBytes());
		
		StringBuffer stringBuffer = new StringBuffer();
		for (int i = 0; i < hashedBytes.length; i++) 
		{
			stringBuffer.append(Integer.toString((hashedBytes[i] & 0xff) + 0x100, 16).substring(1));
		}

			hash = stringBuffer.toString();
		return hash;
	}
}
<file_sep>package edu.neu.interceptor;

import javax.ws.rs.core.Response;
import javax.ws.rs.ext.ExceptionMapper;
import javax.ws.rs.ext.Provider;

import org.codehaus.jackson.JsonParseException;
import org.springframework.stereotype.Component;

@Provider
@Component
public class JsonParsingExceptionMapping implements ExceptionMapper<JsonParseException> {

	@Override
	public Response toResponse(JsonParseException exception) {
		// TODO Auto-generated method stub
        return Response.status(Response.Status.BAD_REQUEST).build();
	}

}
<file_sep>package edu.neu.bean;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;

@Entity
@Table(name = "Diagnosis")
public class DiagnosisBean {

	@Id @GeneratedValue(strategy = GenerationType.IDENTITY)
	@Column(name = "diagnosisId")
	private int diagnosisId;
	
	@Column(name = "diagnosisName")
	private String diagnosisName;
	
	@Column(name = "eduLink")
	private String eduLink;
	
	@Transient
	private PatientBean patient;

	public PatientBean getPatient() {
		return patient;
	}

	public void setPatient(PatientBean patient) {
		this.patient = patient;
	}

	public int getDiagnosisId() {
		return diagnosisId;
	}

	public void setDiagnosisId(int diagnosisId) {
		this.diagnosisId = diagnosisId;
	}

	public String getDiagnosisName() {
		return diagnosisName;
	}

	public void setDiagnosisName(String diagnosisName) {
		this.diagnosisName = diagnosisName;
	}

	public String getEduLink() {
		return eduLink;
	}

	public void setEduLink(String eduLink) {
		this.eduLink = eduLink;
	}
	
	
}
<file_sep>package edu.neu.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

import org.springframework.stereotype.Component;

import edu.neu.bean.EncounterBean;
import edu.neu.bean.PatientBean;
import edu.neu.bean.PersonBean;
import edu.neu.bean.VitalSignBean;

//@Component
public class DoctorDAO extends DAO {
	
	public void updateDiagnosis(EncounterBean encounter)
	{
		Connection conn = null;
		PreparedStatement stmt = null;
		try 
		{
			conn = getConnection();
			String sql = "UPDATE encounter SET doctor_name = ?, diagnosis = ?, status = ? WHERE encounter_id = ?";
			stmt = conn.prepareStatement(sql);
			stmt.setString(1, encounter.getDoctor());
			stmt.setString(2, encounter.getDiagnosis());
			stmt.setInt(3, encounter.getEncounterId());
			stmt.setString(4, "Closed");
			
			stmt.executeUpdate();
		} 
		catch (SQLException e) {
			e.printStackTrace();
		}
		finally{
			try {
				stmt.close();
				conn.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}
	
	public EncounterBean getVitalSignDetails(EncounterBean encounter)
	{
		Connection conn = null;
		PreparedStatement stmt = null;
		PreparedStatement stmt2 = null;
		PreparedStatement stmt3 = null;
		PreparedStatement stmt4 = null;
		ResultSet rs = null;
		String sql = null;
		try 
		{
			conn = getConnection();
			sql = "SELECT v.temp, v.pulse, v.bloodpreesure, v.glucose, v.respiratoryrate, v.weight, v.height, v.bmi"
					+ " FROM vitalsign v INNER JOIN encounter e ON e.vitalsign_id = v.VitalSign_Id WHERE e.encounter_id = ?";
			stmt = conn.prepareStatement(sql);
			stmt.setInt(1, encounter.getEncounterId());
			rs = stmt.executeQuery();
			
			while(rs.next())
			{
				VitalSignBean vs = new VitalSignBean();
				vs.setTemp(rs.getFloat("temp"));
				vs.setPulse(rs.getInt("pulse"));
				vs.setBloodPressure(rs.getInt("bloodpreesure"));
				vs.setGlucose(rs.getInt("glucose"));
				vs.setRespRate(rs.getInt("respiratoryrate"));
				vs.setWeight(rs.getFloat("weight"));
				vs.setHeight(rs.getFloat("height"));
				vs.setBmi(rs.getInt("bmi"));
				encounter.setVitalSign(vs);
			}
			
			sql = "SELECT a.name FROM allergies a INNER JOIN encounter e ON a.encounter_id = e.encounter_id "
					+ "WHERE e.encounter_id = ?";
			stmt2 = conn.prepareStatement(sql);
			stmt2.setInt(1, encounter.getEncounterId());
			rs = stmt2.executeQuery();
			
			encounter.setAllergies(new ArrayList<String>());
			while(rs.next())
			{
				encounter.getAllergies().add(rs.getString("name"));
			}
			
			sql = "SELECT a.name FROM medication a INNER JOIN encounter e ON a.encounter_id = e.encounter_id "
					+ "WHERE e.encounter_id = ?";
			stmt3 = conn.prepareStatement(sql);
			stmt3.setInt(1, encounter.getEncounterId());
			rs = stmt3.executeQuery();
			
			encounter.setActiveMeds(new ArrayList<String>());
			while(rs.next())
			{
				encounter.getActiveMeds().add(rs.getString("name"));
			}
			
			sql = "SELECT a.name FROM symptoms a INNER JOIN encounter e ON a.encounter_id = e.encounter_id "
					+ "WHERE e.encounter_id = ?";
			stmt4 = conn.prepareStatement(sql);
			stmt4.setInt(1, encounter.getEncounterId());
			rs = stmt4.executeQuery();
			
			encounter.setSymptoms(new ArrayList<String>());			
			while(rs.next())
			{
				encounter.getSymptoms().add(rs.getString("name"));
			}
			
		} 
		catch (SQLException e) {
			e.printStackTrace();
		}
		finally{
			try {
				stmt.close();
				stmt2.close();
				stmt3.close();
				stmt4.close();
				conn.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		return encounter;
	}
	
	public PersonBean getPatientDetails(PersonBean doc)
	{
		Connection conn = null;
		PreparedStatement stmt = null;
		PreparedStatement stmt2 = null;
		try {
			String sql = "Select name FROM person WHERE Person_Id = ?";
			conn = getConnection();
			stmt = conn.prepareStatement(sql);
			stmt.setInt(1, doc.getPersonId());
			
			ResultSet rs = stmt.executeQuery();
			
			while(rs.next())
			{
				doc.setName(rs.getString("name"));
			}
			
			String sql2 = "select a.patient_Id, a.name, a.age, a.phone, a.gender, "
					+ "b.encounter_id, b.chiefComplaint, b.doctor_name, b.diagnosis, b.status"
					+ " from patientprofile a inner join encounter b on a.patient_id = b.pateint_id where a.patient_id = ?";
			stmt2 = conn.prepareStatement(sql2);
			for(PatientBean p : doc.getPatients())
			{
				stmt2.setInt(1, p.getPatientId());
			}
			rs = stmt2.executeQuery();
			
			
				for(PatientBean p : doc.getPatients())
				{
					p.setEncounterHistory(new ArrayList<EncounterBean>());
					while(rs.next())
					{
						p.setName(rs.getString("name"));
						p.setGender(rs.getString("gender"));
						p.setAge(rs.getInt("age"));
						p.setPhone(rs.getInt("phone"));
						EncounterBean enc = new EncounterBean();
						enc.setEncounterId(rs.getInt("encounter_id"));
						enc.setChiefComplaint(rs.getString("chiefComplaint"));
						enc.setDoctor(rs.getString("doctor_name"));
						enc.setDiagnosis(rs.getString("diagnosis"));
						enc.setStatus(rs.getString("status"));
						p.getEncounterHistory().add(enc);
					}
				}
			
		} 
		catch (SQLException e) {
			e.printStackTrace();
		}
		finally{
			try {
				stmt.close();
				stmt2.close();
				conn.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		
		return doc;
	}

	public PersonBean getDoctorDetails(PersonBean doc)
	{
		Connection conn = null;
		PreparedStatement stmt = null;
		PreparedStatement stmt2 = null;
		try 
		{
			String sql = "Select name FROM person WHERE Person_Id = ?";
			conn = getConnection();
			stmt = conn.prepareStatement(sql);
			stmt.setInt(1, doc.getPersonId());
			
			ResultSet rs = stmt.executeQuery();
			
			while(rs.next())
			{
				doc.setName(rs.getString("name"));
			}
			
			String sql2 = "Select patient_id as patientId, name FROM patientprofile";
			stmt2 = conn.prepareStatement(sql2);
			rs = stmt2.executeQuery();
			
			doc.setPatients(new ArrayList<PatientBean>());
			while(rs.next())
			{
				PatientBean p = new PatientBean();
				p.setPatientId(rs.getInt("patientId"));
				p.setName(rs.getString("name"));
				doc.getPatients().add(p);
			}
			
		} 
		catch (SQLException e) {
			e.printStackTrace();
		}
		finally{
			try {
				stmt.close();
				stmt2.close();
				conn.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		
		return doc;
	}
}
<file_sep>package edu.neu.bean;

import java.util.ArrayList;
import java.util.Date;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToOne;
import javax.persistence.Table;

@Entity
@Table(name = "WorkRequest")
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS) 
public class WorkRequestBean {

	@Id	@GeneratedValue(strategy = GenerationType.TABLE)
	@Column(name = "WorkId")
	private int workId;
	
	@ManyToOne(fetch = FetchType.EAGER)
	@JoinColumn(name = "sender", nullable = false)
	private PersonBean sender;
	
	
	@ManyToOne(cascade = CascadeType.ALL)
	@JoinColumn(name = "encounterId")
	private EncounterBean encounter;
	
	@Column(name = "updated")
	private Date updated;

	public int getWorkId() {
		return workId;
	}

	public void setWorkId(int workId) {
		this.workId = workId;
	}

	public PersonBean getSender() {
		return sender;
	}

	public void setSender(PersonBean sender) {
		this.sender = sender;
	}

	public EncounterBean getEncounter() {
		return encounter;
	}

	public void setEncounter(EncounterBean encounter) {
		this.encounter = encounter;
	}

	public Date getUpdated() {
		return updated;
	}

	public void setUpdated(Date updated) {
		this.updated = updated;
	}
	
	
}
<file_sep>package edu.neu.interceptor;

import javax.ws.rs.core.Response;
import javax.ws.rs.ext.ExceptionMapper;
import javax.ws.rs.ext.Provider;

import org.codehaus.jackson.JsonParseException;
import org.codehaus.jackson.map.JsonMappingException;
import org.springframework.stereotype.Component;

@Provider
@Component
public class JsonMappingExceptionMapper implements ExceptionMapper<JsonMappingException> {
    
	@Override
    public Response toResponse(JsonMappingException exception) {
    	
        return Response.status(Response.Status.BAD_REQUEST).build();
    }
}<file_sep>'use strict';
 
var app = angular.module('Doctor');
 
app.factory('LabTechService',
    ['Base64', '$http', '$cookieStore', '$rootScope', '$timeout',
    function (Base64, $http, $cookieStore, $rootScope, $timeout) {
        var service = {};

        service.GetAllOrders = function (callback) {
        	$http.get('http://localhost:8080/Assignment4_REST/rest/lab/getAllOrders')
            .success(function (data, status) {
                callback(data);
            });
		};
        
        service.UpdateOrder = function (order, callback) {
        	$http.put('http://localhost:8080/Assignment4_REST/rest/lab/updateOrder', order)
            .success(function (data, status) {
                callback(data);
            });
		}
        
        return service;
    }]);<file_sep>//'use strict';
 
var app = angular.module('Doctor');
 
app.factory('PateintDetailsService',
    ['Base64', '$http', '$cookieStore', '$rootScope', '$timeout',
    function (Base64, $http, $cookieStore, $rootScope, $timeout) {
        var service = {};

        service.Details = function (patientId, personId, callback) {

            $http.get('http://localhost:8080/Assignment4_REST/rest/doctor/patientDetails/' + personId + '/' + patientId)
                .success(function (data, status) {
                    callback(data);
                });
            	
        };
        
        service.GetDiagnosis = function (callback) {
        	$http.get('http://localhost:8080/Assignment4_REST/rest/doctor/getDiagnosis')
            .success(function (data, status) {
                callback(data);
            });
		}
        
        service.SendResources = function (diagnosis, callback) {
        	$http.post('http://localhost:8080/Assignment4_REST/rest/notify/sendResources', diagnosis)
            .success(function (data, status) {
                callback(data);
            });
		}
        
        service.SendEmail = function (encounter, callback) {
        	$http.post('http://localhost:8080/Assignment4_REST/rest/notify/sendEncounter', encounter)
            .success(function (data, status) {
                callback(data);
            });
		}
        
        service.UpdateDiagnosis = function (encounter, callback) {
			$http.put('http://localhost:8080/Assignment4_REST/rest/doctor/updateDiagnosis', encounter)
				.success(function (data, status) {
					callback(data);
				})
		}
        return service;
    }]);

app.factory('LabResultsService',
	    ['Base64', '$http', '$cookieStore', '$rootScope', '$timeout',
	     function (Base64, $http, $cookieStore, $rootScope, $timeout) {
	         var service = {};

	         service.GetEncounters = function (patientId, callback) {
				$http.get('http://localhost:8080/Assignment4_REST/rest/lab/getEncounters/' + patientId)
					.success(function (data, status) {
						callback(data);
					});
			};
			
			service.GetOrders = function (patientId, callback) {
				$http.get('http://localhost:8080/Assignment4_REST/rest/lab/getOrders/' + patientId)
					.success(function (data, status) {
						callback(data);
				});
			};
			
			service.OrderTest = function (personId, encounterId, testName, callback) {
				labOrder = {};
				labOrder.encounter = encounterId;
				labOrder.testName = testName;
				labOrder.sender = {};
				labOrder.sender.personId = personId;

				$http.post('http://localhost:8080/Assignment4_REST/rest/lab/orderTest', labOrder)
					.success(function(data, status) {
						callback(data);
					});
			};
			
     
			
	         
	         return service;
	     }]);

app.factory('PrescriptionService',
	    ['Base64', '$http', '$cookieStore', '$rootScope', '$timeout',
	     function (Base64, $http, $cookieStore, $rootScope, $timeout) {
	         var service = {};

	         service.GetEncounters = function (patientId, callback) {
				$http.get('http://localhost:8080/Assignment4_REST/rest/lab/getEncounters/' + patientId)
					.success(function (data, status) {
						callback(data);
					});
			};
			
			service.GetDrugs = function (callback) {
				$http.get('http://localhost:8080/Assignment4_REST/rest/doctor/getDrugs')
				.success(function (data, status) {
					callback(data);
				});
			}
			
			service.GetPrescriptions = function (patientId, callback) {
				$http.get('http://localhost:8080/Assignment4_REST/rest/doctor/getPrescriptions/' + patientId)
				.success(function (data, status) {
					callback(data);
				});
			}
			
			service.CheckAllergy = function (encounter, callback) {
				$http.post('http://localhost:8080/Assignment4_REST/rest/doctor/checkAllergy', encounter)
				.success(function(data, status) {
					callback(data);
				});
			}
			
			service.AddPrescription = function (encounter, callback) {
				$http.post('http://localhost:8080/Assignment4_REST/rest/doctor/addPrescription', encounter)
				.success(function(data, status) {
					callback(data);
				});
			}
			
	        return service;
	     }]);<file_sep>package edu.neu.bean;

import java.util.ArrayList;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;

import org.springframework.stereotype.Component;

@Entity
@Table(name = "UserAccount")
public class UserAccountBean {

	@Id @GeneratedValue(strategy = GenerationType.IDENTITY)
	@Column(name = "userId")
	private int userId;
	
	@OneToOne(cascade = CascadeType.ALL)
	@JoinColumn(name = "PersonId")
	private PersonBean person;
	
	@NotNull(message="Name is a required field")
	@Column(name = "username")
	private String username;
	
	@NotNull(message="Password is a required field")
	@Column(name = "password")
	private String password;
	
	@OneToOne(cascade = CascadeType.ALL)
	@JoinColumn(name = "RoleId")
	private RoleBean role;
	
	public PersonBean getPerson() {
		return person;
	}
	public void setPerson(PersonBean person) {
		this.person = person;
	}
	public String getUsername() {
		return username;
	}
	public void setUsername(String username) {
		this.username = username;
	}
	public String getPassword() {
		return password;
	}
	public void setPassword(String password) {
		this.password = password;
	}
	public RoleBean getRole() {
		return role;
	}
	public void setRole(RoleBean role) {
		this.role = role;
	}
	
	
}
<file_sep>package edu.neu.bean;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;


@Entity
@Table(name = "vitalSign")
public class VitalSignBean {

	@Id @GeneratedValue(strategy = GenerationType.IDENTITY)
	@Column(name = "vitalSignId")
	private int vitalSignId;
	
	@Column(name = "temp")
	private float temp;
	
	@Column(name = "pulse")
	private int pulse;
	
	@Column(name = "bloodPressure")
	private int bloodPressure;
	
	@Column(name = "glucose")
	private int glucose;
	
	@Column(name = "respRate")
	private int respRate;
	
	@Column(name = "weight")
	private float weight;
	
	@Column(name = "height")
	private float height;
	
	@Column(name = "bmi")
	private int bmi;
	
	public int getVitalSignId() {
		return vitalSignId;
	}
	public void setVitalSignId(int vitalSignId) {
		this.vitalSignId = vitalSignId;
	}
	public float getTemp() {
		return temp;
	}
	public void setTemp(float temp) {
		this.temp = temp;
	}
	public int getPulse() {
		return pulse;
	}
	public void setPulse(int pulse) {
		this.pulse = pulse;
	}
	public int getBloodPressure() {
		return bloodPressure;
	}
	public void setBloodPressure(int bloodPressure) {
		this.bloodPressure = bloodPressure;
	}
	public int getGlucose() {
		return glucose;
	}
	public void setGlucose(int glucose) {
		this.glucose = glucose;
	}
	public int getRespRate() {
		return respRate;
	}
	public void setRespRate(int respRate) {
		this.respRate = respRate;
	}
	public float getWeight() {
		return weight;
	}
	public void setWeight(float weight) {
		this.weight = weight;
	}
	public float getHeight() {
		return height;
	}
	public void setHeight(float height) {
		this.height = height;
	}
	public int getBmi() {
		return bmi;
	}
	public void setBmi(int bmi) {
		this.bmi = bmi;
	}
	
	
}
<file_sep>function register(){
	var sPageURL = window.location.search.substring(1);
    var sURLVariables = sPageURL.split('&');
    var key;
    for (var i = 0; i < sURLVariables.length; i++)
    {
    	var sParameterName = sURLVariables[i].split('=');
    	if(sParameterName[0] == 'AUTH_KEY')
    	{
    		key = sParameterName[1];
    	}
	}
	var dob = new Date($("#dob").val());
	var dobJSON = dob.toJSON();
	pat = {}
	pat["name"] = $("#name").val();
	pat["age"] = $("#age").val();
	pat["gender"] = $("#gender").val();
	pat["address"] = $("#address").val();
	pat["phone"] = $("#phone").val();
	
	$.ajax({
        url: "http://localhost:8080/Assignment4_REST/rest/nurse/registerPatient",
        data: JSON.stringify(pat),
        dataType: "json",
        contentType: "application/json; charset=utf-8",
        type: "POST",
        beforeSend: function (xhr) {
            /////   Authorization header////////
              xhr.setRequestHeader("AUTH_KEY", key);
          },
        success: function(data) {
        	alert("Patient Registered");                 	
        },
        error: function(er) {
        	alert(er);
        },
		failure: function(errormsg) {
			alert(errormsg);
		}
    });
	/*actMed = {}
	for(var i=0; i<med.length; i++){
		actMed[i] = med[i];
	}
	pat[""]*/
}<file_sep>'use strict';

var app = angular.module('Doctor');

app.controller('DoctorController', [ '$scope', '$rootScope', function($scope, $rootScope) {
	$scope.logout = "true";
	$scope.name = $rootScope.name;
	$scope.patients = $rootScope.patients;
	$scope.personId = $rootScope.personId;
} ]);

app.controller('PatientProfileController', [ '$scope', '$rootScope', '$routeParams', '$timeout', 'PateintDetailsService', 
                                             function($scope, $rootScope, $routeParams, $timeout, PateintDetailsService) {
	$scope.patientId = $routeParams.patientId;
	$scope.notify = true;
	PateintDetailsService.Details($scope.patientId, $rootScope.personId, function(data) {
		$scope.patient = data.patients[0];		
	})
	$scope.idSelected = null;
	$scope.getVitalSign = function (encs) {
		$scope.idSelected = encs.encounterId;
		$scope.notify = false;
		$scope.encounter = encs;
		$scope.vs = encs.vitalSign;
		$scope.symptoms = encs.symptoms;
		$scope.activeMeds = encs.activeMeds;
		$scope.allergies = encs.allergies;
	}
	
	$scope.getDiagnosis = function () {
		PateintDetailsService.GetDiagnosis(function (data) {
			$scope.allDiag = data;
		})
	}
	
	$scope.sendEmail = function() {
		$scope.dataLoading = true;
		$scope.success = false;
		PateintDetailsService.SendEmail($scope.encounter, function (data) {
			$scope.dataLoading = false;
			$scope.success = data;
			$timeout(function () {
			      $scope.success = false;
			  }, 3000);
		})
	}
	$scope.updateDiagnosis = function (diagObj) {
		
		$scope.encounter.diagnosis = diagObj.diagnosisName;
		$scope.encounter.doctor = $scope.name;
		$scope.encounter.status = "Closed";
		PateintDetailsService.UpdateDiagnosis($scope.encounter, function(data) {
			diagObj.patient = $scope.encounter.patientId;
			PateintDetailsService.SendResources(diagObj, function(data) {
				
			})
		})
	}
}]);

app.controller('LabResultsController', [ '$scope', '$filter', '$rootScope', '$routeParams', 'LabResultsService', 
                                         function($scope, $filter, $rootScope, $routeParams, LabResultsService) {
	$scope.logout = "true";
	$scope.patientId = $routeParams.patientId;
	$scope.name = $rootScope.name;
	$scope.patients = $rootScope.patients;
	$scope.personId = $rootScope.personId;
	
	$scope.getEncounters = function() {
		LabResultsService.GetEncounters($scope.patientId, function(data) {
			$scope.encs = data;
		})
	}
	
	
	$scope.orderTest = function () {
		LabResultsService.OrderTest($scope.personId, $scope.selEncounter, $scope.testName, function(data) {
			$scope.orders.push(data);
		})
	}
	
	$scope.getOrders = function () {
		LabResultsService.GetOrders($scope.patientId, function(data) {
			$scope.orders = [];
			$scope.orders = data;
		})
		
	}
	
} ]);

app.controller('PrescriptionController', [ '$scope', '$rootScope', '$routeParams', 'PrescriptionService',
                                           function($scope, $rootScope, $routeParams, PrescriptionService) {
	
	$scope.logout = "true";
	$scope.patientId = $routeParams.patientId;
	$scope.name = $rootScope.name;
	$scope.patients = $rootScope.patients;
	$scope.personId = $rootScope.personId;
	
	$scope.getEncounters = function() {
		PrescriptionService.GetEncounters($scope.patientId, function(data) {
			$scope.encs = data;
		})
	}
	
	$scope.getDrugs = function() {
		PrescriptionService.GetDrugs(function(data) {
			$scope.allDrugs = data;
		})
	}
	
	$scope.getPrescriptions = function() {
		PrescriptionService.GetPrescriptions($scope.patientId, function(data) {
			$scope.drugs = data;
		})
	}	
	
	$scope.addPrescription = function(encounter) {
		encounter.doctor = $scope.name;
		PrescriptionService.CheckAllergy(encounter, function(data) {
			$scope.drugAllergy = data;
		})
		if($scope.drugAllergy.length > 0){
			PrescriptionService.AddPrescription(encounter, function(data) {
				$scope.drugs = data;
			})
		}
	}
	
} ]);<file_sep>package edu.neu.bean;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;

import org.springframework.stereotype.Component;

@Entity
@Table(name = "Roles")
public class RoleBean {

	@Id @GeneratedValue(strategy = GenerationType.IDENTITY)
	@Column(name = "RoleId")
	private int roleId;
	
	@Column(name = "RoleName")
	private String roleName;

	public String getRoleName() {
		return roleName;
	}

	public void setRoleName(String roleName) {
		this.roleName = roleName;
	}
	
	
}
