/**
  * @see BaseOpenmrsDatatype#doGetTextSummary(Object)
  * @should use the name in summary instance
  */
 @Override
 public Summary doGetTextSummary(Concept concept) {
   String name = "";
   if (concept.getName() != null) {
     name = concept.getName().getName();
   }
   return new CustomDatatype.Summary(name, true);
 }
  @Test
  @Verifies(
      value = "should return a list consisting of active, not retired, states",
      method = "getPossibleNextStates")
  public void getPossibleNextStates_shouldReturnNonRetiredStates() throws Exception {
    executeDataSet(PROGRAM_NEXT_STATES_XML);

    Integer patient = 11;
    Integer workflow = 501;
    Vector<ListItem> possibleNextStates;

    /* retire a workflow state  */
    PatientProgram pp = Context.getProgramWorkflowService().getPatientProgram(patient);
    ProgramWorkflow pw = pp.getProgram().getWorkflow(workflow);
    Set<ProgramWorkflowState> pwss = pw.getStates();

    for (ProgramWorkflowState pws : pwss) {
      Concept cp = pws.getConcept();
      ConceptName cn = cp.getName();
      if (cn != null) {
        String cnn = cn.getName();
        if (cnn.equalsIgnoreCase("Test State 3")) {
          pws.setRetired(true);
        }
      }
    }

    possibleNextStates = dwrProgramWorkflowService.getPossibleNextStates(patient, workflow);
    assertFalse(possibleNextStates.isEmpty());
    assertEquals(2, possibleNextStates.size());
  }
  @Test
  public void addSetMembers() throws Exception {
    ConceptSetRow conceptRow = new ConceptSetRow();
    conceptRow.name = "New concept";
    conceptRow.conceptClass = "New Class";
    conceptRow.description = "some description";

    List<KeyValue> children = new ArrayList<>();
    children.add(new KeyValue("1", "Child1"));
    children.add(new KeyValue("2", "Child2"));
    conceptRow.children = children;
    Messages persistErrorMessages = conceptSetPersister.persist(conceptRow);
    assertTrue(persistErrorMessages.isEmpty());
    Context.openSession();
    Context.authenticate("admin", "test");
    Concept persistedConcept = conceptService.getConceptByName(conceptRow.name);
    assertNotNull(persistedConcept);
    assertEquals(conceptRow.name, persistedConcept.getName(Context.getLocale()).getName());
    assertEquals(conceptRow.conceptClass, persistedConcept.getConceptClass().getName());
    assertEquals("some description", persistedConcept.getDescription().getDescription());

    assertEquals(2, persistedConcept.getSetMembers().size());
    assertEquals("some description", persistedConcept.getDescription().getDescription());
    assertEquals(0, persistedConcept.getSynonyms().size());
    assertTrue(persistedConcept.isSet());
    Context.flushSession();
    Context.closeSession();
  }
 /** @param concept the concept to set */
 public void setConcept(Concept concept) {
   this.concept = concept;
   if (concept != null) {
     setName(concept.getName().getName());
     setDescription(concept.getDisplayString());
   }
 }
 public CodeableConceptDt addTRCodingOrDisplay(Concept concept) {
   CodeableConceptDt codeableConceptDt = addTRCoding(concept);
   if (CollectionUtils.isEmpty(codeableConceptDt.getCoding())) {
     CodingDt coding = codeableConceptDt.addCoding();
     coding.setDisplay(concept.getName().getName());
   }
   return codeableConceptDt;
 }
  public DataObject simplifyConcept(Concept concept, Locale locale) throws Exception {

    List<Object> propertyNamesAndValues = new ArrayList<Object>();
    ConceptName preferredName = concept.getPreferredName(locale);

    propertyNamesAndValues.add("conceptId");
    propertyNamesAndValues.add(Integer.toString((concept.getConceptId())));

    if (preferredName != null && preferredName.getName() != null) {
      propertyNamesAndValues.add("conceptName");
      propertyNamesAndValues.add(preferredName.getName());
    } else if (preferredName == null && concept.getName() != null) {
      propertyNamesAndValues.add("conceptName");
      propertyNamesAndValues.add(concept.getName().getName());
    }
    DataObject dataObject = DataObject.create(propertyNamesAndValues);
    return dataObject;
  }
 public CodeableConceptDt getTRValueSetCodeableConcept(
     Concept concept, String valueSetURL, CodeableConceptDt codeableConcept) {
   CodingDt coding = codeableConcept.addCoding();
   if (null != idMappingsRepository.findByInternalId(concept.getUuid())) {
     coding.setCode(getTRValueSetCode(concept));
     coding.setSystem(valueSetURL);
   }
   coding.setDisplay(concept.getName().getName());
   return codeableConcept;
 }
 public ConceptSearchResult(Concept con) {
   this.conceptId = con.getConceptId();
   if (con.getName() != null) {
     this.conceptName = con.getName().getName();
   }
   if (con.getDescription() != null) {
     this.conceptDescription = con.getDescription().getDescription();
   }
   if (con.getConceptClass() != null) {
     this.conceptClass = con.getConceptClass().getName();
   }
   if (con.getDatatype() != null) {
     this.conceptDatatype = con.getDatatype().getName();
   }
   this.otherNames = new Vector<String>();
   for (ConceptName cn : con.getNames()) {
     this.otherNames.add(cn.getName());
   }
 }
 public String getTRValueSetCode(Concept concept) {
   for (ConceptMap mapping : concept.getConceptMappings()) {
     if (mapping.getConceptMapType().getUuid().equals(ConceptMapType.SAME_AS_MAP_TYPE_UUID)) {
       return mapping.getConceptReferenceTerm().getCode();
     }
   }
   for (ConceptName conceptName : concept.getShortNames()) {
     return conceptName.getName();
   }
   return concept.getName().getName();
 }
 private void addTRCodingForConcept(
     Concept concept,
     IdMappingsRepository idMappingsRepository,
     CodeableConceptDt codeableConcept) {
   IdMapping idMapping = idMappingsRepository.findByInternalId(concept.getUuid());
   if (idMapping != null) {
     addFHIRCoding(
         codeableConcept,
         idMapping.getExternalId(),
         idMapping.getUri(),
         concept.getName().getName());
   }
 }
 private void addTRCodingsForReferenceTerms(
     Concept concept,
     IdMappingsRepository idMappingsRepository,
     CodeableConceptDt codeableConcept,
     ConceptMap mapping) {
   ConceptReferenceTerm conceptReferenceTerm = mapping.getConceptReferenceTerm();
   IdMapping idMapping = idMappingsRepository.findByInternalId(conceptReferenceTerm.getUuid());
   if (idMapping != null) {
     addFHIRCoding(
         codeableConcept,
         conceptReferenceTerm.getCode(),
         idMapping.getUri(),
         concept.getName().getName());
   }
 }
 @Test
 public void shouldPersistNewConceptSetWithNameClassDescriptionInputOnly() throws Exception {
   ConceptSetRow conceptRow = new ConceptSetRow();
   conceptRow.name = "New concept";
   conceptRow.conceptClass = "New Class";
   conceptRow.description = "some description";
   Messages persistErrorMessages = conceptSetPersister.persist(conceptRow);
   assertTrue(persistErrorMessages.isEmpty());
   Context.openSession();
   Context.authenticate("admin", "test");
   Concept persistedConcept = conceptService.getConceptByName(conceptRow.name);
   assertNotNull(persistedConcept);
   assertEquals(conceptRow.name, persistedConcept.getName(Context.getLocale()).getName());
   assertEquals(conceptRow.conceptClass, persistedConcept.getConceptClass().getName());
   assertEquals("some description", persistedConcept.getDescription().getDescription());
   assertEquals(0, persistedConcept.getSynonyms().size());
   assertTrue(persistedConcept.isSet());
   Context.flushSession();
   Context.closeSession();
 }
 private String getConceptName(Concept concept) {
   if (concept != null) {
     return concept.getName().getName();
   }
   return null;
 }
 public int compare(Concept o1, Concept o2) {
   return o1.getName().getName().compareToIgnoreCase(o2.getName().getName());
 }
 public ResourceReference map(Concept concept) {
   return new ResourceReference(concept.getUuid(), concept.getName(Context.getLocale()).getName());
 }
  @RequestMapping(method = RequestMethod.POST)
  public void savePatientInfo(
      @RequestParam("patientId") Integer patientId,
      @RequestParam(value = "encounterId", required = false) Integer encounterId,
      HttpServletRequest request,
      HttpServletResponse response)
      throws ParseException, IOException {

    Map<String, String> parameters = RegistrationWebUtils.optimizeParameters(request);

    // get patient
    Patient patient = Context.getPatientService().getPatient(patientId);

    /*
     * SAVE ENCOUNTER
     */
    Encounter encounter = null;
    if (encounterId != null) {
      encounter = Context.getEncounterService().getEncounter(encounterId);
    } else {
      encounter = RegistrationWebUtils.createEncounter(patient, true);

      // create OPD obs
      Concept opdWardConcept =
          Context.getConceptService().getConcept(RegistrationConstants.CONCEPT_NAME_OPD_WARD);
      Concept selectedOPDConcept =
          Context.getConceptService()
              .getConcept(
                  Integer.parseInt(
                      parameters.get(RegistrationConstants.FORM_FIELD_PATIENT_OPD_WARD)));
      Obs opd = new Obs();
      opd.setConcept(opdWardConcept);
      opd.setValueCoded(selectedOPDConcept);
      encounter.addObs(opd);

      // send patient to opd room/bloodbank

      // harsh 5/10/2012 changed the way to get blood bank concept->shifted hardcoded dependency
      // from id to name
      //			Concept bloodbankConcept = Context.getConceptService().getConcept(
      //			    GlobalPropertyUtil.getInteger(RegistrationConstants.PROPERTY_BLOODBANK_CONCEPT_ID,
      // 6425));
      String bloodBankWardName =
          GlobalPropertyUtil.getString(
              RegistrationConstants.PROPERTY_BLOODBANK_OPDWARD_NAME, "Blood Bank Room");

      // ghanshyam 03-sept-2013 Bug #394 [Blood bank]queue
      String socn = new String(selectedOPDConcept.getName().toString());
      String substringofsocn = socn.substring(0, 15);

      if (!substringofsocn.equalsIgnoreCase(bloodBankWardName)) {
        RegistrationWebUtils.sendPatientToOPDQueue(patient, selectedOPDConcept, true);
      } else {
        OrderType orderType = null;
        String orderTypeName =
            Context.getAdministrationService().getGlobalProperty("bloodbank.orderTypeName");
        orderType = OrderUtil.getOrderTypeByName(orderTypeName);

        Order order = new Order();
        order.setConcept(selectedOPDConcept);
        order.setCreator(Context.getAuthenticatedUser());
        order.setDateCreated(new Date());
        order.setOrderer(Context.getAuthenticatedUser());
        order.setPatient(patient);
        order.setStartDate(new Date());
        order.setAccessionNumber("0");
        order.setOrderType(orderType);
        order.setEncounter(encounter);
        encounter.addOrder(order);
      }
    }

    // create temporary attributes
    for (String name : parameters.keySet()) {
      if ((name.contains(".attribute.")) && (!StringUtils.isBlank(parameters.get(name)))) {
        String[] parts = name.split("\\.");
        String idText = parts[parts.length - 1];
        Integer id = Integer.parseInt(idText);
        Concept tempCatConcept = Context.getConceptService().getConceptByName("TEMPORARY CATEGORY");

        Concept temporaryAttributeConcept =
            Context.getConceptService().getConcept(tempCatConcept.getConceptId());
        Obs temporaryAttribute = new Obs();
        temporaryAttribute.setConcept(temporaryAttributeConcept);
        logger.info("concept: " + temporaryAttributeConcept);
        logger.info("value: " + parameters.get(name));
        temporaryAttribute.setValueAsString(parameters.get(name));
        encounter.addObs(temporaryAttribute);
      }
    }

    // save encounter
    Context.getEncounterService().saveEncounter(encounter);
    logger.info(
        String.format(
            "Save encounter for the visit of patient [encounterId=%s, patientId=%s]",
            encounter.getId(), patient.getId()));

    response.setContentType("text/html;charset=UTF-8");
    PrintWriter out = response.getWriter();
    out.print("success");
  }