def Import(request): if request.method == "POST": date_errors=exists=errors=() first = True try: csv_file = request.FILES['file'] imported_csv = c1CSV.import_data(data=csv_file) except CsvDataException: return render_to_response('error.html', {"message": _("You are not using the Template csv. The number of fields is different.") }, context_instance=RequestContext(request)) for line in imported_csv: if first: first = False continue try: if datetime.strptime(line.date_of_birth, "%Y-%m-%d") > datetime.strptime(line.date_of_delivery, "%Y-%m-%d"): raise DateException(_("Born after date of delivery!")) new_c1 = c1.objects.create( patient_id=parseInt(line.patient_id), case_id=parseInt(line.case_id), date_of_birth=datetime.strptime(line.date_of_birth, "%Y-%m-%d"), date_of_delivery=datetime.strptime(line.date_of_delivery+' '+line.time_of_delivery, "%Y-%m-%d %H:%M"), number_of_prev_deliveries = parseInt(line.number_of_prev_deliveries), number_of_prev_deliveries_by_c = parseInt(line.number_of_prev_deliveries_by_c), the_c_section = parseInt(line.the_c_section), weight_of_the_newborn = parseFloat(line.weight_of_the_newborn), mother_illness = parseInt(line.mother_illness), specify_mother_illness = line.specify_mother_illness, drg_code = line.drg_code, added_by = request.user, ) if not line.other_diagnoses == "": od = line.other_diagnoses.split(",") for o in od: try: obj = c1OtherDiagnose.objects.get(name=str(o)) new_c1.other_diagnoses.add(obj) except ObjectDoesNotExist: pass new_c1.save() except IntegrityError: exists += (line.patient_id,) except DateException, (instance): date_errors += ((line.case_id,instance.parameter),) except:
def Import(request): if request.method == "POST": try: csv_file = request.FILES['file'] imported_csv = r1CSV.import_data(data=csv_file) first = True except UnicodeDecodeError: return render_to_response('error.html', {"message": _("You probably forgot to delete the first row of the csv file, please recheck.") }, context_instance=RequestContext(request)) except CsvDataException: return render_to_response('error.html', {"message": _("You are not using the Template csv. The number of fields is different.") }, context_instance=RequestContext(request)) for line in imported_csv: if first: first = False continue try: dob = datetime.strptime(line.date_of_birth, "%Y-%m-%d") except: dob = None try: doa = datetime.strptime(line.date_of_admission, "%Y-%m-%d") except: doa = None try: fima = datetime.strptime(line.FIM_date_of_assess, "%Y-%m-%d") except: fima = None try: bia = datetime.strptime(line.BI_date_of_assess, "%Y-%m-%d") except: bia = None try: smwta = datetime.strptime(line.SMWT_date_of_assess, "%Y-%m-%d") except: smwta = None try: sfa = datetime.strptime(line.SF_date_of_assess, "%Y-%m-%d") except: sfa = None try: sata = datetime.strptime(line.SAT_date_of_assess, "%Y-%m-%d") except: sata = None try: feva = datetime.strptime(line.FEV_date_of_assess, "%Y-%m-%d") except: feva = None try: aia = datetime.strptime(line.AI_date_of_assess, "%Y-%m-%d") except: aia = None try: snca = datetime.strptime(line.SNC_date_of_assess, "%Y-%m-%d") except: snca = None try: scia = datetime.strptime(line.SCI_date_of_assess, "%Y-%m-%d") except: scia = None try: oa = datetime.strptime(line.Other_date_of_assess, "%Y-%m-%d") except: oa = None try: dod = datetime.strptime(line.date_of_discharge, "%Y-%m-%d") except: dod = None try: fimd = datetime.strptime(line.FIM_date_of_assess_discharge, "%Y-%m-%d") except: fimd = None try: bid = datetime.strptime(line.BI_date_of_assess_discharge, "%Y-%m-%d") except: bid = None try: smwtd = datetime.strptime(line.SMWT_date_of_assess_discharge, "%Y-%m-%d") except: smwtd = None try: sfd = datetime.strptime(line.SF_date_of_assess_discharge, "%Y-%m-%d") except: sfd = None try: satd = datetime.strptime(line.SAT_date_of_assess_discharge, "%Y-%m-%d") except: satd = None try: fevd = datetime.strptime(line.FEV_date_of_assess_discharge, "%Y-%m-%d") except: fevd = None try: aid = datetime.strptime(line.AI_date_of_assess_discharge, "%Y-%m-%d") except: aid = None try: sncd = datetime.strptime(line.SNC_date_of_assess_discharge, "%Y-%m-%d") except: sncd = None try: scid = datetime.strptime(line.SCI_date_of_assess_discharge, "%Y-%m-%d") except: scid = None try: od = datetime.strptime(line.Other_date_of_assess_discharge, "%Y-%m-%d") except: od = None if dob > doa: raise DateException(_("Can't be born after admission!")) if doa > dod: raise DateException(_("Can't be born after admission!")) if (fima and fima > dod) or (fima and fima < doa): raise DateException(_("FIM assessment can't be after discharge!")) if (bia and bia > dod) or (bia and bia < doa): raise DateException(_("Barthel index assessment can't be after discharge!")) if (smwta and smwta > dod) or (smwta and smwta < doa): raise DateException(_("6 minutes walk test assessment can't be after discharge!")) if (sfa and sfa > dod) or (sfa and sfa < doa): raise DateException(_("SF-36 assessment can't be after discharge!")) if (sata and sata > dod) or (sata and sata < doa): raise DateException(_("SAT assessment can't be after discharge!")) if (feva and feva > dod) or (feva and feva < doa): raise DateException(_("FEV-1 assessment can't be after discharge!")) if (aia and aia > dod) or (aia and aia < doa): raise DateException(_("ASIA impairment assessment can't be after discharge!")) if (snca and snca > dod) or (snca and snca < doa): raise DateException(_("Standard neurological classification of spinal cord injury assessment can't be after discharge!")) if (scia and scia > dod) or (scia and scia < doa): raise DateException(_("Spinal Cord Independence Measure assessment can't be after discharge!")) if (oa and oa > dod) or (oa and oa < doa): raise DateException(_("Other assessment can't be after discharge!")) if (fimd and fimd > dod) or (fimd and fimd < doa): raise DateException(_("FIM assessment at discharge can't be after discharge!")) if (bid and bid > dod) or (bid and bid < doa): raise DateException(_("Barthel index assessment at discharge can't be after discharge!")) if (smwtd and smwtd > dod) or (smwtd and smwtd < doa): raise DateException(_("6 minutes walk test assessment at discharge can't be after discharge!")) if (sfd and sfd > dod) or (sfd and sfd < doa): raise DateException(_("SF-36 assessment at discharge can't be after discharge!")) if (satd and satd > dod) or (satd and satd < doa): raise DateException(_("SAT assessment at discharge can't be after discharge!")) if (fevd and fevd > dod) or (fevd and fevd < doa): raise DateException(_("FEV-1 assessment at discharge can't be after discharge!")) if (aid and aid > dod) or (aid and aid < doa): raise DateException(_("ASIA impairment assessment at discharge can't be after discharge!")) if (sncd and sncd > dod) or (sncd and sncd < doa): raise DateException(_("Standard neurological classification of spinal cord injury assessment at discharge can't be after discharge!")) if (scid and scid > dod) or (scid and scid < doa): raise DateException(_("Spinal Cord Independence Measure assessment at discharge can't be after discharge!")) if (od and od > dod) or (od and od < doa): raise DateException(_("Other assessment at discharge can't be after discharge!")) if parseInt(line.Other_applied_discharge) is None: oad = 0 else: oad = parseInt(line.Other_applied_discharge) try: new_r1 = r1.objects.create( patient_id = parseInt(line.patient_id), case_id = parseInt(line.case_id), date_of_birth = dob, field_of_rehab = parseInt(line.field_of_rehab), field_of_rehab_other = line.field_of_rehab_other, date_of_admission = doa, FIM_applied = parseInt(line.FIM_applied), FIM_date_of_assess = fima, FIM_score = parseFloat(line.FIM_score), BI_applied = parseInt(line.BI_applied), BI_date_of_assess = bia, BI_score = parseFloat(line.BI_score), SMWT_applied = parseInt(line.SMWT_applied), SMWT_date_of_assess = smwta, SMWT_score = parseFloat(line.SMWT_score), SF_applied = parseInt(line.SF_applied), SF_date_of_assess = sfa, SF_score = parseFloat(line.SF_score), SAT_applied = parseInt(line.SAT_applied), SAT_date_of_assess = sata, SAT_score = parseFloat(line.SAT_score), FEV_applied = parseInt(line.FEV_applied), FEV_date_of_assess = feva, FEV_score = parseFloat(line.FEV_score), AI_applied = parseInt(line.AI_applied), AI_date_of_assess = aia, AI_score = parseFloat(line.AI_score), SNC_applied = parseInt(line.SNC_applied), SNC_date_of_assess = snca, SNC_score = parseFloat(line.SNC_score), SCI_applied = parseInt(line.SCI_applied), SCI_date_of_assess = scia, SCI_score = parseFloat(line.SCI_score), Other_applied = parseInt(line.Other_applied), Other_name_of = line.Other_name_of, Other_date_of_assess = oa, Other_score = parseFloat(line.Other_score), patient_discharge_status = parseInt(line.patient_discharge_status), discharge = parseInt(line.discharge), if_unplanned = parseInt(line.if_unplanned), date_of_discharge = dod, FIM_applied_discharge = parseInt(line.FIM_applied_discharge), FIM_date_of_assess_discharge = fimd, FIM_score_discharge = parseFloat(line.FIM_score_discharge), BI_applied_discharge = parseInt(line.BI_applied_discharge), BI_date_of_assess_discharge = bid, BI_score_discharge = parseFloat(line.BI_score_discharge), SMWT_applied_discharge = parseInt(line.SMWT_applied_discharge), SMWT_date_of_assess_discharge = smwtd, SMWT_score_discharge = parseFloat(line.SMWT_score_discharge), SF_applied_discharge = parseInt(line.SF_applied_discharge), SF_date_of_assess_discharge = sfd, SF_score_discharge = parseFloat(line.SF_score_discharge), SAT_applied_discharge = parseInt(line.SAT_applied_discharge), SAT_date_of_assess_discharge = satd, SAT_score_discharge = parseFloat(line.SAT_score_discharge), FEV_applied_discharge = parseInt(line.FEV_applied_discharge), FEV_date_of_assess_discharge = fevd, FEV_score_discharge = parseFloat(line.FEV_score_discharge), AI_applied_discharge = parseInt(line.AI_applied_discharge), AI_date_of_assess_discharge = aid, AI_score_discharge = parseFloat(line.AI_score_discharge), SNC_applied_discharge = parseInt(line.SNC_applied_discharge), SNC_date_of_assess_discharge = sncd, SNC_score_discharge = parseFloat(line.SNC_score_discharge), SCI_applied_discharge = parseInt(line.SCI_applied_discharge), SCI_date_of_assess_discharge = scid, SCI_score_discharge = parseFloat(line.SCI_score_discharge), Other_applied_discharge = oad, Other_name_of_discharge = line.Other_name_of_discharge, Other_date_of_assess_discharge = od, Other_score_discharge = parseFloat(line.Other_score_discharge), added_by = request.user, ) new_r1.save() except CsvDataException: pass return HttpResponseRedirect(reverse('r1_stat')) else: form = FileUploadForm() context = { "form" : form } return render_to_response('r1_file_upload.html', context, context_instance=RequestContext(request))
def Import(request): if request.method == "POST": date_errors=errors=() first = True try: csv_file = request.FILES['file'] imported_csv = c23CSV.import_data(data=csv_file) except UnicodeDecodeError: return render_to_response('error.html', {"message": _("You probably forgot to delete the first row of the csv file, please recheck.") }, context_instance=RequestContext(request)) except CsvDataException: return render_to_response('error.html', {"message": _("You are not using the Template csv. The number of fields is different.") }, context_instance=RequestContext(request)) for line in imported_csv: if first: first = False continue try: try: si = datetime.strptime(line.surgical_incision+" "+line.surgical_incision_time, "%Y-%m-%d %H:%M") except ValueError: raise DateException(_("Date format is unaccaptable! YYYY-MM-DD is the only acceptable format.")) try: dofd = datetime.strptime(line.date_of_first_dose+" "+line.time_of_first_dose, "%Y-%m-%d %H:%M") except ValueError: raise DateException(_("Date format is unaccaptable! YYYY-MM-DD is the only acceptable format.")) try: dold =datetime.strptime(line.date_of_last_dose+" "+line.time_of_last_dose, "%Y-%m-%d %H:%M") except ValueError: raise DateException(_("Date format is unaccaptable! YYYY-MM-DD is the only acceptable format.")) try: dowc =datetime.strptime(line.date_of_wound_close+" "+line.time_of_wound_close, "%Y-%m-%d %H:%M") except ValueError: raise DateException(_("Date format is unaccaptable! YYYY-MM-DD is the only acceptable format.")) if dofd > dold and dofd is not None and dold is not None: raise DateException(_("Date of last dose happened before date of first dose!")) if si > dowc and si is not None and dowc is not None: raise DateException(_("Can't close the wound before the incision!")) if not parseInt(line.penicilin_allergy): pa = 1 else: pa = parseInt(line.penicilin_allergy) if not line.principal_diagnoses_code: raise DateException(_("There is no diagnoses code for this record!")) new_c23 = c23.objects.create( case_id = parseInt(line.case_id), hospital_registration_number = line.hospital_registration_number, date_of_birth = datetime.strptime(line.date_of_birth, "%Y-%m-%d"), weight_of_patient = parseInt(line.weight_of_patient), principal_diagnoses_code = line.principal_diagnoses_code, principal_procedure_code = line.principal_procedure_code, procedure_planned = parseInt(line.procedure_planned), patient_allergy = parseInt(line.patient_allergy), generic_name_of_drug = line.generic_name_of_drug, penicilin_allergy = pa, preoperative_infection = parseInt(line.preoperative_infection), type_of_infection = unidecode(line.type_of_infection), surgical_incision = si, antibiotic_given = parseInt(line.antibiotic_given), name_of_first_dose = line.name_of_first_dose, name_of_second_dose = line.name_of_second_dose, first_dose = parseFloat(line.first_dose), second_dose = parseFloat(line.second_dose), route_of_admin = parseInt(line.route_of_admin), date_of_first_dose = dofd, total_dose_in_24h = parseFloat(line.total_dose_in_24h), date_of_last_dose = dold, date_of_wound_close = dowc, added_by = request.user, ) new_c23.save() except IntegrityError: if not parseInt(line.weight_of_patient): date_errors += ((line.case_id,_("Weight of the patient can't be null!")),) else: date_errors += ((line.case_id,_("This case is already in the database!")),) except DateException, (instance): date_errors += ((line.case_id,instance.parameter),) except CsvDataException: errors += (line.case_id,)