@Test
 public void testStarted() throws Exception {
   new EbolaExampleActivator().started();
   assertThat(
       conceptService.getConceptByUuid("162599AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA").getConceptId(),
       is(162599));
 }
  @Test
  public void shouldAddNewDrugOrderWhenPrnIsTrueWIthNoDosageFrequencyOrDosageInstruction() {

    EncounterTransaction.DrugOrder drugOrder =
        new DrugOrderBuilder()
            .withBasicValues("drug-uuid", "test-concept-uuid", today, today, 3, "", "")
            .withPrn(true)
            .build();
    Concept drugConcept = new Concept(3);
    OrderType drugOrderType = new OrderType("Drug Order", "this is a drug order type");

    when(orderService.getAllOrderTypes()).thenReturn(asList(drugOrderType));
    when(conceptService.getConceptByUuid("test-concept-uuid")).thenReturn(drugConcept);
    Drug drug = new Drug();
    drug.setName("test drug");
    when(conceptService.getDrugByUuid("drug-uuid")).thenReturn(drug);

    encounterDrugOrderServiceHelper.update(encounter, asList(drugOrder));

    assertThat(encounter.getOrders().size(), is(1));
    org.openmrs.DrugOrder order = (org.openmrs.DrugOrder) encounter.getOrders().iterator().next();
    assertEquals(drugConcept, order.getConcept());
    assertEquals(drugOrderType, order.getOrderType());
    assertEquals(patient, order.getPatient());
    assertEquals(encounter, order.getEncounter());
    assertEquals(today, order.getStartDate());
    assertEquals(today, order.getAutoExpireDate());
    assertEquals(drug.getDisplayName(), order.getDrug().getDisplayName());
    assertEquals(Double.valueOf(3), order.getDose());

    assertEquals(true, order.getPrn());
    assertEquals(null, order.getFrequency());
    assertEquals(null, order.getUnits());
  }
 private Concept newConcept(ConceptDatatype conceptDatatype, String conceptUuid) {
   Concept concept = new Concept();
   concept.setDatatype(conceptDatatype);
   concept.setUuid(conceptUuid);
   when(conceptService.getConceptByUuid(conceptUuid)).thenReturn(concept);
   return concept;
 }
  @Test
  public void createNewOrderFromEtOrder() throws Exception {
    Provider provider = mock(Provider.class);
    handleEncounterProvider(provider);

    Concept mrsBloodConcept = mock(Concept.class);
    when(conceptService.getConceptByUuid("bloodConceptUuid")).thenReturn(mrsBloodConcept);

    Date currentDate = new Date();

    EncounterTransaction.Concept blood =
        new EncounterTransaction.Concept("bloodConceptUuid", "blood");

    EncounterTransaction.Order etOrder = new EncounterTransaction.Order();
    etOrder.setConcept(blood);
    etOrder.setDateCreated(currentDate);

    OpenMRSOrderMapper orderMapper = new OpenMRSOrderMapper(orderService, conceptService);

    Order order = orderMapper.map(etOrder, encounter);

    Assert.assertEquals(encounter, order.getEncounter());
    Assert.assertEquals(mrsBloodConcept, order.getConcept());
    Assert.assertEquals(provider, order.getOrderer());
  }
  @Test
  public void setPreferredConceptName_shouldTagShortName() throws Exception {
    metadataDeployService.installBundles(Arrays.<MetadataBundle>asList(ebolaMetadata));
    ConceptNameTag nameTag =
        MetadataUtils.existing(ConceptNameTag.class, EbolaMetadata._ConceptNameTag.PREFERRED);

    String uuid = "c607c80f-1ea9-4da3-bb88-6276ce8868dd";
    assertThat(
        conceptService.getConceptByUuid(uuid).getPreferredName(Locale.ENGLISH).getName(),
        is("WEIGHT (KG)"));

    new EbolaExampleActivator().setPreferredConceptName(conceptService, uuid, "WT");
    assertThat(
        conceptService.getConceptByUuid(uuid).getPreferredName(Locale.ENGLISH).getName(),
        is("WEIGHT (KG)"));
    assertThat(
        conceptService.getConceptByUuid(uuid).findNameTaggedWith(nameTag).getName(), is("WT"));
  }
 static Obs jsonObservationToObs(
     Object jsonObservation, Patient patient, Date encounterTime, Location location) {
   Map observationObject = (Map) jsonObservation;
   String questionUuid = (String) observationObject.get(QUESTION_UUID);
   ConceptService conceptService = Context.getConceptService();
   Concept questionConcept = conceptService.getConceptByUuid(questionUuid);
   if (questionConcept == null) {
     log.warn("Question concept not found: " + questionUuid);
     return null;
   }
   Obs obs = new Obs(patient, questionConcept, encounterTime, location);
   String answerUuid = (String) observationObject.get(ANSWER_UUID);
   String answerDate = (String) observationObject.get(ANSWER_DATE);
   String answerNumber = (String) observationObject.get(ANSWER_NUMBER);
   if (answerUuid != null) {
     Concept answerConcept = conceptService.getConceptByUuid(answerUuid);
     if (answerConcept == null) {
       log.warn("Answer concept not found: " + answerUuid);
       return null;
     }
     obs.setValueCoded(answerConcept);
   } else if (answerDate != null) {
     try {
       obs.setValueDate(Utils.YYYYMMDD_UTC_FORMAT.parse(answerDate));
     } catch (ParseException e) {
       log.warn("Invalid date answer: " + answerDate);
       return null;
     }
   } else if (observationObject.containsKey(ANSWER_NUMBER)) {
     try {
       obs.setValueNumeric(Double.parseDouble(answerNumber));
     } catch (IllegalArgumentException e) {
       log.warn("Invalid numeric answer: " + answerUuid);
       return null;
     }
   } else {
     log.warn("Invalid answer type: " + observationObject);
     return null;
   }
   return obs;
 }
