Examples of Obs


Examples of org.openmrs.Obs

        e.setEncounterDatetime(date);
        e.setLocation(Context.getLocationService().getLocation(2));
        e.setProvider(Context.getPersonService().getPerson(502));

        // first create DST parent group
        Obs dstParent = TestUtil.createObs(e, 3040, null, date);
        e.addObs(dstParent);

        Obs resultParent = TestUtil.createObs(e, 3025, null, date);
        dstParent.addGroupMember(resultParent);
        Obs resultParent2 = TestUtil.createObs(e, 3025, null, date);
        dstParent.addGroupMember(resultParent2);
        Obs resultParent3 = TestUtil.createObs(e, 3025, null, date);
        dstParent.addGroupMember(resultParent3);

        Obs dstStartDate = TestUtil.createObs(e, 3032, date, date);
        dstParent.addGroupMember(dstStartDate);

        //let's make rifampin susceptible -- 2474 is susceptible
        Obs drugResult = TestUtil.createObs(e, 2474, Context.getConceptService().getConcept(767), date);
        resultParent.addGroupMember(drugResult);

        //let's make INH resistant 1441 is resistant
        Obs drugResult2 = TestUtil.createObs(e, 1441, Context.getConceptService().getConcept(656), date);
        resultParent2.addGroupMember(drugResult2);
        //and add colonies for just INH
        Obs colonies1 = TestUtil.createObs(e, 3016, 200, date);
        resultParent2.addGroupMember(colonies1);

        //let's make ETHIO intermediate
        Obs drugResult4 = TestUtil.createObs(e, 3017, Context.getConceptService().getConcept(1414), date);
        resultParent3.addGroupMember(drugResult4);
        //and add colonies for ETHIO
        Obs colonies3 = TestUtil.createObs(e, 3016, 500, date);
        resultParent3.addGroupMember(colonies3);

        //THINGS THAT SHOULD BE IGNORED:
        //THESE TEST THE BEHAVIOR THAT IF AN OBS GROUP CONCEPT IS UNIQUE AT THAT LEVEL IN AN OBS GROUP HIERARCHY,
        //IT WILL BE RETURNED EVEN IF THE MEMBER OBS DONT 'SUPPORT' THE obsgroup SCHEMA
        //let's add some 'right' data at the 'wrong' place in the hierarchy:
        //let's put another colonies obs in the wrong place in the hierarchy, with colonies value 400
        Obs colonies2 = TestUtil.createObs(e, 3016, 400, date);
        dstParent.addGroupMember(colonies2);
        //and here's a drug result added directly to the encounter (bypassing the DST parentConstructObs)
        Obs drugResult3 = TestUtil.createObs(e, 3017, Context.getConceptService().getConcept(767), date);
        resultParent3.addGroupMember(drugResult3);
        e.addObs(resultParent3);

        e = Context.getEncounterService().saveEncounter(e);
        return e;
View Full Code Here

Examples of org.openmrs.Obs

                results.assertEncounterCreated();
                results.assertProvider(502);
                results.assertLocation(2);
                results.assertObsCreatedCount(1);

                Obs locationObs = results.getEncounterCreated().getObs().iterator().next();

                Assert.assertEquals("2", locationObs.getValueText());
                Assert.assertNull(locationObs.getValueCoded());
                Assert.assertEquals("org.openmrs.Location", locationObs.getComment());
            }
        }.run();
    }
View Full Code Here

Examples of org.openmrs.Obs

                results.assertNoErrors();;
                results.assertProvider(502);
                results.assertLocation(2);
                results.assertObsCreatedCount(1);

                Obs locationObs = results.getEncounterCreated().getObs().iterator().next();

                Assert.assertEquals("3", locationObs.getValueText());
                Assert.assertNull(locationObs.getValueCoded());
                Assert.assertEquals("org.openmrs.Location", locationObs.getComment());
            };

        }.run();
    }
View Full Code Here

