Beispiel #1
0
		///<summary></summary>
		public static long Insert(Disease disease) {
			if(RemotingClient.RemotingRole==RemotingRole.ClientWeb) {
				disease.DiseaseNum=Meth.GetLong(MethodBase.GetCurrentMethod(),disease);
				return disease.DiseaseNum;
			}
			return Crud.DiseaseCrud.Insert(disease);
		}
Beispiel #2
0
		///<summary></summary>
		public static void Update(Disease disease) {
			if(RemotingClient.RemotingRole==RemotingRole.ClientWeb) {
				Meth.GetVoid(MethodBase.GetCurrentMethod(),disease);
				return;
			}
			Crud.DiseaseCrud.Update(disease);
		}
Beispiel #3
0
		///<summary></summary>
		public static void Delete(Disease disease) {
			if(RemotingClient.RemotingRole==RemotingRole.ClientWeb) {
				Meth.GetVoid(MethodBase.GetCurrentMethod(),disease);
				return;
			}
			string command="DELETE FROM disease WHERE DiseaseNum ="+POut.Long(disease.DiseaseNum);
			Db.NonQ(command);
		}
Beispiel #4
0
		///<summary></summary>
		public FormDiseaseEdit(Disease diseaseCur)
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();
			Lan.F(this);
			DiseaseCur=diseaseCur;
		}
Beispiel #5
0
		private void SaveDiseases(){
			Disease disease;
			for(int i=0;i<listDiseases.CheckedIndices.Count;i++){
				disease=new Disease();
				disease.PatNum=PatCur.PatNum;
				disease.DiseaseDefNum=DiseaseDefs.List[listDiseases.CheckedIndices[i]].DiseaseDefNum;
				Diseases.Insert(disease);
			}
		}
Beispiel #6
0
		private void butAddProblem_Click(object sender,EventArgs e) {
			FormDiseaseDefs formDD=new FormDiseaseDefs();
			formDD.IsSelectionMode=true;
			formDD.IsMultiSelect=true;
			formDD.ShowDialog();
			if(formDD.DialogResult!=DialogResult.OK) {
				return;
			}
			for(int i=0;i<formDD.SelectedDiseaseDefNums.Count;i++) {
				if(CDSPermissions.GetForUser(Security.CurUser.UserNum).ShowCDS && CDSPermissions.GetForUser(Security.CurUser.UserNum).ProblemCDS){
					FormCDSIntervention FormCDSI=new FormCDSIntervention();
					FormCDSI.ListCDSI=EhrTriggers.TriggerMatch(DiseaseDefs.GetItem(formDD.SelectedDiseaseDefNums[i]),PatCur);
					FormCDSI.ShowIfRequired();
					if(FormCDSI.DialogResult==DialogResult.Abort) {
						continue;//cancel 
					}
				}
				SecurityLogs.MakeLogEntry(Permissions.PatProblemListEdit,PatCur.PatNum,DiseaseDefs.GetName(formDD.SelectedDiseaseDefNums[i])+" added"); //Audit log made outside form because the form is just a list of problems and is called from many places.
				Disease disease=new Disease();
				disease.PatNum=PatCur.PatNum;
				disease.DiseaseDefNum=formDD.SelectedDiseaseDefNums[i];
				Diseases.Insert(disease);
			}
			FillProblems();
		}
