示例#1
0
		///<summary></summary>
		public static void Update(Allergy allergy){
			if(RemotingClient.RemotingRole==RemotingRole.ClientWeb){
				Meth.GetVoid(MethodBase.GetCurrentMethod(),allergy);
				return;
			}
			Crud.AllergyCrud.Update(allergy);
		}
示例#2
0
		///<summary></summary>
		public static long Insert(Allergy allergy){
			if(RemotingClient.RemotingRole==RemotingRole.ClientWeb){
				allergy.AllergyNum=Meth.GetLong(MethodBase.GetCurrentMethod(),allergy);
				return allergy.AllergyNum;
			}
			return Crud.AllergyCrud.Insert(allergy);
		}
示例#3
0
 ///<summary></summary>
 public static void Update(Allergy allergy)
 {
     if (RemotingClient.RemotingRole == RemotingRole.ClientWeb)
     {
         Meth.GetVoid(MethodBase.GetCurrentMethod(), allergy);
         return;
     }
     Crud.AllergyCrud.Update(allergy);
 }
示例#4
0
 ///<summary></summary>
 public static long Insert(Allergy allergy)
 {
     if (RemotingClient.RemotingRole == RemotingRole.ClientWeb)
     {
         allergy.AllergyNum = Meth.GetLong(MethodBase.GetCurrentMethod(), allergy);
         return(allergy.AllergyNum);
     }
     return(Crud.AllergyCrud.Insert(allergy));
 }
