org.openmrs.Obs.setPerson()方法的使用及代码示例

x33g5p2x  于2022-01-26 转载在 其他  
字(12.4k)|赞(0)|评价(0)|浏览(128)

本文整理了Java中org.openmrs.Obs.setPerson()方法的一些代码示例,展示了Obs.setPerson()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Obs.setPerson()方法的具体详情如下:
包路径:org.openmrs.Obs
类名称:Obs
方法名:setPerson

Obs.setPerson介绍

[英]Set the person object to this obs object. This will also set the personId on this obs object
[中]将person对象设置为此obs对象。这也会在obs对象上设置personId

代码示例

代码示例来源:origin: openmrs/openmrs-core

private void setPersonFromEncounter(Obs obs) {
  Encounter encounter = obs.getEncounter();
  if (encounter != null) {
    obs.setPerson(encounter.getPatient());
  }
}

代码示例来源:origin: openmrs/openmrs-core

private void mergeObservationsNotContainedInEncounters(Patient preferred, Patient notPreferred,
    PersonMergeLogData mergedData) {
  // move all obs that weren't contained in encounters
  // TODO: this should be a copy, not a move
  ObsService obsService = Context.getObsService();
  for (Obs obs : obsService.getObservationsByPerson(notPreferred)) {
    if (obs.getEncounter() == null && !obs.getVoided()) {
      obs.setPerson(preferred);
      Obs persisted = obsService.saveObs(obs, "Merged from patient #" + notPreferred.getPatientId());
      mergedData.addMovedIndependentObservation(persisted.getUuid());
    }
  }
}

代码示例来源:origin: openmrs/openmrs-core

/**
 * @see ObsValidator#validate(java.lang.Object, org.springframework.validation.Errors)
 */
@Test
public void validate_shouldFailIfObsHasNoValuesAndNotParent() {
  
  Obs obs = new Obs();
  obs.setPerson(Context.getPersonService().getPerson(2));
  obs.setConcept(Context.getConceptService().getConcept(18));
  obs.setObsDatetime(new Date());
  
  Errors errors = new BindException(obs, "obs");
  obsValidator.validate(obs, errors);
  
  assertTrue(errors.getGlobalErrorCount() > 0);
}

代码示例来源:origin: openmrs/openmrs-core

/**
 * @see ObsValidator#validate(java.lang.Object, org.springframework.validation.Errors)
 */
@Test
public void validate_shouldFailValidationIfConceptDatatypeIsTextAndValueTextIsNull() {
  Obs obs = new Obs();
  obs.setPerson(Context.getPersonService().getPerson(2));
  obs.setConcept(Context.getConceptService().getConcept(19));
  obs.setObsDatetime(new Date());
  
  Errors errors = new BindException(obs, "obs");
  obsValidator.validate(obs, errors);
  
  assertTrue(errors.hasFieldErrors("valueText"));
}

代码示例来源:origin: openmrs/openmrs-core

/**
 * @see ObsValidator#validate(java.lang.Object, org.springframework.validation.Errors)
 */
@Test
public void validate_shouldPassValidationIfAllValuesPresent() {
  Obs obs = new Obs();
  obs.setPerson(Context.getPersonService().getPerson(2));
  obs.setConcept(Context.getConceptService().getConcept(5089));
  obs.setObsDatetime(new Date());
  obs.setValueNumeric(1.0);
  
  Errors errors = new BindException(obs, "obs");
  obsValidator.validate(obs, errors);
  
  assertFalse(errors.hasErrors());
}

代码示例来源:origin: openmrs/openmrs-core

/**
 * @see ObsValidator#validate(java.lang.Object, org.springframework.validation.Errors)
 */
