首页>代码>struts2+spring+hibernate+mysql整合开发医院病人管理系统>/hospital/src/cn/hospital/action/PatientAction.java
package cn.hospital.action;

import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.apache.commons.io.FileUtils;
import org.apache.struts2.ServletActionContext;
import org.apache.struts2.json.annotations.JSON;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;


import cn.hospital.bo.Page;
import cn.hospital.pojo.Films;
import cn.hospital.pojo.PatientCase;


import cn.hospital.service.FilmsService;

import cn.hospital.service.PatientCaseService;
import cn.hospital.service.PatientService;

import cn.hospital.utils.Globals;


import com.opensymphony.xwork2.ActionSupport;
import cn.hospital.pojo.Patient;;


@SuppressWarnings("serial")
@Component("PatientAction")
@Scope("prototype")
public class PatientAction extends BaseAction {
	
	private int id;
	private int pageNumber=1;
	private int pageLength=Globals.PAGE_LENGTH;;
	private int recordSize;
	private int pageSize;
	
	private Page page;
	private List<Patient> patientList;
	private PatientService patientService;
	//private PatientCaseMapService patientCaseMapService;
	private PatientCaseService patientCaseService;
	private Patient patient;
	private PatientCase patientCase;
	//private PatientCaseMap patientCaseMap;
	private List<Films> films=new ArrayList<Films>();
	private FilmsService filmsService;
	
	private boolean[][] isCases;
	
	private String hosNum;
	private String filmsNum;
	
	private String message;
	
	
	private String currAction="queryPatient";
	private String currCondition="";
	
	private String oldHoNum;	//保存旧的住院号
	
	
	/*提供添加病例文档的属性*/
	private File myDoc;
	private String myDocFileName; // 文件名称
	private String myDocContentType; // 文件类型
	
	
	/*提供添加影像的属性*/
	private List<File> image=new ArrayList<File>();
	private String[] imageFileName; // 文件名称
	private String[] imageContentType; // 文件类型
	
	
	/*模糊查询所需变量*/
	private String patient_name="";
	private String patient_sex="";
	private String patient_casedes="";
	private String patient_casesecdes="";
	private String way_opera="";
	private String juade_opera="";
	private String patient_age_low="";
	private String patient_age_high="";

	

	public String getCurrCondition() {
		return currCondition;
	}

	public void setCurrCondition(String currCondition) {
		this.currCondition = currCondition;
	}

	public String query(){
		if(pageNumber < 1) pageNumber = 1;
		System.out.println("num:"+pageNumber+"--len:"+pageLength);
		Page page = patientService.query(pageNumber, pageLength);
		patientList = (List<Patient>)page.getDataList();
		recordSize = page.getRecordSize();
		pageSize = page.getPageSize();
		if(pageNumber > pageSize){
			pageNumber = pageSize;
			page = patientService.query(pageNumber, pageLength);
			System.out.println("page:"+page);
			patientList = (List<Patient>)page.getDataList();
			recordSize = page.getRecordSize();
			pageSize = page.getPageSize();
		}
		setCases();
		return SUCCESS;
	}
	
	public String queryByHosNum() throws UnsupportedEncodingException {
		System.out.println("hosNum----:"+hosNum);
		hosNum=new String( hosNum.getBytes("ISO-8859-1") , "utf-8");  
		String condition=" where inHoNnum='"+hosNum+"'";
		System.out.println("condition----:"+condition);
		Page page = patientService.query(pageNumber, pageLength,condition);
		patientList = (List<Patient>)page.getDataList();
		recordSize = page.getRecordSize();
		pageSize = page.getPageSize();
		System.out.println("recordSize:"+recordSize+"--pagesize:"+pageSize);
		currAction="queryByHosNum";
		currCondition="&hosNum="+hosNum;
		if(pageNumber > pageSize){
			pageNumber = pageSize;
			page = patientService.query(pageNumber, pageLength);
			System.out.println("page:"+page);
			patientList = (List<Patient>)page.getDataList();
			recordSize = page.getRecordSize();
			pageSize = page.getPageSize();
		}
		if(patientList==null||patientList.size()==0){
				message="住院号不存在";
				recordSize=0;
				pageNumber=0;
				pageSize=0;
				return Globals.FAILURE;
				
				
				
		}
		setCases();
		return Globals.SUCCESS;
	}
	
