Package org.openmrs

Examples of org.openmrs.Patient


     
      @Override
      public Patient getPatient() {
        // preemptively create a relationship
        RelationshipType type = Context.getPersonService().getRelationshipType(1);
        Patient parent = Context.getPatientService().getPatient(2);
        Person child = Context.getPersonService().getPerson(6);
       
        Relationship rel = new Relationship(parent, child, type);
        Context.getPersonService().saveRelationship(rel);
       
View Full Code Here


     
      @Override
      public Patient getPatient() {
        // preemptively create a relationship
        RelationshipType type = Context.getPersonService().getRelationshipType(1);
        Patient parent = Context.getPatientService().getPatient(2);
        Person child = Context.getPersonService().getPerson(6);
       
        Relationship rel = new Relationship(parent, child, type);
        Context.getPersonService().saveRelationship(rel);
       
View Full Code Here

      }
     
      @SuppressWarnings("deprecation")
            @Override
            public Patient getPatient()  {
        Patient patient = Context.getPatientService().getPatient(2);
        Program program = Context.getProgramWorkflowService().getProgram(1);
       
        // as a sanity check, make sure the patient is currently enrolled in the program before we run the test
        Assert.assertTrue("Patient should be in program", Context.getProgramWorkflowService().isInProgram(patient, program, new Date(), null));
       
        return patient;
      };
       
      @Override
      public String[] widgetLabels() {
        return new String[] { "Date:", "Location:", "Provider:" };
      }
     
      @Override
      public void setupRequest(MockHttpServletRequest request, Map<String, String> widgets) {
        request.addParameter(widgets.get("Date:"), dateAsString(date));
        request.addParameter(widgets.get("Location:"), "2");
        request.addParameter(widgets.get("Provider:"), "502");
      }
     
      @SuppressWarnings("deprecation")
            @Override
            public void testResults(SubmissionResults results) {
        // do all the basic assertions to make sure the program was processed correctly
        results.assertNoErrors();
        results.assertEncounterCreated();
        results.assertProvider(502);
        results.assertLocation(2);
       
        // confirm that that patient is no longer in the program
        Patient patient = Context.getPatientService().getPatient(2);
        Program program = Context.getProgramWorkflowService().getProgram(1);
        Assert.assertFalse("Patient should no longer be in program", Context.getProgramWorkflowService().isInProgram(patient, program, new Date(), null));
       
        // but confirm that the patient was in the program in the past
        Assert.assertTrue("Patient should still be in program in the past", Context.getProgramWorkflowService().isInProgram(patient, program, null, new Date()))
View Full Code Here

        results.assertEncounterCreated();
        results.assertProvider(502);
        results.assertLocation(2);
       
        // confirm that that patient is no longer in the program
        Patient patient = Context.getPatientService().getPatient(2);
        Program program = Context.getProgramWorkflowService().getProgram(1);
        Assert.assertFalse("Patient should no longer be in program", Context.getProgramWorkflowService().isInProgram(patient, program, new Date(), null));
       
        // but confirm that the patient was in the program in the past
        Assert.assertTrue("Patient should still be in program in the past", Context.getProgramWorkflowService().isInProgram(patient, program, null, new Date()))
View Full Code Here

            session.getSubmissionActions().addCustomFormSubmissionAction(this);
        }

        @Override
        public void applyAction(FormEntrySession session) {
            Patient patient = session.getPatient();
            Encounter encounter = session.getEncounter();
            patient.setDead(true);
            if (deathDateFromEncounter) {
                if (patient.getDeathDate() == null || !preserveExistingDeathDate) {
                    patient.setDeathDate(encounter.getEncounterDatetime());
                }
            }
            if (patient.getCauseOfDeath() == null || !preserveExistingCauseOfDeath) {
                Concept causeOfDeath = null;
                if (causeOfDeathFromObs != null) {
                    causeOfDeath = findObsCodedValue(session.getEncounter(), causeOfDeathFromObs);
                }
                if (causeOfDeath == null) {
                    // don't overwrite with Unknown, even if we haven't specifically said to preserve existing
                    causeOfDeath = patient.getCauseOfDeath();
                }
                if (causeOfDeath == null) {
                    causeOfDeath = getUnknownConcept();
                }
                patient.setCauseOfDeath(causeOfDeath);
            }
            patientService.savePatient(patient);
        }
View Full Code Here

    createElement(context, attributes);
  }

  public void createElement(FormEntryContext context, Map<String, String> attributes) {
    String field = attributes.get("field");
    Patient existingPatient = context.getExistingPatient();

    // Required attribute defaults to true if not specified
    required = ! "false".equalsIgnoreCase(attributes.get("required"));

    if (FIELD_PERSON_NAME.equalsIgnoreCase(field)) {
      nameWidget = new NameWidget();
      nameErrorWidget = new ErrorWidget();
      createWidgets(context, nameWidget, nameErrorWidget,
          existingPatient != null && existingPatient.getPersonName() != null ? existingPatient.getPersonName() : null);
    }
    else if (FIELD_GENDER.equalsIgnoreCase(field)) {
      MessageSourceService msg = Context.getMessageSourceService();
      genderWidget = new DropdownWidget();
      genderErrorWidget = new ErrorWidget();
      genderWidget.addOption(new Option(msg.getMessage("Patient.gender.male"), "M", false));
      genderWidget.addOption(new Option(msg.getMessage("Patient.gender.female"), "F", false));
      createWidgets(context, genderWidget, genderErrorWidget, existingPatient != null ? existingPatient.getGender() : null);
    }
    else if (FIELD_AGE.equalsIgnoreCase(field)) {
      ageWidget = new NumberFieldWidget(0d, 200d, false);
      ageErrorWidget = new ErrorWidget();
      createWidgets(context, ageWidget, ageErrorWidget, existingPatient != null ? existingPatient.getAge() : null);
    }
    else if (FIELD_BIRTH_DATE.equalsIgnoreCase(field)) {
      birthDateWidget = new DateWidget();
      birthDateErrorWidget = new ErrorWidget();
      createWidgets(context, birthDateWidget, birthDateErrorWidget, existingPatient != null ? existingPatient.getBirthdate() : null);
    }
    else if (FIELD_BIRTH_DATE_OR_AGE.equalsIgnoreCase(field)) {
      ageWidget = new NumberFieldWidget(0d, 200d, false);
      ageErrorWidget = new ErrorWidget();
      createWidgets(context, ageWidget, ageErrorWidget, existingPatient != null ? existingPatient.getAge() : null);

      birthDateWidget = new DateWidget();
      birthDateErrorWidget = new ErrorWidget();
      createWidgets(context, birthDateWidget, birthDateErrorWidget, existingPatient != null ? existingPatient.getBirthdate() : null);

    }
    else if (FIELD_IDENTIFIER.equalsIgnoreCase(field)) {

      PatientIdentifierType idType = HtmlFormEntryUtil.getPatientIdentifierType(attributes.get("identifierTypeId"));
     
      identifierTypeValueWidget = new TextFieldWidget();
      identifierTypeValueErrorWidget = new ErrorWidget();
      String initialValue = null;
      if (existingPatient != null) {
        if (idType == null) {
          if (existingPatient.getPatientIdentifier() != null) {
            initialValue = existingPatient.getPatientIdentifier().getIdentifier();
          }
        } else {
          if (existingPatient.getPatientIdentifier(idType) != null) {
            initialValue = existingPatient.getPatientIdentifier(idType).getIdentifier();
          }
        }
      }
      createWidgets(context, identifierTypeValueWidget, identifierTypeValueErrorWidget, initialValue);

      if (idType != null) {
        identifierTypeWidget = new HiddenFieldWidget();
        createWidgets(context, identifierTypeWidget, null, idType.getId().toString());
      }
      else {
        identifierTypeWidget = new DropdownWidget();
        List<PatientIdentifierType> patientIdentifierTypes = HtmlFormEntryUtil.getPatientIdentifierTypes();

        for (PatientIdentifierType patientIdentifierType : patientIdentifierTypes) {
          ((DropdownWidget) identifierTypeWidget).addOption(new Option(patientIdentifierType.getName(), patientIdentifierType
              .getPatientIdentifierTypeId().toString(), false));
        }

        createWidgets(context, identifierTypeWidget, null,
            existingPatient != null && existingPatient.getPatientIdentifier() != null ? existingPatient.getPatientIdentifier()
                .getIdentifierType().getId() : null);
      }
    }
    else if (FIELD_IDENTIFIER_LOCATION.equalsIgnoreCase(field)) {
      identifierLocationWidget = new DropdownWidget();
      identifierLocationErrorWidget = new ErrorWidget();

            Location defaultLocation = existingPatient != null
          && existingPatient.getPatientIdentifier() != null ? existingPatient.getPatientIdentifier().getLocation() : null;
      defaultLocation = defaultLocation == null ? context.getDefaultLocation() : defaultLocation;
            identifierLocationWidget.setInitialValue(defaultLocation);

            List<Option> locationOptions = new ArrayList<Option>();
            for(Location location:Context.getLocationService().getAllLocations()) {
                Option option = new Option(location.getName(), location.getId().toString(), location.equals(defaultLocation));
                locationOptions.add(option);
            }
            Collections.sort(locationOptions, new OptionComparator());

            // if initialValueIsSet=false, no initial/default location, hence this shows the 'select input' field as first option
            boolean initialValueIsSet = !(defaultLocation == null);
            ((DropdownWidget) identifierLocationWidget).addOption(new Option(Context.getMessageSourceService().getMessage("htmlformentry.chooseALocation"), "", !initialValueIsSet));
            if (!locationOptions.isEmpty()) {
                    for(Option option: locationOptions){
                    ((DropdownWidget) identifierLocationWidget).addOption(option);
                    }
            }
      createWidgets(context, identifierLocationWidget, identifierLocationErrorWidget, defaultLocation);
    }

    else if (FIELD_ADDRESS.equalsIgnoreCase(field)) {
      addressWidget = new AddressWidget();
      createWidgets(context, addressWidget, null, existingPatient != null ? existingPatient.getPersonAddress() : null);
    }
  }