@Test
public void validate_shouldFailValidationIfObsAncestorsContainsObs() {
  Obs obs = new Obs();
  obs.setPerson(Context.getPersonService().getPerson(2));
  obs.setConcept(Context.getConceptService().getConcept(3)); // datatype = N/A
  obs.setObsDatetime(new Date());
  
  Set<Obs> group = new HashSet<>();
  group.add(obs);
  obs.setGroupMembers(group);
  
  Errors errors = new BindException(obs, "obs");
  obsValidator.validate(obs, errors);
  
  assertFalse(errors.hasFieldErrors("person"));
  assertFalse(errors.hasFieldErrors("concept"));
  assertFalse(errors.hasFieldErrors("obsDatetime"));
  assertTrue(errors.hasFieldErrors("groupMembers"));
}

代码示例来源:origin: openmrs/openmrs-core

/**
 * @see ObsService#saveObs(Obs,String)
 */
@Test
public void saveObs_shouldCreateVeryBasicObsAndAddNewObsId() {
  Obs o = new Obs();
  o.setConcept(Context.getConceptService().getConcept(3));
  o.setPerson(new Patient(2));
  o.setEncounter(new Encounter(3));
  o.setObsDatetime(new Date());
  o.setLocation(new Location(1));
  o.setValueNumeric(50d);
  
  Obs oSaved = Context.getObsService().saveObs(o, null);
  
  // make sure the returned Obs and the passed in obs
  // now both have primary key obsIds
  assertTrue(oSaved.getObsId().equals(o.getObsId()));
}

代码示例来源:origin: openmrs/openmrs-core

@Test
public void saveEncounter_shouldSaveEncounterWithComplexObs() {
  executeDataSet(ENC_OBS_HIERARCHY_DATA_XML);
  EncounterService es = Context.getEncounterService();
  Encounter encounter = es.getEncounter(101);
  Obs observation = buildObs();
  observation.setLocation(encounter.getLocation());
  observation.setPerson(encounter.getPatient());
  encounter.addObs(observation);
  es.saveEncounter(encounter);
  Context.flushSession();
  Context.clearSession();
  encounter = es.getEncounter(101);
  assertEquals(2, encounter.getObsAtTopLevel(true).size());
}

代码示例来源:origin: openmrs/openmrs-core

/**
 * @see ObsValidator#validate(java.lang.Object, org.springframework.validation.Errors)
 */
@Test
public void validate_shouldFailValidationIfConceptIsNull() {
  Obs obs = new Obs();
  obs.setPerson(Context.getPersonService().getPerson(2));
  obs.setObsDatetime(new Date());
  obs.setValueNumeric(1.0);
  
  Errors errors = new BindException(obs, "obs");
  obsValidator.validate(obs, errors);
  
  assertFalse(errors.hasFieldErrors("person"));
  assertTrue(errors.hasFieldErrors("concept"));
  assertFalse(errors.hasFieldErrors("obsDatetime"));
  assertFalse(errors.hasFieldErrors("valueNumeric"));
}

代码示例来源:origin: openmrs/openmrs-core

/**
 * @see ObsService#saveObs(Obs,String)
 */
@Test
public void saveObs_shouldSetCreatorAndDateCreatedOnNewObs() {
  Obs o = new Obs();
  o.setConcept(Context.getConceptService().getConcept(3));
  o.setPerson(new Patient(2));
  o.setEncounter(new Encounter(3));
  o.setObsDatetime(new Date());
  o.setLocation(new Location(1));
  o.setValueNumeric(50d);
  
  Context.getObsService().saveObs(o, null);
  assertNotNull(o.getDateCreated());
  assertNotNull(o.getCreator());
}

代码示例来源:origin: openmrs/openmrs-core

/**
 * @see ObsValidator#validate(java.lang.Object, org.springframework.validation.Errors)
 */
@Test
public void validate_shouldFailValidationIfConceptDatatypeIsCodedAndValueCodedIsNull() {
  Obs obs = new Obs();
  obs.setPerson(Context.getPersonService().getPerson(2));
  obs.setConcept(Context.getConceptService().getConcept(4));
  obs.setObsDatetime(new Date());
  
  Errors errors = new BindException(obs, "obs");
  obsValidator.validate(obs, errors);
  
  assertFalse(errors.hasFieldErrors("person"));
  assertFalse(errors.hasFieldErrors("concept"));
  assertFalse(errors.hasFieldErrors("obsDatetime"));
  assertTrue(errors.hasFieldErrors("valueCoded"));
}