	public String queryByFilmsNum() throws UnsupportedEncodingException {
		filmsNum=new String(filmsNum.getBytes("ISO-8859-1") , "utf-8");  
		System.out.println("filmsNum:"+filmsNum);
		String condition=" where numFilms='"+filmsNum+"'";
		List<Films> films=this.filmsService.queryFilms(condition);
		if(films==null||films.size()==0){
			message="影片号不存在";
			recordSize=0;
			pageNumber=0;
			return Globals.FAILURE;
		}
		condition=" where id="+films.get(0).getPatientId();
		Page page = patientService.query(pageNumber, pageLength,condition);
		patientList = (List<Patient>)page.getDataList();
		recordSize = page.getRecordSize();
		pageSize = page.getPageSize();
		currAction="queryByFilmsNum";
		currCondition="&filmsNum="+filmsNum;
		if(pageNumber > pageSize){
			pageNumber = pageSize;
			page = patientService.query(pageNumber, pageLength);
			System.out.println("page:"+page);
			patientList = (List<Patient>)page.getDataList();
			recordSize = page.getRecordSize();
			pageSize = page.getPageSize();
		}
		setCases();
		return Globals.SUCCESS;
	}
	
	
	

	public String blurSearch() throws UnsupportedEncodingException{
		currCondition=""; 
		String condition1="";
		if(patient_name!=""){
			patient_name=new String(patient_name.getBytes("ISO-8859-1") , "utf-8");  
			condition1=" where name='"+patient_name+"'";
			currCondition="&patient_name="+patient_name;
		}
		if(patient_sex!=""){
			patient_sex=new String(patient_sex.getBytes("ISO-8859-1") , "utf-8");  
			if(condition1=="")
				condition1=" where sex='"+patient_sex+"'";
			else
				condition1=condition1+" and sex='"+patient_sex+"'";
			currCondition=currCondition+"&patient_sex="+patient_sex;
		}
		
		if(patient_age_low!=""&&patient_age_high!=""){
			if(condition1=="")
				condition1=" where age>="+patient_age_low+" and age <="+patient_age_high;
			else
				condition1=condition1+" and age>="+patient_age_low+" and age <="+patient_age_high;
			currCondition=currCondition+"&patient_age_low="+patient_age_low+"&patient_age_high="+patient_age_high;
		}
		
		String condition2="";
		if(patient_casedes!=""){
			patient_casedes=new String(patient_casedes.getBytes("ISO-8859-1") , "utf-8");  
			condition2=" where desInHos like '%"+patient_casedes+"%'";
			currCondition=currCondition+"&patient_casedes="+patient_casedes;
		}
		
		if(patient_casesecdes!=""){
			patient_casesecdes=new String(patient_casesecdes.getBytes("ISO-8859-1") , "utf-8");  
			if(condition2=="")
				condition2=" where desSecInHos like '%"+patient_casesecdes+"%'";
			else
				condition2=condition2+" and desSecInHos like '%"+patient_casesecdes+"%'";
			currCondition=currCondition+"&patient_casesecdes="+patient_casesecdes;
		}
		
		if(way_opera!=""){
			way_opera=new String(way_opera.getBytes("ISO-8859-1") , "utf-8");  
			if(condition2=="")
				condition2=" where wayOpera like '%"+way_opera+"%'";
			else
				condition2=condition2+" and wayOpera like '%"+way_opera+"%'";
			currCondition=currCondition+"&way_opera="+way_opera;
		}
		
		
		if(juade_opera!=""){
			juade_opera=new String(juade_opera.getBytes("ISO-8859-1") , "utf-8");  
			if(condition2=="")
				condition2=" where juadeOpera like '%"+juade_opera+"%'";
			else
				condition2=condition2+" and juadeOpera like '%"+juade_opera+"%'";
			currCondition=currCondition+"&juade_opera="+juade_opera;
		}
		String condition="";
		if(condition2!=""&&condition1!="")
			condition=condition1 +" and  id in(select patientId from PatientCase "+condition2+")";
		else if(condition1==""&&condition2!="")
			 condition=" where id in(select patientId from PatientCase "+condition2+")";
		else
			condition=condition1+condition2;
		
		System.out.println("zuhede condition:"+condition+"------------condition1:"+condition1);
		System.out.println("currCondition:"+currCondition);
		Page page = patientService.query(pageNumber, pageLength,condition);
		patientList = (List<Patient>)page.getDataList();
		recordSize = page.getRecordSize();
		pageSize = page.getPageSize();
		currAction="blurSearch";
		//currCondition="&filmsNum="+filmsNum;
		if(pageNumber > pageSize){
			pageNumber = pageSize;
			page = patientService.query(pageNumber, pageLength);
			System.out.println("page:"+page);
			patientList = (List<Patient>)page.getDataList();
			recordSize = page.getRecordSize();
			pageSize = page.getPageSize();
		}
		
		if(patientList==null||patientList.size()==0){
			message="查询结果不存在";
			recordSize=0;
			pageNumber=0;
			pageSize=0;
			return Globals.FAILURE;
		}
		setCases();
		return Globals.SUCCESS;
		
	}
	
	
	public void setCases(){
		System.out.println("patientList:"+patientList);
		isCases=new boolean[2][patientList.size()];
		for(int i=0;i<patientList.size();i++){
		
			isCases[0][i]=patientCaseService.isExists(patientList.get(i).getId());
			isCases[1][i]=filmsService.isExists(patientList.get(i).getId());
		}
		
	}
	

	
	public String  addPatient(){
		//this.patientService.
		String condition=" where inHoNnum='"+this.patient.getInHoNnum()+"'";
		if(patientService.queryCondition(condition)!=null){
			this.message="已经存在此住院号的信息,请重新添加";
			return Globals.FAILURE;
		}
		System.out.println("------films:"+films);
		System.out.println("---image.length:"+image.size());
		System.out.println(films.size()+"---image.length:"+image.size());
		
		if(films!=null&&films.size()!=0&&films.get(0).getNumFilms()!=""){
			condition=" where numFilms='"+films.get(0).getNumFilms()+"'";
			System.out.println("condition-----:"+condition);
			if(this.filmsService.queryFilms(condition).size()!=0){
				this.message="已经存在该影像号信息,请重新添加";
				return Globals.FAILURE;
			}
		}
		this.patientService.addPatient(patient);	
		int maxId=this.patientService.getMaxId();
		
		System.out.println("this.patientCase.getDesInHos():"+this.patientCase.getDesInHos());
		if(!"".equals(this.patientCase.getDesInHos()))
			addPatientCase(maxId);
		if(!"".equals(films.get(0).getNumFilms()))
			addFilms(maxId);
		return Globals.SUCCESS;
	}
	