Examples of org.openmrs.Obs

        e.setDateCreated(new Date());
        e.setEncounterDatetime(date);
        e.setLocation(Context.getLocationService().getLocation(2));
        e.setProvider(Context.getPersonService().getPerson(502));

        Obs obs = new Obs();
        obs.setConcept(Context.getConceptService().getConcept(4));
        obs.setValueNumeric(new Double(1))// set this obs to a valid Boolean value
           
        e.addObs(obs);
        Context.getEncounterService().saveEncounter(e);
       
        return e;
View Full Code Here

Examples of org.openmrs.Obs

        e.setDateCreated(new Date());
        e.setEncounterDatetime(date);
        e.setLocation(Context.getLocationService().getLocation(2));
        e.setProvider(Context.getPersonService().getPerson(502));

        Obs obs = new Obs();
        obs.setConcept(Context.getConceptService().getConcept(4));
        obs.setValueNumeric(null)// set this obs to an invalid Boolean value
           
        e.addObs(obs);
        Context.getEncounterService().saveEncounter(e);
       
        return e;
View Full Code Here

Examples of org.openmrs.Obs

        e.setDateCreated(new Date());
        e.setEncounterDatetime(date);
        e.setLocation(Context.getLocationService().getLocation(2));
        e.setProvider(Context.getPersonService().getPerson(502));
       
        Obs obs = new Obs();
        obs.setConcept(Context.getConceptService().getConcept(6100));
        obs.setComplexData(new ComplexData("complex_obs_image_test.gif", image));
        obs.setValueComplex("gif image |complex_obs_image_test.gif");
       
        e.addObs(obs);
        Context.getEncounterService().saveEncounter(e);
        return e;
      }
View Full Code Here

Examples of org.openmrs.Obs

   * @param datetime date/time associated with the Obs (may be null)
   * @param accessionNumber accession number associated with the Obs (may be null)
   * @return the created Obs instance
   */
  public static Obs createObs(Concept concept, Object value, Date datetime, String accessionNumber) {
    Obs obs = new Obs();
    obs.setConcept(concept);
    ConceptDatatype dt = obs.getConcept().getDatatype();
    if (dt.isNumeric()) {
      obs.setValueNumeric(Double.parseDouble(value.toString()));
    } else if (HtmlFormEntryConstants.COMPLEX_UUID.equals(dt.getUuid())) {
      obs.setComplexData((ComplexData) value);
      obs.setValueComplex(obs.getComplexData().getTitle());
    } else if (dt.isText()) {
      if (value instanceof Location) {
        Location location = (Location) value;
        obs.setValueText(location.getId().toString() + " - " + location.getName());
      } else if (value instanceof Person) {
        Person person = (Person) value;
        obs.setValueText(person.getId().toString() + " - " + person.getPersonName().toString());
      } else {
        obs.setValueText(value.toString());
      }
    } else if (dt.isCoded()) {
            if (value instanceof Drug) {
                obs.setValueDrug((Drug) value);
                obs.setValueCoded(((Drug) value).getConcept());
            } else if (value instanceof ConceptName) {
                obs.setValueCodedName((ConceptName) value);
                obs.setValueCoded(obs.getValueCodedName().getConcept());
            } else if (value instanceof Concept) {
        obs.setValueCoded((Concept) value);
            } else {
        obs.setValueCoded((Concept) convertToType(value.toString(), Concept.class));
            }
    } else if (dt.isBoolean()) {
      if (value != null) {
        try {
          obs.setValueAsString(value.toString());
        }
        catch (ParseException e) {
          throw new IllegalArgumentException("Unable to convert " + value + " to a Boolean Obs value", e);
        }
      }
    } else if (ConceptDatatype.DATE.equals(dt.getHl7Abbreviation())
            || ConceptDatatype.TIME.equals(dt.getHl7Abbreviation())
            || ConceptDatatype.DATETIME.equals(dt.getHl7Abbreviation())) {
      Date date = (Date) value;
      obs.setValueDatetime(date);
    } else if ("ZZ".equals(dt.getHl7Abbreviation())) {
      // don't set a value
    } else {
      throw new IllegalArgumentException("concept datatype not yet implemented: " + dt.getName()
              + " with Hl7 Abbreviation: " + dt.getHl7Abbreviation());
    }
    if (datetime != null)
      obs.setObsDatetime(datetime);
    if (accessionNumber != null)
      obs.setAccessionNumber(accessionNumber);
    return obs;
  }