Beispiel #7
0
		///<summary>Helper for GenerateCCD().</summary>
		private void GenerateCcdSectionFunctionalStatus(bool hasFunctionalStatus) {
			_w.WriteComment(@"
=====================================================================================================
Functional and Cognitive Status
=====================================================================================================");
			List<Disease> listProblemsFiltered;
			if(!hasFunctionalStatus) {
				listProblemsFiltered=new List<Disease>();
			}
			else {
				listProblemsFiltered=_listProblemsFuncFiltered;
			}
			Start("component");
			Start("section");
			TemplateId("2.16.840.1.113883.10.20.22.2.14");//Functional Status section. There is only one allowed template id.
			_w.WriteComment("Functional Status section template");//(Page 232)
			StartAndEnd("code","code","47420-5","codeSystem",strCodeSystemLoinc,"codeSystemName",strCodeSystemNameLoinc,"displayName","Functional Status");
			_w.WriteElementString("title","Functional Status");
			Start("text");//The following text will be parsed as html with a style sheet to be human readable.
			if(listProblemsFiltered.Count>0 && hasFunctionalStatus) {
				Start("table","width","100%","border","1");
				Start("thead");
				Start("tr");
				_w.WriteElementString("th","Condition");
				_w.WriteElementString("th","Effective Dates");
				_w.WriteElementString("th","Condition Status");
				End("tr");
				End("thead");
				Start("tbody");
				for(int i=0;i<listProblemsFiltered.Count;i++) {
					DiseaseDef diseaseDef=null;
					Snomed snomedProblem=null;
					if(listProblemsFiltered[i].DiseaseDefNum>0) {
						diseaseDef=DiseaseDefs.GetItem(listProblemsFiltered[i].DiseaseDefNum);
						if(diseaseDef!=null && !String.IsNullOrEmpty(diseaseDef.SnomedCode)) {
							snomedProblem=Snomeds.GetByCode(diseaseDef.SnomedCode);
						}
					}
					Start("tr");
					if(diseaseDef==null || snomedProblem==null) {
						_w.WriteElementString("td","");
					}
					else {
						_w.WriteElementString("td",snomedProblem.SnomedCode+" - "+snomedProblem.Description);
					}
					if(listProblemsFiltered[i].FunctionStatus==FunctionalStatus.FunctionalResult || listProblemsFiltered[i].FunctionStatus==FunctionalStatus.CognitiveResult) {
						DateText("td",listProblemsFiltered[i].DateStart);
					}
					else {//functional problem and cognitive problem
						if(listProblemsFiltered[i].DateStop.Year>1880) {
							_w.WriteElementString("td",listProblemsFiltered[i].DateStart.ToString("yyyyMMdd")+" to "+listProblemsFiltered[i].DateStop.ToString("yyyyMMdd"));
						}
						else {
							DateText("td",listProblemsFiltered[i].DateStart);
						}
					}
					_w.WriteElementString("td","Completed");
					End("tr");
				}
				End("tbody");
				End("table");
			}
			else {
				_w.WriteString("None");
			}
			End("text");
			if(listProblemsFiltered.Count==0) {//If there are no entries in the filtered list, then we want to add a dummy entry since at least one is required.
				Disease dis=new Disease();
				dis.FunctionStatus=FunctionalStatus.FunctionalProblem;//Just needs a version other than problem.
				listProblemsFiltered.Add(dis);
			}
			for(int i=0;i<listProblemsFiltered.Count;i++) {
				DiseaseDef diseaseDef=null;
				Snomed snomedProblem=null;
				if(listProblemsFiltered[i].PatNum!=0) {
					diseaseDef=DiseaseDefs.GetItem(listProblemsFiltered[i].DiseaseDefNum);
					snomedProblem=Snomeds.GetByCode(diseaseDef.SnomedCode);
				}
				if(diseaseDef==null) {
					diseaseDef=new DiseaseDef();
				}
				if(snomedProblem==null) {
					snomedProblem=new Snomed();
				}
				Start("entry","typeCode","DRIV");
				Start("observation","classCode","OBS","moodCode","EVN");
				if(listProblemsFiltered[i].FunctionStatus==FunctionalStatus.FunctionalResult) {
					TemplateId("2.16.840.1.113883.10.20.22.4.67");//(Page 383)
					_w.WriteComment("Functional Status Result Observation");
					Guid();
					StartAndEnd("code","code","54744-8","codeSystem",strCodeSystemLoinc,"codeSystemName",strCodeSystemNameLoinc);
					StartAndEnd("statusCode","code","completed");
					if(listProblemsFiltered[i].DateStart.Year<1880) {
						StartAndEnd("effectiveTime","nullFlavor","UNK");
					}
					else {
						DateElement("effectiveTime",listProblemsFiltered[i].DateStart);
					}
					if(String.IsNullOrEmpty(snomedProblem.SnomedCode)) {
						Start("value");
						_w.WriteAttributeString("xsi","type",null,"CD");
						Attribs("nullFlavor","UNK");
						End("value");
					}
					else {
						Start("value");
						_w.WriteAttributeString("xsi","type",null,"CD");
						Attribs("code",snomedProblem.SnomedCode,"displayName",snomedProblem.Description,"codeSystem",strCodeSystemSnomed,"codeSystemName",strCodeSystemNameSnomed);
						End("value");
					}
				}
				else if(listProblemsFiltered[i].FunctionStatus==FunctionalStatus.CognitiveResult) {
					TemplateId("2.16.840.1.113883.10.20.22.4.74");//(Page 342)
					_w.WriteComment("Cognitive Status Result Observation");
					Guid();
					StartAndEnd("code","code","5249-2","codeSystem",strCodeSystemLoinc,"codeSystemName",strCodeSystemNameLoinc);
					StartAndEnd("statusCode","code","completed");
					if(listProblemsFiltered[i].DateStart.Year<1880) {
						StartAndEnd("effectiveTime","nullFlavor","UNK");
					}
					else {
						DateElement("effectiveTime",listProblemsFiltered[i].DateStart);
					}
					if(String.IsNullOrEmpty(snomedProblem.SnomedCode)) {
						Start("value");
						_w.WriteAttributeString("xsi","type",null,"CD");
						Attribs("nullFlavor","UNK");
						End("value");
					}
					else {
						Start("value");
						_w.WriteAttributeString("xsi","type",null,"CD");
						Attribs("code",snomedProblem.SnomedCode,"displayName",snomedProblem.Description,"codeSystem",strCodeSystemSnomed,"codeSystemName",strCodeSystemNameSnomed);
						End("value");
					}
				}
				else if(listProblemsFiltered[i].FunctionStatus==FunctionalStatus.FunctionalProblem) {
					TemplateId("2.16.840.1.113883.10.20.22.4.68");//(Page 379)
					_w.WriteComment("Functional Status Problem Observation");
					Guid();
					StartAndEnd("code","code","404684003","codeSystem",strCodeSystemSnomed,"codeSystemName",strCodeSystemNameSnomed,"displayName","Finding of Functional Performance and Activity");
					StartAndEnd("statusCode","code","completed");
					Start("effectiveTime");
					if(listProblemsFiltered[i].DateStart.Year<1880) {
						StartAndEnd("low","nullFlavor","UNK");
					}
					else {
						DateElement("low",listProblemsFiltered[i].DateStart);
					}
					//"If the problem is known to be resolved, but the date of resolution is not known, then the high element SHALL be present, and 
					//the nullFlavor attribute SHALL be set to 'UNK'. Therefore, the existence of an high element within a problem does indicate that the problem has been resolved."
					if(listProblemsFiltered[i].DateStop.Year<1880) {
						StartAndEnd("high","nullFlavor","UNK");
					}
					else {
						DateElement("high",listProblemsFiltered[i].DateStop);
					}
					End("effectiveTime");
					if(String.IsNullOrEmpty(snomedProblem.SnomedCode)) {
						Start("value");
						_w.WriteAttributeString("xsi","type",null,"CD");
						Attribs("nullFlavor","UNK");
						End("value");
					}
					else {
						Start("value");
						_w.WriteAttributeString("xsi","type",null,"CD");
						Attribs("code",snomedProblem.SnomedCode,"displayName",snomedProblem.Description,"codeSystem",strCodeSystemSnomed,"codeSystemName",strCodeSystemNameSnomed);
						End("value");
					}
				}
				else if(listProblemsFiltered[i].FunctionStatus==FunctionalStatus.CognitiveProblem) {
					TemplateId("2.16.840.1.113883.10.20.22.4.73");//(Page 336)
					_w.WriteComment("Cognitive Status Problem Observation");
					Guid();
					StartAndEnd("code","code","373930000","codeSystem",strCodeSystemSnomed,"codeSystemName",strCodeSystemNameSnomed,"displayName","Cognitive Function Finding");
					StartAndEnd("statusCode","code","completed");
					//"If the problem is known to be resolved, but the date of resolution is not known, then the high element SHALL be present, and 
					//the nullFlavor attribute SHALL be set to 'UNK'. Therefore, the existence of a high element within a problem does indicate that the problem has been resolved."
					Start("effectiveTime");
					if(listProblemsFiltered[i].DateStart.Year<1880) {
						StartAndEnd("low","nullFlavor","UNK");
					}
					else {
						DateElement("low",listProblemsFiltered[i].DateStart);
					}
					if(listProblemsFiltered[i].DateStop.Year<1880) {
						StartAndEnd("high","nullFlavor","UNK");
					}
					else {
						DateElement("high",listProblemsFiltered[i].DateStop);
					}
					End("effectiveTime");
					if(String.IsNullOrEmpty(snomedProblem.SnomedCode)) {
						Start("value");
						_w.WriteAttributeString("xsi","type",null,"CD");
						Attribs("nullFlavor","UNK");
						End("value");
					}
					else {
						Start("value");
						_w.WriteAttributeString("xsi","type",null,"CD");
						Attribs("code",snomedProblem.SnomedCode,"displayName",snomedProblem.Description,"codeSystem",strCodeSystemSnomed,"codeSystemName",strCodeSystemNameSnomed);
						End("value");
					}
				}
				End("observation");
				End("entry");
			}
			End("section");
			End("component");
		}
Beispiel #8
0
		///<summary>Fills listDiseases and listDiseaseDef using the information found in the CCD document xmlDocCcd.  Does NOT insert any records into the db.</summary>
		public static void GetListDiseases(XmlDocument xmlDocCcd,List<Disease> listDiseases,List<DiseaseDef> listDiseaseDef) {
			//The length of listDiseases and listDiseaseDef will be the same. The information in listDiseaseDef might have duplicates.
			//Neither list of objects will be inserted into the db, so there will be no primary or foreign keys.
			List<XmlNode> listProblemActTemplate=GetNodesByTagNameAndAttributes(xmlDocCcd,"templateId","root","2.16.840.1.113883.10.20.22.4.3");// problem act template.
			List<XmlNode> listProbs=GetParentNodes(listProblemActTemplate);
			for(int i=0;i<listProbs.Count;i++) {
				//We have to start fairly high in the tree so that we can get the effective time if it is available.
				List<XmlNode> xmlNodeEffectiveTimes=GetNodesByTagNameAndAttributes(listProbs[i],"effectiveTime");
				DateTime dateTimeEffectiveLow=DateTime.MinValue;
				DateTime dateTimeEffectiveHigh=DateTime.MinValue;
				if(xmlNodeEffectiveTimes.Count>0) {
					XmlNode xmlNodeEffectiveTime=xmlNodeEffectiveTimes[0];
					dateTimeEffectiveLow=GetEffectiveTimeLow(xmlNodeEffectiveTime);
					dateTimeEffectiveHigh=GetEffectiveTimeHigh(xmlNodeEffectiveTime);
				}
				List<XmlNode> listProblemObservTemplate=GetNodesByTagNameAndAttributes(listProbs[i],"templateId","root","2.16.840.1.113883.10.20.22.4.4");// problem act template.
				List<XmlNode> listProbObs=GetParentNodes(listProblemObservTemplate);
				List<XmlNode> listTypeCodes=GetNodesByTagNameAndAttributesFromList(listProbObs,"code");
				List<XmlNode> listCodes=GetNodesByTagNameAndAttributesFromList(listProbObs,"value");
				if(listCodes[0].Attributes["nullFlavor"]!=null) {
					continue;
				}
				string probType=listTypeCodes[0].Attributes["code"].Value;
				string probCode=listCodes[0].Attributes["code"].Value;
				string probName=listCodes[0].Attributes["displayName"].Value;
				List<XmlNode> listStatusObservTemplate=GetNodesByTagNameAndAttributes(listProbs[i],"templateId","root","2.16.840.1.113883.10.20.22.4.6");// Status Observation template.
				List<XmlNode> listStatusObs=GetParentNodes(listStatusObservTemplate);
				List<XmlNode> listActive=GetNodesByTagNameAndAttributesFromList(listStatusObs,"value");
				Disease dis=new Disease();
				dis.SnomedProblemType=probType;
				dis.DateStart=dateTimeEffectiveLow;
				dis.IsNew=true;
				if(listActive.Count>0 && listActive[0].Attributes["code"].Value=="55561003") {//Active (qualifier value)
					dis.ProbStatus=ProblemStatus.Active;
				}
				else if(listActive.Count>0 && listActive[0].Attributes["code"].Value=="413322009") {//Problem resolved (finding)
					dis.ProbStatus=ProblemStatus.Resolved;
					dis.DateStop=dateTimeEffectiveHigh;
				}
				else {
					dis.ProbStatus=ProblemStatus.Inactive;
					dis.DateStop=dateTimeEffectiveHigh;
				}
				listDiseases.Add(dis);
				DiseaseDef disD=new DiseaseDef();
				disD.IsHidden=false;
				disD.IsNew=true;
				disD.SnomedCode=probCode;
				disD.DiseaseName=probName;
				listDiseaseDef.Add(disD);
			}
		}
Beispiel #9
0
		///<summary>Helper for GenerateCCD().  Problem section.</summary>
		private void GenerateCcdSectionProblems(bool hasProblem) {
			_w.WriteComment(@"
=====================================================================================================
Problems
=====================================================================================================");
			string snomedProblemType="55607006";
			List<Disease> listProblemsFiltered;
			if(!hasProblem) {
				listProblemsFiltered=new List<Disease>();
			}
			else {
				listProblemsFiltered=_listProblemsFiltered;
			}
			string status="Inactive";
			string statusCode="73425007";
			string statusOther="active";
			Start("component");
			Start("section");
			TemplateId("2.16.840.1.113883.10.20.22.2.5.1");//Problems section with coded entries required.
			_w.WriteComment("Problems section template");
			StartAndEnd("code","code","11450-4","codeSystem",strCodeSystemLoinc,"codeSystemName",strCodeSystemNameLoinc,"displayName","Problem list");
			_w.WriteElementString("title","Problems");
			Start("text");//The following text will be parsed as html with a style sheet to be human readable.
			if(listProblemsFiltered.Count>0 && hasProblem) {
				Start("table","width","100%","border","1");
				Start("thead");
				Start("tr");
				_w.WriteElementString("th","Problem");
				_w.WriteElementString("th","Date Start");
				_w.WriteElementString("th","Date End");
				_w.WriteElementString("th","Status");
				End("tr");
				End("thead");
				Start("tbody");
				for(int i=0;i<listProblemsFiltered.Count;i++) {
					DiseaseDef diseaseDef;
					if(listProblemsFiltered[i].DiseaseDefNum==0) {
						diseaseDef=new DiseaseDef();
					}
					else {
						diseaseDef=DiseaseDefs.GetItem(listProblemsFiltered[i].DiseaseDefNum);
					}
					Start("tr");
					if(String.IsNullOrEmpty(diseaseDef.SnomedCode)) {
						_w.WriteElementString("td","");
					}
					else {
						_w.WriteElementString("td",diseaseDef.SnomedCode+" - "+diseaseDef.DiseaseName);
					}
					if(listProblemsFiltered[i].DateStart.Year<1880) {
						_w.WriteElementString("td","");//Directions
					}
					else {
						DateText("td",listProblemsFiltered[i].DateStart);//Start Date
					}
					if(listProblemsFiltered[i].DateStop.Year<1880) {
						_w.WriteElementString("td","");//Directions
					}
					else {
						DateText("td",listProblemsFiltered[i].DateStop);//End Date
					}
					if(listProblemsFiltered[i].ProbStatus==ProblemStatus.Active) {
						status="Active";
						statusCode="55561003";
						statusOther="active";
					}
					else if(listProblemsFiltered[i].ProbStatus==ProblemStatus.Inactive) {
						status="Inactive";
						statusCode="73425007";
						statusOther="completed";
					}
					else {
						status="Resolved";
						statusCode="413322009";
						statusOther="completed";
					}
					_w.WriteElementString("td",status);
					End("tr");
				}
				End("tbody");
				End("table");
			}
			else {
				_w.WriteString("None");
			}
			End("text");
			//Start("text");
			//StartAndEnd("content","ID","problems");
			//Start("list","listType","ordered");
			//for(int i=0;i<listProblemsFiltered.Count;i++) {//Fill Problems Table
			//	DiseaseDef diseaseDef=DiseaseDefs.GetItem(listProblemsFiltered[i].DiseaseDefNum);
			//	Start("item");
			//	_w.WriteString(diseaseDef.SnomedCode+" - "+diseaseDef.DiseaseName+" : "+"Status - ");
			//	if(listProblemsFiltered[i].ProbStatus==ProblemStatus.Active) {
			//		_w.WriteString("Active");
			//		status="Active";
			//		statusCode="55561003";
			//		statusOther="active";
			//	}
			//	else if(listProblemsFiltered[i].ProbStatus==ProblemStatus.Inactive) {
			//		_w.WriteString("Inactive");
			//		status="Inactive";
			//		statusCode="73425007";
			//		statusOther="completed";
			//	}
			//	else {
			//		_w.WriteString("Resolved");
			//		status="Resolved";
			//		statusCode="413322009";
			//		statusOther="completed";
			//	}
			//	End("item");
			//}
			//End("list");
			//End("text");
			if(listProblemsFiltered.Count==0) {//If there are no entries in the filtered list, then we want to add a dummy entry since at least one is required.
				Disease dis=new Disease();
				listProblemsFiltered.Add(dis);
			}
			for(int i=0;i<listProblemsFiltered.Count;i++) {//Fill Problems Info
				DiseaseDef diseaseDef;
				if(listProblemsFiltered[i].DiseaseDefNum==0) {
					diseaseDef=new DiseaseDef();
				}
				else {
					diseaseDef=DiseaseDefs.GetItem(listProblemsFiltered[i].DiseaseDefNum);
				}
				Start("entry","typeCode","DRIV");
				Start("act","classCode","ACT","moodCode","EVN");
				_w.WriteComment("Problem Concern Act template");//Concern Act Section
				TemplateId("2.16.840.1.113883.10.20.22.4.3");
				Guid();
				StartAndEnd("code","code","CONC","codeSystem","2.16.840.1.113883.5.6","displayName","Concern");
				StartAndEnd("statusCode","code",statusOther);//Allowed values: active, suspended, aborted, completed.
				Start("effectiveTime");
				if(listProblemsFiltered[i].DateStart.Year<1880) {
					StartAndEnd("low","nullFlavor","UNK");
				}
				else {
					DateElement("low",listProblemsFiltered[i].DateStart);
				}
				if(listProblemsFiltered[i].DateStop.Year<1880) {
					StartAndEnd("high","nullFlavor","UNK");
				}
				else {
					DateElement("high",listProblemsFiltered[i].DateStop);
				}
				End("effectiveTime");
				Start("entryRelationship","typeCode","SUBJ");
				Start("observation","classCode","OBS","moodCode","EVN");
				_w.WriteComment("Problem Observation template");//Observation Section
				TemplateId("2.16.840.1.113883.10.20.22.4.4");
				Guid();
				StartAndEnd("code","code",snomedProblemType,"codeSystem",strCodeSystemSnomed,"displayName","Problem");
				StartAndEnd("statusCode","code","completed");//Allowed values: completed.
				Start("effectiveTime");
				if(listProblemsFiltered[i].DateStart.Year<1880) {
					StartAndEnd("low","nullFlavor","UNK");
				}
				else {
					DateElement("low",listProblemsFiltered[i].DateStart);
				}
				End("effectiveTime");
				Start("value");
				_w.WriteAttributeString("xsi","type",null,"CD");
				if(String.IsNullOrEmpty(diseaseDef.SnomedCode)) {
					Attribs("nullFlavor","UNK");
				}
				else {
					Attribs("code",diseaseDef.SnomedCode,"codeSystem",strCodeSystemSnomed,"displayName",diseaseDef.DiseaseName);
				}
				End("value");
				Start("entryRelationship","typeCode","REFR");
				Start("observation","classCode","OBS","moodCode","EVN");
				_w.WriteComment("Status Observation template");//Status Observation Section
				TemplateId("2.16.840.1.113883.10.20.22.4.6");
				Start("code");
				_w.WriteAttributeString("xsi","type",null,"CE");
				Attribs("code","33999-4","codeSystem",strCodeSystemLoinc,"codeSystemName",strCodeSystemNameLoinc,"displayName","Status");
				End("code");
				StartAndEnd("statusCode","code","completed");//Allowed values: completed.
				Start("value");
				_w.WriteAttributeString("xsi","type",null,"CD");
				Attribs("code",statusCode,"codeSystem",strCodeSystemSnomed,"displayName",status);
				End("value");
				End("observation");
				End("entryRelationship");
				End("observation");
				End("entryRelationship");
				End("act");
				End("entry");
			}
			End("section");
			End("component");
		}
		private static void OnCreated(object source,FileSystemEventArgs e) {
			//MessageBox.Show("File created.  It will now be deleted.");
			Thread.Sleep(200);//just to make sure the other process is done writing.
			string[] lines=File.ReadAllLines(e.FullPath);
			File.Delete(e.FullPath);
			if(lines.Length!=1){
				MessageBox.Show(e.FullPath+" was supposed to have exactly one line.  Invalid file.");
				return;
			}
			string rawFieldNames="PAT_PK,PAT_LOGFK,PAT_LANFK,PAT_TITLE,PAT_FNAME,PAT_MI,PAT_LNAME,PAT_CALLED,PAT_ADDR1,PAT_ADDR2,PAT_CITY,PAT_ST,PAT_ZIP,PAT_HPHN,PAT_WPHN,PAT_EXT,PAT_FAX,PAT_PAGER,PAT_CELL,PAT_EMAIL,PAT_SEX,PAT_EDOCS,PAT_STATUS,PAT_TYPE,PAT_BIRTH,PAT_SSN,PAT_NOCALL,PAT_NOCORR,PAT_DISRES,PAT_LSTUPD,PAT_INSNM,PAT_INSGPL,PAT_INSAD1,PAT_INSAD2,PAT_INSCIT,PAT_INSST,PAT_INSZIP,PAT_INSPHN,PAT_INSEXT,PAT_INSCON,PAT_INSGNO,PAT_EMPNM,PAT_EMPAD1,PAT_EMPAD2,PAT_EMPCIT,PAT_EMPST,PAT_EMPZIP,PAT_EMPPHN,PAT_REFLNM,PAT_REFFNM,PAT_REFMI,PAT_REFPHN,PAT_REFEML,PAT_REFSPE,PAT_NOTES,PAT_NOTE1,PAT_NOTE2,PAT_NOTE3,PAT_NOTE4,PAT_NOTE5,PAT_NOTE6,PAT_NOTE7,PAT_NOTE8,PAT_NOTE9,PAT_NOTE10,PAT_FPSCAN,PAT_PREMED,PAT_MEDS,PAT_FTSTUD,PAT_PTSTUD,PAT_COLLEG,PAT_CHRTNO,PAT_OTHID,PAT_RESPRT,PAT_POLHLD,PAT_CUSCD,PAT_PMPID";
			fieldNames=rawFieldNames.Split(',');
			fieldVals=lines[0].Split(',');
			if(fieldNames.Length!=fieldVals.Length){
				MessageBox.Show(e.FullPath+" contains "+fieldNames.Length.ToString()+" field names, but "+fieldVals.Length.ToString()+" field values.  Invalid file.");
				return;
			}
			for(int i=0;i<fieldVals.Length;i++) {
				fieldVals[i]=fieldVals[i].Replace("\"","");//remove quotes
			}
			long patNum=PIn.Long(GetVal("PAT_OTHID"));
			if(patNum==0){
				MessageBox.Show(patNum.ToString()+" is not a recognized PatNum.");
				return;
			}
			Family fam=Patients.GetFamily(patNum);
			if(fam==null){
				MessageBox.Show("Could not find patient based on PatNum "+patNum.ToString());
				return;
			}
			Patient pat=fam.GetPatient(patNum);
			Patient patOld=pat.Copy();
			string txt;
			string note="PT Dental import processed.  Some information is shown below which was too complex to import automatically.\r\n";
			txt=GetVal("PAT_FNAME");
			if(txt!=""){
				pat.FName=txt;
			}
			txt=GetVal("PAT_MI");
			if(txt!=""){
				pat.MiddleI=txt;
			}
			txt=GetVal("PAT_LNAME");
			if(txt!=""){
				pat.LName=txt;
			}
			txt=GetVal("PAT_CALLED");
			if(txt!=""){
				pat.Preferred=txt;
			}
			txt=GetVal("PAT_ADDR1");
			if(txt!=""){
				pat.Address=txt;
			}
			txt=GetVal("PAT_ADDR2");
			if(txt!=""){
				pat.Address2=txt;
			}
			txt=GetVal("PAT_CITY");
			if(txt!=""){
				pat.City=txt;
			}
			txt=GetVal("PAT_ST");
			if(txt!=""){
				pat.State=txt;
			}
			txt=GetVal("PAT_ZIP");
			if(txt!=""){
				pat.Zip=txt;
			}
			txt=GetVal("PAT_HPHN");//No punct
			if(txt!=""){
				pat.HmPhone=TelephoneNumbers.ReFormat(txt);
			}
			txt=GetVal("PAT_WPHN");
			if(txt!=""){
				pat.WkPhone=TelephoneNumbers.ReFormat(txt);
			}
			//no matching fields for these three:
			txt=GetVal("PAT_EXT");
			if(txt!="") {
				note+="Ph extension: "+txt+"\r\n";
			}
			txt=GetVal("PAT_FAX");
			if(txt!="") {
				note+="Fax: "+txt+"\r\n";
			}
			txt=GetVal("PAT_PAGER");
			if(txt!="") {
				note+="Pager: "+txt+"\r\n";
			}
			txt=GetVal("PAT_CELL");
			if(txt!=""){
				pat.WirelessPhone=TelephoneNumbers.ReFormat(txt);
			}
			txt=GetVal("PAT_EMAIL");
			if(txt!=""){
				pat.Email=txt;
			}
			txt=GetVal("PAT_SEX");//M or F
			if(txt=="M"){
				pat.Gender=PatientGender.Male;
			}
			if(txt=="F"){
				pat.Gender=PatientGender.Male;
			}
			txt=GetVal("PAT_STATUS");//our patStatus, Any text allowed
			switch(txt){
				case "Archived": pat.PatStatus=PatientStatus.Archived; break;
				case "Deceased": pat.PatStatus=PatientStatus.Deceased; break;
				//case "Archived": pat.PatStatus=PatientStatus.Deleted; break;
				case "Inactive": pat.PatStatus=PatientStatus.Inactive; break;
				case "NonPatient": pat.PatStatus=PatientStatus.NonPatient; break;
				case "Patient": pat.PatStatus=PatientStatus.Patient; break;
			}
			txt=GetVal("PAT_TYPE");//our Position, Any text allowed
			switch(txt){
				case "Child": pat.Position=PatientPosition.Child; break;
				case "Divorced": pat.Position=PatientPosition.Divorced; break;
				case "Married": pat.Position=PatientPosition.Married; break;
				case "Single": pat.Position=PatientPosition.Single; break;
				case "Widowed": pat.Position=PatientPosition.Widowed; break;
			}
			txt=GetVal("PAT_BIRTH");// yyyyMMdd
			if(txt!=""){
				pat.Birthdate=PIn.Date(txt);
			}
			txt=GetVal("PAT_SSN");// No punct
			if(txt!=""){
				pat.SSN=txt;
			}
			txt=GetVal("PAT_NOCALL");// T if no call
			if(txt!=""){
				note+="No Call Patient: "+txt+"\r\n";
			}
			txt=GetVal("PAT_NOCORR");// T/F
			if(txt!="") {
				note+="No Correspondence: "+txt+"\r\n";
			}
			txt=GetVal("PAT_NOTES");// No limits.
			if(txt!=""){
				note+=txt+"\r\n";
			}
			txt=GetVal("PAT_PREMED");// F or T
			//I don't like giving the patient control of this field, but I guess the office has the option of not showing this on forms.
			if(txt=="T") {
				pat.Premed=true;
			}
			if(txt=="F") {
				pat.Premed=false;
			}
			txt=GetVal("PAT_MEDS");// The meds that they must premedicate with.
			if(txt!="") {
				note+="Patient Meds: "+txt+"\r\n";
			}
			string ft=GetVal("PAT_FTSTUD");// T/F
			string pt=GetVal("PAT_PTSTUD");//parttime
			if(ft=="T"){
				pat.StudentStatus="F";//fulltime
			}
			else if(pt=="T"){
				pat.StudentStatus="P";//parttime
			}
			else if(ft=="F" && pt=="F"){
				pat.StudentStatus="";//nonstudent
			}
			else if(ft=="F" && pat.StudentStatus=="F"){
				pat.StudentStatus="";
			}
			else if(pt=="F" && pat.StudentStatus=="P"){
				pat.StudentStatus="";
			}
			txt=GetVal("PAT_COLLEG");
			if(txt!="") {
				pat.SchoolName=txt;
			}
			txt=GetVal("PAT_CHRTNO");
			//I don't think patient should have control of this field.
			if(txt!="") {
				pat.ChartNumber=txt;
			}
			txt=GetVal("PAT_RESPRT");// Responsible party checkbox T/F
			if(txt=="T" && pat.PatNum!=pat.Guarantor) {
				note+="Responsible party: True\r\n";
			}
			if(txt=="F" && pat.PatNum==pat.Guarantor) {
				note+="Responsible party: False\r\n";
			}
			txt=GetVal("PAT_POLHLD");// Policy holder checkbox T/F
			if(txt=="T") {
				note+="Policy holder: True\r\n";
			}
			if(txt=="F") {
				note+="Policy holder: False\r\n";
			}
			txt=GetVal("PAT_INSNM");
			if(txt!="") {
				note+="Insurance name: "+txt+"\r\n";
			}
			txt=GetVal("PAT_INSGPL");
			if(txt!="") {
				note+="Ins group plan name: "+txt+"\r\n";
			}
			txt=GetVal("PAT_INSAD1");
			if(txt!="") {
				note+="Ins address: "+txt+"\r\n";
			}
			txt=GetVal("PAT_INSAD2");
			if(txt!="") {
				note+="Ins address2: "+txt+"\r\n";
			}
			txt=GetVal("PAT_INSCIT");
			if(txt!="") {
				note+="Ins city: "+txt+"\r\n";
			}
			txt=GetVal("PAT_INSST");
			if(txt!="") {
				note+="Ins state: "+txt+"\r\n";
			}
			txt=GetVal("PAT_INSZIP");
			if(txt!="") {
				note+="Ins zip: "+txt+"\r\n";
			}
			txt=GetVal("PAT_INSPHN");
			if(txt!="") {
				note+="Ins phone: "+TelephoneNumbers.ReFormat(txt)+"\r\n";
			}
			txt=GetVal("PAT_INSGNO");// Ins group number
			if(txt!="") {
				note+="Ins group number: "+txt+"\r\n";
			}
			txt=GetVal("PAT_EMPNM");
			if(txt!="") {
				note+="Employer name: "+txt+"\r\n";
			}
			txt=GetVal("PAT_REFLNM");
			if(txt!="") {
				note+="Referral last name: "+txt+"\r\n";
			}
			txt=GetVal("PAT_REFFNM");
			if(txt!="") {
				note+="Referral first name: "+txt+"\r\n";
			}
			txt=GetVal("PAT_REFMI");
			if(txt!="") {
				note+="Referral middle init: "+txt+"\r\n";
			}
			txt=GetVal("PAT_REFPHN");
			if(txt!="") {
				note+="Referral phone: "+txt+"\r\n";
			}
			txt=GetVal("PAT_REFEML");// Referral source email
			if(txt!="") {
				note+="Referral email: "+txt+"\r\n";
			}
			txt=GetVal("PAT_REFSPE");// Referral specialty. Customizable, so any allowed
			if(txt!="") {
				note+="Referral specialty: "+txt+"\r\n";
			}
			Patients.Update(pat,patOld);
			if(File.Exists(dir+"\\"+importMedCsv)){
				lines=File.ReadAllLines(dir+"\\"+importMedCsv);
				File.Delete(dir+"\\"+importMedCsv);
				if(lines.Length<1) {
					MessageBox.Show(e.FullPath+" was supposed to have at least one line.  Invalid file.");
					return;
				}
				fieldNames=lines[0].Split(',');
				long diseaseDefNum;
				Disease disease;
				string diseaseNote;
				for(int i=1;i<lines.Length;i++){
					fieldVals=lines[i].Split(',');
					txt=GetVal("PMA_MALDES");
					diseaseNote=GetVal("PMA_NOTES");
					if(txt==""){
						continue;
					}
					diseaseDefNum=DiseaseDefs.GetNumFromName(txt);
					if(diseaseDefNum==0){
						note+="Disease: "+txt+", "+diseaseNote+"\r\n";
					}
					disease=Diseases.GetSpecificDiseaseForPatient(patNum,diseaseDefNum);
					if(disease==null){
						disease=new Disease();
						disease.DiseaseDefNum=diseaseDefNum;
						disease.PatNum=patNum;
						disease.PatNote=diseaseNote;
						Diseases.Insert(disease);
					}
					else{
						if(txt!=""){
							if(disease.PatNote!=""){
								disease.PatNote+="  ";
							}
							disease.PatNote+=diseaseNote;
							Diseases.Update(disease);
						}
					}
				}
			}
			Commlog comm=new Commlog();
			comm.PatNum=patNum;
			comm.SentOrReceived=CommSentOrReceived.Received;
			comm.CommDateTime=DateTime.Now;
			comm.CommType=Commlogs.GetTypeAuto(CommItemTypeAuto.MISC);
			comm.Mode_=CommItemMode.None;
			comm.Note=note;
			comm.UserNum=Security.CurUser.UserNum;
			Commlogs.Insert(comm);
			MessageBox.Show("PT Dental import complete.");
		}
Beispiel #11
0
		private void butOK_Click(object sender,EventArgs e) {
			#region Validate
			DateTime date;
			if(textDateTaken.Text=="") {
				MsgBox.Show(this,"Please enter a date.");
				return;
			}
			try {
				date=DateTime.Parse(textDateTaken.Text);
			}
			catch {
				MsgBox.Show(this,"Please fix date first.");
				return;
			}
			if(date<patCur.Birthdate) {
				MsgBox.Show(this,"Exam date cannot be before the patient's birthdate.");
				return;
			}
			//validate height
			float height=0;
			try {
				if(textHeight.Text!="") {
					height = float.Parse(textHeight.Text);
				}
			}
			catch {
				MsgBox.Show(this,"Please fix height first.");
				return;
			}
			if(height<0) {
				MsgBox.Show(this,"Please fix height first.");
				return;
			}
			//validate weight
			float weight=0;
			try {
				if(textWeight.Text!="") {
					weight = float.Parse(textWeight.Text);
				}
			}
			catch {
				MsgBox.Show(this,"Please fix weight first.");
				return;
			}
			if(weight<0) {
				MsgBox.Show(this,"Please fix weight first.");
				return;
			}
			//validate bp
			int BPsys=0;
			int BPdia=0;
			try {
				if(textBPs.Text!="") {
					BPsys = int.Parse(textBPs.Text);
				}
				if(textBPd.Text!="") {
					BPdia = int.Parse(textBPd.Text);
				}
			}
			catch {
				MsgBox.Show(this,"Please fix BP first.");
				return;
			}
			if(BPsys<0 || BPdia<0) {
				MsgBox.Show(this,"Please fix BP first.");
				return;
			}
			#endregion
			#region Save
			VitalsignCur.DateTaken=date;
			VitalsignCur.Height=height;
			VitalsignCur.Weight=weight;
			VitalsignCur.BpDiastolic=BPdia;
			VitalsignCur.BpSystolic=BPsys;
			//textBMIPercentile will be the calculated percentile or -1 if not in age range or there is an error calculating the percentile.
			//In this case the text box will be not visible, but the text will be set to -1 and we will store it that way to indicate no valid BMIPercentile
			VitalsignCur.BMIPercentile=PIn.Int(textBMIPercentile.Text);//could be -1 if not in age range or error calculating percentile
			VitalsignCur.BMIExamCode="";
			if(textBMIPercentileCode.Visible && textBMIPercentileCode.Text!="") {
				VitalsignCur.BMIExamCode="59576-9";//Body mass index (BMI) [Percentile] Per age and gender, only code used for percentile, only visible if under 17 at time of exam
			}
			if(comboHeightExamCode.SelectedIndex>0) {
				VitalsignCur.HeightExamCode=listHeightCodes[comboHeightExamCode.SelectedIndex-1].LoincCode;
			}
			if(comboWeightExamCode.SelectedIndex>0) {
				VitalsignCur.WeightExamCode=listWeightCodes[comboWeightExamCode.SelectedIndex-1].LoincCode;
			}
			switch(labelWeightCode.Text) {
				case "Overweight":
					if(Snomeds.GetByCode("238131007")!=null) {
						VitalsignCur.WeightCode="238131007";
					}
					break;
				case "Underweight":
					if(Snomeds.GetByCode("248342006")!=null) {
						VitalsignCur.WeightCode="248342006";
					}
					break;
				case "":
				default:
					VitalsignCur.WeightCode="";
					break;
			}
			#region PregnancyDx
			if(checkPregnant.Checked) {//pregnant, add pregnant dx if necessary
				if(pregDisDefNumCur==0) {
					//shouldn't happen, if checked this must be set to either an existing problem def or a new problem that requires inserting, return to form with checkPregnant unchecked
					MsgBox.Show(this,"This exam must point to a valid pregnancy diagnosis.");
					checkPregnant.Checked=false;
					labelPregNotice.Visible=false;
					return;
				}
				if(VitalsignCur.PregDiseaseNum==0) {//insert new preg disease and update vitalsign to point to it
					Disease pregDisNew=new Disease();
					pregDisNew.PatNum=VitalsignCur.PatNum;
					pregDisNew.DiseaseDefNum=pregDisDefNumCur;
					pregDisNew.DateStart=VitalsignCur.DateTaken;
					pregDisNew.ProbStatus=ProblemStatus.Active;
					VitalsignCur.PregDiseaseNum=Diseases.Insert(pregDisNew);
				}
				else {
					Disease disCur=Diseases.GetOne(VitalsignCur.PregDiseaseNum);
					if(VitalsignCur.DateTaken<disCur.DateStart
						|| (disCur.DateStop.Year>1880 && VitalsignCur.DateTaken>disCur.DateStop))
					{//the current exam is no longer within dates of preg problem, uncheck the pregnancy box and remove the pointer to the disease
						MsgBox.Show(this,"This exam is not within the active dates of the attached pregnancy problem.");
						checkPregnant.Checked=false;
						textPregCode.Clear();
						textPregCodeDescript.Clear();
						labelPregNotice.Visible=false;
						VitalsignCur.PregDiseaseNum=0;
						butChangeDefault.Text="Change Default";
						return;
					}
				}
			}
			else {//checkPregnant not checked
				VitalsignCur.PregDiseaseNum=0;
			}
			#endregion
			#region EhrNotPerformed
			if(!checkNotPerf.Checked) {
				if(VitalsignCur.EhrNotPerformedNum!=0) {
					EhrNotPerformeds.Delete(VitalsignCur.EhrNotPerformedNum);
					VitalsignCur.EhrNotPerformedNum=0;
				}
			}
			if(VitalsignCur.IsNew) {
			  Vitalsigns.Insert(VitalsignCur);
			}
			else {
				Vitalsigns.Update(VitalsignCur);
			}
			#endregion
			#endregion
			#region CDS Intervention Trigger
			if(CDSPermissions.GetForUser(Security.CurUser.UserNum).ShowCDS && CDSPermissions.GetForUser(Security.CurUser.UserNum).VitalCDS) {
				FormCDSIntervention FormCDSI=new FormCDSIntervention();
				FormCDSI.ListCDSI=EhrTriggers.TriggerMatch(VitalsignCur,Patients.GetPat(VitalsignCur.PatNum));
				FormCDSI.ShowIfRequired(false);
			}
			#endregion
			DialogResult=DialogResult.OK;
		}
Beispiel #12
0
 private void butAddProblem_Click(object sender,EventArgs e)
 {
     FormDiseaseDefs formDD=new FormDiseaseDefs();
     formDD.IsSelectionMode=true;
     formDD.ShowDialog();
     if(formDD.DialogResult!=DialogResult.OK) {
         return;
     }
     Disease disease=new Disease();
     disease.PatNum=PatCur.PatNum;
     disease.DiseaseDefNum=formDD.SelectedDiseaseDefNum;
     Diseases.Insert(disease);
     FillProblems();
 }
Beispiel #13
0
 private void butIcd9_Click(object sender,EventArgs e)
 {
     FormIcd9s formI=new FormIcd9s();
     formI.IsSelectionMode=true;
     formI.ShowDialog();
     if(formI.DialogResult!=DialogResult.OK) {
         return;
     }
     Disease disease=new Disease();
     disease.PatNum=PatCur.PatNum;
     disease.ICD9Num=formI.SelectedIcd9Num;
     Diseases.Insert(disease);
     FillProblems();
 }
		private void butOK_Click(object sender,EventArgs e) {
			bool importsPresent=false;
			for(int i=0;i<Rows.Count;i++) {
				if(Rows[i].DoImport) {
					importsPresent=true;
					break;
				}
			}
			if(!importsPresent) {
				MsgBox.Show(this,"No rows are set for import.");
				return;
			}
			#region Patient Form
			if(SheetCur.SheetType==SheetTypeEnum.PatientForm) {
				bool importPriIns=false;
				bool importSecIns=false;
				for(int i=0;i<Rows.Count;i++) {
					if(!Rows[i].DoImport) {
						continue;
					}
					//Importing insurance happens later.
					if(Rows[i].FieldName.StartsWith("ins1")) {
						importPriIns=true;
						continue;
					}
					if(Rows[i].FieldName.StartsWith("ins2")) {
						importSecIns=true;
						continue;
					}
					switch(Rows[i].FieldName) {
						#region Personal
						case "LName":
							PatCur.LName=Rows[i].ImpValDisplay;
							break;
						case "FName":
							PatCur.FName=Rows[i].ImpValDisplay;
							break;
						case "MiddleI":
							PatCur.MiddleI=Rows[i].ImpValDisplay;
							break;
						case "Preferred":
							PatCur.Preferred=Rows[i].ImpValDisplay;
							break;
						case "Gender":
							PatCur.Gender=(PatientGender)Rows[i].ImpValObj;
							break;
						case "Position":
							PatCur.Position=(PatientPosition)Rows[i].ImpValObj;
							break;
						case "Birthdate":
							PatCur.Birthdate=(DateTime)Rows[i].ImpValObj;
							break;
						case "SSN":
							PatCur.SSN=Rows[i].ImpValDisplay;
							break;
						case "WkPhone":
							PatCur.WkPhone=Rows[i].ImpValDisplay;
							break;
						case "WirelessPhone":
							PatCur.WirelessPhone=Rows[i].ImpValDisplay;
							break;
						case "Email":
							PatCur.Email=Rows[i].ImpValDisplay;
							break;
						case "PreferContactMethod":
							PatCur.PreferContactMethod=(ContactMethod)Rows[i].ImpValObj;
							break;
						case "PreferConfirmMethod":
							PatCur.PreferConfirmMethod=(ContactMethod)Rows[i].ImpValObj;
							break;
						case "PreferRecallMethod":
							PatCur.PreferRecallMethod=(ContactMethod)Rows[i].ImpValObj;
							break;
						case "referredFrom":
							RefAttach ra=new RefAttach();
							ra.IsFrom=true;
							ra.ItemOrder=1;
							ra.PatNum=PatCur.PatNum;
							ra.RefDate=DateTimeOD.Today;
							ra.ReferralNum=((Referral)Rows[i].ImpValObj).ReferralNum;
							RefAttaches.Insert(ra);//no security to block this action.
							SecurityLogs.MakeLogEntry(Permissions.RefAttachAdd,PatCur.PatNum,"Referred From "+Referrals.GetNameFL(ra.ReferralNum));
							break;
						#endregion
						#region Address and Home Phone
						//AddressSameForFam already set, but not really importable by itself
						case "Address":
							PatCur.Address=Rows[i].ImpValDisplay;
							break;
						case "Address2":
							PatCur.Address2=Rows[i].ImpValDisplay;
							break;
						case "City":
							PatCur.City=Rows[i].ImpValDisplay;
							break;
						case "State":
							PatCur.State=Rows[i].ImpValDisplay;
							break;
						case "Zip":
							PatCur.Zip=Rows[i].ImpValDisplay;
							break;
						case "HmPhone":
							PatCur.HmPhone=Rows[i].ImpValDisplay;
							break;
						#endregion
					}
				}
				//Insurance importing happens before updating the patient information because there is a possibility of returning for more information.
				if(HasRequiredInsFields) {//Do not attempt to import any insurance unless they have the required fields for importing.
					#region Insurance importing
					bool primaryImported=false;
					if(importPriIns) {//A primary insurance field was flagged for importing.
						if(!ValidateAndImportInsurance(true)) {
							//Field missing or user chose to back out to correct information.
							return;//Nothing has been updated so it's okay to just return here.
						}
						primaryImported=true;
					}
					if(importSecIns) {//A secondary insurance field was flagged for importing.
						if(!ValidateAndImportInsurance(false)) {
							//Field missing or user chose to back out to correct information.
							if(primaryImported) {
								//Primary has been imported, we cannot return at this point.  Simply notify the user that secondary could not be imported correctly.
								MsgBox.Show(this,"Primary insurance was imported successfully but secondary was unable to import.");
							}
							else {//Secondary had problems importing or the user chose to back out and correct information.
								return;//Nothing has been updated so it's okay to just return here.
							}
						}
					}
					#endregion
				}
				else {//Sheet does not contain the required ins fields.
					if(importPriIns) {//The user has manually flagged a primary ins row for importing.
						MsgBox.Show(this,"Required primary insurance fields are missing on this sheet.  You cannot import primary insurance with this sheet until it contains all of required fields.  Required fields: Relationship, Subscriber, SubscriberID, CarrierName, and CarrierPhone.");
					}
					if(importSecIns) {//The user has manually flagged a secondary ins row for importing.
						MsgBox.Show(this,"Required secondary insurance fields are missing on this sheet.  You cannot import secondary insurance with this sheet until it contains all of required fields.  Required fields: Relationship, Subscriber, SubscriberID, CarrierName, and CarrierPhone.");
					}
				}
				//Patient information updating---------------------------------------------------------------------------------------------------------
				Patients.Update(PatCur,PatOld);
				if(AddressSameForFam) {
					Patients.UpdateAddressForFam(PatCur);
				}
			}
			#endregion
			#region Medical History
			else if(SheetCur.SheetType==SheetTypeEnum.MedicalHistory) {
				for(int i=0;i<Rows.Count;i++) {
					if(!Rows[i].DoImport) {
						continue;
					}
					if(Rows[i].ObjType==null) {//Should never happen.
						continue;
					}
					YN hasValue=YN.Unknown;
					if(Rows[i].ImpValDisplay=="Y") {
						hasValue=YN.Yes;
					}
					if(Rows[i].ImpValDisplay=="N") {
						hasValue=YN.No;
					}
					if(hasValue==YN.Unknown) {//Unknown, nothing to do.
						continue;
					}
					#region Allergies
					if(Rows[i].ObjType==typeof(Allergy)) {
						//Patient has this allergy in the db so just update the value.
						if(Rows[i].OldValObj!=null) {
							Allergy oldAllergy=(Allergy)Rows[i].OldValObj;
							if(hasValue==YN.Yes) {
								oldAllergy.StatusIsActive=true;
							}
							else {
								oldAllergy.StatusIsActive=false;
							}
							Allergies.Update(oldAllergy);
							continue;
						}
						if(hasValue==YN.No) {//We never import allergies with inactive status.
							continue;
						}
						//Allergy does not exist for this patient yet so create one.
						List<AllergyDef> allergyList=AllergyDefs.GetAll(false);
						SheetField allergySheet=(SheetField)Rows[i].NewValObj;
						//Find what allergy user wants to import.
						for(int j=0;j<allergyList.Count;j++) {
							if(allergyList[j].Description==allergySheet.FieldName.Remove(0,8)) {
								Allergy newAllergy=new Allergy();
								newAllergy.AllergyDefNum=allergyList[j].AllergyDefNum;
								newAllergy.PatNum=PatCur.PatNum;
								newAllergy.StatusIsActive=true;
								Allergies.Insert(newAllergy);
								break;
							}
						}
					}
					#endregion
					#region Medications
					else if(Rows[i].ObjType==typeof(MedicationPat)) {
					  //Patient has this medication in the db so leave it alone or set the stop date.
					  if(Rows[i].OldValObj!=null) {
					    //Set the stop date for the current medication(s).
					    MedicationPat oldMedPat=(MedicationPat)Rows[i].OldValObj;
					    if(hasValue==YN.Yes) {
								if(!MedicationPats.IsMedActive(oldMedPat)) {
									oldMedPat.DateStop=new DateTime(0001,1,1);//This will activate the med.
					      }
					    }
							else {
								oldMedPat.DateStop=DateTime.Today;//Set the med as inactive.
							}
							MedicationPats.Update(oldMedPat);
					    continue;
					  }
						if(hasValue==YN.No) {//Don't import medications with inactive status.
							continue;
						}
					  //Medication does not exist for this patient yet so create it.
					  List<Medication> medList=Medications.GetList("");
					  SheetField medSheet=(SheetField)Rows[i].NewValObj;
					  //Find what medication user wants to import.
					  for(int j=0;j<medList.Count;j++) {
					    if(Medications.GetDescription(medList[j].MedicationNum)==medSheet.FieldValue) {
					      MedicationPat medPat=new MedicationPat();
					      medPat.PatNum=PatCur.PatNum;
					      medPat.MedicationNum=medList[j].MedicationNum;
					      MedicationPats.Insert(medPat);
					      break;
					    }
					  }
					}
					#endregion
					#region Diseases
					else if(Rows[i].ObjType==typeof(Disease)) {
						//Patient has this problem in the db so just update the value.
						if(Rows[i].OldValObj!=null) {
							Disease oldDisease=(Disease)Rows[i].OldValObj;
							if(hasValue==YN.Yes) {
								oldDisease.ProbStatus=ProblemStatus.Active;
							}
							else {
								oldDisease.ProbStatus=ProblemStatus.Inactive;
							}
							Diseases.Update(oldDisease);
							continue;
						}
						if(hasValue==YN.No) {//Don't create new problem with inactive status.
							continue;
						}
						//Problem does not exist for this patient yet so create one.
						SheetField diseaseSheet=(SheetField)Rows[i].NewValObj;
						//Find what allergy user wants to import.
						for(int j=0;j<DiseaseDefs.List.Length;j++) {
							if(DiseaseDefs.List[j].DiseaseName==diseaseSheet.FieldName.Remove(0,8)) {
								Disease newDisease=new Disease();
								newDisease.PatNum=PatCur.PatNum;
								newDisease.DiseaseDefNum=DiseaseDefs.List[j].DiseaseDefNum;
								newDisease.ProbStatus=ProblemStatus.Active;
								Diseases.Insert(newDisease);
								break;
							}
						}
					}
					#endregion
				}
			}
			#endregion
			MsgBox.Show(this,"Done.");
			DialogResult=DialogResult.OK;
		}