@Test
  public void testParsingDispositionWithDateOfDeath() throws Exception {
    Concept admit =
        new ConceptBuilder(
                null,
                conceptService.getConceptDatatypeByName("N/A"),
                conceptService.getConceptClassByName("Misc"))
            .addName("Death")
            .get();
    when(emrConceptService.getConcept("test:death")).thenReturn(admit);

    Obs dispositionObs =
        dispositionDescriptor.buildObsGroup(
            new Disposition(
                "emrapi.death",
                "Death",
                "test:death",
                Collections.<String>emptyList(),
                Collections.<DispositionObs>emptyList()),
            emrConceptService);

    Date dateOfDeath = new DateTime(2012, 2, 20, 10, 10, 10).toDate();
    Obs dateOfDeathObs = new Obs();
    dateOfDeathObs.setObsId(100);
    dateOfDeathObs.setConcept(dispositionDescriptor.getDateOfDeathConcept());
    dateOfDeathObs.setValueDate(dateOfDeath);
    dispositionObs.addGroupMember(dateOfDeathObs);

    encounter.addObs(doNotGoToServiceToFormatMembers(dispositionObs));
    ParsedObs parsed = parser.parseObservations(Locale.ENGLISH);

    SimpleObject expectedAdmissionLocationObject =
        SimpleObject.create("obsId", dateOfDeathObs.getObsId());
    expectedAdmissionLocationObject.put("question", "Date of death");
    expectedAdmissionLocationObject.put("answer", "20 Feb 2012 10:10 AM");

    List<SimpleObject> expectedAdditionalObsList = new ArrayList<SimpleObject>();
    expectedAdditionalObsList.add(expectedAdmissionLocationObject);

    assertThat(parsed.getDiagnoses().size(), is(0));
    assertThat(parsed.getDispositions().size(), is(1));
    assertThat(parsed.getObs().size(), is(0));
    assertThat(path(parsed.getDispositions(), 0, "disposition"), is((Object) "Death"));
    assertThat(
        path(parsed.getDispositions(), 0, "additionalObs"), is((Object) expectedAdditionalObsList));
  }
Exemplo n.º 2
0
 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;
 }
  @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);
                  }
                }));
  }