Skip to content

Commit

Permalink
Revert "Bindu | BAH-439 | Person attributes with coded concept answer…
Browse files Browse the repository at this point in the history
…s display concept IDs on registration search"

This reverts commit 02a7f5a.
  • Loading branch information
binduak committed Apr 9, 2018
1 parent f835236 commit 140a6db
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 91 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,8 @@
import org.openmrs.PersonAttribute;
import org.openmrs.Visit;
import org.openmrs.VisitAttribute;
import org.openmrs.Concept;
import org.openmrs.ConceptName;
import org.openmrs.api.APIException;
import org.openmrs.api.VisitService;
import org.openmrs.api.context.Context;
import org.openmrs.module.bahmniemrapi.encountertransaction.command.impl.BahmniVisitAttributeService;
import org.openmrs.module.bahmniemrapi.visitlocation.BahmniVisitLocationServiceImpl;

Expand All @@ -23,7 +20,6 @@
import java.util.Arrays;
import java.util.List;
import java.util.Set;
import java.util.Locale;
import java.util.stream.Collectors;

public class PatientResponseMapper {
Expand Down Expand Up @@ -84,18 +80,7 @@ private void mapPersonAttributes(Patient patient, List<String> patientSearchResu
String queriedPersonAttributes = patientSearchResultFields.stream()
.map(attributeName -> {
PersonAttribute attribute = patient.getAttribute(attributeName);
if(attribute != null) {
if("org.openmrs.Concept".equals(attribute.getAttributeType().getFormat())) {
Concept concept = Context.getConceptService().getConcept(attribute.getValue());
ConceptName shortNameInLocale = concept.getShortNameInLocale(Context.getLocale());
ConceptName conceptShortName = (shortNameInLocale == null) ? concept.getShortNameInLocale(new Locale("en", "GB")) : concept.getShortNameInLocale(Context.getLocale());
return formKeyPair(attributeName, conceptShortName != null ? conceptShortName.getName() : null);
}
else {
return formKeyPair(attributeName, attribute.getValue());
}
}
return null;
return attribute == null ? null : formKeyPair(attributeName, attribute.getValue());
}).filter(Objects::nonNull)
.collect(Collectors.joining(","));
patientResponse.setCustomAttribute(formJsonString(queriedPersonAttributes));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import org.apache.commons.lang3.StringUtils;
import org.hibernate.type.StandardBasicTypes;
import org.hibernate.type.Type;
import org.openmrs.api.context.Context;

import java.util.HashMap;
import java.util.List;
Expand All @@ -26,7 +25,7 @@ public String selectClause(String select){

if(personAttributeResultsIds.size() > 0)
selectClause =
"concat('{',group_concat(DISTINCT (coalesce(concat('\"',attrt_results.name,'\":\"', REPLACE(REPLACE(coalesce(cn.name, def_loc_cn.name, pattr_results.value),'\\\\','\\\\\\\\'),'\"','\\\\\"'),'\"'))) SEPARATOR ','),'}')";
"concat('{',group_concat(DISTINCT (coalesce(concat('\"',attrt_results.name,'\":\"', REPLACE(REPLACE(pattr_results.value,'\\\\','\\\\\\\\'),'\"','\\\\\"'),'\"'))) SEPARATOR ','),'}')";

return String.format("%s,%s as customAttribute", select, selectClause);
}
Expand All @@ -37,10 +36,7 @@ public String appendToJoinClause(String join){
if(personAttributeResultsIds.size() > 0)
join +=
" LEFT OUTER JOIN person_attribute pattr_results on pattr_results.person_id = p.person_id and pattr_results.person_attribute_type_id in ("+ StringUtils.join(personAttributeResultsIds, ',')+") " +
" LEFT OUTER JOIN person_attribute_type attrt_results on attrt_results.person_attribute_type_id = pattr_results.person_attribute_type_id and pattr_results.voided = 0 " +
" LEFT OUTER JOIN concept_name cn on cn.concept_id = pattr_results.value and cn.concept_name_type = 'SHORT' and attrt_results.format = 'org.openmrs.Concept' and cn.locale = '"+ Context.getLocale() + "'" +
" LEFT OUTER JOIN concept_name def_loc_cn on def_loc_cn.concept_id = pattr_results.value and def_loc_cn.concept_name_type = 'SHORT' and attrt_results.format = 'org.openmrs.Concept' and def_loc_cn.locale = 'en' ";

" LEFT OUTER JOIN person_attribute_type attrt_results on attrt_results.person_attribute_type_id = pattr_results.person_attribute_type_id";
return join;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
import org.mockito.Mock;
import org.mockito.internal.util.collections.Sets;
import org.openmrs.*;
import org.openmrs.api.ConceptNameType;
import org.openmrs.api.ConceptService;
import org.openmrs.api.VisitService;
import org.openmrs.api.context.Context;
import org.openmrs.module.bahmniemrapi.visitlocation.BahmniVisitLocationServiceImpl;
Expand All @@ -20,10 +18,8 @@
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Locale;

import static org.mockito.Matchers.any;
import static org.mockito.Mockito.when;

@RunWith(PowerMockRunner.class)
@PrepareForTest(Context.class)
Expand All @@ -37,9 +33,6 @@ public class PatientResponseMapperTest {
@Mock
BahmniVisitLocationServiceImpl bahmniVisitLocationService;

@Mock
ConceptService conceptService;

Patient patient;

@Before
Expand Down Expand Up @@ -91,31 +84,6 @@ public void shouldMapPersonAttributes() throws Exception {
Assert.assertEquals(patientResponse.getCustomAttribute(),"{\"givenNameLocal\" : \"someName\"}");
}

@Test
public void shouldMapPersonAttributesForConceptType() throws Exception {
PersonAttributeType personAttributeType = new PersonAttributeType();
personAttributeType.setName("occupation");
personAttributeType.setFormat("org.openmrs.Concept");
patient.setAttributes(Sets.newSet(new PersonAttribute(personAttributeType,"100")));
String[] patientResultFields = {"occupation"};
Concept concept = new Concept();
ConceptName conceptName = new ConceptName();
conceptName.setName("shortname");
Locale defaultLocale = new Locale("en", "GB");
conceptName.setLocale(defaultLocale);
concept.setShortName(conceptName);
conceptName.setConceptNameType(ConceptNameType.SHORT);
PowerMockito.mockStatic(Context.class);
PowerMockito.when(Context.getLocale()).thenReturn(defaultLocale);

when(Context.getConceptService()).thenReturn(conceptService);
PowerMockito.when(conceptService.getConcept("100")).thenReturn(concept);

PatientResponse patientResponse = patientResponseMapper.map(patient, null, patientResultFields, null, null);

Assert.assertEquals(patientResponse.getCustomAttribute(),"{\"occupation\" : \"shortname\"}");
}

@Test
public void shouldAddSlashToSupportSpecialCharactersInJSON() throws Exception {
PersonAttributeType personAttributeType = new PersonAttributeType();
Expand Down

This file was deleted.

0 comments on commit 140a6db

Please sign in to comment.