代码示例来源:origin: openmrs/openmrs-core

/**
 * @see ObsValidator#validate(java.lang.Object, org.springframework.validation.Errors)
 */
@Test
public void validate_shouldFailValidationIfConceptDatatypeIsDateAndValueDatetimeIsNull() {
  Obs obs = new Obs();
  obs.setPerson(Context.getPersonService().getPerson(2));
  obs.setConcept(Context.getConceptService().getConcept(20));
  obs.setObsDatetime(new Date());
  
  Errors errors = new BindException(obs, "obs");
  obsValidator.validate(obs, errors);
  
  assertFalse(errors.hasFieldErrors("person"));
  assertFalse(errors.hasFieldErrors("concept"));
  assertFalse(errors.hasFieldErrors("obsDatetime"));
  assertTrue(errors.hasFieldErrors("valueDatetime"));
}

代码示例来源:origin: openmrs/openmrs-core

/**
 * @see ObsValidator#validate(java.lang.Object, org.springframework.validation.Errors)
 */
@Test
public void validate_shouldFailValidationIfConceptDatatypeIsBooleanAndValueBooleanIsNull() {
  Obs obs = new Obs();
  obs.setPerson(Context.getPersonService().getPerson(2));
  obs.setConcept(Context.getConceptService().getConcept(18));
  obs.setObsDatetime(new Date());
  
  Errors errors = new BindException(obs, "obs");
  obsValidator.validate(obs, errors);
  
  assertFalse(errors.hasFieldErrors("person"));
  assertFalse(errors.hasFieldErrors("concept"));
  assertFalse(errors.hasFieldErrors("obsDatetime"));
  assertTrue(errors.hasFieldErrors("valueBoolean"));
}

代码示例来源:origin: openmrs/openmrs-core

/**
 * @see ObsValidator#validate(java.lang.Object, org.springframework.validation.Errors)
 */
@Test
public void validate_shouldFailValidationIfConceptDatatypeIsNumericAndValueNumericIsNull() {
  Obs obs = new Obs();
  obs.setPerson(Context.getPersonService().getPerson(2));
  obs.setConcept(Context.getConceptService().getConcept(5089));
  obs.setObsDatetime(new Date());
  
  Errors errors = new BindException(obs, "obs");
  obsValidator.validate(obs, errors);
  
  assertFalse(errors.hasFieldErrors("person"));
  assertFalse(errors.hasFieldErrors("concept"));
  assertFalse(errors.hasFieldErrors("obsDatetime"));
  assertTrue(errors.hasFieldErrors("valueNumeric"));
}

代码示例来源:origin: openmrs/openmrs-core

/**
 * @see ObsValidator#validate(java.lang.Object, org.springframework.validation.Errors)
 */
@Test
public void validate_shouldNotValidateIfObsIsVoided() {
  Obs obs = new Obs();
  obs.setPerson(Context.getPersonService().getPerson(2));
  obs.setConcept(Context.getConceptService().getConcept(5089));
  obs.setObsDatetime(new Date());
  obs.setValueNumeric(null);
  
  Errors errors = new BindException(obs, "obs");
  obsValidator.validate(obs, errors);
  assertTrue(errors.hasFieldErrors("valueNumeric"));
  
  obs.setVoided(true);
  errors = new BindException(obs, "obs");
  obsValidator.validate(obs, errors);
  assertFalse(errors.hasErrors());
  
}

代码示例来源:origin: openmrs/openmrs-core

/**
 * @see ObsValidator#validate(java.lang.Object, org.springframework.validation.Errors)
 */
@Test
public void validate_shouldPassValidationIfFieldLengthsAreCorrect() {
  Obs obs = new Obs();
  obs.setPerson(Context.getPersonService().getPerson(2));
  obs.setConcept(Context.getConceptService().getConcept(5089));
  obs.setObsDatetime(new Date());
  obs.setValueNumeric(1.0);
  
  obs.setAccessionNumber("AccessionNumber");
  obs.setValueModifier("m");
  obs.setValueComplex("ValueComplex");
  obs.setVoidReason("VoidReason");
  obs.setComment("comment");
  
  Errors errors = new BindException(obs, "obs");
  obsValidator.validate(obs, errors);
  
  assertFalse(errors.hasErrors());
}

