/**
   * @see RadiologyObsFormController#saveObs(HttpServletRequest, HttpServletResponse, String,
   *     RadiologyOrder, Obs Obs, BindingResult)
   */
  @Test
  @Verifies(
      value = "should edit obs with edit reason and complex concept",
      method =
          "saveObs(HttpServletRequest, HttpServletResponse, String, RadiologyOrder, Obs Obs, BindingResult)")
  public void saveObs_ShouldEditObsWithEditReasonAndComplexConcept() {

    MockHttpSession mockSession = new MockHttpSession();
    mockRequest.addParameter("saveObs", "saveObs");
    mockRequest.setSession(mockSession);

    when(obsErrors.hasErrors()).thenReturn(false);
    ConceptComplex concept = new ConceptComplex();
    ConceptDatatype cdt = new ConceptDatatype();
    cdt.setHl7Abbreviation("ED");
    concept.setDatatype(cdt);
    mockObs.setConcept(concept);

    ModelAndView modelAndView =
        radiologyObsFormController.saveObs(
            mockRequest, null, "Test Edit Reason", mockRadiologyOrder, mockObs, obsErrors);

    assertNotNull(mockSession.getAttribute(WebConstants.OPENMRS_MSG_ATTR));
    assertThat((String) mockSession.getAttribute(WebConstants.OPENMRS_MSG_ATTR), is("Obs.saved"));
    assertThat(
        modelAndView.getViewName(),
        is(
            "redirect:"
                + RADIOLOGY_OBS_FORM_URL
                + "orderId="
                + mockRadiologyOrder.getId()
                + "&obsId="
                + mockObs.getId()));
  }
  /**
   * @see RadiologyObsFormController#saveObs(HttpServletRequest, HttpServletResponse, String,
   *     RadiologyOrder, Obs Obs, BindingResult)
   */
  @Test
  @Verifies(
      value =
          "should edit obs with edit reason, complex concept and request which is an instance of multihttpserveletrequest",
      method =
          "saveObs(HttpServletRequest, HttpServletResponse, String, RadiologyOrder, Obs Obs, BindingResult)")
  public void
      saveObs_ShouldEditObsWithEditReasonComplexConceptANdRequestWhichIsAnInstanceOfMultiHTTPServletRequest() {

    MockHttpSession mockSession = new MockHttpSession();
    MockMultipartHttpServletRequest mockRequest = new MockMultipartHttpServletRequest();
    mockRequest.addParameter("saveObs", "saveObs");
    mockRequest.setSession(mockSession);

    when(obsErrors.hasErrors()).thenReturn(false);
    ConceptComplex concept = new ConceptComplex();
    ConceptDatatype cdt = new ConceptDatatype();
    cdt.setHl7Abbreviation("ED");
    concept.setDatatype(cdt);
    mockObs.setConcept(concept);
    final String fileName = "test.txt";
    final byte[] content = "Hello World".getBytes();
    MockMultipartFile mockMultipartFile =
        new MockMultipartFile("complexDataFile", fileName, "text/plain", content);

    mockRequest.addFile(mockMultipartFile);

    radiologyObsFormController.saveObs(
        mockRequest, null, "Test Edit Reason", mockRadiologyOrder, mockObs, obsErrors);

    assertNotNull(mockSession.getAttribute(WebConstants.OPENMRS_MSG_ATTR));
    assertThat((String) mockSession.getAttribute(WebConstants.OPENMRS_MSG_ATTR), is("Obs.saved"));
  }
コード例 #3
0
  private Obs getObsGroup() {
    ConceptDatatype datatype = new ConceptDatatype();
    datatype.setUuid(ConceptDatatype.CODED_UUID);
    datatype.setHl7Abbreviation(ConceptDatatype.CODED);

    Concept concept = new Concept(1);
    concept.setDatatype(datatype);
    concept.addName(new ConceptName("MedSet", Locale.ENGLISH));

    ConceptSource source = new ConceptSource();
    source.setName("LOCAL");

    ConceptMap map = new ConceptMap();
    map.setSourceCode("100");
    map.setSource(source);

    concept.addConceptMapping(map);

    Date dateCreated = new Date(213231421890234L);

    Obs obs = new Obs(1);
    obs.setConcept(concept);
    obs.setDateCreated(dateCreated);

    return obs;
  }
