Skip to content

Commit

Permalink
BAH-987|Praveena| - Internationalisation of patient attributes in reg…
Browse files Browse the repository at this point in the history
…istration page (#94)

* BAH-929 | Updated Concept names property-getter to include names in user & global locale

* Praveena | BAH-989 Response to  patient attributes should include answers in user default locale and global locale

* Praveena | Removed unused JAVA import
  • Loading branch information
praveenadayanand committed Apr 1, 2021
1 parent c8b8c84 commit b7c974f
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,35 +56,58 @@ public DelegatingResourceDescription getRepresentationDescription(Representation

DelegatingResourceDescription representationDescription = super.getRepresentationDescription(rep);
if (representationDescription == null) {
if (rep instanceof NamedRepresentation && rep.getRepresentation().equals("bahmni")) {
DelegatingResourceDescription description = new DelegatingResourceDescription();
description.addProperty("uuid");
description.addProperty("name",Representation.DEFAULT);
description.addProperty("names",Representation.DEFAULT);
description.addProperty("set");
description.addProperty("datatype",Representation.DEFAULT);
description.addProperty("conceptClass",Representation.DEFAULT);
description.addProperty("hiNormal");
description.addProperty("hiAbsolute");
description.addProperty("hiCritical");
description.addProperty("lowNormal");
description.addProperty("lowAbsolute");
description.addProperty("lowCritical");
description.addProperty("units");
description.addProperty("precise");
description.addProperty("allowDecimal");
description.addProperty("handler");
description.addProperty("descriptions", Representation.DEFAULT);
description.addProperty("answers", new NamedRepresentation("bahmniAnswer"));
description.addProperty("setMembers", new NamedRepresentation("bahmni"));
return description;
} else if (rep instanceof NamedRepresentation && rep.getRepresentation().equals("bahmniAnswer")) {
DelegatingResourceDescription description = new DelegatingResourceDescription();
description.addProperty("uuid", Representation.DEFAULT);
description.addProperty("name", Representation.DEFAULT);
description.addProperty("names", Representation.DEFAULT);
description.addProperty("displayString");
return description;
if (rep instanceof NamedRepresentation) {
if (rep.getRepresentation().equals("bahmni")) {
DelegatingResourceDescription description = new DelegatingResourceDescription();
description.addProperty("uuid");
description.addProperty("name",Representation.DEFAULT);
description.addProperty("names",Representation.DEFAULT);
description.addProperty("set");
description.addProperty("datatype",Representation.DEFAULT);
description.addProperty("conceptClass",Representation.DEFAULT);
description.addProperty("hiNormal");
description.addProperty("hiAbsolute");
description.addProperty("hiCritical");
description.addProperty("lowNormal");
description.addProperty("lowAbsolute");
description.addProperty("lowCritical");
description.addProperty("units");
description.addProperty("precise");
description.addProperty("allowDecimal");
description.addProperty("handler");
description.addProperty("descriptions", Representation.DEFAULT);
description.addProperty("answers", new NamedRepresentation("bahmniAnswer"));
description.addProperty("setMembers", new NamedRepresentation("bahmni"));
return description;
} else if (rep.getRepresentation().equals("bahmniAnswer")) {
DelegatingResourceDescription description = new DelegatingResourceDescription();
description.addProperty("uuid", Representation.DEFAULT);
description.addProperty("name", Representation.DEFAULT);
description.addProperty("names", Representation.DEFAULT);
description.addProperty("displayString");
return description;
} else if (rep.getRepresentation().equals("bahmniFullAnswers")) {
DelegatingResourceDescription description = new DelegatingResourceDescription();
description.addProperty("uuid");
description.addProperty("display");
description.addProperty("name", Representation.DEFAULT);
description.addProperty("datatype", Representation.DEFAULT);
description.addProperty("conceptClass", Representation.DEFAULT);
description.addProperty("set");
description.addProperty("version");
description.addProperty("retired");

description.addProperty("names", Representation.DEFAULT);
description.addProperty("descriptions", Representation.DEFAULT);

description.addProperty("mappings", Representation.DEFAULT);

description.addProperty("answers", new NamedRepresentation("bahmniAnswer"));
description.addProperty("setMembers", Representation.DEFAULT);
description.addProperty("auditInfo");
description.addSelfLink();
return description;
}
}
}
return representationDescription;
Expand All @@ -93,10 +116,12 @@ public DelegatingResourceDescription getRepresentationDescription(Representation

@PropertyGetter("names")
public static Object getNames(Concept concept) {
Locale globalDefaultLocale = LocaleUtility.getDefaultLocale();
Locale userDefaultLocale = LocaleUtility.fromSpecification(Context.getAuthenticatedUser().getUserProperty(OpenmrsConstants.USER_PROPERTY_DEFAULT_LOCALE));

Collection<ConceptName> names = concept.getNames(userDefaultLocale);
if(names.isEmpty()) {
names.addAll(concept.getNames(LocaleUtility.getDefaultLocale()));
if (globalDefaultLocale != userDefaultLocale) {
names.addAll(concept.getNames(globalDefaultLocale));
}
return names;
}
Expand All @@ -111,4 +136,5 @@ public static Object getDescriptions(Concept concept) {
}
return conceptDescriptions;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package org.openmrs.module.bahmnicore.web.v1_0.resource;

import org.openmrs.Concept;
import org.openmrs.PersonAttributeType;
import org.openmrs.api.context.Context;
import org.openmrs.module.webservices.rest.web.ConversionUtil;
import org.openmrs.module.webservices.rest.web.RequestContext;
import org.openmrs.module.webservices.rest.web.RestConstants;
import org.openmrs.module.webservices.rest.web.annotation.PropertyGetter;
import org.openmrs.module.webservices.rest.web.annotation.Resource;
import org.openmrs.module.webservices.rest.web.representation.NamedRepresentation;
import org.openmrs.module.webservices.rest.web.representation.Representation;
import org.openmrs.module.webservices.rest.web.resource.impl.DelegatingResourceDescription;
import org.openmrs.module.webservices.rest.web.response.ResponseException;
import org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_8.PersonAttributeTypeResource1_8;
import org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_9.BaseAttributeTypeCrudResource1_9;
import org.openmrs.util.OpenmrsUtil;

@Resource(name = RestConstants.VERSION_1 + "/personattributetype", supportedClass = PersonAttributeType.class, supportedOpenmrsVersions = {"1.12.*","2.0.*", "2.1.*"}, order = 0)
public class PersonAttributeTypeResource extends PersonAttributeTypeResource1_8 {
@PropertyGetter("concept")
public Object getConcept(PersonAttributeType delegate) {
if (OpenmrsUtil.nullSafeEquals(delegate.getFormat(), Concept.class.getCanonicalName())) {
Concept concept = Context.getConceptService().getConcept(delegate.getForeignKey());
return ConversionUtil.convertToRepresentation(concept, new NamedRepresentation("bahmniFullAnswers"));
}
return null;
}
}

0 comments on commit b7c974f

Please sign in to comment.