Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BAH-987 - Internationalization changes - Disposition,Drug order and Lab order #77

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package org.openmrs.module.bahmniemrapi.disposition.contract;

import org.openmrs.ConceptName;
import org.openmrs.module.emrapi.encounter.domain.EncounterTransaction;

import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.*;

public class BahmniDisposition {
private String code;
Expand All @@ -18,6 +16,16 @@ public class BahmniDisposition {
private Date dispositionDateTime;
private Set<EncounterTransaction.Provider> providers = new HashSet<>();

public String getPreferredName() {
return preferredName;
}

public void setPreferredName(String preferredName) {
this.preferredName = preferredName;
}

private String preferredName;

public String getCode() {
return code;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
package org.openmrs.module.bahmniemrapi.disposition.mapper;

import org.openmrs.Concept;
import org.openmrs.User;
import org.openmrs.api.ConceptService;
import org.openmrs.module.bahmniemrapi.disposition.contract.BahmniDisposition;
import org.openmrs.module.emrapi.encounter.domain.EncounterTransaction;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Set;
import java.util.Locale;

@Component
public class BahmniDispositionMapper {

public BahmniDisposition map(EncounterTransaction.Disposition disposition, Set<EncounterTransaction.Provider> providers, User user){
@Autowired
private ConceptService conceptService;
public BahmniDisposition map(EncounterTransaction.Disposition disposition, Set<EncounterTransaction.Provider> providers, User user , Locale locale){
BahmniDisposition bahmniDisposition = new BahmniDisposition();
bahmniDisposition.setAdditionalObs(disposition.getAdditionalObs());
bahmniDisposition.setCode(disposition.getCode());
Expand All @@ -21,7 +26,8 @@ public BahmniDisposition map(EncounterTransaction.Disposition disposition, Set<E
bahmniDisposition.setVoidReason(disposition.getVoidReason());
bahmniDisposition.setProviders(providers);
bahmniDisposition.setCreatorName(user.getPersonName().toString());

Concept concept = conceptService.getConcept(disposition.getConceptName());
bahmniDisposition.setPreferredName(concept.getPreferredName(locale).getName());
return bahmniDisposition;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
import org.openmrs.module.bahmniemrapi.disposition.contract.BahmniDisposition;

import java.util.List;
import java.util.Locale;

public interface BahmniDispositionService {
List<BahmniDisposition> getDispositionByVisitUuid(String visitUuid);
List<BahmniDisposition> getDispositionByVisits(List<Visit> visits);
List<BahmniDisposition> getDispositionByVisitUuid(String visitUuid , Locale locale);
// List<BahmniDisposition> getDispositionByVisits(List<Visit> visits);
List<BahmniDisposition> getDispositionByVisits(List<Visit> visits , Locale locale);

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.Set;

@Service
Expand Down Expand Up @@ -43,7 +44,7 @@ public BahmniDispositionServiceImpl(VisitService visitService, DispositionMapper
}

@Override
public List<BahmniDisposition> getDispositionByVisitUuid(String visitUuid) {
public List<BahmniDisposition> getDispositionByVisitUuid(String visitUuid , Locale locale) {
Assert.notNull(visitUuid);

Visit visit = visitService.getVisitByUuid(visitUuid);
Expand All @@ -52,38 +53,38 @@ public List<BahmniDisposition> getDispositionByVisitUuid(String visitUuid) {
return new ArrayList<>();
}

return getDispositionByVisit(visit);
return getDispositionByVisit(visit, locale);
}

public List<BahmniDisposition> getDispositionByVisits(List<Visit> visits){
public List<BahmniDisposition> getDispositionByVisits(List<Visit> visits , Locale locale){
List<BahmniDisposition> dispositions = new ArrayList<>();

for(Visit visit: visits){
dispositions.addAll(getDispositionByVisit(visit));
dispositions.addAll(getDispositionByVisit(visit , locale));
}

return dispositions;
}

private List<BahmniDisposition> getDispositionByVisit(Visit visit) {
private List<BahmniDisposition> getDispositionByVisit(Visit visit , Locale locale) {
List<BahmniDisposition> dispositions = new ArrayList<>();
for (Encounter encounter : visit.getEncounters()) {
Set<Obs> observations = encounter.getObsAtTopLevel(false);
Set<EncounterTransaction.Provider> eTProvider = encounterProviderMapper.convert(encounter.getEncounterProviders());

for (Obs observation : observations) {
if(ObservationTypeMatcher.ObservationType.DISPOSITION.equals(observationTypeMatcher.getObservationType(observation))){
addBahmniDisposition(dispositions, eTProvider, observation);
addBahmniDisposition(dispositions, eTProvider, observation , locale);
}
}
}
return dispositions;
}

private void addBahmniDisposition(List<BahmniDisposition> dispositions, Set<EncounterTransaction.Provider> eTProvider, Obs observation) {
private void addBahmniDisposition(List<BahmniDisposition> dispositions, Set<EncounterTransaction.Provider> eTProvider, Obs observation , Locale locale) {
EncounterTransaction.Disposition eTDisposition = dispositionMapper.getDisposition(observation);
if(eTDisposition!=null){
dispositions.add(bahmniDispositionMapper.map(eTDisposition, eTProvider, observation.getCreator()));
dispositions.add(bahmniDispositionMapper.map(eTDisposition, eTProvider, observation.getCreator(),locale));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import java.util.Collection;
import java.util.List;
import java.util.Map;

import java.util.Locale;
public class BahmniDrugOrderMapper {

private BahmniProviderMapper providerMapper;
Expand All @@ -28,7 +28,8 @@ public BahmniDrugOrderMapper() {

public List<BahmniDrugOrder> mapToResponse(List<DrugOrder> activeDrugOrders,
Collection<BahmniObservation> orderAttributeObs,
Map<String, DrugOrder> discontinuedOrderMap) throws IOException {
Map<String, DrugOrder> discontinuedOrderMap,
String locale) throws IOException {

OrderMapper drugOrderMapper = new OrderMapper1_12();

Expand All @@ -37,6 +38,9 @@ public List<BahmniDrugOrder> mapToResponse(List<DrugOrder> activeDrugOrders,
for (DrugOrder openMRSDrugOrder : activeDrugOrders) {
BahmniDrugOrder bahmniDrugOrder = new BahmniDrugOrder();
bahmniDrugOrder.setDrugOrder(drugOrderMapper.mapDrugOrder(openMRSDrugOrder));
if(locale != null) {
bahmniDrugOrder.getDrugOrder().getDosingInstructions().setFrequency(openMRSDrugOrder.getFrequency().getConcept().getPreferredName(new Locale((locale))).getName());
}
bahmniDrugOrder.setVisit(openMRSDrugOrder.getEncounter().getVisit());
bahmniDrugOrder.setProvider(providerMapper.map(openMRSDrugOrder.getOrderer()));
if(openMRSDrugOrder.getDrug() != null){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ public class LabOrderResult {
private Boolean referredOut;
private Date resultDateTime;
private String uploadedFileName;
private String preferredNameForTestLocale;
private String preferredNameForPanelLocale;

public LabOrderResult() {
}
Expand All @@ -46,7 +48,22 @@ public LabOrderResult(String orderUuid, String action, String accessionUuid, Dat
this.uploadedFileName = uploadedFileName;
this.accessionNotes = accessionNotes;
}

public LabOrderResult(String orderUuid, String action, String accessionUuid, Date accessionDateTime, String testName, String testUnitOfMeasurement, Double minNormal, Double maxNormal, String result, Boolean abnormal, Boolean referredOut, String uploadedFileName, List<AccessionNote> accessionNotes ,String preferredNameByLocale) {
this.orderUuid = orderUuid;
this.action = action;
this.accessionUuid = accessionUuid;
this.testName = testName;
this.testUnitOfMeasurement = testUnitOfMeasurement;
this.minNormal = minNormal;
this.maxNormal = maxNormal;
this.accessionDateTime = accessionDateTime;
this.result = result;
this.abnormal = abnormal;
this.referredOut = referredOut;
this.uploadedFileName = uploadedFileName;
this.accessionNotes = accessionNotes;
this.preferredNameForTestLocale = preferredNameByLocale;
}
public String getOrderUuid() {
return orderUuid;
}
Expand Down Expand Up @@ -214,4 +231,17 @@ public String getUploadedFileName() {
public void setUploadedFileName(String uploadedFileName) {
this.uploadedFileName = uploadedFileName;
}

public String getPreferredNameForTestLocale() { return preferredNameForTestLocale; }

public void setPreferredNameForTestLocale(String preferredNameForTestLocale) { this.preferredNameForTestLocale = preferredNameForTestLocale; }

public String getPreferredNameForPanelLocale() {
return preferredNameForPanelLocale;
}

public void setPreferredNameForPanelLocale(String preferredNameForPanelLocale) {
this.preferredNameForPanelLocale = preferredNameForPanelLocale;
}

}