示例#5
0
文件: EhrCCD.cs 项目: mnisl/OD
		///<summary>Helper for GenerateCCD().</summary>
		private void GenerateCcdSectionAllergies(bool hasAllergy) {
			_w.WriteComment(@"
=====================================================================================================
Allergies
=====================================================================================================");
			AllergyDef allergyDef;
			List<Allergy> listAllergiesFiltered=new List<Allergy>();
			if(!hasAllergy) {
				listAllergiesFiltered=new List<Allergy>();
			}
			else {
				listAllergiesFiltered=_listAllergiesFiltered;
			}
			Start("component");
			Start("section");
			TemplateId("2.16.840.1.113883.10.20.22.2.6.1");//page 230 Allergy template with required entries.
			_w.WriteComment("Allergies section template");
			StartAndEnd("code","code","48765-2","codeSystem",strCodeSystemLoinc,"codeSystemName",strCodeSystemNameLoinc,"displayName","Allergies");
			_w.WriteElementString("title","Allergies and Adverse Reactions");
			Start("text");//The following text will be parsed as html with a style sheet to be human readable.
			if(listAllergiesFiltered.Count>0 && hasAllergy) {
				Start("table","width","100%","border","1");
				Start("thead");
				Start("tr");
				_w.WriteElementString("th","Substance");
				_w.WriteElementString("th","Reaction");
				_w.WriteElementString("th","Allergy Type");
				_w.WriteElementString("th","Status");
				End("tr");
				End("thead");
				Start("tbody");
				for(int i=0;i<listAllergiesFiltered.Count;i++) {
					Allergy allergy=listAllergiesFiltered[i];
					if(allergy.PatNum==0) {
						allergyDef=new AllergyDef();
					}
					else {
						allergyDef=AllergyDefs.GetOne(allergy.AllergyDefNum);
					}
					Start("tr");
					//if(allergyDef.SnomedAllergyTo!="") {//Is Snomed allergy.
					//	Snomed snomedAllergyTo=Snomeds.GetByCode(allergyDef.SnomedAllergyTo);
					//	_w.WriteElementString("td",snomedAllergyTo.SnomedCode+" - "+snomedAllergyTo.Description);
					//}
					//else {//Medication allergy
					Medication med;
					if(allergyDef.MedicationNum==0) {
						if(allergyDef.UniiCode=="") {
							_w.WriteElementString("td","");
						}
						else {
							_w.WriteElementString("td",allergyDef.UniiCode+" - "+allergyDef.Description);
						}
					}
					else {
						med=Medications.GetMedication(allergyDef.MedicationNum);
						_w.WriteElementString("td",med.RxCui.ToString()+" - "+med.MedName);
					}
					//}
					_w.WriteElementString("td",allergy.Reaction);
					_w.WriteElementString("td",AllergyDefs.GetSnomedAllergyDesc(allergyDef.SnomedType));
					_w.WriteElementString("td",allergy.StatusIsActive?"Active":"Inactive");
					End("tr");
				}
				End("tbody");
				End("table");
			}
			else {
				_w.WriteString("None");
			}
			End("text");
			if(listAllergiesFiltered.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.
				Allergy al=new Allergy();
				listAllergiesFiltered.Add(al);
			}
			for(int i=0;i<listAllergiesFiltered.Count;i++) {
				Allergy allergy=listAllergiesFiltered[i];
				if(allergy.PatNum==0) {
					allergyDef=new AllergyDef();
				}
				else {
					allergyDef=AllergyDefs.GetOne(allergy.AllergyDefNum);
				}
				string allergyType="";
				string allergyTypeName="";
				#region Allergy Type
				if(allergyDef.SnomedType==SnomedAllergy.AdverseReactionsToDrug) {
					allergyType="419511003";
					allergyTypeName="Propensity to adverse reaction to drug";
				}
				else if(allergyDef.SnomedType==SnomedAllergy.AdverseReactionsToFood) {
					allergyType="418471000";
					allergyTypeName="Propensity to adverse reaction to food";
				}
				else if(allergyDef.SnomedType==SnomedAllergy.AdverseReactionsToSubstance) {
					allergyType="419199007";
					allergyTypeName="Propensity to adverse reaction to substance";
				}
				else if(allergyDef.SnomedType==SnomedAllergy.AllergyToSubstance) {
					allergyType="418038007";
					allergyTypeName="Allergy to substance";
				}
				else if(allergyDef.SnomedType==SnomedAllergy.DrugAllergy) {
					allergyType="416098002";
					allergyTypeName="Drug allergy";
				}
				else if(allergyDef.SnomedType==SnomedAllergy.DrugIntolerance) {
					allergyType="59037007";
					allergyTypeName="Drug intolerance";
				}
				else if(allergyDef.SnomedType==SnomedAllergy.FoodAllergy) {
					allergyType="414285001";
					allergyTypeName="Food allergy";
				}
				else if(allergyDef.SnomedType==SnomedAllergy.FoodIntolerance) {
					allergyType="235719002";
					allergyTypeName="Food intolerance";
				}
				else if(allergyDef.SnomedType==SnomedAllergy.AdverseReactions) {
					allergyType="420134006";
					allergyTypeName="Adverse reaction";
				}
				else {
					allergyType="";
					allergyTypeName="None";
				}
				#endregion
				Start("entry","typeCode","DRIV");
				Start("act","classCode","ACT","moodCode","EVN");
				TemplateId("2.16.840.1.113883.10.20.22.4.30");//Allergy Problem Act template
				Guid();
				StartAndEnd("code","code","48765-2","codeSystem",strCodeSystemLoinc,"codeSystemName",strCodeSystemNameLoinc,"displayName","Allergies and adverse reactions");
				//statusCode values allowed: active, suspended, aborted, completed.
				if(allergy.StatusIsActive) {
					StartAndEnd("statusCode","code","active");
				}
				else {
					StartAndEnd("statusCode","code","completed");
				}
				Start("effectiveTime");
				if(allergy.DateTStamp.Year<1880) {
					StartAndEnd("low","nullFlavor","UNK");
					StartAndEnd("high","nullFlavor","UNK");
				}
				else if(allergy.StatusIsActive) {
					StartAndEnd("low","value",allergy.DateTStamp.ToString("yyyyMMdd"));
					StartAndEnd("high","nullFlavor","UNK");
				}
				else {
					StartAndEnd("low","nullFlavor","UNK");
					StartAndEnd("high","value",allergy.DateTStamp.ToString("yyyyMMdd"));
				}
				End("effectiveTime");
				Start("entryRelationship","typeCode","SUBJ");
				Start("observation","classCode","OBS","moodCode","EVN");
				_w.WriteComment("Allergy Observation template");
				TemplateId("2.16.840.1.113883.10.20.22.4.7");
				Guid();
				StartAndEnd("code","code","ASSERTION","codeSystem","2.16.840.1.113883.5.4");//Fixed Value
				StartAndEnd("statusCode","code","completed");//fixed value (required)
				StartAndEnd("effectiveTime","nullFlavor","UNK");//We have no field to store the date the allergy became active. DateTStamp is not the same as the active date.
				Start("value");
				_w.WriteAttributeString("xsi","type",null,"CD");
				if(allergyDef.SnomedType==SnomedAllergy.None) {
					Attribs("nullFlavor","UNK");
				}
				else {
					Attribs("code",allergyType,"displayName",allergyTypeName,"codeSystem",strCodeSystemSnomed,"codeSystemName",strCodeSystemNameSnomed);
				}
				End("value");
				Start("participant","typeCode","CSM");
				Start("participantRole","classCode","MANU");
				Start("playingEntity","classCode","MMAT");
				//pg. 331 item 9:
				//In an allergy to a specific medication the code SHALL be selected from the ValueSet 2.16.840.1.113883.3.88.12.80.16 Medication Brand Name (code system: RxNorm 2.16.840.1.113883.6.88); Example: 205734		RxNorm	Amoxicillin 25 MG/ML Oral Suspension [Amoxil]
				//Or the ValueSet 2.16.840.1.113883.3.88.12.80.17 Medication Clinical Drug (code system: RxNorm 2.16.840.1.113883.6.88). Example: 313850	RxNorm	Amoxicillin 40 MG/ML Oral Suspensionv 
				//In an allergy to a class of medications the code SHALL be selected from the ValueSet 2.16.840.1.113883.3.88.12.80.18 Medication Drug Class (code system: NDF-RT 2.16.840.1.113883.3.26.1.5). Example: 2-Propanol, Inhibitors
				//In an allergy to a food or other substance the code SHALL be selected from the ValueSet 2.16.840.1.113883.3.88.12.80.20 Ingredient Name (code system: Unique Ingredient Identifier (UNII) 2.16.840.1.113883.4.9). Example: Peanut, Red 40
				if(allergyDef.MedicationNum==0) {//Unique Ingredient Identifier (UNII codes)
					if(allergyDef.UniiCode=="") {
						StartAndEnd("code","nullFlavor","UNK");
					}
					else {
						StartAndEnd("code","code",allergyDef.UniiCode,"displayName",allergyDef.Description,"codeSystem",strCodeSystemUnii,"codeSystemName",strCodeSystemNameUnii);
					}
				}
				//else if() {//Medication Drug Class (NDF-RT codes) //TODO: We need a UI box for this in allergy def.
				//Current work around is (per js on 10/02/2013):
				//If using eRx, search for a class such as NSAID.
				//If that's not an option, pick a common medication in that class such as Ibuprofen, and the eRx will automatically list cross-sensitivity and allergy warnings for any other related medication.
				//The allergy alerts built into OD do not have that rich database available.
				//If you are not using paper Rx from within OD, then you could enter the allergy however it makes sense, either NSAID or Ibuprofen.
				//If you are using paper Rx and you are trying to generate allergy warnings, then you also enter any specific medications that you might prescribe.
				//For example, you might enter an allergy for Vicoprofen.
				//}
				else {//Medication Brand Name or Medication Clinical Drug (RxNorm codes)
					Medication med=Medications.GetMedication(allergyDef.MedicationNum);
					StartAndEnd("code","code",med.RxCui.ToString(),"displayName",med.MedName,"codeSystem",strCodeSystemRxNorm,"codeSystemName",strCodeSystemNameRxNorm);
				}
				End("playingEntity");
				End("participantRole");
				End("participant");
				Start("entryRelationship","typeCode","SUBJ","inversionInd","true");
				Start("observation","classCode","OBS","moodCode","EVN");
				_w.WriteComment("Allergy Status Observation template");
				TemplateId("2.16.840.1.113883.10.20.22.4.28");
				StartAndEnd("code","code","33999-4","codeSystem",strCodeSystemLoinc,"codeSystemName",strCodeSystemNameLoinc,"displayName","Status");
				StartAndEnd("statusCode","code","completed");//fixed value (required)
				string status=allergy.StatusIsActive?"Active":"Inactive";
				if(allergy.AllergyNum==0) {
					Start("value");
					_w.WriteAttributeString("xsi","type",null,"CE");
					Attribs("nullFlavor","UNK");
					End("value");
				}
				else if(status=="Active") {
					Start("value");
					_w.WriteAttributeString("xsi","type",null,"CE");
					Attribs("code","55561003","codeSystem",strCodeSystemSnomed,"displayName",status);
					End("value");
				}
				else {
					Start("value");
					_w.WriteAttributeString("xsi","type",null,"CE");
					Attribs("code","73425007","codeSystem",strCodeSystemSnomed,"displayName",status);
					End("value");
				}
				End("observation");
				End("entryRelationship");
				Start("entryRelationship","typeCode","SUBJ","inversionInd","true");
				Start("observation","classCode","OBS","moodCode","EVN");
				_w.WriteComment("Reaction Observation template");
				TemplateId("2.16.840.1.113883.10.20.22.4.9");
				Guid();
				StartAndEnd("code","code","ASSERTION","codeSystem","2.16.840.1.113883.5.4");
				StartAndEnd("statusCode","code","completed");//fixed value (required)
				Start("effectiveTime");
				if(allergy.DateTStamp.Year<1880) {
					StartAndEnd("low","nullFlavor","UNK");
				}
				else if(allergy.StatusIsActive) {
					StartAndEnd("low","value",allergy.DateTStamp.ToString("yyyyMMdd"));
				}
				else {
					StartAndEnd("low","nullFlavor","UNK");
				}
				End("effectiveTime");
				if(String.IsNullOrEmpty(allergy.SnomedReaction)) {
					Start("value");
					_w.WriteAttributeString("xsi","type",null,"CD");
					Attribs("nullFlavor","UNK");
					End("value");
				}
				else {
					Start("value");
					_w.WriteAttributeString("xsi","type",null,"CD");
					Attribs("code",allergy.SnomedReaction,"codeSystem",strCodeSystemSnomed,"displayName",allergy.Reaction);
					End("value");
				}
				End("observation");
				End("entryRelationship");
				End("observation");
				End("entryRelationship");
				End("act");
				End("entry");
			}
			End("section");
			End("component");
		}
示例#6
0
文件: EhrCCD.cs 项目: mnisl/OD
		///<summary>Fills listAllergies and listAllergyDefs using the information found in the CCD document xmlDocCcd.  Inserts a medication in the db corresponding to the allergy.</summary>
		public static void GetListAllergies(XmlDocument xmlDocCcd,List<Allergy> listAllergies,List<AllergyDef> listAllergyDefs) {
			//The length of listAllergies and listAllergyDefs will be the same. The information in listAllergyDefs might have duplicates.
			//Neither list of objects will be inserted into the db, so there will be no primary or foreign keys.
			List<XmlNode> listAllergyProblemActTemplate=GetNodesByTagNameAndAttributes(xmlDocCcd,"templateId","root","2.16.840.1.113883.10.20.22.4.30");//Allergy problem act template.
			List<XmlNode> listActs=GetParentNodes(listAllergyProblemActTemplate);
			for(int i=0;i<listActs.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(listActs[i],"effectiveTime");//POCD_HD00040.xls line 492. Not required.
				DateTime dateTimeEffectiveLow=DateTime.MinValue;
				DateTime dateTimeEffectiveHigh=DateTime.MinValue;
				if(xmlNodeEffectiveTimes.Count>0) {
					XmlNode xmlNodeEffectiveTime=xmlNodeEffectiveTimes[0];
					dateTimeEffectiveLow=GetEffectiveTimeLow(xmlNodeEffectiveTime);
					dateTimeEffectiveHigh=GetEffectiveTimeHigh(xmlNodeEffectiveTime);
				}
				List<XmlNode> listAllergyObservationTemplates=GetNodesByTagNameAndAttributes(listActs[i],"templateId","root","2.16.840.1.113883.10.20.22.4.7");//Allergy observation template.
				List<XmlNode> listAllergy=GetParentNodes(listAllergyObservationTemplates);//List of Allergy Observations.
				List<XmlNode> listCodes=GetNodesByTagNameAndAttributesFromList(listAllergy,"value");
				#region Determine if Active
				bool isActive=true;
				string strStatus="";
				List<XmlNode> listAllergyObservationTemplatesActive=GetNodesByTagNameAndAttributes(listActs[i],"templateId","root","2.16.840.1.113883.10.20.22.4.28");//Allergy observation template.
				List<XmlNode> listAllergyActive=GetParentNodes(listAllergyObservationTemplatesActive);//List of Allergy Observations.
				List<XmlNode> listCodesActive=GetNodesByTagNameAndAttributesFromList(listAllergyActive,"value");
				if(listCodesActive.Count>0) {
					listCodes.Remove(listCodesActive[0]);
					XmlNode xmlNodeCode=listCodesActive[0];
					if(xmlNodeCode.Attributes["nullFlavor"]!=null) {
						continue;
					}
					strStatus=xmlNodeCode.Attributes["code"].Value;
					if(xmlNodeCode.Attributes["codeSystem"].Value!=strCodeSystemSnomed) {
						continue;//We can only import Snomeds
					}
					isActive=(strStatus=="55561003");//Active (qualifier value)
				}
				#endregion
				#region Find Reaction Snomed
				List<XmlNode> listAllergyStatusObservationTemplates=GetNodesByTagNameAndAttributes(listActs[i],"templateId","root","2.16.840.1.113883.10.20.22.4.9");//Allergy status observation template.
				List<XmlNode> listAllergyStatus=GetParentNodes(listAllergyStatusObservationTemplates);//List of Allergy Observations.
				List<XmlNode> listAlgCodes=GetNodesByTagNameAndAttributesFromList(listAllergyStatus,"value");
				for(int j=0;j<listAlgCodes.Count;j++) {
					listCodes.Remove(listAlgCodes[j]);
					XmlNode xmlNodeCode=listAlgCodes[j];
					string strCodeReaction=xmlNodeCode.Attributes["code"].Value;
					string strAlgStatusDescript=xmlNodeCode.Attributes["displayName"].Value;
					if(xmlNodeCode.Attributes["codeSystem"].Value!=strCodeSystemSnomed) {
						continue;//We can only import Snomeds
					}
					Allergy allergy=new Allergy();
					allergy.IsNew=true;//Needed for reconcile window to know this record is not in the db yet.
					allergy.SnomedReaction=PIn.String(strCodeReaction);
					allergy.Reaction=PIn.String(strAlgStatusDescript);
					allergy.DateAdverseReaction=dateTimeEffectiveLow;
					allergy.StatusIsActive=isActive;
					listAllergies.Add(allergy);
				}
				#endregion
				#region Remove Severe Reaction
				List<XmlNode> listAllergySevereTemplates=GetNodesByTagNameAndAttributes(listActs[i],"templateId","root","2.16.840.1.113883.10.20.22.4.8");//Allergy observation template.
				List<XmlNode> listAllergySevere=GetParentNodes(listAllergySevereTemplates);//List of Allergy Observations.
				List<XmlNode> listCodesSevere=GetNodesByTagNameAndAttributesFromList(listAllergySevere,"value");
				for(int j=0;j<listCodesSevere.Count;j++) {
					listCodes.Remove(listCodesSevere[j]);
					XmlNode xmlNodeCode=listCodesSevere[j];
					string strCodeReaction=xmlNodeCode.Attributes["code"].Value;
					string strAlgStatusDescript=xmlNodeCode.Attributes["displayName"].Value;
					if(xmlNodeCode.Attributes["codeSystem"].Value!=strCodeSystemSnomed) {
						continue;//We can only import Snomeds
					}
				}
				#endregion
				#region Find RxNorm or Snomed
				string allergyDefName="";
				Medication med=new Medication();
				List<XmlNode> listRxCodes=GetNodesByTagNameAndAttributesFromList(listAllergy,"code");
				List<Medication> allergyMeds=new List<Medication>();
				for(int j=0;j<listRxCodes.Count;j++) {
					XmlNode xmlNodeCode=listRxCodes[j];
					if(xmlNodeCode.Attributes[0].Name!="code") {
						continue;
					}
					if(xmlNodeCode.Attributes["codeSystem"].Value!=strCodeSystemRxNorm) {
						continue;//We only want RxNorms here.
					}
					string strCodeRx=xmlNodeCode.Attributes["code"].Value;
					string strRxName=xmlNodeCode.Attributes["displayName"].Value;//Look into this being required or not.
					allergyDefName=strRxName;
					med=Medications.GetMedicationFromDbByRxCui(PIn.Long(strCodeRx));
					if(med==null) {
						med=new Medication();
						med.MedName=strRxName;
						med.RxCui=PIn.Long(strCodeRx);
						Medications.Insert(med);
						med.GenericNum=med.MedicationNum;
						Medications.Update(med);
					}
					allergyMeds.Add(med);
				}
				#endregion
				for(int j=0;j<listCodes.Count;j++) {
					XmlNode xmlNodeCode=listCodes[j];
					string strCode=xmlNodeCode.Attributes["code"].Value;
					if(xmlNodeCode.Attributes["codeSystem"].Value!=strCodeSystemSnomed) {
						continue;//We can only import Snomeds
					}
					AllergyDef allergyDef=new AllergyDef();
					allergyDef.IsNew=true;//Needed for reconcile window to know this record is not in the db yet.
					if(med.MedicationNum!=0) {
						allergyDef.MedicationNum=med.MedicationNum;
					}
					//else {TODO: Change to Unii
					//	allergyDef.SnomedAllergyTo=PIn.String(strCode);
					//}
					allergyDef.Description=allergyDefName;
					allergyDef.IsHidden=false;
					allergyDef.MedicationNum=allergyMeds[j].MedicationNum;
					#region Snomed type determination
					if(strCode=="419511003") {
						allergyDef.SnomedType=SnomedAllergy.AdverseReactionsToDrug;
					}
					else if(strCode=="418471000") {
						allergyDef.SnomedType=SnomedAllergy.AdverseReactionsToFood;
					}
					else if(strCode=="419199007") {
						allergyDef.SnomedType=SnomedAllergy.AdverseReactionsToSubstance;
					}
					else if(strCode=="418038007") {
						allergyDef.SnomedType=SnomedAllergy.AllergyToSubstance;
					}
					else if(strCode=="416098002") {
						allergyDef.SnomedType=SnomedAllergy.DrugAllergy;
					}
					else if(strCode=="59037007") {
						allergyDef.SnomedType=SnomedAllergy.DrugIntolerance;
					}
					else if(strCode=="414285001") {
						allergyDef.SnomedType=SnomedAllergy.FoodAllergy;
					}
					else if(strCode=="235719002") {
						allergyDef.SnomedType=SnomedAllergy.FoodIntolerance;
					}
					else if(strCode=="420134006") {
						allergyDef.SnomedType=SnomedAllergy.AdverseReactions;
					}
					else {
						allergyDef.SnomedType=SnomedAllergy.None;
					}
					#endregion
					listAllergyDefs.Add(allergyDef);
				}
			}
		}
		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;
		}