Beispiel #7
0
 /** Gets or creates a Concept with a given UUID and name. */
 public static Concept getConcept(String name, String uuid, String typeUuid) {
   ConceptService conceptService = Context.getConceptService();
   Concept concept = conceptService.getConceptByUuid(uuid);
   if (concept == null) {
     concept = new Concept();
     concept.setUuid(uuid);
     concept.setShortName(new ConceptName(name, new Locale("en")));
     concept.setDatatype(conceptService.getConceptDatatypeByUuid(typeUuid));
     concept.setConceptClass(conceptService.getConceptClassByUuid(ConceptClass.MISC_UUID));
     conceptService.saveConcept(concept);
   }
   return concept;
 }
  @Test
  public void shouldSubmitEDConsultNoteWithAdditionalObservationsOfTypeDate() throws Exception {
    int primaryConceptNameId = 2460;

    String diagnosisJson =
        "{ \"certainty\": \"PRESUMED\", \"diagnosisOrder\": \"PRIMARY\", \"diagnosis\": \""
            + CodedOrFreeTextAnswer.CONCEPT_NAME_PREFIX
            + primaryConceptNameId
            + "\" }";

    String additionalObsJson =
        "{ \"concept\": \"uuid-123\", \"value\": \"2013-05-21 17:23:47\", \"datatype\": \"Date\"}";

    Concept conceptFor2460 = new Concept();
    final ConceptName conceptName2460 = new ConceptName();
    conceptName2460.setConcept(conceptFor2460);

    when(conceptService.getConceptName(primaryConceptNameId)).thenReturn(conceptName2460);

    final Concept conceptForAdditionalObs = new Concept();
    conceptForAdditionalObs.setUuid("uuid-123");
    Calendar calendar = new GregorianCalendar(2013, 04, 21, 17, 23, 47);
    final Date dateForAdditionalObs = calendar.getTime();

    when(conceptService.getConceptByUuid("uuid-123")).thenReturn(conceptForAdditionalObs);

    Patient patient = new Patient();
    patient.addName(new PersonName("Jean", "Paul", "Marie"));
    final Location sessionLocation = new Location();
    final Provider currentProvider = new Provider();

    DispositionFactory dispositionFactory = mock(DispositionFactory.class);

    EmrContext emrContext = new EmrContext();
    emrContext.setSessionLocation(sessionLocation);
    emrContext.setCurrentProvider(currentProvider);

    MockHttpSession httpSession = new MockHttpSession();
    MockHttpServletRequest httpServletRequest = new MockHttpServletRequest();
    ConsultPageController controller = new ConsultPageController();
    String result =
        controller.post(
            patient,
            asList(diagnosisJson),
            "",
            asList(additionalObsJson),
            "",
            httpSession,
            httpServletRequest,
            consultService,
            conceptService,
            dispositionFactory,
            emrContext,
            new TestUiUtils());

    final Obs traumaObs = new Obs();
    traumaObs.setConcept(conceptForAdditionalObs);
    traumaObs.setValueDate(dateForAdditionalObs);

    verify(consultService)
        .saveConsultNote(
            argThat(
                new ArgumentMatcher<ConsultNote>() {
                  @Override
                  public boolean matches(Object o) {
                    ConsultNote actual = (ConsultNote) o;
                    Obs actualObs = actual.getAdditionalObs().get(0);
                    return containsInAnyOrder(
                                new Diagnosis(
                                    new CodedOrFreeTextAnswer(conceptName2460),
                                    Diagnosis.Order.PRIMARY))
                            .matches(actual.getDiagnoses())
                        && actual.getAdditionalObs().size() == 1
                        && actualObs.getConcept() == conceptForAdditionalObs
                        && actualObs.getValueDate().equals(dateForAdditionalObs);
                  }
                }));
  }