	public void addPatientCase(int patient_id){
		
		
		String savePath = ServletActionContext.getServletContext().getRealPath(
				File.separator + Globals.SAVE_DIR + File.separator
						+ Globals.DIR_DOC);
		System.out.println("savePath:"+savePath);
		if (myDoc != null) {
			myDocFileName=Globals.getString(6)+"-"+myDocFileName.replace(" ", "");;
			File saveFile = new File(new File(savePath), myDocFileName);
			if (!saveFile.getParentFile().exists()) {
				saveFile.getParentFile().mkdirs();
			}
			try {
				FileUtils.copyFile(myDoc, saveFile);
				patientCase.setDocUrl(myDocFileName);
			} catch (IOException e) {
				System.out.println("上传海报异常");
				e.printStackTrace();
			}
		}
		
		this.patientCase.setPatientId(patient_id);
		this.patientCaseService.addPatientCase(patientCase);
		//this.patientS
	}
	
	
	
	public void addFilms(int patient_id){
		String savePath = ServletActionContext.getServletContext().getRealPath(
				File.separator + Globals.SAVE_DIR + File.separator
						+ Globals.DIR_IMAGES);
		System.out.println("savePath:"+savePath+"--"+films.size()+"---image.length:"+image.size());
		for(int i=0;i<image.size();i++){
			if (image != null) {	
				 imageFileName[i]=Globals.getString(6)+"-"+ imageFileName[i].replace(" ", "");
				File saveFile = new File(new File(savePath), imageFileName[i]);
				if (!saveFile.getParentFile().exists()) {
					saveFile.getParentFile().mkdirs();
				}
				try {
					FileUtils.copyFile(image.get(i), saveFile);
					films.get(i).setImageUrl(imageFileName[i]);
				} catch (IOException e) {
					System.out.println("上传海报异常");
					e.printStackTrace();
				}
			}
			this.films.get(i).setPatientId(patient_id);
			this.filmsService.addFilms(films.get(i));
		}
	}
	
	
	public String toQueryPatientById(){
		this.patient=this.patientService.query(id);
		return Globals.SUCCESS;
	}
	
