Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 40 additions & 5 deletions src/form-builder/components/ControlPropertiesContainer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,53 @@ export class ControlPropertiesContainer extends Component {
this.filterOptions = this.filterOptions.bind(this);
}

onSelect(concept) {
onSelect(concept) {
const conceptName = concept.name.name;

httpInterceptor
.get(new UrlHelper().getFullConceptRepresentation(conceptName))
.then((data) => {
const result = data.results[0];
result.display = result.name.name;
this.props.dispatch(selectSource(result, this.props.selectedControl.id));

// Recursively replace fully specified names with short names for answers only
const setShortNames = (concept) => {
if (!concept) return concept;

// Find and apply short name if it exists
const shortName = concept.names &&
concept.names.find(name => name.conceptNameType === 'SHORT');

if (shortName) {
if (concept.name) {
concept.name = Object.assign({}, concept.name, {
display: shortName.name
});
}
if (concept.displayString) {
concept.displayString = shortName.name;
}
}

// Recursively process nested answers and set members
if (concept.answers && concept.answers.length) {
concept.answers = concept.answers.map(setShortNames);
}
if (concept.setMembers && concept.setMembers.length) {
concept.setMembers = concept.setMembers.map(setShortNames);
}

return concept;
};

// Process the result, but keep the parent's display as fully specified
const processedResult = setShortNames(result);
// Restore the parent's display to the fully specified name
processedResult.display = result.name.name;

this.props.dispatch(selectSource(processedResult, this.props.selectedControl.id));
})
.catch((error) => this.setErrorMessage(error));
}

}
onPropertyUpdate(properties, id) {
this.props.dispatch(setChangedProperty(properties, id));
}
Expand Down
2 changes: 1 addition & 1 deletion src/form-builder/constants.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export const formBuilderConstants = {
conceptUrl: '/openmrs/ws/rest/v1/concept',
conceptRepresentation: 'custom:(uuid,set,display,allowDecimal,name:(uuid,name),' +
conceptRepresentation: 'custom:(uuid,set,display,allowDecimal,name:(uuid,name),names:(uuid,name,conceptNameType),' +
'conceptClass:(uuid,name),datatype:(uuid,name),answers,handler,hiNormal,lowNormal,' +
'hiAbsolute,lowAbsolute,units,setMembers:(uuid,set,display,allowDecimal,name:(uuid,name),' +
'conceptClass:(uuid,name),datatype:(uuid,name),' +
Expand Down