コード例 #4
0
 @Before
 public void setUp() throws Exception {
   drugMetaDataMapper = new DrugMetaDataMapper();
   drugConceptClass = new ConceptClass();
   drugConceptClass.setUuid(ConceptClass.DRUG_UUID);
   ConceptDatatype naDatatype = new ConceptDatatype();
   naDatatype.setUuid(ConceptDatatype.N_A_UUID);
 }
コード例 #5
0
  @Test
  @Verifies(
      value = "shouldSetTheValueComplexOfObsIfConceptIsComplex",
      method = "createObs(Concept concept, Object value, Date datetime, String accessionNumber)")
  public void createObs_shouldSetTheValueComplexOfObsIfConceptIsComplex() {

    ComplexData complexData = new ComplexData("test", null);
    Concept c = new Concept();
    ConceptDatatype cd = new ConceptDatatype();
    cd.setUuid(HtmlFormEntryConstants.COMPLEX_UUID);
    c.setDatatype(cd);
    Obs o = HtmlFormEntryUtil.createObs(c, complexData, null, null);
    Assert.assertEquals(o.getValueComplex(), complexData.getTitle());
  }
 // private String usedInForms;
 // private static Log log = LogFactory.getLog(ConceptSearchResult.class);
 public ConceptSearchResult(
     int id,
     ConceptName name,
     ConceptDescription description,
     ConceptClass cclass,
     ConceptDatatype datatype) {
   this.conceptId = id;
   this.conceptName = name.getName();
   this.conceptDescription = description.getDescription();
   this.conceptClass = cclass.getName();
   this.conceptDatatype = datatype.getName();
 }
コード例 #7
0
ファイル: Result.java プロジェクト: abickerton/openmrs-core
  /**
   * Builds a coded result from an observation
   *
   * @param obs
   */
  public Result(Obs obs) {
    this(
        obs.getObsDatetime(),
        null,
        obs.getValueAsBoolean(),
        obs.getValueCoded(),
        obs.getValueDatetime(),
        obs.getValueNumeric(),
        obs.getValueText(),
        obs);

    Concept concept = obs.getConcept();
    ConceptDatatype conceptDatatype = null;

    if (concept != null) {
      conceptDatatype = concept.getDatatype();

      if (conceptDatatype == null) {
        return;
      }
      if (conceptDatatype.isCoded()) {
        this.datatype = Datatype.CODED;
      } else if (conceptDatatype.isNumeric()) {
        this.datatype = Datatype.NUMERIC;
      } else if (conceptDatatype.isDate()) {
        this.datatype = Datatype.DATETIME;
      } else if (conceptDatatype.isText()) {
        this.datatype = Datatype.TEXT;
      } else if (conceptDatatype.isBoolean()) {
        this.datatype = Datatype.BOOLEAN;
      }
    }
  }