代码示例来源:origin: openmrs/openmrs-core

/**
 * @see ObsValidator#validate(Object,Errors)
 */
@Test
public void validate_shouldPassIfAnswerConceptAndConceptOfValueDrugMatch() {
  Obs obs = new Obs();
  obs.setPerson(new Person(7));
  obs.setObsDatetime(new Date());
  Concept questionConcept = new Concept(100);
  ConceptDatatype dt = new ConceptDatatype(1);
  dt.setUuid(ConceptDatatype.CODED_UUID);
  questionConcept.setDatatype(dt);
  obs.setConcept(questionConcept);
  Concept answerConcept = new Concept(101);
  obs.setValueCoded(answerConcept);
  
  Drug drug = new Drug();
  drug.setConcept(answerConcept);
  obs.setValueDrug(drug);
  
  Errors errors = new BindException(obs, "obs");
  obsValidator.validate(obs, errors);
  assertFalse(errors.hasFieldErrors());
}

代码示例来源:origin: openmrs/openmrs-core

/**
 * @see ObsValidator#validate(Object,Errors)
 */
@Test
public void validate_shouldRejectAnInvalidConceptAndDrugCombination() {
  Obs obs = new Obs();
  obs.setPerson(new Person(7));
  obs.setObsDatetime(new Date());
  Concept questionConcept = new Concept(100);
  ConceptDatatype dt = new ConceptDatatype(1);
  dt.setUuid(ConceptDatatype.CODED_UUID);
  questionConcept.setDatatype(dt);
  obs.setConcept(questionConcept);
  obs.setValueCoded(new Concept(101));
  
  Drug drug = new Drug();
  drug.setConcept(new Concept(102));
  obs.setValueDrug(drug);
  
  Errors errors = new BindException(obs, "obs");
  obsValidator.validate(obs, errors);
  assertTrue(errors.hasFieldErrors("valueDrug"));
}

代码示例来源:origin: openmrs/openmrs-core

/**
 * @see ConceptService#purgeConcept(Concept)
 */
@Test(expected = ConceptNameInUseException.class)
public void purgeConcept_shouldFailIfAnyOfTheConceptNamesOfTheConceptIsBeingUsedByAnObs() {
  Obs o = new Obs();
  o.setConcept(Context.getConceptService().getConcept(3));
  o.setPerson(new Patient(2));
  o.setEncounter(new Encounter(3));
  o.setObsDatetime(new Date());
  o.setLocation(new Location(1));
  ConceptName conceptName = new ConceptName(1847);
  o.setValueCodedName(conceptName);
  Context.getObsService().saveObs(o, null);
  //ensure that the association between the conceptName and the obs has been established
  Assert.assertEquals(true, conceptService.hasAnyObservation(conceptName));
  
  Concept concept = conceptService.getConceptByName("cd4 count");
  //make sure the name concept name exists
  Assert.assertNotNull(concept);
  conceptService.purgeConcept(concept);
}

代码示例来源:origin: openmrs/openmrs-core

/**
 * @see ObsValidator#validate(java.lang.Object, org.springframework.validation.Errors)
 */
@Test
public void validate_shouldFailValidationIfObsDatetimeIsNull() {
  Obs obs = new Obs();
  obs.setPerson(Context.getPersonService().getPerson(2));
  obs.setConcept(Context.getConceptService().getConcept(5089));
  obs.setValueNumeric(1.0);
  
  Errors errors = new BindException(obs, "obs");
  obsValidator.validate(obs, errors);
  
  assertFalse(errors.hasFieldErrors("person"));
  assertFalse(errors.hasFieldErrors("concept"));
  assertTrue(errors.hasFieldErrors("obsDatetime"));
  assertFalse(errors.hasFieldErrors("valueNumeric"));
}

相关文章