Skip to content

Commit

Permalink
changes for CWC Visit form change and changed ws-api dependency to 1.2
Browse files Browse the repository at this point in the history
  • Loading branch information
subhrajitroy committed Jul 19, 2011
1 parent ea53c46 commit 021cc51
Show file tree
Hide file tree
Showing 13 changed files with 436 additions and 106 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package org.motechproject.server.builder;

import org.motechproject.server.model.ObsValueType;
import org.openmrs.*;

import java.util.Date;

public class ObsBuilder {

private Object value;
private Concept concept;
private Person person;
private Encounter encounter;
private Location location;
private User recordedBy;
private Date observationDate;
private ObsValueType type;


public ObsBuilder withValue(Object value) {
this.value = value;
return this;
}

public ObsBuilder withConcept(Concept concept) {
this.concept = concept;
return this;
}

public ObsBuilder withValueType(ObsValueType valueType) {
this.type = valueType;
return this;
}

public ObsBuilder forPerson(Person person) {
this.person = person;
return this;
}

public ObsBuilder against(Encounter encounter) {
this.encounter = encounter;
return this;
}

public ObsBuilder recordedOn(Date date) {
this.observationDate = date;
return this;
}

public ObsBuilder recordedAt(Location location) {
this.location = location;
return this;
}

public ObsBuilder recordedBy(User user) {
this.recordedBy = user;
return this;
}

public Obs done() {
Obs obs = new Obs();
obs.setConcept(concept);
obs.setObsDatetime(observationDate);
obs.setPerson(person);
obs.setLocation(location);
if (encounter != null) {
obs.setEncounter(encounter);
}
if (recordedBy != null) {
obs.setCreator(recordedBy);
}
return type.setValue(obs,value);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package org.motechproject.server.model;

import org.motechproject.server.builder.ObsBuilder;
import org.motechproject.server.service.ConceptEnum;
import org.openmrs.*;
import org.openmrs.api.ConceptService;

import java.util.Date;

public enum Immunizations {

BCG("bcg", ConceptEnum.CONCEPT_BCG_VACCINATION),
YELLOW_FEVER("yellowfever", ConceptEnum.CONCEPT_YELLOW_FEVER_VACCINATION),
MEASLES("measles", ConceptEnum.CONCEPT_MEASLES_VACCINATION),
CSM("csm", ConceptEnum.CONCEPT_CEREBRO_SPINAL_MENINGITIS_VACCINATION),
VITAMIN_A("vitamina", ConceptEnum.CONCEPT_VITAMIN_A),
DEWORMER("dewormer", ObsValueType.BOOLEAN, ConceptEnum.CONCEPT_DEWORMER, null) {
@Override
public Object getValue(ConceptService conceptService) {
return Boolean.TRUE;
}};


private String key;
private ObsValueType valueType;
private ConceptEnum concept;
private ConceptEnum valueConcept;

private Immunizations(String key, ConceptEnum valueConcept) {
this(key, ObsValueType.CODED, ConceptEnum.CONCEPT_IMMUNIZATIONS_ORDERED, valueConcept);
}

private Immunizations(String key, ObsValueType type, ConceptEnum concept, ConceptEnum valueConcept) {
this.key = key;
this.valueType = type;
this.concept = concept;
this.valueConcept = valueConcept;
}

public Obs obsWith(Date date, Patient patient, Location location, Encounter encounter,
User user, ConceptService conceptService) {
Obs obs = new ObsBuilder()
.withValue(getValue(conceptService))
.withConcept(concept.getConcept(conceptService))
.withValueType(valueType)
.forPerson(patient).against(encounter)
.recordedOn(date).recordedBy(user).recordedAt(location)
.done();
return obs;
}

public Object getValue(ConceptService conceptService) {
return this.valueConcept.getConcept(conceptService);
}


public static Immunizations enumFor(String key) {
for (Immunizations immunization : values()) {
if (immunization.key.equals(key)) {
return immunization;
}
}
return null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package org.motechproject.server.model;

import org.openmrs.Concept;
import org.openmrs.Obs;

import java.util.Date;

public enum ObsValueType {
NUMERIC {
@Override
public Obs setValue(Obs obs, Object value) {
obs.setValueNumeric((Double) value);
return obs;
}},
DATE {
@Override
public Obs setValue(Obs obs, Object value) {
obs.setValueDatetime((Date) value);
return obs;
}},
CODED {
@Override
public Obs setValue(Obs obs, Object value) {
obs.setValueCoded((Concept) value);
return obs;
}},
BOOLEAN {
@Override
public Obs setValue(Obs obs, Object value) {
Boolean boolValue = (Boolean) value;
Double numeric = Boolean.TRUE.equals(boolValue) ? new Double(1) : new Double(0);
return NUMERIC.setValue(obs, numeric);
}},
TEXT {
@Override
public Obs setValue(Obs obs, Object value) {
obs.setValueText((String) value);
return obs;
}};

public abstract Obs setValue(Obs obs, Object value);
}
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,12 @@ public enum ConceptEnum {
this.conceptName = conceptName;
}

public String conceptName(){
return conceptName;
}

public Concept getConcept(ConceptService conceptService){
return conceptService.getConcept(conceptName);
}

public Concept getConcept(ContextService contextService){
return contextService.getConceptService().getConcept(conceptName);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -214,12 +214,12 @@ public void recordDeath(@RunAsUserParam User staff, Location facility,

@RunAsAdminUser
public void recordChildCWCVisit(@RunAsUserParam User staff,
Location facility, Date date, Patient patient, String serialNumber, Integer cwcLocation,
String house, String community, Boolean bcg, Integer opvDose,
Integer pentaDose, Boolean measles, Boolean yellowFever,
Boolean csm, Integer iptiDose, Boolean vitaminA, Boolean dewormer,
Double weight, Double muac, Double height, Boolean maleInvolved,
String comments);
Location facility, Date date, Patient patient, String serialNumber, Integer cwcLocation,
String house, String community, String immunizations, Integer opvDose,
Integer pentaDose,
Integer iptiDose,
Double weight, Double muac, Double height, Boolean maleInvolved,
String comments);

public void recordGeneralOutpatientVisit(Integer staffId,
Integer facilityId, Date date, String serialNumber, Gender sex,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.motechproject.server.model.ghana.Community;
import org.motechproject.server.model.ExpectedEncounter;
import org.motechproject.server.model.ExpectedObs;
import org.motechproject.server.model.ghana.Community;
import org.motechproject.server.model.ghana.Facility;
import org.motechproject.server.model.rct.RCTFacility;
import org.motechproject.server.svc.*;
Expand Down Expand Up @@ -464,15 +464,10 @@ public void recordChildCWCVisit(
@WebParam(name = "cwcLocation") Integer cwcLocation,
@WebParam(name = "house") String house,
@WebParam(name = "community") String community,
@WebParam(name = "bcg") Boolean bcg,
@WebParam(name = "immunizations") String immunizations,
@WebParam(name = "opvDose") Integer opvDose,
@WebParam(name = "pentaDose") Integer pentaDose,
@WebParam(name = "measles") Boolean measles,
@WebParam(name = "yellowFever") Boolean yellowFever,
@WebParam(name = "csm") Boolean csm,
@WebParam(name = "iptiDose") Integer iptiDose,
@WebParam(name = "vitaminA") Boolean vitaminA,
@WebParam(name = "dewormer") Boolean dewormer,
@WebParam(name = "weight") Double weight,
@WebParam(name = "muac") Double muac,
@WebParam(name = "height") Double height,
Expand All @@ -493,9 +488,9 @@ public void recordChildCWCVisit(
}

registrarBean.recordChildCWCVisit(staff, facility.getLocation(), date,
patient, serialNumber, cwcLocation, house, community, bcg, opvDose,
pentaDose, measles, yellowFever, csm, iptiDose, vitaminA,
dewormer, weight, muac, height, maleInvolved, comments);
patient, serialNumber, cwcLocation, house, community, immunizations, opvDose,
pentaDose, iptiDose,
weight, muac, height, maleInvolved, comments);
}

@WebMethod
Expand Down Expand Up @@ -613,14 +608,14 @@ public Patient registerPatient(
patient, cwcRegNumber, enroll, consent, ownership, phoneNumber,
format, language, dayOfWeek, timeOfDay, howLearned);
}
if (registrantType == RegistrantType.PREGNANT_MOTHER) {
ancRegDate = decideANCRegistrationDate(ancRegToday, ancRegDate);
Facility ancFacility = decideFacility(facilityId, errors, ancRegToday);
registrarBean.registerANCMother(staff, ancFacility.getLocation(), ancRegDate,
patient, ancRegNumber, expDeliveryDate, height, gravida,
parity, enroll, consent, ownership, phoneNumber, format,
language, dayOfWeek, timeOfDay, howLearned);
}
if (registrantType == RegistrantType.PREGNANT_MOTHER) {
ancRegDate = decideANCRegistrationDate(ancRegToday, ancRegDate);
Facility ancFacility = decideFacility(facilityId, errors, ancRegToday);
registrarBean.registerANCMother(staff, ancFacility.getLocation(), ancRegDate,
patient, ancRegNumber, expDeliveryDate, height, gravida,
parity, enroll, consent, ownership, phoneNumber, format,
language, dayOfWeek, timeOfDay, howLearned);
}

registrarBean.recordPatientHistory(staff, facility.getLocation(), date,
patient, lastIPT, lastIPTDate, lastTT, lastTTDate, bcgDate,
Expand Down Expand Up @@ -718,7 +713,7 @@ public void registerANCMother(@WebParam(name = "staffId") Integer staffId,
throws ValidationException {

ValidationErrors errors = new ValidationErrors();
validatePhoneNumber(phoneNumber,"PhoneNumber",errors);
validatePhoneNumber(phoneNumber, "PhoneNumber", errors);
User staff = validateStaffId(staffId, errors, "StaffID");
Facility facility = validateFacility(facilityId, errors, "FacilityID");
org.openmrs.Patient patient = validateMotechId(motechId, errors, "MotechID", true);
Expand Down Expand Up @@ -753,7 +748,7 @@ public void registerCWCChild(@WebParam(name = "staffId") Integer staffId,
throws ValidationException {

ValidationErrors errors = new ValidationErrors();
validatePhoneNumber(phoneNumber,"PhoneNumber",errors);
validatePhoneNumber(phoneNumber, "PhoneNumber", errors);
User staff = validateStaffId(staffId, errors, "StaffID");
Facility facility = validateFacility(facilityId, errors, "FacilityID");
org.openmrs.Patient patient = validateMotechId(motechId, errors,
Expand Down Expand Up @@ -789,7 +784,7 @@ public void editPatient(
throws ValidationException {

ValidationErrors errors = new ValidationErrors();
validatePhoneNumber(phoneNumber,"PhoneNumber",errors);
validatePhoneNumber(phoneNumber, "PhoneNumber", errors);
User staff = validateStaffId(staffId, errors, "StaffID");
validateFacility(facilityId, errors, "FacilityID");
org.openmrs.Patient patient = validateMotechId(motechId, errors, "MotechID", true);
Expand Down Expand Up @@ -872,10 +867,10 @@ public void recordGeneralVisit(@WebParam(name = "staffId") Integer staffId,
}

private void validateDuplicateOPDVisitEntry(ValidationErrors errors, Integer facilityId, Date visitDate, String serialNumber, Gender sex, Date dateOfBirth, Boolean newCase, Integer diagnosis) {
boolean valid = registrarBean.isValidOutPatientVisitEntry(facilityId, visitDate, serialNumber, sex, dateOfBirth, newCase, diagnosis);
if(!valid){
errors.add(messageBean.getMessage("motechmodule.ws.duplicate.opdVisitEntry", "OPDVistEntryForm"));
}
boolean valid = registrarBean.isValidOutPatientVisitEntry(facilityId, visitDate, serialNumber, sex, dateOfBirth, newCase, diagnosis);
if (!valid) {
errors.add(messageBean.getMessage("motechmodule.ws.duplicate.opdVisitEntry", "OPDVistEntryForm"));
}
}

@WebMethod
Expand Down Expand Up @@ -955,8 +950,8 @@ public void recordMotherVisit(@WebParam(name = "staffId") Integer staffId,
}

private void validateDiagnosis(Integer diagnosis, Integer secondDiagnosis, ValidationErrors errors) {
if(diagnosis == secondDiagnosis){
errors.add(messageBean.getMessage("motechmodule.ws.invalid.opdVisitEntry.secondDiagnosis", "OPDVistEntryForm"));
if (diagnosis == secondDiagnosis) {
errors.add(messageBean.getMessage("motechmodule.ws.invalid.opdVisitEntry.secondDiagnosis", "OPDVistEntryForm"));
}
}

Expand Down Expand Up @@ -1321,7 +1316,7 @@ public RCTRegistrationConfirmation registerForRCT(@WebParam(name = "staffId") In
@WebMethod
public MotechStaff getStaffDetails(@WebParam(name = "staffId") String staffId) {
User staff = openmrsBean.getStaffBySystemId(staffId);
return staff == null ? new MotechStaff() : new MotechStaff(staff.getSystemId(),staff.getGivenName(),staff.getFamilyName());
return staff == null ? new MotechStaff() : new MotechStaff(staff.getSystemId(), staff.getGivenName(), staff.getFamilyName());
}

private void returnRegistrationError(String error) throws ValidationException {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package org.motechproject.server.model;

import org.junit.Test;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;

public class ImmunizationsTest {

@Test
public void shouldGetEnumForKey() {
assertEquals(Immunizations.BCG,Immunizations.enumFor("bcg"));
assertEquals(Immunizations.YELLOW_FEVER,Immunizations.enumFor("yellowfever"));
assertEquals(Immunizations.CSM,Immunizations.enumFor("csm"));
assertEquals(Immunizations.MEASLES,Immunizations.enumFor("measles"));
assertEquals(Immunizations.DEWORMER,Immunizations.enumFor("dewormer"));
assertEquals(Immunizations.VITAMIN_A,Immunizations.enumFor("vitamina"));
assertNull(Immunizations.enumFor("some random key"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1025,15 +1025,15 @@ public void recordChildCWCVisit() throws ValidationException {
expect(openmrsBean.getPatientByMotechId(motechId.toString()))
.andReturn(patient);
registrarBean.recordChildCWCVisit(staff, facilityLocation, date,
patient, serialNumber, location, house, community, bcg, opvDose, pentaDose,
measles, yellowFever, csm, iptiDose, vitaminA, dewormer,
weight, muac, height, maleInvolved, comments);
patient, serialNumber, location, house, community, "bcg yellowfever", opvDose, pentaDose,
iptiDose,
weight, muac, height, maleInvolved, comments);

replay(registrarBean, openmrsBean);

regWs.recordChildCWCVisit(staffId, facilityId, date, motechId, serialNumber,
location, house, community, bcg, opvDose, pentaDose, measles,
yellowFever, csm, iptiDose, vitaminA, dewormer, weight, muac,
location, house, community, "bcg yellowfever", opvDose, pentaDose,
iptiDose, weight, muac,
height, maleInvolved, comments);

verify(registrarBean, openmrsBean);
Expand Down Expand Up @@ -1068,9 +1068,8 @@ public void recordChildCWCVisitInvalidPatientId()

try {
regWs.recordChildCWCVisit(staffId, facilityId, date, motechId,serialNumber,
location, house, community, bcg, opvDose, pentaDose,
measles, yellowFever, csm, iptiDose, vitaminA, dewormer,
weight, muac, height, maleInvolved, comments);
location, house, community, "bcg yellowfever", opvDose, pentaDose,
iptiDose, weight, muac, height, maleInvolved, comments);
fail("Expected ValidationException");
} catch (ValidationException e) {
assertEquals("Errors in Record Child CWC Visit request", e
Expand Down
Loading

0 comments on commit 021cc51

Please sign in to comment.