コード例 #8
0
 /**
  * Creates an OpenMRS Obs instance
  *
  * @param concept concept associated with the Obs
  * @param value value associated with the Obs
  * @param datetime date/time associated with the Obs (may be null)
  * @param accessionNumber accession number associatd 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 (dt.isText()) {
     if (value instanceof Location) {
       obs.setValueText(((Location) value).getLocationId().toString());
     } else {
       obs.setValueText(value.toString());
     }
   } else if (dt.isCoded()) {
     if (value instanceof Concept) obs.setValueCoded((Concept) value);
     else obs.setValueCoded((Concept) convertToType(value.toString(), Concept.class));
   } else if (dt.isBoolean()) {
     boolean booleanValue =
         value != null && !Boolean.FALSE.equals(value) && !"false".equals(value);
     obs.setValueNumeric(booleanValue ? 1.0 : 0.0);
   } else if (dt.isDate()) {
     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;
 }
コード例 #9
0
  @Test
  public void shouldEvaluateOBRORUR01TemplateForOBSGroup() throws Exception {
    // given
    Encounter encounter = new Encounter();

    Date date = new Date();
    encounter.setEncounterDatetime(date);
    encounter.setUuid("ENCOUNTER UUID");

    EncounterType encounterType = new EncounterType();
    encounterType.setName("ENCOUNTER TYPE NAME");
    encounter.setEncounterType(encounterType);

    Location location = new Location(1);
    location.setUuid("LOCATION UUID");
    location.setName("LOCATION NAME");
    encounter.setLocation(location);

    Person provider = new Person(1);
    provider.setUuid("PROVIDER UUID");
    provider.addName(
        new PersonName("PROVIDER GIVENNAME", "PROVIDER MIDDLENAME", "PROVIDER FAMILYNAME"));
    encounter.setProvider(provider);

    ConceptSource source = new ConceptSource();
    source.setName("AMPATH");

    ConceptMap map = new ConceptMap();
    map.setSourceCode("200");
    map.setSource(source);

    ConceptDatatype datatype = new ConceptDatatype();
    datatype.setUuid(ConceptDatatype.NUMERIC_UUID);
    datatype.setHl7Abbreviation(ConceptDatatype.NUMERIC);

    ConceptNumeric concept = new ConceptNumeric();
    concept.setDatatype(datatype);
    concept.addConceptMapping(map);
    concept.addName(new ConceptName("NumericConcept", Locale.ENGLISH));
    concept.setUnits("mg");

    Date dateCreated = new Date(213231421890234L);

    Obs obs = new Obs(2);
    obs.setConcept(concept);
    obs.setDateCreated(dateCreated);
    obs.setValueNumeric(10d);

    obs.setObsGroup(getObsGroup());
    obs.getObsGroup().addGroupMember(obs);

    encounter.addObs(obs);

    obs = new Obs(3);
    obs.setConcept(concept);
    obs.setDateCreated(dateCreated);
    obs.setValueNumeric(23d);
    encounter.addObs(obs);

    Map<String, Object> bindings = new HashMap<String, Object>();
    bindings.put("encounter", encounter);
    bindings.put("implementationId", "MVP");

    // when
    HL7Template hl7Template = hl7QueryService.getHL7TemplateByName("Generic Obs Group");
    String evaluatedTemplate = hl7QueryService.evaluateTemplate(hl7Template, bindings);

    // then
    evaluatedTemplate = StringUtils.deleteWhitespace(evaluatedTemplate);
    Assert.assertEquals(
        "<ORU_R01.ORDER_OBSERVATION><OBR><OBR.1>0</OBR.1><OBR.4><CE.1>100</CE.1>"
            + "<CE.2>MEDICALRECORDOBSERVATIONS</CE.2><CE.3>LOCAL</CE.3></OBR.4><OBR.18>0</OBR.18>"
            + "<OBR.29><EIP.2><EI.3>ENCOUNTERUUID</EI.3></EIP.2></OBR.29></OBR><ORU_R01.OBSERVATION>"
            + "<OBX><OBX.1>1</OBX.1><OBX.2>NM</OBX.2><OBX.3><CE.1>200</CE.1><CE.2>NumericConcept</CE.2>"
            + "<CE.3>AMPATH</CE.3></OBX.3><OBX.5>23.0</OBX.5><OBX.6><CE.1>mg</CE.1><CE.3>UCUM</CE.3></OBX.6>"
            + "<OBX.14><TS.1>"
            + new HL7TemplateFunctions().formatDate(dateCreated, null)
            + "</TS.1>"
            + "</OBX.14></OBX></ORU_R01.OBSERVATION></ORU_R01.ORDER_OBSERVATION>"
            + "<ORU_R01.ORDER_OBSERVATION><OBR><OBR.1>2</OBR.1><OBR.4><CE.1>100</CE.1><CE.2>MedSet</CE.2>"
            + "<CE.3>LOCAL</CE.3></OBR.4><OBR.18>0</OBR.18><OBR.29><EIP.2><EI.3>ENCOUNTERUUID</EI.3></EIP.2></OBR.29"
            + "></OBR><ORU_R01.OBSERVATION><OBX><OBX.1>2</OBX.1><OBX.2>NM</OBX.2><OBX.3><CE.1>200</CE.1>"
            + "<CE.2>NumericConcept</CE.2><CE.3>AMPATH</CE.3></OBX.3><OBX.5>10.0</OBX.5><OBX.6><CE.1>mg</CE.1>"
            + "<CE.3>UCUM</CE.3></OBX.6><OBX.14><TS.1>"
            + new HL7TemplateFunctions().formatDate(dateCreated, null)
            + "</TS.1></OBX.14></OBX></ORU_R01.OBSERVATION></ORU_R01.ORDER_OBSERVATION>",
        evaluatedTemplate);
  }