	public String updatePatient(){
		Patient db_patient=this.patientService.query(id);
		if(!patient.getInHoNnum().equals(db_patient.getInHoNnum())){
			if(!oldHoNum.equals(patient.getInHoNnum())){
				System.out.println("对比通过了。。。11");
				String condition=" where inHoNnum='"+this.patient.getInHoNnum()+"'";
				if(patientService.queryCondition(condition)!=null){
					this.message="已经存在此住院号的信息,请重新修改";
					this.id=db_patient.getId();
					patient.setId(id);
					return Globals.FAILURE;
				}
				
			}
		}
		patient.setId(id);
		this.patientService.updatePatient(patient);
		return Globals.SUCCESS;
	}
	
	public String delPatient() throws UnsupportedEncodingException{
		deleteMode(id);	
		deleteJump();
		return Globals.SUCCESS;
	}
	
	/*批量删除的patient id数组*/
	private String ids;
	public String deleteAll() throws UnsupportedEncodingException{
		System.out.println("ids:"+ids);
		String[] patient_ids=ids.split(",");
		for(int i=0;i<patient_ids.length;i++){
			deleteMode(Integer.parseInt(patient_ids[i]));
		}
		deleteJump();
		return Globals.SUCCESS;
	}
	
	public void deleteJump() throws UnsupportedEncodingException{
		System.out.println("currAction::::"+currAction+"------currCondition:"+currCondition);
		if("queryPatient".equals(currAction))
			this.query();
		else if("queryByHosNum".equals(currAction))
			this.queryByFilmsNum();
		else if("queryByFilmsNum".equals(currAction))
			this.queryByHosNum();
		else if("blurSearch".equals(currAction))
			this.blurSearch();
		else
			this.query();
	}
	
	
	public void deleteMode(int del_id){
		
		/*先删除病人对应的病例PatientCase对应的文档,再删除病例PatientCase*/
		PatientCase patientCase=this.patientCaseService.lookPatientCase(del_id);
		if(patientCase!=null){
				if(patientCase.getDocUrl()!="" && patientCase.getDocUrl()!=null){
					String savePath = ServletActionContext.getServletContext().getRealPath(
							File.separator + Globals.SAVE_DIR + File.separator
									+ Globals.DIR_DOC);
					File docFile = new File(new File(savePath), patientCase.getDocUrl());	//删除旧文件
					if(docFile.exists()&&docFile.isFile())
						docFile.delete();
				}
				this.patientCaseService.delPatientCase(patientCase.getId());
		}
		
		
		/*先删除病人对应的影像Films对应的图片,再删除影像Films*/
		List<Films> filmsList=this.filmsService.lookFilms(del_id);
		for(int i=0;i<filmsList.size();i++){
			if(filmsList.get(i)!=null){
				if(filmsList.get(i).getImageUrl()!="" && filmsList.get(i).getImageUrl()!=null){
					String savePath = ServletActionContext.getServletContext().getRealPath(
							File.separator + Globals.SAVE_DIR + File.separator
									+ Globals.DIR_IMAGES);
					File imgFile = new File(new File(savePath), filmsList.get(i).getImageUrl());	//删除旧文件
					if(imgFile.exists()&&imgFile.isFile())
						imgFile.delete();
				}
				this.filmsService.deleteFilms(filmsList.get(i).getId());
			}
		}
		this.patientService.deletePatient(del_id);
	}
	
	
	public String testHosNum() throws IOException{
		String responseText="inHos";
		String condition=" where inHoNnum='"+hosNum+"'";
		if(this.patientService.queryCondition(condition)==null)
			responseText="false";
		PrintWriter out = response.getWriter();
		out.println(responseText);
		out.flush();
		out.close();
		 return null;
	}
	

	

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public int getPageNumber() {
		return pageNumber;
	}