View Full Code Here

Examples of org.openmrs.Obs

     
      //note: we can do this because we're not going to manipulate anything about these obs or orders, and this copy won't be persisted...
     
      Set<Obs> newObs = new HashSet<Obs>();
      for (Obs o : source.getAllObs(true)) {
        Obs oNew = returnObsCopy(o, replacementObs);
        newObs.add(oNew);
      }
      encNew.setObs(newObs);
     
      Set<Order> newOrders = new HashSet<Order>();
View Full Code Here

Examples of org.openmrs.Obs

   * @param replacements
   * @return
   * @throws Exception
   */
  private static Obs returnObsCopy(Obs obsToCopy, Map<Obs, Obs> replacements) throws Exception {
    Obs newObs = (Obs) returnCopy(obsToCopy);
   
    if (obsToCopy.isObsGrouping()) {
      newObs.setGroupMembers(null);
      for (Obs oinner : obsToCopy.getGroupMembers()) {
        Obs oinnerNew = returnObsCopy(oinner, replacements);
        newObs.addGroupMember(oinnerNew);
      }
    }
   
    replacements.put(newObs, obsToCopy);
View Full Code Here

Examples of org.openmrs.Obs

        // propagate encounterDatetime to Obs where necessary
        if (submissionActions.getObsToCreate() != null) {
            List<Obs> toCheck = new ArrayList<Obs>();
            toCheck.addAll(submissionActions.getObsToCreate());
            while (toCheck.size() > 0) {
                Obs o = toCheck.remove(toCheck.size() - 1);
                if (o.getObsDatetime() == null && o.getEncounter() != null) {
                    o.setObsDatetime(o.getEncounter().getEncounterDatetime());
                    if (log.isDebugEnabled())
                        log.debug("Set obsDatetime to " + o.getObsDatetime() + " for "
                                + o.getConcept().getBestName(Context.getLocale()));
                }
                if (o.getLocation() == null && o.getEncounter() != null) {
                    o.setLocation(o.getEncounter().getLocation());
                }
                if (o.hasGroupMembers())
                    toCheck.addAll(o.getGroupMembers());
            }
        }

        // propagate encounterDatetime to PatientPrograms where necessary
        if (submissionActions.getPatientProgramsToCreate() != null) {
            for (PatientProgram pp : submissionActions.getPatientProgramsToCreate()) {
                if (pp.getDateEnrolled() == null)
                    pp.setDateEnrolled(encounter.getEncounterDatetime());
            }
        }

        if (submissionActions.getPatientProgramsToComplete() != null) {
            for (PatientProgram pp : submissionActions.getPatientProgramsToComplete()) {
                if (pp.getDateCompleted() == null)
                    pp.setDateCompleted(encounter.getEncounterDatetime());
            }
        }

        // TODO wrap this in a transaction
        if (submissionActions.getPersonsToCreate() != null) {
            for (Person p : submissionActions.getPersonsToCreate()) {
                if (p instanceof Patient) {
                    Patient patient = (Patient) p;
                    PatientIdentifier patientIdentifier = patient.getPatientIdentifier();
                    if (!StringUtils.hasText(patient.getGivenName()) || !StringUtils.hasText(patient.getFamilyName())
                            || !StringUtils.hasText(patient.getGender()) || patient.getBirthdate() == null
                            || patientIdentifier == null || !StringUtils.hasText(patientIdentifier.getIdentifier())
                            || patientIdentifier.getIdentifierType() == null || patientIdentifier.getLocation() == null) {
                        throw new BadFormDesignException(
                                "Please check the design of your form to make sure the following fields are mandatory to create a patient: <br/><b>&lt;personName/&gt;</b>, <b>&lt;birthDateOrAge/&gt;</b>, <b>&lt;gender/&gt;</b>, <b>&lt;identifierType/&gt;</b>, <b>&lt;identifier/&gt;</b>, and <b>&lt;identifierLocation/&gt;</b>");
                    }
                }
                Context.getPersonService().savePerson(p);
            }
        }
        if (submissionActions.getEncountersToCreate() != null) {
            for (Encounter e : submissionActions.getEncountersToCreate()) {
                if (form != null) {
                    e.setForm(form);
                    if (form.getEncounterType() != null)
                        e.setEncounterType(form.getEncounterType());
                }
                Context.getEncounterService().saveEncounter(encounter);
            }
        }

        //deal with relationships
        if (submissionActions.getRelationshipsToCreate() != null) {
            for (Relationship r : submissionActions.getRelationshipsToCreate()) {
                if (log.isDebugEnabled()) {
                    log.debug("creating relationships" + r.getRelationshipType().getDescription());
                }
                Context.getPersonService().saveRelationship(r);
            }
        }

        if (submissionActions.getRelationshipsToVoid() != null) {
            for (Relationship r : submissionActions.getRelationshipsToVoid()) {
                if (log.isDebugEnabled()) {
                    log.debug("voiding relationships" + r.getId());
                }
                Context.getPersonService().voidRelationship(r, "htmlformentry");
            }
        }

        if (submissionActions.getRelationshipsToEdit() != null) {
            for (Relationship r : submissionActions.getRelationshipsToCreate()) {
                if (log.isDebugEnabled()) {
                    log.debug("editing relationships" + r.getId());
                }
                Context.getPersonService().saveRelationship(r);
            }
        }

        // program enrollments are trickier since we need to make sure the patient isn't already enrolled
        // 1. if the patient is already enrolled on the given date, just skip this
        // 2. if the patient is enrolled *after* the given date, shift the existing enrollment to start earlier. (TODO decide if this is right)
        // 3. otherwise just enroll them as requested
        if (submissionActions.getPatientProgramsToCreate() != null) {
            for (PatientProgram toCreate : submissionActions.getPatientProgramsToCreate()) {
                boolean skip = false;
                PatientProgram earliestAfter = null;
                List<PatientProgram> already = Context.getProgramWorkflowService().getPatientPrograms(toCreate.getPatient(),
                        toCreate.getProgram(), null, null, null, null, false);
                for (PatientProgram pp : already) {
                    if (pp.getActive(toCreate.getDateEnrolled())) {
                        skip = true;
                        break;
                    }
                    // if the existing one starts after toCreate
                    if (OpenmrsUtil.compare(pp.getDateEnrolled(), toCreate.getDateEnrolled()) > 0) {
                        if (earliestAfter == null
                                || OpenmrsUtil.compare(pp.getDateEnrolled(), earliestAfter.getDateEnrolled()) < 0) {
                            earliestAfter = pp;
                        }
                    }
                }
                if (skip) {
                    continue;
                }
                if (earliestAfter != null) {
                    // edit this enrollment to move its start date earlier
                    earliestAfter.setDateEnrolled(toCreate.getDateEnrolled());
                    Context.getProgramWorkflowService().savePatientProgram(earliestAfter);
                } else {
                    // just enroll as requested
                    Context.getProgramWorkflowService().savePatientProgram(toCreate);
                }
            }
        }

        //complete any necessary programs
        if (submissionActions.getPatientProgramsToComplete() != null) {
            for (PatientProgram toComplete : submissionActions.getPatientProgramsToComplete()) {
                Context.getProgramWorkflowService().savePatientProgram(toComplete);
            }
        }

        if (submissionActions.getPatientProgramsToUpdate() != null) {
            for (PatientProgram patientProgram : submissionActions.getPatientProgramsToUpdate()) {
                Context.getProgramWorkflowService().savePatientProgram(patientProgram);
            }
        }

        ObsService obsService = Context.getObsService();
       
        if (submissionActions.getObsToVoid() != null) {
            for (Obs o : submissionActions.getObsToVoid()) {
                if (log.isDebugEnabled())
                    log.debug("voiding obs: " + o.getObsId());
                obsService.voidObs(o, "htmlformentry");
                // if o was in a group and it has no obs left, void the group
        voidObsGroupIfAllChildObsVoided(o.getObsGroup());
            }
        }

        // If we're in EDIT mode, we have to save the encounter so that any new obs are created.
        // This feels a bit like a hack, but actually it's a good thing to update the encounter's dateChanged in this case. (PS- turns out there's no dateChanged on encounter up to 1.5.)
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.