View Full Code Here

        return "simpleCreatePatientForm";
      }
     
      @Override
      public Patient getPatient() {
        return new Patient();
      }
     
      @Override
      public String[] widgetLabels() {
        return new String[] { "PersonName.givenName", "PersonName.familyName", "Gender:", "Birthdate:",
View Full Code Here

        return "simplePatientAndEncounterForm";
      }
     
      @Override
      public Patient getPatient() {
        return new Patient();
      }
     
      @Override
      public String[] widgetLabels() {
        return new String[] { "PersonName.givenName", "PersonName.familyName", "Gender:", "Birthdate:",
View Full Code Here

     
      public Date patientDateChanged;
     
      @Override
      public Patient getPatient() {
        Patient patient = Context.getPatientService().getPatient(2);
        patientDateChanged = patient.getDateChanged();
        return patient;
      }
     
      @Override
      public String getFormName() {
        return "singleObsForm";
      }
     
      @Override
      public String[] widgetLabels() {
        return new String[] { "Date:", "Location:", "Provider:", "Weight:" };
      }
     
      @Override
      public void setupRequest(MockHttpServletRequest request, Map<String, String> widgets) {
        request.setParameter(widgets.get("Date:"), dateAsString(date));
        request.setParameter(widgets.get("Location:"), "2");
        request.setParameter(widgets.get("Provider:"), "502");
        request.setParameter(widgets.get("Weight:"), "70");
      }
     
      @Override
      public boolean doViewPatient() {
        return true;
      }
     
      @Override
      public void testViewingPatient(Patient patient, String html) {
        // confirm that the patient date changed has not changed
        Assert.assertTrue("patient date changed has been errorneously changed", patient.getDateChanged() == null
                && patientDateChanged == null || patient.getDateChanged().equals(patientDateChanged));
      }
     
    }.run();
  }
View Full Code Here

     
      public Date patientDateChanged;
     
      @Override
      public Patient getPatient() {
        Patient patient = Context.getPatientService().getPatient(2);
        patientDateChanged = patient.getDateChanged();
        return patient;
      }
     
      @Override
      public String getFormName() {
        return "multipleObsForm";
      }
     
      @Override
      public Patient getPatientToView() throws Exception {
        return Context.getPatientService().getPatient(2);
      };
     
      @Override
      public Encounter getEncounterToEdit() {
        return Context.getEncounterService().getEncounter(101);
      }
     
      @Override
      public String[] widgetLabelsForEdit() {
        return new String[] { "Weight:", "Allergy:", "Allergy Date:" };
      };
     
      @Override
      public void setupEditRequest(MockHttpServletRequest request, Map<String, String> widgets) {
        request.setParameter(widgets.get("Weight:"), "75");
        request.setParameter(widgets.get("Allergy:"), "Bee stings");
      };
     
      @Override
      public boolean doViewPatient() {
        return true;
      }
     
      @Override
      public void testViewingPatient(Patient patient, String html) {
        // confirm that the patient date changed has not changed
        Assert.assertTrue("patient date changed has been errorneously changed", patient.getDateChanged() == null
                && patientDateChanged == null || patient.getDateChanged().equals(patientDateChanged));
      }
     
    }.run();
  }
View Full Code Here

TOP

Related Classes of org.openmrs.Patient

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.