	public void setPageNumber(int pageNumber) {
		this.pageNumber = pageNumber;
	}

	public int getPageLength() {
		return pageLength;
	}

	public void setPageLength(int pageLength) {
		this.pageLength = pageLength;
	}

	public int getRecordSize() {
		return recordSize;
	}

	public void setRecordSize(int recordSize) {
		this.recordSize = recordSize;
	}

	public int getPageSize() {
		return pageSize;
	}

	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}

	public Page getPage() {
		return page;
	}

	public void setPage(Page page) {
		this.page = page;
	}

	public List<Patient> getPatientList() {
		return patientList;
	}

	public void setPatientList(List<Patient> patientList) {
		this.patientList = patientList;
	}

	@JSON(serialize = false)
	public PatientService getPatientService() {
		return patientService;
	}

	@Resource(name = "patientService")
	public void setPatientService(PatientService patientService) {
		this.patientService = patientService;
	}



	public Patient getPatient() {
		return patient;
	}



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

	
	@JSON(serialize = false)
	public PatientCaseService getPatientCaseService() {
		return patientCaseService;
	}

	@Resource(name = "patientCaseService")
	public void setPatientCaseService(PatientCaseService patientCaseService) {
		this.patientCaseService = patientCaseService;
	}

	public PatientCase getPatientCase() {
		return patientCase;
	}

	public void setPatientCase(PatientCase patientCase) {
		this.patientCase = patientCase;
	}
	public boolean[][] getIsCases() {
		return isCases;
	}
	public void setIsCases(boolean[][] isCases) {
		this.isCases = isCases;
	}
	
	@JSON(serialize = false)
	public FilmsService getFilmsService() {
		return filmsService;
	}
	
	@Resource(name = "filmsService")
	public void setFilmsService(FilmsService filmsService) {
		this.filmsService = filmsService;
	}

	public String getHosNum() {
		return hosNum;
	}

	public void setHosNum(String hosNum) {
		this.hosNum = hosNum;
	}

	public String getFilmsNum() {
		return filmsNum;
	}

	public void setFilmsNum(String filmsNum) {
		this.filmsNum = filmsNum;
	}
	
	public String getCurrAction() {
		return currAction;
	}

	public void setCurrAction(String currAction) {
		this.currAction = currAction;
	}

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}

	public String getPatient_age_low() {
		return patient_age_low;
	}

	public void setPatient_age_low(String patient_age_low) {
		this.patient_age_low = patient_age_low;
	}

	public String getPatient_age_high() {
		return patient_age_high;
	}

	public void setPatient_age_high(String patient_age_high) {
		this.patient_age_high = patient_age_high;
	}

	public String getOldHoNum() {
		return oldHoNum;
	}

	public void setOldHoNum(String oldHoNum) {
		this.oldHoNum = oldHoNum;
	}

	public File getMyDoc() {
		return myDoc;
	}

	public void setMyDoc(File myDoc) {
		this.myDoc = myDoc;
	}

	public String getMyDocFileName() {
		return myDocFileName;
	}

	public void setMyDocFileName(String myDocFileName) {
		this.myDocFileName = myDocFileName;
	}

	public String getMyDocContentType() {
		return myDocContentType;
	}

	public void setMyDocContentType(String myDocContentType) {
		this.myDocContentType = myDocContentType;
	}

	/*public Films getFilms() {
		return films;
	}

	public void setFilms(Films films) {
		this.films = films;
	}


	public File getImage() {
		return image;
	}

	public void setImage(File image) {
		this.image = image;
	}

	public String getImageFileName() {
		return imageFileName;
	}

	public void setImageFileName(String imageFileName) {
		this.imageFileName = imageFileName;
	}

	public String getImageContentType() {
		return imageContentType;
	}

	public void setImageContentType(String imageContentType) {
		this.imageContentType = imageContentType;
	}
	*/
	public String getPatient_name() {
		return patient_name;
	}

	public void setPatient_name(String patient_name) {
		this.patient_name = patient_name;
	}

	public String getPatient_sex() {
		return patient_sex;
	}

	public void setPatient_sex(String patient_sex) {
		this.patient_sex = patient_sex;
	}

	public String getPatient_casedes() {
		return patient_casedes;
	}

	public void setPatient_casedes(String patient_casedes) {
		this.patient_casedes = patient_casedes;
	}

	public String getPatient_casesecdes() {
		return patient_casesecdes;
	}

	public void setPatient_casesecdes(String patient_casesecdes) {
		this.patient_casesecdes = patient_casesecdes;
	}

	public String getWay_opera() {
		return way_opera;
	}

	public void setWay_opera(String way_opera) {
		this.way_opera = way_opera;
	}

	public String getJuade_opera() {
		return juade_opera;
	}

	public void setJuade_opera(String juade_opera) {
		this.juade_opera = juade_opera;
	}

	public String getIds() {
		return ids;
	}

	public void setIds(String ids) {
		this.ids = ids;
	}




	public List<Films> getFilms() {
		return films;
	}

	public void setFilms(List<Films> films) {
		this.films = films;
	}

	public List<File> getImage() {
		return image;
	}

	public String[] getImageFileName() {
		return imageFileName;
	}

	public void setImageFileName(String[] imageFileName) {
		this.imageFileName = imageFileName;
	}

	public String[] getImageContentType() {
		return imageContentType;
	}

	public void setImageContentType(String[] imageContentType) {
		this.imageContentType = imageContentType;
	}

	public void setImage(List<File> image) {
		this.image = image;
	}






}
最近下载更多
Mr_VVcat  LV8 4月16日
zhaoming200677  LV12 2023年4月18日
xiquyiyuan  LV10 2023年3月29日
adfsxz  LV3 2022年8月29日
wanglinddad  LV54 2021年12月29日
17683946472  LV9 2021年11月26日
圈子圈  LV3 2021年4月10日
lhw549624  LV3 2021年1月9日
2639891331  LV8 2021年1月4日
于明豪  LV1 2020年12月8日
最近浏览更多
hmf1989 4月29日
暂无贡献等级
Mr_VVcat  LV8 4月16日
FF加菲猫  LV4 2月15日
微笑刺客  LV15 1月17日
952773464 1月15日
暂无贡献等级
qq2901732871  LV9 1月8日
iiiiiiixiiiiii  LV1 1月5日
xk16675552250  LV33 1月4日
WBelong  LV7 2023年12月25日
liqing1  LV1 2023年12月23日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友