0% found this document useful (0 votes)
16 views

Patient Source Code

This Java web service uses JDBC to query a SQL database and retrieve patient information. It takes a user name, patient ID, and client IP as parameters. It first checks that the user is allowed to access the service based on time and IP restrictions stored in the Policy table. If allowed, it queries the Patient table and returns the patient's name, ID, and other fields concatenated into a string, or returns an error message if the patient is invalid or the user is not allowed access.

Uploaded by

sankar2010
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views

Patient Source Code

This Java web service uses JDBC to query a SQL database and retrieve patient information. It takes a user name, patient ID, and client IP as parameters. It first checks that the user is allowed to access the service based on time and IP restrictions stored in the Policy table. If allowed, it queries the Patient table and returns the patient's name, ID, and other fields concatenated into a string, or returns an error message if the patient is invalid or the user is not allowed access.

Uploaded by

sankar2010
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 2

Patient source code

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

package login;

import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;
import java.sql.*;
import java.util.Date;
import java.net.*;

/**
*
* @author Easter
*/
@WebService()
public class patient {

/**
* Web service operation
*/
@WebMethod(operationName = "getPatientInfo")
public String getPatientInfo(@WebParam(name = "User")
String User, @WebParam(name = "Pid")
String Pid)
{
String result="";
int flag=0;
try
{
String ss1[]=Pid.split("@");
Pid=ss1[0];
String sn=ss1[1];
String clip=ss1[2];
System.out.println("Comes in Patient Service");
String
addr[]=InetAddress.getLocalHost().toString().split("/");
System.out.println("Client Address : "+ss1[2]);

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection
con=DriverManager.getConnection("jdbc:odbc:LocalServer");
Statement st=con.createStatement();
st.executeUpdate("use RemoteService");

ResultSet rs=st.executeQuery("select * from Policy where


UserName='"+User+"'and Service='"+sn+"'");
while(rs.next())
{
String user1=rs.getString(1);
String service=rs.getString(2);
String ip=rs.getString(3);
System.out.println("service & IP : "+service + " :
"+ip+" : "+user1);

if(ip.equals(clip) && service.equals("Patient"))


{
int from=Integer.parseInt(rs.getString(4));
int to=Integer.parseInt(rs.getString(5));

Date dt=new Date();


int hours=dt.getHours();

System.out.println("Time : "+from+" : "+hours+" :


"+to);
if(hours>from && hours<to)
{
flag=1;
}

}
}
// con.close();
rs.close();
System.out.println("Flag : "+flag);
if(flag==1)
{
rs=st.executeQuery("select * from Patient where
PatientId='"+Pid+"'");
if(rs.next())
{

result=rs.getString(1)+"#"+rs.getString(2)+"#"+rs.getString(3);
}
else
{
result="Invalid Patient Id" ;
}
}
else
{
result="You are Not Allowed to Access This service at
this time";
}
System.out.println("Result : "+result);
}
catch(Exception e)
{
System.out.println(e);
}
//TODO write your implementation code here:
return result;
}

You might also like