Package org.openmrs

Examples of org.openmrs.Patient


  }

  @Override
  public void handleSubmission(FormEntrySession session, HttpServletRequest request) {

    Patient patient = (Patient) session.getSubmissionActions().getCurrentPerson();

    if (patient == null) {
      throw new RuntimeException("Programming exception: person shouldn't be null");
    }

    FormEntryContext context = session.getContext();

    if (nameWidget != null) {
      PersonName name = (PersonName) nameWidget.getValue(context, request);

      if (patient != null) {
        if (!name.isPreferred()) {
          PersonName currentPreferredName = context.getExistingPatient().getPersonName();
          if (currentPreferredName != null){
            currentPreferredName.setPreferred(false);
            currentPreferredName.setVoided(true);
          }
        }
      }
     
      // HACK: we need to set the date created and uuid here as a hack around a hibernate flushing issue (see saving the Patient in FormEntrySession applyActions())
      if (name.getDateCreated() == null) {
        name.setDateCreated(new Date());
      }
      if (name.getUuid() == null) {
        name.setUuid(UUID.randomUUID().toString());
      }
     
     
      name.setPreferred(true);
      patient.addName(name);
    }

    if (genderWidget != null) {
      String value = (String) genderWidget.getValue(context, request);
      patient.setGender(value);
    }

    if (ageWidget != null) {
      Double value = (Double) ageWidget.getValue(context, request);
      if (value != null)
        calculateBirthDate(patient, null, value);
    }

    if (birthDateWidget != null) {
      Date value = (Date) birthDateWidget.getValue(context, request);
      if (value != null) {
        calculateBirthDate(patient, value, null);
      }
    }
    if (identifierTypeValueWidget != null && identifierTypeWidget != null) {
      String identifier = (String) identifierTypeValueWidget.getValue(context, request);
      PatientIdentifierType identifierType = getIdentifierType((String) identifierTypeWidget.getValue(context, request));

      // Look for an existing identifier of this type
      PatientIdentifier patientIdentifier = patient.getPatientIdentifier(identifierType);

      if (StringUtils.hasText(identifier)) {
        // No existing identifier of this type, so create new
        if (patientIdentifier == null) {
          patientIdentifier = new PatientIdentifier();
          patientIdentifier.setIdentifierType(identifierType);

          // HACK: we need to set the date created  and uuid here as a hack around a hibernate flushing issue (see saving the Patient in FormEntrySession applyActions())
          patientIdentifier.setDateChanged(new Date());
          patientIdentifier.setUuid(UUID.randomUUID().toString());

          // For 1.9+ onwards patients require a preferred identifier
          if (patient.getPatientId() == null) {
            patientIdentifier.setPreferred(true);
          }

          patient.addIdentifier(patientIdentifier);
        }

        if (!identifier.equals(patientIdentifier.getIdentifier()) || !identifierType.equals(patientIdentifier.getIdentifierType())) {
          validateIdentifier(identifierType.getId(), identifier);
        }

        patientIdentifier.setIdentifier(identifier);
      }
      else if (patientIdentifier != null) {
        // If this field is not required, then we interpret a blank value as a request to avoid any existing identifier
        session.getSubmissionActions().getIdentifiersToVoid().add(patientIdentifier);
      }
    }

    //
    // TODO current behavior always updates location of the preferred identifier rather than
    // a specific identifier type being edited by the identifier widget. But identifier location
    // widget isn't aware of the identifier type widget
    //
    if (identifierLocationWidget != null) {
      PatientIdentifier patientIdentifier = patient.getPatientIdentifier();
      if (patientIdentifier == null) {
        patientIdentifier = new PatientIdentifier();
        patient.addIdentifier(patientIdentifier);
      }

      Object locationString = identifierLocationWidget.getValue(context, request);
      Location location = (Location) HtmlFormEntryUtil.convertToType(locationString.toString().trim(), Location.class);
      patientIdentifier.setLocation(location);
      patientIdentifier.setPreferred(true);

    }

    if (addressWidget != null) {
      PersonAddress personAddress = (PersonAddress) addressWidget.getValue(context, request);
      if (context.getMode() == Mode.EDIT) {
        if (!personAddress.isPreferred()) {
          PersonAddress currentPreferredAddress = context.getExistingPatient().getPersonAddress();
          currentPreferredAddress.setPreferred(false);
          currentPreferredAddress.setVoided(true);
        }
      }
      personAddress.setPreferred(true);
      patient.addAddress(personAddress);
    }

        session.getSubmissionActions().setPatientUpdateRequired(true);
  }
View Full Code Here


        return "patientAndObsForm";
      }
     
      @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 "patientAndEnrollInProgramForm";
            }

            @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 "patientAddressForm";
      }
     
      @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 "patientAddressForm";
      }
     
      @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 "editPatientBirthdateForm";
      }
     
      @Override
      public Patient getPatientToEdit() {
        Patient p = Context.getPatientService().getPatient(2);
        return Context.getPatientService().getPatient(2);
      };
     
      @Override
      public boolean doViewEncounter() {
View Full Code Here

    form.setEncounterType(new EncounterType(1));
        htmlform.setForm(form);
        htmlform.setDateChanged(new Date());
        htmlform.setXmlData("<htmlform></htmlform>");

        Patient p = new Patient(patientId);
        String[] datePattern = {"yyyy.MM.dd"};
        p.setBirthdate(DateUtils.parseDate("1970.01.01",datePattern ));
        measureAgeInDaysAndMonths(new Date(), p.getBirthdate());
        FormEntrySession session = new FormEntrySession(p, htmlform, null);
        return new VelocityFunctions(session);
  }
View Full Code Here

        createElement(context, parameters);
    }

    private void createElement(FormEntryContext context, Map<String, String> parameters) {

        Patient patient = context.getExistingPatient();

        dateWidget = new DateWidget();
        dateErrorWidget = new ErrorWidget();

        reasonForExitWidget = new DropdownWidget();
View Full Code Here

        List<FormSubmissionError> ret = new ArrayList<FormSubmissionError>();
        Date exitDate = null;
        Concept exitReasonAnswerConcept = null;
        Concept causeOfDeathAnswerConcept = null;

        Patient patient = context.getExistingPatient();
        String reasonConId = Context.getAdministrationService().getGlobalProperty("concept.reasonExitedCare");
        Concept reasonExitConcept = Context.getConceptService().getConcept(reasonConId);
        List<Obs> obsList = Context.getObsService().getObservationsByPersonAndConcept(patient, reasonExitConcept);

        String causeOfDeathConId = Context.getAdministrationService().getGlobalProperty("concept.causeOfDeath");
View Full Code Here

    @Override
    public String generateHtml(FormEntryContext context) {

        StringBuilder sb = new StringBuilder();

        Patient patient = context.getExistingPatient();

        String patientDiedConId = Context.getAdministrationService().getGlobalProperty("concept.patientDied");
        Concept patientDiedConcept = Context.getConceptService().getConcept(patientDiedConId);
        String otherNonCodedConId = Context.getAdministrationService().getGlobalProperty("concept.otherNonCoded");
        Concept otherNonCodedConcept = Context.getConceptService().getConcept(otherNonCodedConId);
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.