def _create_new_patient(row):
        print(f"Adding patient {row['Patient number']}")
        patient = Patient()

        patient.unique_id = row["Patient number"]
        patient.government_id = row["State Patient Number"]
        patient.diagnosed_date = datetime.strptime(row["Date Announced"],
                                                   "%d/%m/%Y")
        if row["Age Bracket"].strip():
            patient.age = int(row["Age Bracket"])
        if row["Gender"] == "M":
            patient.gender = Gender.MALE
        elif row["Gender"] == "F":
            patient.gender = Gender.FEMALE
        elif row["Gender"]:
            patient.gender = Gender.OTHERS
        else:
            patient.gender = Gender.UNKNOWN
        city = row.get("Detected City", None).strip()
        patient.detected_city = city
        patient.detected_district = row["Detected District"]
        state = row.get("Detected State", None).strip()

        patient.detected_state = state
        patient.detected_city_pt = Patient.get_point_for_location(city=city,
                                                                  state=state)
        patient.current_location_pt = patient.detected_city_pt
        patient.nationality = ""
        if row["Current Status"] in PatientStatus.CHOICES:
            patient.current_status = row["Current Status"]
        patient.status_change_date = datetime.strptime(
            row["Status Change Date"], "%d/%m/%Y")

        patient.notes = row["Notes"]
        if row["Backup Notes"].strip() and row["Backup Notes"] != row["Notes"]:
            patient.notes += ".\n" + row["Backup Notes"]
        patient.nationality = row["Nationality"]
        patient.save()

        links = row["Contracted from which Patient (Suspected)"].split(",")
        for link in links:
            link = link.strip().strip("P")
            try:
                contact = Patient.objects.get(unique_id=link)
                patient.contacts.add(contact)
            except Patient.DoesNotExist:
                continue
        patient.save()

        for source in ["Source_1", "Source_2", "Source_3"]:
            text = row.get(source, "")
            if not text:
                continue
            if text.startswith("http") or text.startswith("www"):
                patient.source_set.create(url=text, is_verified=True)
            else:
                patient.source_set.create(description=text, is_verified=True)
Exemplo n.º 2
0
def Add_patient(request):
    if request.method =="POST":
        form =request.POST
        #print(form)
        patient= Patient()
        patient.name = form['name']
        patient.mobile = form['mobile']
        patient.id_number = form['id_number']
        patient.address = form['address']
        patient.age = form['age']
        patient.gender = form['gender']
        #patient.address = form['address']
        patient.save()   #insert in database
        
        #give us a new id of the recorded item
        return redirect ('patients:detail', patient.pk)
    return render(request, 'patients/add_patient.html')
Exemplo n.º 3
0
    def create(self, request):
        try:
            result = ''
            data = request.POST.dict().get('data')
            try:
                data = json.loads(data)
            except Exception as e:
                print(e)
                pass
            patient = data.get('patient')
            patient_name = patient.get('name').strip()
            patients = Patient.objects.filter(name=patient_name)
            if len(patients) > 0:
                return HttpResponse(status=400)
            p = Patient()
            p.name = patient_name
            p.age = patient.get('age').strip()
            p.phone = patient.get('phone').strip()
            p.gender = patient.get('gender').strip()
            p.save()

            treatments = data.get('treatments')
            for treatment in treatments:
                pictures = treatment.get('pictures')
                t = Treatment()
                t.name = treatment.get('name').strip()
                t.detail = treatment.get('detail')
                t.patient = p
                t.save()
                for picture in pictures:
                    pic = Picture()
                    pic.treatment = t
                    pic.name = picture.get('name').strip()
                    pic.data = picture.get('data')
                    pic.save()
            return HttpResponse(status=201)
        except Exception as e:
            return HttpResponse(status=500)
Exemplo n.º 4
0
    def _create_new_patient(row):
        print(f"Adding patient {row['Patient number']}")
        patient = Patient()

        patient.unique_id = row["Patient number"]
        patient.diagnosed_date = datetime.strptime(row["Date Announced"],
                                                   "%d/%m/%Y")
        patient.status_change_date = datetime.strptime(
            row["Status Change Date"], "%d/%m/%Y")
        if row["Age Bracket"].strip():
            patient.age = int(row["Age Bracket"])
        if row["Gender"] == "M":
            patient.gender = Gender.MALE
        elif row["Gender"] == "F":
            patient.gender = Gender.FEMALE
        elif row["Gender"]:
            patient.gender = Gender.OTHERS
        else:
            patient.gender = Gender.UNKNOWN
        city = row.get("Detected City", None).strip()
        patient.detected_city = city
        patient.detected_district = row["Detected District"]
        state = row.get("Detected State", None).strip()

        patient.detected_state = state
        patient.detected_city_pt = Patient.get_point_for_location(city=city,
                                                                  state=state)
        patient.current_location_pt = patient.detected_city_pt
        patient.nationality = ""
        if row["Current Status"] in PatientStatus.CHOICES:
            patient.current_status = row["Current Status"]

        patient.notes = row["Notes"]
        patient.source = "\n".join(
            [row["Source_1"], row["Source_2"], row["Source_3"]]).strip()
        patient.nationality = row["Nationality"]

        patient.save()